-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Mining interface followups, reduce cs_main locking, test rpc bug fix #30335
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
Mining interface followups, reduce cs_main locking, test rpc bug fix #30335
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
2eab0eb
to
22fe97a
Compare
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.
tested ACK 22fe97a
Manually validated all instances of testBlockValidity
in the entire code base are having their parameter list updated with state
as their last output parameter using good old git grep -n testBlockValidity
. Now, the interface can be used with the libmultiprocess
code generator!
As for the standard testing, I got the pr from upstream, built and run all unit and functional tests including the entire extended test harness and all tests pass.
(Special thanks for incorporating that empty line, it makes eyeballing of different methods pretty easier to spot even for people with poorer eyesight!)
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.
Tested ACK 22fe97a
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.
ACK 22fe97a
Changes look straightforward. Took a quick look at the other interface functions in mining.h
, and the function arguments look to all now be in the in/inout/out order. Also manually ran getblocktemplate
RPC on signet and on regtest (after broadcasting a few transactions). All looked well.
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.
CHECK_NONFATAL
can be used to write shorter code and not pollute the scope with single-use symbols. That is:
std::optional<uint256> maybe_tip{miner.getTipHash()};
CHECK_NONFATAL(maybe_tip);
uint256 tip{maybe_tip.value()};
can be:
uint256 tip{CHECK_NONFATAL(miner.getTipHash()).value()};
Needed for std::unique_ptr
d23968e
to
18d6b0f
Compare
18d6b0f
to
c8343e2
Compare
src/node/interfaces.cpp
Outdated
LOCK(cs_main); | ||
CBlockIndex* tip{chainman().ActiveChain().Tip()}; | ||
// Fail if the tip updated before the lock was taken | ||
if (block.hashPrevBlock != tip->GetBlockHash()) return false; |
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.
state
will be valid, no? So this may be confusing?
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.
just a nit, because it only affects test-only code, but wanted to leave the comment.
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.
In commit "Have testBlockValidity hold cs_main instead of caller" (c8343e2)
re: #30335 (comment)
state
will be valid, no? So this may be confusing?
It seems like it would be better to do something like:
if (block.hashPrevBlock != tip->GetBlockHash()) {
state.Error("Block does not connect to current chain tip.")
return false;
}
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.
Taken
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.
Code review ACK c8343e2
Nice changes getting rid of some over-broad and recursive uses of cs_main.
src/node/interfaces.cpp
Outdated
LOCK(cs_main); | ||
CBlockIndex* tip{chainman().ActiveChain().Tip()}; | ||
// Fail if the tip updated before the lock was taken | ||
if (block.hashPrevBlock != tip->GetBlockHash()) return false; |
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.
In commit "Have testBlockValidity hold cs_main instead of caller" (c8343e2)
re: #30335 (comment)
state
will be valid, no? So this may be confusing?
It seems like it would be better to do something like:
if (block.hashPrevBlock != tip->GetBlockHash()) {
state.Error("Block does not connect to current chain tip.")
return false;
}
It would be good to mention that the are some changes to cs_main locking (including a potential bugfix) in the PR description, otherwise this should be a refactoring with no changes in behavior. |
This was added in 4bf2e36, but BlockAssembler::CreateNewBlock already locks cs_main internally.
The goal of interfaces is to eventually run in their own process, so we can't use EXCLUSIVE_LOCKS_REQUIRED in their declaration. However TestBlockValidaty will crash (in its call to ConnectBlock) if the tip changes from under the proposed block. Have the testBlockValidity implementation hold the lock instead, and non-fatally check for this condition.
c8343e2
to
a74b0f9
Compare
Addressed feedback and expanded PR description. |
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.
Code Review ACK a74b0f9
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.
Tested ACK a74b0f9
Code reviewed and validated all the initial refactor and appended fix changes as they were discovered during the course of this PR.
Cleaned up and rebuilt this commit running the unit, functional and extended tests that all pass.
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.
Code review ACK a74b0f9. Just new error string is added since last review, and a commit message was updated
std::optional<uint256> maybe_tip{miner.getTipHash()}; | ||
CHECK_NONFATAL(maybe_tip); | ||
uint256 tip{maybe_tip.value()}; | ||
uint256 tip{CHECK_NONFATAL(miner.getTipHash()).value()}; |
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.
nit: The same can be done below where tip
is assigned again.
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.
Added to #30356.
…ptions c504b69 refactor: add coinbase constraints to BlockCreateOptions (Sjors Provoost) 6b4c817 refactor: pass BlockCreateOptions to createNewBlock (Sjors Provoost) 323cfed refactor: use CHECK_NONFATAL to avoid single-use symbol (Sjors Provoost) Pull request description: When generating a block template through e.g. getblocktemplate RPC, we reserve 4000 weight units and 400 sigops. Pools use this space for their coinbase outputs. At least one pool patched their Bitcoin Core node to adjust these hardcoded values. They eventually [produced an invalid block](https://bitcoin.stackexchange.com/questions/117837/how-many-sigops-are-in-the-invalid-block-783426) which exceeded the sigops limit. The existince of such patches suggests it may be useful to make this value configurable. This PR would make such a change easier. However, the main motivation is that in the Stratum v2 spec requires the pool to communicate the maximum bytes they intend to add to the coinbase outputs. Specifically the `CoinbaseOutputDataSize` message which is part of the [Template Distribution Protocol](https://github.com/stratum-mining/sv2-spec/blob/main/07-Template-Distribution-Protocol.md#71-coinbaseoutputdatasize-client---server) has a field `coinbase_output_max_additional_size`. A proposed change to the spec adds the max additional sigops as well: stratum-mining/sv2-spec#86. Whether that change makes it into the spec is not important though, as adding both to `BlockAssembler::Options` makes sense. The first commit is a test refactor followup for #30335, related to the code that's changed here, but not required. The second commit introduces BlockCreateOptions, with just `use_mempool`. The thirds commit adds `coinbase_max_additional_weight` and `coinbase_output_max_additional_sigops` to `BlockCreateOptions`. They use the originally hardcoded values, and no existing caller overrides these defaults. This changes in #29432. ACKs for top commit: itornaza: tested ACK c504b69 ryanofsky: Code review ACK c504b69 ismaelsadeeq: Code review ACK c504b69 Tree-SHA512: de2fa085f47048c91d95524e03f909f6f27f175c1fefa3d6106445e7eb5cf5b710eda6ea5b641cf3b4704a4e4e0181a0c829003b9fd35465f2a46167e5d64487
Followups from #30200
Fixes:
std::unique_ptr
needs#include <memory>
(noticed while working on Stratum v2 connman #30332, which has fewer includes than its parent PR that I originally tested with)Refactor:
state
to the end oftestBlockValidity
, see Introduce Mining interface #30200 (comment)