-
Notifications
You must be signed in to change notification settings - Fork 37.4k
refactor, kernel: Decouple ArgsManager from blockstorage #27125
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
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
f736f9e
to
0d99466
Compare
validation.cpp:80:13: error: using decl 'ReadBlockFromDisk' is unused [misc-unused-using-decls,-warnings-as-errors]
using node::ReadBlockFromDisk;
^
/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/validation.cpp:80:13: note: remove the using
using node::ReadBlockFromDisk; |
0d99466
to
352d2f0
Compare
Thank you, I'm improving my clang tidy workflow. |
352d2f0
to
e8b095f
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.
Concept ACK
e8b095f
to
b640db3
Compare
Updated e8b095f -> 899ba71 (removeBlockstorageArgs_0 -> removeBlockstorageArgs_1, compare) with suggested changes. |
b640db3
to
3ded321
Compare
Updated b640db3 -> 3ded321 (removeBlockstorageArgs_2 -> removeBlockstorageArgs_3, compare) with suggested typo fix. |
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.
Concept ACK
Seeing all that effort to pass around the hacky fastprune
arg (which doesn't make any sense outside of functional tests) seems a bit sad, so I wonder if it's really inevitable.
Did you consider whether it's possible to also move BlockFileSeq
into blockmanager? I guess it doesn't work just because of one remaining call site for node::ReadBlockFromDisk
from zmqpublishnotifier
?
Concept ACK |
3ded321
to
88e88a5
Compare
Thanks for the reviews!
Yes, totally echo this sentiment. Indeed BlockFileSeq and its dependants are not class members because of the call site in Updated 3ded321 -> 5964043 (removeBlockstorageArgs_3 -> removeBlockstorageArgs_4, compare) removing unused declaration. |
88e88a5
to
f87c393
Compare
Ensures better memory safety for this global. This came up during discussion of the following commit, but is not strictly required for its implementation.
8f94f05
to
886a473
Compare
Rebased 8f94f05 -> 886a473 (removeBlockstorageArgs_23 -> removeBlockstorageArgs_24, compare)
|
trivial re-ACK 886a473 🐗 Show signatureSignature:
|
{ | ||
std::map<std::string, CZMQNotifierFactory> factories; | ||
factories["pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>; | ||
factories["pubhashtx"] = CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>; | ||
factories["pubrawblock"] = CZMQAbstractNotifier::Create<CZMQPublishRawBlockNotifier>; | ||
factories["pubrawblock"] = [&get_block_by_index]() -> std::unique_ptr<CZMQAbstractNotifier> { |
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 "zmq: Pass lambda to zmq's ZMQPublishRawBlockNotifier" (6247b3c)
It looks like the lambda is taking a reference to the local get_block_by_index
variable here, which doesn't seem right, since the variable will go out of scope before the lambda is called. So I think &
should be dropped here.
Not totally sure though, since I would expect there to be problems in CI if there was a bug.
EDIT: I think moving instead of copying would also work:
factories["pubrawblock"] = [gb = std::move(get_block_by_index)]() -> std::unique_ptr<CZMQAbstractNotifier> {
return std::make_unique<CZMQPublishRawBlockNotifier>(std::move(gb));
};
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.
CZMQPublishRawBlockNotifier
takes get_block_by_index
by value (meaning instead of borrowing, copies its value), so I think that is why this works out.
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.
re: #27125 (comment)
Yeah sorry, I saw the "factories" map and assumed the factories would be long-lived, not destroyed before the function returns. This code is pretty strange, because it creates a map and then never looks anything up in the map. Could be cleaned up later, though. Probably a more sane way to write it would be to drop the map, change the outer for loop into an add_notifiers
lambda, and do
add_notifiers("pubhashblock", CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>);
add_notifiers("pubhashtx", CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>);
...
In any case, agree the current code is safe
886a473
to
e3311d6
Compare
Updated 886a473 -> e3311d6 (removeBlockstorageArgs_24 -> removeBlockstorageArgs_25, compare)
EDIT: Sorry, forgot the second part :P Updated e3311d6 -> 87479b2 (removeBlockstorageArgs_25 -> removeBlockstorageArgs_26, compare) |
e3311d6
to
87479b2
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.
Code review ACK 886a473
re: #27125 (comment)
* Addressed @ryanofsky's [comment](https://github.com/bitcoin/bitcoin/pull/27125#discussion_r1190097934), moving the lambda instead of borrowing.
Actually I think my suggestion won't work. There can be multiple notifiers, so the function needs to be copied into all of them not moved into the first one. ACKed previous version of the PR 886a473 though, so would suggest reverting.
{ | ||
std::map<std::string, CZMQNotifierFactory> factories; | ||
factories["pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>; | ||
factories["pubhashtx"] = CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>; | ||
factories["pubrawblock"] = CZMQAbstractNotifier::Create<CZMQPublishRawBlockNotifier>; | ||
factories["pubrawblock"] = [&get_block_by_index]() -> std::unique_ptr<CZMQAbstractNotifier> { |
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.
re: #27125 (comment)
Yeah sorry, I saw the "factories" map and assumed the factories would be long-lived, not destroyed before the function returns. This code is pretty strange, because it creates a map and then never looks anything up in the map. Could be cleaned up later, though. Probably a more sane way to write it would be to drop the map, change the outer for loop into an add_notifiers
lambda, and do
add_notifiers("pubhashblock", CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>);
add_notifiers("pubhashtx", CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>);
...
In any case, agree the current code is safe
The lambda captures a reference to the chainman unique_ptr to retrieve block data. An assert is added on the chainman to ensure that the lambda is not used while the chainman is uninitialized. This is done in preparation for the following commits where blockstorage functions are made BlockManager methods.
This is a commit in preparation for the next few commits. The functions are moved to methods to avoid their re-declaration for the purpose of passing in BlockManager options. The functions that were now moved into the BlockManager should no longer use the params as an argument, but instead use the member variable. In the moved ReadBlockFromDisk and UndoReadFromDisk, change the function signature to accept a reference to a CBlockIndex instead of a raw pointer. The pointer is expected to be non-null, so reflect that in the type. To allow for the move of functions to BlockManager methods all call sites require an instantiated BlockManager, or a callback to one.
Remove access to the global gArgs for the fastprune argument and replace it by adding a field to the existing BlockManager Options struct. When running `clang-tidy-diff` on this commit, there is a diagnostic error: `unknown type name 'uint64_t' [clang-diagnostic-error] uint64_t prune_target{0};`, which is fixed by including cstdint. This should eventually allow users of the BlockManager to not rely on the global gArgs and instead pass in their own options.
Add a blocks_dir field to the BlockManager options. Move functions relying on the global gArgs to get the blocks_dir into the BlockManager class. This should eventually allow users of the BlockManager to not rely on the global Args and instead pass in their own options.
Add a stop_after_block_import field to the BlockManager options. Use this field instead of the global gArgs. This should allow users of the BlockManager to not rely on the global Args.
https://github.com/bitcoin/bitcoin/pull/27125/checks?check_run_id=13380672723 clang-tidy-16 -p=/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu -quiet /tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/zmq/zmqnotificationinterface.cpp
zmq/zmqnotificationinterface.cpp:48:62: error: std::move of the const variable 'gb' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg,-warnings-as-errors]
return std::make_unique<CZMQPublishRawBlockNotifier>(std::move(gb));
^~~~~~~~~~ ~ |
87479b2
to
5ff63a0
Compare
Updated 87479b2 -> 5ff63a0 (removeBlockstorageArgs_26 -> removeBlockstorageArgs_27, 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.
Code review ACK 5ff63a0. Since last ACK just added std::move and fixed commit title. Sorry for the noise!
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 5ff63a0
@@ -53,11 +54,10 @@ static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10}; | |||
* @param[in] block_index The block to read from disk, or nullptr | |||
* @param[in] mempool If provided, check mempool for tx | |||
* @param[in] hash The txid | |||
* @param[in] consensusParams The params | |||
* @param[out] hashBlock The block hash, if the tx was found via -txindex or block_index |
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 (if you repush): blockman should be added to the doc, also it would be nice to keep the out param at the end according to dev notes.
…base from kernel library db77f87 scripted-diff: move settings to common namespace (TheCharlatan) c27e4bd move-only: Move settings to the common library (TheCharlatan) c2dae5d kernel: Remove chainparams, chainparamsbase, args, settings from kernel library (TheCharlatan) 05870b1 refactor: Remove gArgs access from validation.cpp (TheCharlatan) 8789b11 refactor: Add path argument to FindSnapshotChainstateDir (TheCharlatan) ef95be3 refactor: Add stop_at_height option in ChainstateManager (TheCharlatan) Pull request description: This pull request is part of the `libbitcoinkernel` project #27587 https://github.com/bitcoin/bitcoin/projects/18 and more specifically its "Step 2: Decouple most non-consensus code from libbitcoinkernel". --- This completes the removal of the node's chainparams, chainparamsbase, args and settings files and their respective classes from the kernel library. This is the last pull request in a long series working towards decoupling the `ArgsManager` and the `gArgs` global from kernel code. These prior pull requests are: #26177 #27125 #25527 #25487 #25290 ACKs for top commit: MarcoFalke: lgtm ACK db77f87 🍄 hebasto: ACK db77f87, I have reviewed the code and it looks OK. ryanofsky: Code review ACK db77f87. Looks great! Tree-SHA512: cbfbd705d056f2f10f16810d4f869eb152362fff2c5ddae5e1ac6785deae095588e52ad48b29d921962b085e51de1e0ecab6e50f46149ffe3c16250608a2c93a
The libbitcoin_kernel library should not rely on the
ArgsManager
, but rather use option structs that can be passed to the various classes it uses. This PR removes reliance on theArgsManager
from theblockstorage.*
files. Like similar prior work, it uses the options struct in theBlockManager
that can be populated withArgsManager
values.Some related prior work: #26889 #25862 #25527 #25487
Related PR removing blockstorage globals: #25781