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
AssumeUTXO follow-ups #28562
AssumeUTXO follow-ups #28562
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. |
45aa654
to
2bd1d39
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.
Github ACK 26c815b
Thanks for addressing these!
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.
Could also rename HaveTxsDownloaded
to HaveNumChainTxs
to fix the TODO in the function?
0081d12
to
69fbb77
Compare
Addressed feedback from @MarcoFalke |
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 69fbb77
Left some more review comments on the parent pull. |
69fbb77
to
7a407a8
Compare
The handling of timeouts in |
7a407a8
to
2c9a841
Compare
Can you point back to / comment on #27596 in regards to what is fixed / followed up on here, and what still needs fixing? Given there are now a number of post-merge review comments. |
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 2c9a841
re: #28562 (comment)
This would be great, but there are a lot of open review comments on #27596 right now and this PR only addresses a small number of them, so it would be hard to compile a list of what is left and decide what is worth spending time to fix. It would be good to comment on #27596 about what things were addressed here, though, so if someone wants to make another PR that addresses other issues that seem important, they can do that after this one. |
🐙 This pull request conflicts with the target branch and needs rebase. |
… return a list of chainstates a9ef702 assumeutxo: change getchainstates RPC to return a list of chainstates (Ryan Ofsky) Pull request description: Current `getchainstates` RPC returns "normal" and "snapshot" fields which are not ideal because it requires new "normal" and "snapshot" terms to be defined, and the definitions are not really consistent with internal code. (In the RPC interface, the "snapshot" chainstate becomes the "normal" chainstate after it is validated, while in internal code there is no "normal chainstate" and the "snapshot chainstate" is still called that temporarily after it is validated). The current `getchainstates` RPC is also awkward to use if you to want information about the most-work chainstate, because you have to look at the "snapshot" field if it exists, and otherwise fall back to the "normal" field. Fix these issues by having `getchainstates` just return a flat list of chainstates ordered by work, and adding a new chainstate "validated" field alongside the existing "snapshot_blockhash" field so it is explicit if a chainstate was originally loaded from a snapshot, and whether the snapshot has been validated. This change was motivated by comment thread in bitcoin/bitcoin#28562 (comment) ACKs for top commit: Sjors: re-ACK a9ef702 jamesob: re-ACK a9ef702 achow101: ACK a9ef702 Tree-SHA512: b364e2e96675fb7beaaee60c4dff4b69e6bc2d8a30dea1ba094265633d1cddf9dbf1c5ce20c07d6e23222cf1e92a195acf6227e4901f3962e81a1e53a43490aa
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.
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
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 62db927. Just new commit removing assumevalid mentions and rebase since last review
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
…sing cursor Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
Co-authored-by: MarcoFalke <falke.marco@gmail.com>
Co-authored-by: MarcoFalke <falke.marco@gmail.com>
62db927
to
5d227a6
Compare
Rebased, addressed a few more comments, dropped the changes that have been addressed elsewhere in the meantime. I also tried to comment on everything that is addressed here or elsewhere in #27596. |
… flat list of chainstates Also add m_validated and m_target_block members to Chainstate class it is possible to determine chainstate properties directly from Chainstate objects and it is not neccessary for validation code make calls to ChainstateManager and decide what to do by looking at assumeutxo download state. Goal is to remove hardcoded logic handling assumeutxo snapshots from most validation code. Also to make it easy to fix locking issues like the fact that cs_main is currently held unnecessarily validating snapshots, and the fact that background chainstate is not immediately deleted when it is no longer used, wasting disk space and adding a long startup delay next time the node is restarted. This follows up on some previous discussions: bitcoin#24232 (comment) bitcoin#27746 (comment) bitcoin#28562 (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 5d227a6. Just suggested doc change and new EnsureChainman RPC cleanup commit since last review.
// Make sure nChainTx sum is correctly computed. | ||
unsigned int prev_chain_tx = pindex->pprev ? pindex->pprev->nChainTx : 0; | ||
assert((pindex->nChainTx == pindex->nTx + prev_chain_tx) | ||
// For testing, allow transaction counts to be completely unset. |
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.
Which testing do you mean? -chain=main -checkblockindex
on mainnet?
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.
The tests that are changed in the same commit.
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 removed the "testing" check and ran the main binary (not the tests) and it crashed here.
Generally I don't think a good place to put test-only code is the main production code. Especially when it comes to consensus critical code. This makes it impossible to properly test and review the code in a production environment outside of unit tests.
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 removed the "testing" check and ran the main binary (not the tests) and it crashed here.
Hm, can you say what exactly you removed and what you can to see the crash? I couldn't reproduce that so far.
Generally I don't think a good place to put test-only code is the main production code. Especially when it comes to consensus critical code. This makes it impossible to properly test and review the code in a production environment outside of unit tests.
I guess we should improve our test setup to include realistic nTx
and nChainTx
values so we can remove those checks 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.
I used this diff IIRC, which also fails the functional tests:
diff --git a/src/validation.cpp b/src/validation.cpp
index 9108f911f0..3bfa5091ad 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -4847,10 +4847,7 @@ void ChainstateManager::CheckBlockIndex()
// Make sure nChainTx sum is correctly computed.
unsigned int prev_chain_tx = pindex->pprev ? pindex->pprev->nChainTx : 0;
assert((pindex->nChainTx == pindex->nTx + prev_chain_tx)
- // For testing, allow transaction counts to be completely unset.
- || (pindex->nChainTx == 0 && pindex->nTx == 0)
- // For testing, allow this nChainTx to be unset if previous is also unset.
- || (pindex->nChainTx == 0 && prev_chain_tx == 0 && pindex->pprev));
+ );
if (pindexFirstAssumeValid == nullptr && pindex->nStatus & BLOCK_ASSUMED_VALID) pindexFirstAssumeValid = pindex;
if (pindexFirstInvalid == nullptr && pindex->nStatus & BLOCK_FAILED_VALID) pindexFirstInvalid = 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.
Another report, which could replicate the crash, see ##28791
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.
Turned into an issue: #29261
… flat list of chainstates Also add m_validity and m_target_block members to Chainstate class it is possible to determine chainstate properties directly from Chainstate objects and it is not neccessary for validation code make calls to ChainstateManager and decide what to do by looking at assumeutxo download state. Goal is to remove hardcoded logic handling assumeutxo snapshots from most validation code. Also to make it easy to fix locking issues like the fact that cs_main is currently held unnecessarily validating snapshots, and the fact that background chainstate is not immediately deleted when it is no longer used, wasting disk space and adding a long startup delay next time the node is restarted. This follows up on some previous discussions: bitcoin#24232 (comment) bitcoin#27746 (comment) bitcoin#28562 (comment)
… flat list of chainstates Also add m_validity and m_target_block members to Chainstate class it is possible to determine chainstate properties directly from Chainstate objects and it is not neccessary for validation code make calls to ChainstateManager and decide what to do by looking at assumeutxo download state. Goal is to remove hardcoded logic handling assumeutxo snapshots from most validation code. Also to make it easy to fix locking issues like the fact that cs_main is currently held unnecessarily validating snapshots, and the fact that background chainstate is not immediately deleted when it is no longer used, wasting disk space and adding a long startup delay next time the node is restarted. This follows up on some previous discussions: bitcoin#24232 (comment) bitcoin#27746 (comment) bitcoin#28562 (comment)
… flat list of chainstates Also add m_validity and m_target_block members to Chainstate class it is possible to determine chainstate properties directly from Chainstate objects and it is not neccessary for validation code make calls to ChainstateManager and decide what to do by looking at assumeutxo download state. Goal is to remove hardcoded logic handling assumeutxo snapshots from most validation code. Also to make it easy to fix locking issues like the fact that cs_main is currently held unnecessarily validating snapshots, and the fact that background chainstate is not immediately deleted when it is no longer used, wasting disk space and adding a long startup delay next time the node is restarted. This follows up on some previous discussions: bitcoin#24232 (comment) bitcoin#27746 (comment) bitcoin#28562 (comment)
… flat list of chainstates Also add m_validity and m_target_block members to Chainstate class it is possible to determine chainstate properties directly from Chainstate objects and it is not neccessary for validation code make calls to ChainstateManager and decide what to do by looking at assumeutxo download state. Goal is to remove hardcoded logic handling assumeutxo snapshots from most validation code. Also to make it easy to fix locking issues like the fact that cs_main is currently held unnecessarily validating snapshots, and the fact that background chainstate is not immediately deleted when it is no longer used, wasting disk space and adding a long startup delay next time the node is restarted. This follows up on some previous discussions: bitcoin#24232 (comment) bitcoin#27746 (comment) bitcoin#28562 (comment)
… flat list of chainstates Also add m_validity and m_target_block members to Chainstate class it is possible to determine chainstate properties directly from Chainstate objects and it is not neccessary for validation code make calls to ChainstateManager and decide what to do by looking at assumeutxo download state. Goal is to remove hardcoded logic handling assumeutxo snapshots from most validation code. Also to make it easy to fix locking issues like the fact that cs_main is currently held unnecessarily validating snapshots, and the fact that background chainstate is not immediately deleted when it is no longer used, wasting disk space and adding a long startup delay next time the node is restarted. This follows up on some previous discussions: bitcoin#24232 (comment) bitcoin#27746 (comment) bitcoin#28562 (comment)
… flat list of chainstates Also add m_validity and m_target_block members to Chainstate class it is possible to determine chainstate properties directly from Chainstate objects and it is not neccessary for validation code make calls to ChainstateManager and decide what to do by looking at assumeutxo download state. Goal is to remove hardcoded logic handling assumeutxo snapshots from most validation code. Also to make it easy to fix locking issues like the fact that cs_main is currently held unnecessarily validating snapshots, and the fact that background chainstate is not immediately deleted when it is no longer used, wasting disk space and adding a long startup delay next time the node is restarted. This follows up on some previous discussions: bitcoin#24232 (comment) bitcoin#27746 (comment) bitcoin#28562 (comment)
…a list of chainstates a9ef702 assumeutxo: change getchainstates RPC to return a list of chainstates (Ryan Ofsky) Pull request description: Current `getchainstates` RPC returns "normal" and "snapshot" fields which are not ideal because it requires new "normal" and "snapshot" terms to be defined, and the definitions are not really consistent with internal code. (In the RPC interface, the "snapshot" chainstate becomes the "normal" chainstate after it is validated, while in internal code there is no "normal chainstate" and the "snapshot chainstate" is still called that temporarily after it is validated). The current `getchainstates` RPC is also awkward to use if you to want information about the most-work chainstate, because you have to look at the "snapshot" field if it exists, and otherwise fall back to the "normal" field. Fix these issues by having `getchainstates` just return a flat list of chainstates ordered by work, and adding a new chainstate "validated" field alongside the existing "snapshot_blockhash" field so it is explicit if a chainstate was originally loaded from a snapshot, and whether the snapshot has been validated. This change was motivated by comment thread in bitcoin#28562 (comment) ACKs for top commit: Sjors: re-ACK a9ef702 jamesob: re-ACK a9ef702 achow101: ACK a9ef702 Tree-SHA512: b364e2e96675fb7beaaee60c4dff4b69e6bc2d8a30dea1ba094265633d1cddf9dbf1c5ce20c07d6e23222cf1e92a195acf6227e4901f3962e81a1e53a43490aa
… flat list of chainstates Also add m_validity and m_target_block members to Chainstate class it is possible to determine chainstate properties directly from Chainstate objects and it is not neccessary for validation code make calls to ChainstateManager and decide what to do by looking at assumeutxo download state. Goal is to remove hardcoded logic handling assumeutxo snapshots from most validation code. Also to make it easy to fix locking issues like the fact that cs_main is currently held unnecessarily validating snapshots, and the fact that background chainstate is not immediately deleted when it is no longer used, wasting disk space and adding a long startup delay next time the node is restarted. This follows up on some previous discussions: bitcoin#24232 (comment) bitcoin#27746 (comment) bitcoin#28562 (comment)
… flat list of chainstates Also add m_validity and m_target_block members to Chainstate class it is possible to determine chainstate properties directly from Chainstate objects and it is not neccessary for validation code make calls to ChainstateManager and decide what to do by looking at assumeutxo download state. Goal is to remove hardcoded logic handling assumeutxo snapshots from most validation code. Also to make it easy to fix locking issues like the fact that cs_main is currently held unnecessarily validating snapshots, and the fact that background chainstate is not immediately deleted when it is no longer used, wasting disk space and adding a long startup delay next time the node is restarted. This follows up on some previous discussions: bitcoin#24232 (comment) bitcoin#27746 (comment) bitcoin#28562 (comment)
Addressing what I consider to be non- or not-too-controversial comments from #27596.
Let me know if I missed anything among the many comments that can be easily included here.