Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MiniMiner: use FeeFrac in AncestorFeerateComparator #30412

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

glozow
Copy link
Member

@glozow glozow commented Jul 9, 2024

Closes #30284. Closes #30367, see #30367 (comment)

Previously, we were only comparing feerates up to 1/1000 precision, since CFeeRate comparison just looks at their respective nSatoshisPerK. This could lead to MiniMiner selecting packages in the wrong order (i.e. by txid) if their feerates were less than 0.001sat/vB different. Fix this by creating + comparing FeeFracs instead.

Also, FeeFrac::Mul doesn't have the overflow problem.

Also added a few minor fuzzer fixups that caught my eye while I was debugging this.

@glozow glozow added the Bug label Jul 9, 2024
@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 9, 2024

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ismaelsadeeq, murchandamus, dergoegge
Stale ACK sipa

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #30079 (Fee Estimation: Ignore all transactions that are CPFP'd by ismaelsadeeq)
  • #28676 ([WIP] Cluster mempool implementation by sdaftuar)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Member

@ismaelsadeeq ismaelsadeeq left a comment

Choose a reason for hiding this comment

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

Concept ACK 271469b

Copy link
Member

@sipa sipa left a comment

Choose a reason for hiding this comment

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

utACK 271469b

@DrahtBot DrahtBot requested a review from ismaelsadeeq July 9, 2024 15:59
glozow added 2 commits July 9, 2024 17:22
Comparing using FeeFracs is more precise, allows us to simply the
code since FeeFrac comparison internally does cross-multiplication,
and avoids potential overflow in the multiplication.

Previously, we were only comparing feerates up to 0.001sat/vB precision,
since CFeeRate comparison just looks at their respective nSatoshisPerK.
This could lead to MiniMiner selecting packages in the wrong order (i.e.
by txid) if their feerates were less than 0.001sat/vB different.
Delete asserts that are redundant with the == assert.
Add assertion that the coinbase isn't already in mock_template_txids.
@glozow glozow force-pushed the 2024-07-miniminer-feefrac branch from 271469b to 0937052 Compare July 9, 2024 16:23
Copy link
Member

@ismaelsadeeq ismaelsadeeq left a comment

Choose a reason for hiding this comment

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

Tested ACK 0937052

@DrahtBot DrahtBot requested a review from sipa July 9, 2024 17:51
@glozow glozow requested a review from murchandamus July 10, 2024 11:03
Copy link
Contributor

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

ACK 0937052 with nits

@@ -174,7 +174,7 @@ MiniMiner::MiniMiner(const std::vector<MiniMinerMempoolEntry>& manual_entries,
SanityCheck();
Copy link
Contributor

Choose a reason for hiding this comment

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

In the commit message of "MiniMiner: use FeeFrac in AncestorFeerateComparator":

- Comparing using FeeFracs is more precise, allows us to simply the
+ Comparing feerates using FeeFracs is more precise, allows us to simplify the

Comment on lines +191 to +192
auto [iter, new_entry] = mock_template_txids.emplace(blocktemplate->block.vtx[0]->GetHash());
assert(new_entry);
Copy link
Contributor

Choose a reason for hiding this comment

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

In 'fuzz: mini_miner_selection fixups':

The comment in L189 threw me off. I assume that it’s meant to indicate that we are able to add the coinbase transaction to mock_template_txids because MiniMiner did not add it, but I first understood it to indicate that we should not be able to add a coinbase transaction to mock_template_txids and therefore the assert was inverse to my expectation.

Also, TIL that the return values of emplace(…) differ between set and vector.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add an update to the comment if I retouch

Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

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

tACK 0937052

Fuzzed both mini miner harnesses for a while.

@fanquake fanquake merged commit 01ed492 into bitcoin:master Jul 15, 2024
16 checks passed
@glozow glozow deleted the 2024-07-miniminer-feefrac branch July 15, 2024 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
7 participants