-
Notifications
You must be signed in to change notification settings - Fork 36.6k
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
Add waitNext() to BlockTemplate interface #31283
base: master
Are you sure you want to change the base?
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31283. ReviewsSee the guideline for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
src/node/interfaces.cpp
Outdated
return block_template; | ||
} | ||
|
||
const CScript m_script_pub_key; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate from this PR, I'm looking into whether we can avoid passing script_pub_key
around. Afaik it's only used by tests and for solo CPU mining.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#31318 drops this argument. It's only slightly easier to merge that first, so I'll leave this PR open.
src/node/interfaces.cpp
Outdated
@@ -938,9 +938,71 @@ class BlockTemplateImpl : public BlockTemplate | |||
return chainman().ProcessNewBlock(block_ptr, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/nullptr); | |||
} | |||
|
|||
std::unique_ptr<BlockTemplate> waitNext(CAmount fee_threshold, MillisecondsDouble timeout) override | |||
{ | |||
if (timeout > std::chrono::years{100}) timeout = std::chrono::years{100}; // Upper bound to avoid UB in std::chrono |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to study #31003 (comment) in more detail to see if this code isn't making similar mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dropped this line.
Additionally this PR does not make use of last_mempool_update
, since it's not very useful in a typical production setting where something in the mempool updates all the time.
I think the race condition mentioned there is not an issue here because we don't pass in the current fees via argument, but instead derive them from the original template.
I did forget to update now
at the end of the loop, which I fixed.
I pushed a commit refactoring |
src/test/miner_tests.cpp
Outdated
BlockAssembler::Options options; | ||
|
||
options.nBlockMaxWeight = MAX_BLOCK_WEIGHT; | ||
options.blockMinFeeRate = blockMinFeeRate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a316ba5: I think dropping this doesn't matter?
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
a316ba5
to
6b9b3a1
Compare
6b9b3a1
to
53f2845
Compare
I made the test code alternate calls between Chainman's |
936f055
to
41f83a2
Compare
I added test coverage for |
bc05bc0
to
c931a47
Compare
In commit f9200f6 "Use createNewBlock via the interface instead of calling Chainman's CreateNewBlock." Do you mean "Use createNewBlock via the interface instead of calling CreateNewBlock through the BlockAssembler directly"? There is no |
c931a47
to
171c116
Compare
Made some adjustments based on #31283 (comment) |
171c116
to
e5a9b73
Compare
@TheCharlatan I adjusted the commit message |
618398b
to
7a505f5
Compare
Fixed tidy error. |
7a505f5
to
3fd2daf
Compare
The changes here don't conflict with the merged #31196, but I rebased just in case. |
3fd2daf
to
a19a5f9
Compare
#31325 landed so this is ready for review. |
a19a5f9
to
3827fd2
Compare
I extracted the first commit into its own PR #31581. Review on the second commit is still welcome here, since I don't expect it to change. Marking draft. |
3827fd2
to
a43ea8c
Compare
Rebased on the latest #31581. I added a commit that on testnet3 and testnet4 returns a new template after 20 minutes, to take advantage of the min difficulty rule. Since I also switched to using |
a43ea8c
to
da305ac
Compare
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
0424968 test: use Mining interface in miner_tests (Sjors Provoost) Pull request description: Needed for both #31283 and #31564. By using the Mining interface in `miner_tests.cpp` we increase its coverage in unit tests. ACKs for top commit: achow101: ACK 0424968 ryanofsky: Code review ACK 0424968, just minor suggested changes (renames, comments, BOOST_REQUIREs) since last review and some more extra clarifications and checks added to the CreateNewBlock_validity test. The CreateNewBlock_validity changes seem clear and easy to understand now. vasild: ACK 0424968 tdb3: ACK 0424968 Tree-SHA512: 2761cb7555d759670e40d8f37b96a079f8e12a588ac43313b9e63c69afd478321515873a8896ea56784f0100dac4476b0c0e0ef8b5418f8aea24d9965cace4d4
da305ac
to
8d54cfd
Compare
Rebased after #31581 landed, marking ready for review again. If I need to retouch I'll fix the typo mentioned in #31581 (comment) and maybe add a helper to the test suggested here #31581 (comment). |
This PR introduces
waitNext()
. It waits for either the tip to update or for fees at the top of the mempool to rise sufficiently. It then returns a new template, with which the caller can rinse and repeat.On testnet3 and testnet4 the difficulty drops after 20 minutes, so the second ensures that a new template is returned in that case.
Alternative approach to #31003, suggested in #31109 (comment)