-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: move methods under CChainState (pt. 1) #15976
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
0f7a07c
to
65e2268
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
I dislike that member functions that previously could (and should) only be called in the validation module are now callable from anywhere. To make it worse, they are easily confused e.g. |
An alternative could be to remove the global methods (e.g. |
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.
Would you say the root cause of that is that ::ChainstateActive is global? Maybe we can make that only available through interfaces? There's not that many places we access member functions from. |
Also, |
I like this idea but left it on the table in the interest of minimizing the diff. In general, my preference would be to have anything outside of validation deal with the CChainState interface ( |
65e2268
to
61fd34e
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.
utACK 61fd34e
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
utACK 61fd34e244
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUihkgv/aDDUmSAn14AENjmciWELRSosOaTj/t0ws0/y09T+/f8wcmv/kCBx6tnR
JJkdcyteDAIlxJADIzT3TnhhXg93zwozotbv9hYGt/wTij4bLJIO96mBIWqJc/9V
ivfScok+S1CwLVRp8nT3mzJMWMQLFFp7CyfZmKFnrCWCI6tuK2GSqCuy5dKkDjgk
1hPhYTjk1OsYUhn2OjFVyfK4C1I6U8qfTFh6H6iSTAX4lA5/x9Jx/yINw93PDaH2
mMX8II9Pns7YY+zEXfNhw23IqomDe6GBTMBFw+6VAKAiGV5mIQeoabRcEdeqDT+4
xn6CzXaID4ENm+tqDkiaFTrSP7JW3BIt7Bnz3+D1NbPZzRow2rEwaF9pH8/DPmVk
WWU7ZziPywF2Q3BTCPq1SrkYgBSDYHYlA98XyZ4OAdhiT/tPV1gM5kihyy2LufpE
lec41niuCaOn8zDJeUF4KkhtVfMTdXE8f7od+i6ziBpCJO4UZ6fxxZWQFiDJQIJQ
1DFdLFPI
=enPL
-----END PGP SIGNATURE-----
Timestamp of file with hash 2470d8f5b5b09630c89a5fc8a331144aed1939344367664ad30f7e38bc00a911 -
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.
utACK 61fd34e. Change is simple and looks good, though it might be nice to follow up on some of Marco's suggestions.
61fd34e
to
5fe4eb3
Compare
Thanks for the good feedback @Sjors @MarcoFalke @ryanofsky. I agree with the comments so far and have incorporated all of them aside from those noted above. Initially I hadn't touched the global I took the liberty of renaming the global function equivalents for clarity, and in the process I did notice something sort of interesting. |
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.
utACK 5fe4eb3
5fe4eb3
to
64d0f87
Compare
My mistake: flushes do happen when calling |
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.
utACK 64d0f87. Since previous: ForceFlushStateToDisk and PruneAndFlush are now class members, CBlockIndexWorkComparator compare method is moved to the cpp file, some comments and commit messages are updated
along with DisconnectResult, and CBlockIndexWorkComparator. The CChainState interface needs to be known to the rest of the system because many global functions will move to CChainState methods. This is to allow other parts of the system to be parameterized per chainstate instance instead of assuming a single global.
utACK 403e677 no need to address my nits herein |
int nManualPruneHeight = 0); | ||
|
||
//! Unconditionally flush all changes to disk. | ||
void ForceFlushStateToDisk(); |
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: given context, this could be renamed ForceFlushToDisk
* If FlushStateMode::NONE is used, then FlushStateToDisk(...) won't do anything | ||
* besides checking if we need to prune. | ||
*/ | ||
bool FlushStateToDisk( |
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: given context, this could be renamed FlushToDisk
IF_NEEDED, | ||
PERIODIC, | ||
ALWAYS | ||
}; |
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: this could be moved to CChainState::FlushMode
4 utACKs on this - is there anyone else who wants to give it a look before merge? |
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.
struct CBlockIndexWorkComparator | ||
{ | ||
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const { | ||
// First sort by most total 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.
I don't mind the indentation git show --color-moved=dimmed_zebra --color-moved-ws=ignore-all-space d7c97edeea8cee10ad9da1f940d39d5073ac142d
.
I think this operator was inlined? Does it make sense to declare it inline
?
utACK 403e677 |
403e677 refactoring: IsInitialBlockDownload -> CChainState (James O'Beirne) 3ccbc37 refactoring: FlushStateToDisk -> CChainState (James O'Beirne) 4d66886 refactoring: introduce ChainstateActive() (James O'Beirne) d7c97ed move-only: make the CChainState interface public (James O'Beirne) Pull request description: This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11): Parent PR: #15606 Issue: #15605 Specification: https://github.com/jamesob/assumeutxo-docs/tree/2019-04-proposal/proposal --- This changeset starts moving functionality intimately related to CChainState into methods. Parameterizing these functions by a particular CChainState is necessary for the use of multiple chainstates simultaneously (e.g. for asynchronous background validation). In this change, we - make the CChainState interface public - since other units will start to invoke its methods directly, - introduce `::ChainstateActive()`, the CChainState equivalent for `::ChainActive()`, - and move `IsInitialBlockDownload()` and `FlushStateToDisk()` into methods on CChainState. Independent of assumeutxo, these changes better encapsulate chainstate behavior and allow easier use from a testing context. There are more methods that we'll move in the future, but they require other substantial changes (i.e. moving ownership of the `CCoinsView*` hierarchy into CChainState) so we'll save them for future PRs. --- The first move-only commit is most easily reviewed with `git diff ... --color-moved=dimmed_zebra`. ACKs for commit 403e67: Empact: utACK 403e677 no need to address my nits herein Sjors: utACK 403e677 ryanofsky: utACK 403e677. Only change since previous review is removing global state comment as suggested. MarcoFalke: utACK 403e677, though the diff still seems a bit bloated with some unnecessary changes in the second commit. promag: utACK 403e677 and rebased with current [master](c7cfd20). Tree-SHA512: 6fcf260bb2dc201361170c0b4547405366f5f331fcc3a2bac29b24442814b7b244ca1b58aac5af716885f9a130c343b544590dff780da0bf835c7c5b3ccb2257
403e677 refactoring: IsInitialBlockDownload -> CChainState (James O'Beirne) 3ccbc37 refactoring: FlushStateToDisk -> CChainState (James O'Beirne) 4d66886 refactoring: introduce ChainstateActive() (James O'Beirne) d7c97ed move-only: make the CChainState interface public (James O'Beirne) Pull request description: This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11): Parent PR: bitcoin#15606 Issue: bitcoin#15605 Specification: https://github.com/jamesob/assumeutxo-docs/tree/2019-04-proposal/proposal --- This changeset starts moving functionality intimately related to CChainState into methods. Parameterizing these functions by a particular CChainState is necessary for the use of multiple chainstates simultaneously (e.g. for asynchronous background validation). In this change, we - make the CChainState interface public - since other units will start to invoke its methods directly, - introduce `::ChainstateActive()`, the CChainState equivalent for `::ChainActive()`, - and move `IsInitialBlockDownload()` and `FlushStateToDisk()` into methods on CChainState. Independent of assumeutxo, these changes better encapsulate chainstate behavior and allow easier use from a testing context. There are more methods that we'll move in the future, but they require other substantial changes (i.e. moving ownership of the `CCoinsView*` hierarchy into CChainState) so we'll save them for future PRs. --- The first move-only commit is most easily reviewed with `git diff ... --color-moved=dimmed_zebra`. ACKs for commit 403e67: Empact: utACK bitcoin@403e677 no need to address my nits herein Sjors: utACK 403e677 ryanofsky: utACK 403e677. Only change since previous review is removing global state comment as suggested. MarcoFalke: utACK 403e677, though the diff still seems a bit bloated with some unnecessary changes in the second commit. promag: utACK 403e677 and rebased with current [master](c7cfd20). Tree-SHA512: 6fcf260bb2dc201361170c0b4547405366f5f331fcc3a2bac29b24442814b7b244ca1b58aac5af716885f9a130c343b544590dff780da0bf835c7c5b3ccb2257
fa2b083 [test] Add test to check mempool consistency in case of reorgs (MarcoFalke) fabeb1f validation: Add missing mempool locks (MarcoFalke) fa0c9db txpool: Make nTransactionsUpdated atomic (MarcoFalke) Pull request description: Take the mempool read lock during reorgs, so that we don't accidentally read an inconsistent mempool. ACKs for top commit: laanwj: code review ACK fa2b083 ryanofsky: utACK fa2b083 [EDIT: was ~e284e422e75189794e24fe482819d8b1407857c3~, from bad copy and paste]. Changes since last review: rebase after #15976, adding vTxHashes lock annotation, adding new commit dropping mempool lock for nTransactionsUpdated and making it atomic to avoid deadlock between mempool lock and g_best_block_mutex Tree-SHA512: cfe7777993589087753e000e3736d79d320dca412383fb77b56bef8946a04049722bf888c11b6f722adf677165185c7e58b4a269f7c5fa25e84dda375f6c8a7d
fa2b083 [test] Add test to check mempool consistency in case of reorgs (MarcoFalke) fabeb1f validation: Add missing mempool locks (MarcoFalke) fa0c9db txpool: Make nTransactionsUpdated atomic (MarcoFalke) Pull request description: Take the mempool read lock during reorgs, so that we don't accidentally read an inconsistent mempool. ACKs for top commit: laanwj: code review ACK fa2b083 ryanofsky: utACK fa2b083 [EDIT: was ~e284e422e75189794e24fe482819d8b1407857c3~, from bad copy and paste]. Changes since last review: rebase after bitcoin#15976, adding vTxHashes lock annotation, adding new commit dropping mempool lock for nTransactionsUpdated and making it atomic to avoid deadlock between mempool lock and g_best_block_mutex Tree-SHA512: cfe7777993589087753e000e3736d79d320dca412383fb77b56bef8946a04049722bf888c11b6f722adf677165185c7e58b4a269f7c5fa25e84dda375f6c8a7d
Summary: along with DisconnectResult, and CBlockIndexWorkComparator. The CChainState interface needs to be known to the rest of the system because many global functions will move to CChainState methods. This is to allow other parts of the system to be parameterized per chainstate instance instead of assuming a single global. This is a partial backport of Core [[bitcoin/bitcoin#15976 | PR15976]] : bitcoin/bitcoin@d7c97ed Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Subscribers: jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D5996
Summary: To be used once we move global functions (e.g. FlushStateToDisk()) into CChainState methods. Thanks to Marco Falke for suggestions This is a partial backport of Core [[bitcoin/bitcoin#15976 | PR15976]] : bitcoin/bitcoin@4d66886 Depends on D5996 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D6001
Summary: Also renames global methods for clarity: - ::FlushStateToDisk() -> CChainState::ForceFlushStateToDisk() - This performs an unconditional flush. - ::PruneAndFlush() -> CChainState::PruneAndFlush() This is a partial backport of Core [[bitcoin/bitcoin#15976 | PR15976]] : bitcoin/bitcoin@3ccbc37 Depends on D6001 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D6002
Summary: We introduce CChainState.m_cached_finished_ibd because the static state it replaces would've been shared across all CChainState instances. This is a partial backport of Core [[bitcoin/bitcoin#15976 | PR15976]] : bitcoin/bitcoin@403e677 Depends on D6002 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6035
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
merge bitcoin#15948, bitcoin#15976, bitcoin#16194...: assumeutxo project backports (part 1)
fa2b083 [test] Add test to check mempool consistency in case of reorgs (MarcoFalke) fabeb1f validation: Add missing mempool locks (MarcoFalke) fa0c9db txpool: Make nTransactionsUpdated atomic (MarcoFalke) Pull request description: Take the mempool read lock during reorgs, so that we don't accidentally read an inconsistent mempool. ACKs for top commit: laanwj: code review ACK fa2b083 ryanofsky: utACK fa2b083 [EDIT: was ~e284e422e75189794e24fe482819d8b1407857c3~, from bad copy and paste]. Changes since last review: rebase after bitcoin#15976, adding vTxHashes lock annotation, adding new commit dropping mempool lock for nTransactionsUpdated and making it atomic to avoid deadlock between mempool lock and g_best_block_mutex Tree-SHA512: cfe7777993589087753e000e3736d79d320dca412383fb77b56bef8946a04049722bf888c11b6f722adf677165185c7e58b4a269f7c5fa25e84dda375f6c8a7d
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This is part of the assumeutxo project:
Parent PR: #15606
Issue: #15605
Specification: https://github.com/jamesob/assumeutxo-docs/tree/2019-04-proposal/proposal
This changeset starts moving functionality intimately related to CChainState into methods. Parameterizing these functions by a particular CChainState is necessary for the use of multiple chainstates simultaneously (e.g. for asynchronous background validation).
In this change, we
::ChainstateActive()
, the CChainState equivalent for::ChainActive()
,IsInitialBlockDownload()
andFlushStateToDisk()
into methods on CChainState.Independent of assumeutxo, these changes better encapsulate chainstate behavior and allow easier use from a testing context.
There are more methods that we'll move in the future, but they require other substantial changes (i.e. moving ownership of the
CCoinsView*
hierarchy into CChainState) so we'll save them for future PRs.The first move-only commit is most easily reviewed with
git diff ... --color-moved=dimmed_zebra
.