-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Validation: Remove ConnectTrace and PerBlockConnectTrace #17562
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. ConflictsNo conflicts as of last run. |
ariard
left a 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.
Concept ACK.
Not sure about the wording of commit message, signals can be fired while holding cs_main, would say something more like callbacks can be scheduled while holding cs_main, at a later timer, the scheduler thread may execute them without regard to holding cs_main or not.
|
Thanks @ariard . I agree with you about the commit message. I've reworded along the lines you suggested. |
6b04c24 to
aa882b2
Compare
jonatack
left a 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.
Concept ACK.
Nice simplification and code removal that builds on the work in #17477.
src/validation.cpp
Outdated
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.
If you need to retouch this PR: perhaps add code documentation here like that for GetMainSignals().BlockDisconnected (or GetMainSignals().ChainStateFlushed or GetMainSignals().UpdatedBlockTip)
git grep -C1 "0-confirmed or conflicted"
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. Change seems fine but will wait with code review until #17477 is finalized and merged. |
ConnectTrace was introduced in 6fdd43b when the SyncTransactions signal needed to be fired outside the cs_main scope. The CValidationInterface is now asynchronous and callbacks can be scheduled without holding cs_main. The scheduler thread can execute the callback later without regard to cs_main. Remove the ConnectTrace struct that needs to be passed up and down the stack and just fire BlockConnected() directly in ConnectTip().
aa882b2 to
ab00be0
Compare
|
Run ci |
|
There is a GitHub corruption: |
|
Ok, this was stupid. Ci is running now Concept ACK |
|
#17477 is now merged. Re-opened this PR and rebased it on master. |
maflcko
left a 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.
Removing code is fine, but I'd like to see the documentation updated a bit more. This will also explain why it is safe to reorganize the signals as a result of the changes in this pull request.
-
https://doxygen.bitcoincore.org/class_c_validation_interface.html#ac63500b25a37b34ad2ec234fde239405 says "Provides a vector of transactions evicted from the mempool as a result.", which is wrong after 312d27b. This should be fixed.
-
https://doxygen.bitcoincore.org/class_c_validation_interface.html#a6de358ebc946cbd33ce73eef61993fe5 implies that mempool removal signals are ordered before block connection signals. After the changes in this pull request, this is no longer true. So an operation in a BlockConnected callback, that depends on an operation run in the TransactionRemovedFromMempool, might now fail. Someone should check the wallet code to make sure this is not the case. Though, at the very least in this pull, the documentation should be updated.
-
https://doxygen.bitcoincore.org/class_c_validation_interface.html#a794911828f9350d82bc1941ba82e7463 doesn't explicitly say that this can be used a synchronisation mechanism to catch up with the current chain state and mempool state. With the UpdatedBlockTip signal, it is possible to wait for a chain client to be sure to be up to date (mempool and chainstate) as of that new blockindex. The documentation could be updated to make this explicit.
Concept ACK ab00be0, removing code is my favorite! Though, needs some doc updated, I think 🎌
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Concept ACK ab00be08e8e4371bf1483d139ecb50dacba40e0a, removing code is my favorite! Though, needs some doc updated, I think 🎌
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUi1Xwv8C0bXBK8kwoBLkKTv34M+YT29ESnNrB2kRI95LUZ1J/sXyzIR7nU39wZz
y+/w7cGwxVAITspBSctzKsu42BmrQLs9h4YVYLZLJEmoybHggrvm6c331xMwPexQ
Ktcozmee8qH5i+B0Pqyusk39Jnq/j6S2pm9ahgCh0woypucZWh27Rrjfg/YAgV6i
tbnhe0SY/FFffCH2d9vCFy/HPfPy+ZUSKQOLjY06P+DAJA7NBFzmddKMR7pOp+NB
jGA4RzcqYqACBmjh8WabTWoDf2hgYMyklMYe/HyaUE0Vg1WtYjJf3qapeeFtkMfx
iiGoO+HiASHvqi18Q0489o6nuDhWCIqpKkXl18+hdWvSbiNkySqd7KeWfPEU6s9G
SbEuImgxMJa7KbWkPlsjZxJKPStj8EP9zQr1NaVKt85E+MTCQAgrLj5kZL0/g9Ra
IOfg2RntWbOOqyE3AlT376IAk3sMvhzJZDxWQGhbRMQ4ew1ut+phojsylFGDNyVB
pJVLAPyQ
=fKV2
-----END PGP SIGNATURE-----
Timestamp of file with hash 33cca684633289f50bf74baf0a39711a82c5a0b6fcd6d62d0dc47653f74fa2fa -
| // blocks are added after all the conflicted transactions have | ||
| // been filled in. Thus, the last entry should always be an empty | ||
| // one waiting for the transactions from the next block. We pop | ||
| // the last entry here to make sure the list we return is sane. |
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.
Note to other reviewers: This comment obviously no longer applies after 312d27b
| * The block is added to connectTrace if connection succeeds. | ||
| */ | ||
| bool CChainState::ConnectTip(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions &disconnectpool) | ||
| bool CChainState::ConnectTip(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, DisconnectedBlockTransactions &disconnectpool) |
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.
style-nit:
| bool CChainState::ConnectTip(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, DisconnectedBlockTransactions &disconnectpool) | |
| bool CChainState::ConnectTip(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, DisconnectedBlockTransactions& disconnectpool) |
maflcko
left a 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.
Looks like the wallet is using BlockConnected to determine when it is synced (BlockUntilSyncedToCurrentChain()). This is broken now.
ariard
left a 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.
Code Review ACK ab00be0
@MarcoFalke can you describe your point further ? IIRC BlockUntilSyncedToCurrentChain waits until scheduler queue being drained before letting the wallet moving forward. From where we shot BlockConnected shouldn't change anything ?
| { | ||
| LOCK2(cs_main, ::mempool.cs); // Lock transaction pool for at least as long as it takes for connectTrace to be consumed | ||
| // Do not unlock cs_main or mempool until we've made forward | ||
| // progress (with the exception of shutdown due to hardware issues, |
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: define forward progress (chain tip is the valid most-work chain or most-work chain has been found invalid)
|
|
||
| for (const PerBlockConnectTrace& trace : connectTrace.GetBlocksConnected()) { | ||
| assert(trace.pblock && trace.pindex); | ||
| GetMainSignals().BlockConnected(trace.pblock, trace.pindex); |
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.
Does it change anything for BlockConnected subscribers ? In case of block connections burst or reorgs, instead of receiving the diff at once after full validation, subscribers will now receive block connection after each individual validation in ConnectTip (assuming scheduler catch up). I think it's slightly better because discrepancy is shorter but likely a really marginal case.
|
@ariard If See also my second bullet point here: #17562 (review) |
This PR doesn't inverse mempool removal signals and block connection signals as far as I understand. Mempool removal are triggered in This order guarantee us than when wallet query the chain to know if it's behind ( I read again wallet code, as far as I can tell, Or maybe I miss something, code isn't the clearest here ? |
|
What about the ones in |
|
Thanks for pointing this out Marco. You're right that in a re-org, this changes the order of notification. If there's a one block diconnect/two block connect reorg, then before this PR:
After this PR
So at the point that BlockConnected is called for B2, the mempool is in an inconsistent state. As Marco points out, that should be ok since the validationinterface doesn't guarantee a consistent mempool when BlockConnected is fired. Listeners should use UpdatedBlockTip if they want that. However, I'm going to close this PR since it's difficult to review. It should be possible to bring all of the notification firing into |
|
Opened a PR to simplify ConnectTrace here: #18685 |
ConnectTracewas introduced in 6fdd43bwhen the
SyncTransactionssignal needed to be fired outside the cs_mainscope. The
CValidationInterfaceis now asynchronous and signals can befired while holding
cs_main. Remove theConnectTracestruct that needsto be passed up and down the stack and just fire
BlockConnected()directly in
ConnectTip().