Skip to content

Conversation

murchandamus
Copy link
Contributor

@murchandamus murchandamus commented Feb 2, 2023

Implement Mini version of BlockAssembler to calculate mining scores

Run the mining algorithm on a subset of the mempool, only disturbing the
mempool to copy out fee information for relevant entries. Intended to be
used by wallet to calculate amounts needed for fee-bumping unconfirmed
transactions.

From comments of sipa and glozow below:

In what way does the code added here differ from the real block assembly code?

  • Only operates on the relevant transactions rather than full mempool
  • Has the ability to remove transactions that will be replaced so they don't impact their ancestors
  • Does not hold mempool lock outside of the constructor, makes copies of the entries it needs instead (though I'm not sure if this has an effect in practice)
  • Doesn't do the sanity checks like keeping weight within max block weight and IsFinalTx()
  • After the block template is built, additionally calculates fees to bump remaining ancestor packages to target feerate

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 2, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK achow101, furszy, theStack
Concept ACK glozow
Stale ACK LarryRuane

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrote some more tests for this, please feel free to take: glozow@6761c59

@dergoegge
Copy link
Member

I wrote a fuzz test for the MiniMiner and it crashes on some of the Assumes: https://github.com/dergoegge/bitcoin/tree/2023-01-fuzz-mini-miner

$ echo "AQEWCQEBAAEACf//////////////CBwAAgAAlRwB7QEA/wAAAAL7AAEAAAEB7QEA/wAAAAL7AAAA
AAAAXAD//w==" | base64 -d > mini_miner_crash.input
$ FUZZ=mini_miner ./src/test/fuzz/fuzz ./mini_miner_crash.input

Now that could just mean that my assumptions about what should be passed into the MiniMiner are wrong (i.e. my fuzz target is using the MiniMiner incorrectly). In that case it might make sense to add documentation that outlines what is expected from a MiniMiner user.

Two questions:

  • Are the assumptions (i.e. Assumes in mini_miner.cpp) internal to the MiniMiner or do they rely on external assumptions as well? e.g. Does the mini miner expect the mempool it receives in its constructor to only hold transactions that passed out ATMP checks?
  • Since this is a "mini" version of the BlockAssembler, would it be possible to differentially fuzz the two? Or using one as an oracle to test the other? e.g. Checking if transactions bumped with the help of MiniMiner make it into the next block constructed by the actual BlockAssembler.

@sipa
Copy link
Member

sipa commented Feb 3, 2023

In what way does the code added here differ from the real block assembly code?

@glozow
Copy link
Member

glozow commented Feb 3, 2023

Thanks for fuzzing 💯
It's fully possible the crashing is due to real bugs, I hit a crash yesterday while testing as well. I think there is something wrong with the way it's handling to-be-replaced outputs.

Does the mini miner expect the mempool it receives in its constructor to only hold transactions that passed out ATMP checks?

Actually no. It just uses what's cached in the mempool entries. The fees don't even need to match inputs - outputs, and mini miner definitely doesn't require ATMP checks.

Since this is a "mini" version of the BlockAssembler, would it be possible to differentially fuzz the two?

Differential fuzzing is perfect for this really.MiniMiner::BuildMockTemplate(target_feerate) is supposed to do the exact same thing as BlockAssembler::addPackageTxs with blockmintxfee = target feerate.

Checking if transactions bumped with the help of MiniMiner make it into the next block constructed by the actual BlockAssembler.

That would also be a really good way of testing the results (after the wallet stuff is added?). Add the bumping tx, mine another block with the target feerate as min feerate, and see that they all get mined.

@glozow
Copy link
Member

glozow commented Feb 3, 2023

In what way does the code added here differ from the real block assembly code?

  • Only operates on the relevant transactions rather than full mempool
  • Has the ability to remove transactions that will be replaced so they don't impact their ancestors
  • Does not hold mempool lock outside of the constructor, makes copies of the entries it needs instead (though I'm not sure if this has an effect in practice)
  • Doesn't do the sanity checks like keeping weight within max block weight and IsFinalTx()
  • After the block template is built, additionally calculates fees to bump remaining ancestor packages to target feerate

@murchandamus
Copy link
Contributor Author

Added tests from glozow’s branch

@glozow
Copy link
Member

glozow commented Feb 6, 2023

Is there a reason to leave the CalculateTotalBumpFee commit out of this PR?

@murchandamus
Copy link
Contributor Author

Oh good point, that just grew organically, but really it could be part of the mini-miner changes. I’ll squash it in there.

@murchandamus
Copy link
Contributor Author

I’ve amended this branch to include the CalculateTotalBumpFee method from #26152 in the mini-miner code here.

@murchandamus murchandamus force-pushed the add-mini-miner branch 2 times, most recently from 64d53fd to 590b1fd Compare February 8, 2023 20:09
@glozow glozow force-pushed the add-mini-miner branch 2 times, most recently from 496f31d to bd338ad Compare February 16, 2023 16:00
@glozow
Copy link
Member

glozow commented Feb 16, 2023

I pushed some changes (with @xekyo's permission, thanks):

  • Capped traversal at 500 items in CalculateCluster(). Number is arbitrary, open for commentary
  • Fixed up a few things in the MiniMiner implementation, mostly shuffling things around and updating comments
  • Dropped the chain interface changes (I think those can go in Bump unconfirmed ancestor transactions to target feerate #26152)
  • Expanded unit tests
  • Added a fuzzer (expanded from @dergoegge's, thanks)
  • Added a fuzzer to differentially test block templates built by BlockAssembler and MiniMiner. Hopefully this gives reviewers a bit more confidence that they are doing the same thing even if the implementations are difficult to review/compare.

@murchandamus
Copy link
Contributor Author

Awesome, thanks for the reworking this, @glozow, and the work on the fuzzer, @dergoegge. I've fixed a minor tidy issue and I’ll pick the chain interface changes into #26152 and rebase on this shortly.

Ready for review

@murchandamus murchandamus marked this pull request as ready for review February 16, 2023 21:29
@murchandamus
Copy link
Contributor Author

Pushed again to provide signed commits

@glozow
Copy link
Member

glozow commented Feb 17, 2023

review-beg-pinging @LarryRuane @josibake @stickies-v who have looked at MiniMiner previously

@LarryRuane
Copy link
Contributor

For anyone wanting to review this PR and would like some help with basic mempool concepts, I made a video: https://youtu.be/sQ05azzTp9o -- it mentions 26152 but I think would be helpful for reviewers here as well.

@glozow glozow added this to the 25.0 milestone Feb 23, 2023
@achow101
Copy link
Member

ACK ce882ef

murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 12, 2023
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 12, 2023
Follow-up from bitcoin#27021: accessing of fields in MiniMinerMempoolEntry was
done inconsistently. Even though we had a getter, we would directly
write to the fields when we needed to update them.
This commits sets the fields to private and introduces a method for
updating the ancestor information in transactions using the same method
name as used for Mempool Entries.
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 17, 2023
Follow-up from bitcoin#27021: In the prior commit, the vector started counting
at 0, but the transaction names started with 1. This commit matches the
names to the transactions’ vector indices for better readability.

Co-authored-by: theStack <sebastian.falbesoner@gmail.com>
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 17, 2023
Follow-up from bitcoin#27021.
Also included is an ASCII art visualization of the test’s transaction
topology by theStack.

Co-authored-by: theStack <sebastian.falbesoner@gmail.com>
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 17, 2023
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 17, 2023
Follow-up from bitcoin#27021: accessing of fields in MiniMinerMempoolEntry was
done inconsistently. Even though we had a getter, we would directly
write to the fields when we needed to update them.
This commits sets the fields to private and introduces a method for
updating the ancestor information in transactions using the same method
name as used for Mempool Entries.
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 18, 2023
Follow-up from bitcoin#27021: In the prior commit, the vector started counting
at 0, but the transaction names started with 1. This commit matches the
names to the transactions’ vector indices for better readability.

Co-authored-by: theStack <sebastian.falbesoner@gmail.com>
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 18, 2023
Follow-up from bitcoin#27021.
Also included is an ASCII art visualization of the test’s transaction
topology by theStack.

Co-authored-by: theStack <sebastian.falbesoner@gmail.com>
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 18, 2023
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 18, 2023
Follow-up from bitcoin#27021: accessing of fields in MiniMinerMempoolEntry was
done inconsistently. Even though we had a getter, we would directly
write to the fields when we needed to update them.
This commits sets the fields to private and introduces a method for
updating the ancestor information in transactions using the same method
name as used for Mempool Entries.
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 29, 2023
Follow-up from bitcoin#27021: In the prior commit, the vector started counting
at 0, but the transaction names started with 1. This commit matches the
names to the transactions’ vector indices for better readability.

Co-authored-by: theStack <sebastian.falbesoner@gmail.com>
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 29, 2023
Follow-up from bitcoin#27021.
Also included is an ASCII art visualization of the test’s transaction
topology by theStack.

Co-authored-by: theStack <sebastian.falbesoner@gmail.com>
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 29, 2023
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 29, 2023
Follow-up from bitcoin#27021: accessing of fields in MiniMinerMempoolEntry was
done inconsistently. Even though we had a getter, we would directly
write to the fields when we needed to update them.
This commits sets the fields to private and introduces a method for
updating the ancestor information in transactions using the same method
name as used for Mempool Entries.
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 30, 2023
Follow-up from bitcoin#27021: In the prior commit, the vector started counting
at 0, but the transaction names started with 1. This commit matches the
names to the transactions’ vector indices for better readability.

Co-authored-by: theStack <sebastian.falbesoner@gmail.com>
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 30, 2023
Follow-up from bitcoin#27021.
Also included is an ASCII art visualization of the test’s transaction
topology by theStack.

Co-authored-by: theStack <sebastian.falbesoner@gmail.com>
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 30, 2023
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Aug 30, 2023
Follow-up from bitcoin#27021: accessing of fields in MiniMinerMempoolEntry was
done inconsistently. Even though we had a getter, we would directly
write to the fields when we needed to update them.
This commits sets the fields to private and introduces a method for
updating the ancestor information in transactions using the same method
name as used for Mempool Entries.
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Sep 13, 2023
Follow-up from bitcoin#27021: In the prior commit, the vector started counting
at 0, but the transaction names started with 1. This commit matches the
names to the transactions’ vector indices for better readability.

Co-authored-by: theStack <sebastian.falbesoner@gmail.com>
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Sep 13, 2023
Follow-up from bitcoin#27021.
Also included is an ASCII art visualization of the test’s transaction
topology by theStack.

Co-authored-by: theStack <sebastian.falbesoner@gmail.com>
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Sep 13, 2023
murchandamus added a commit to murchandamus/bitcoin that referenced this pull request Sep 13, 2023
Follow-up from bitcoin#27021: accessing of fields in MiniMinerMempoolEntry was
done inconsistently. Even though we had a getter, we would directly
write to the fields when we needed to update them.
This commits sets the fields to private and introduces a method for
updating the ancestor information in transactions using the same method
name as used for Mempool Entries.
achow101 added a commit to bitcoin-core/gui that referenced this pull request Sep 14, 2023
…o target feerate

f18f9ef Amend bumpfee for inputs with overlapping ancestry (Murch)
2e35e94 Bump unconfirmed parent txs to target feerate (Murch)
3e3e052 coinselection: Move GetSelectionWaste into SelectionResult (Andrew Chow)
c57889d [node] interface to get bump fees (glozow)
c24851b Make MiniMinerMempoolEntry fields private (Murch)
ac6030e Remove unused imports (Murch)
d2f90c3 Fix calculation of ancestor set feerates in test (Murch)
a1f7d98 Match tx names to index in miniminer overlap test (Murch)

Pull request description:

  Includes some commits to address follow-ups from #27021: bitcoin/bitcoin#27021 (comment)

  Reduces the effective value of unconfirmed UTXOs by the fees necessary to bump their ancestor transactions to the same feerate.

  While the individual UTXOs always account for their full ancestry before coin-selection, we can correct potential overestimates with a second pass where we establish the ancestry and bump fee for the whole input set collectively.

  Fixes #9645
  Fixes #9864
  Fixes #15553

ACKs for top commit:
  S3RK:
    ACK f18f9ef
  ismaelsadeeq:
    ACK f18f9ef
  achow101:
    ACK f18f9ef
  brunoerg:
    crACK f18f9ef
  t-bast:
    ACK bitcoin/bitcoin@f18f9ef, I reviewed the latest changes and run e2e tests against eclair, everything looks good 👍

Tree-SHA512: b65180c4243b1f9d13c311ada7a1c9f2f055d530d6c533b78c2068b50b8c29ac1321e89e85675b15515760d4f1b653ebd9da77b37c7be52d9bc565a3538f0aa6
Retropex pushed a commit to Retropex/bitcoin that referenced this pull request Oct 4, 2023
Follow-up from bitcoin#27021: In the prior commit, the vector started counting
at 0, but the transaction names started with 1. This commit matches the
names to the transactions’ vector indices for better readability.

Co-authored-by: theStack <sebastian.falbesoner@gmail.com>
Retropex pushed a commit to Retropex/bitcoin that referenced this pull request Oct 4, 2023
Follow-up from bitcoin#27021.
Also included is an ASCII art visualization of the test’s transaction
topology by theStack.

Co-authored-by: theStack <sebastian.falbesoner@gmail.com>
Retropex pushed a commit to Retropex/bitcoin that referenced this pull request Oct 4, 2023
Retropex pushed a commit to Retropex/bitcoin that referenced this pull request Oct 4, 2023
Follow-up from bitcoin#27021: accessing of fields in MiniMinerMempoolEntry was
done inconsistently. Even though we had a getter, we would directly
write to the fields when we needed to update them.
This commits sets the fields to private and introduces a method for
updating the ancestor information in transactions using the same method
name as used for Mempool Entries.
@bitcoin bitcoin locked and limited conversation to collaborators Jun 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.