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
refactor: Make IsInitialBlockDownload & NotifyHeaderTip not require a Chainstate #28218
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. |
Concept ACK |
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.
lgtm. Left style nits
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.
Updated 3d70aa3 -> bda557e (pr/assumeibd.2
-> pr/assumeibd.3
, compare) with suggested changes
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.
Why not make NotifyHeaderTip
a private ChainstateManager
member? The PR title seems to already hint as much.
re: #28218 (review)
Because it doesn't access private state. I think the point of classes in c++ is to encapsulate private state. If there is a group of functions operating on public state, they should be standalone functions, so they can be split up into files and organized by functionality. This way we can avoid being permanently stuck with a sprawling mess of code like validation.cpp. The urge to make functions class members instead of standalone functions when they only use public interfaces and do not manage private state leads to bad outcomes like CWallet in wallet.cpp. |
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 bda557e
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 bda557e
Nice interface cleanup!
@@ -2641,7 +2644,7 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew) | |||
} | |||
|
|||
bilingual_str warning_messages; | |||
if (!this->IsInitialBlockDownload()) { | |||
if (!m_chainman.IsInitialBlockDownload()) { |
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.
(somewhat unrelated to this pull)
Are there any plans to remove the chainman reference from Chainstate
? I really don't like this pattern in general, i.e. managed object having a reference to the manager. Imo, it is an indication that the responsibilities of Chainstate
and ChainstateManager
are not well defined.
(It's probably also more or less just an artifact of the de-globalization work)
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: #28218 (comment)
Are there any plans to remove the chainman reference from
Chainstate
? I really don't like this pattern in general, i.e. managed object having a reference to the manager. Imo, it is an indication that the responsibilities ofChainstate
andChainstateManager
are not well defined.
I agree, and if I were cleaning this up would get rid of this back reference and make a lot of ChainState members functions into standalone functions that take explicit ChainState and ChainStateManager arguments. But I think this would mainly be an aesthetic improvement and not have a lot of consequences, because in practice after #27746 and this PR the responsibilities of Chainstate
and ChainstateManager
are pretty clear if you just look at the actual state the classes contain and ignore the member functions. Detaching member functions and passing references explicitly instead of explicitly are good things, but less consequential than deciding how to represent and update state, which is what this PR and #27746 are focused on.
ACK bda557e |
This will need to be rebased after #27460: CXX rpc/libbitcoin_node_a-signmessage.o
CXX rpc/libbitcoin_node_a-txoutproof.o
rpc/mempool.cpp:757:28: error: no member named 'IsInitialBlockDownload' in 'Chainstate'
if (chainstate.IsInitialBlockDownload()) {
~~~~~~~~~~ ^
1 error generated.
gmake[2]: *** [Makefile:10829: rpc/libbitcoin_node_a-mempool.o] Error 1 |
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 ebda557e5ebe7f754984a34ddfd33d2540c0303b9 🦈
Show signature
Signature:
untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: ACK ebda557e5ebe7f754984a34ddfd33d2540c0303b9 🦈
yZn/RDpC1vSfiuda6JpUwUzxyXXsJQLislGF0AVNnNF1NjceFmcwfzF5NfWYhjExtf0o0YmRSA9OhqhPHvt0Ag==
bda557e
to
00a2e43
Compare
…ChainstateManager This change makes IsInitialBlockDownload and NotifyHeaderTip functions no longer tied to individual Chainstate objects. It makes them work with the ChainstateManager object instead so code is simpler and it is no longer possible to call them incorrectly with an inactive Chainstate. This change also makes m_cached_finished_ibd caching easier to reason about, because now there is only one cached value instead of two (for background and snapshot chainstates) so the cached IBD state now no longer gets reset when a snapshot is loaded. There should be no change in behavior because these functions were always called on the active ChainState objects. These changes were discussed previously bitcoin#27746 (comment) and bitcoin#27746 (comment) as possible followups for that PR.
00a2e43
to
94a98fb
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.
Rebased bda557e -> 94a98fb (pr/assumeibd.3
-> pr/assumeibd.4
, compare) applying suggestions and fixing silent conflict with #27460
re-ACK 94a98fb 🐺 Show signatureSignature:
|
ACK 94a98fb |
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.
reACK 94a98fb
…aderTip not require a Chainstate
This change makes
IsInitialBlockDownload
andNotifyHeaderTip
functions no longer tied to individualChainstate
objects. It makes them work with theChainstateManager
object instead so code is simpler and it is no longer possible to call them incorrectly with an inactiveChainstate
.This change also makes
m_cached_finished_ibd
caching easier to reason about, because now there is only one cached value instead of two (for background and snapshot chainstates) so the cached IBD state now no longer gets reset when a snapshot is loaded.There should be no change in behavior because these functions were always called on the active
ChainState
objects.These changes were discussed previously #27746 (comment) and #27746 (comment) as possible followups for that PR.