Skip to content
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

Merged
merged 10 commits into from Oct 7, 2023
Merged

AssumeUTXO follow-ups #28562

merged 10 commits into from Oct 7, 2023

Conversation

fjahr
Copy link
Contributor

@fjahr fjahr commented Oct 2, 2023

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 2, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ryanofsky
Stale ACK jamesob, Sjors

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #28608 (assumeutxo state and locking cleanup by ryanofsky)

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.

@fjahr fjahr force-pushed the 2023-10-au-followups branch 2 times, most recently from 45aa654 to 2bd1d39 Compare October 2, 2023 23:20
@fjahr fjahr marked this pull request as ready for review October 2, 2023 23:40
Copy link
Member

@jamesob jamesob left a 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!

src/node/blockstorage.cpp Outdated Show resolved Hide resolved
Copy link
Member

@maflcko maflcko left a 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?

test/functional/feature_assumeutxo.py Outdated Show resolved Hide resolved
@fjahr
Copy link
Contributor Author

fjahr commented Oct 3, 2023

Addressed feedback from @MarcoFalke

Copy link
Contributor

@ryanofsky ryanofsky left a 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

src/rpc/blockchain.cpp Outdated Show resolved Hide resolved
test/functional/feature_assumeutxo.py Outdated Show resolved Hide resolved
test/functional/feature_assumeutxo.py Outdated Show resolved Hide resolved
src/init.cpp Outdated Show resolved Hide resolved
@DrahtBot DrahtBot requested a review from jamesob October 3, 2023 19:38
@maflcko
Copy link
Member

maflcko commented Oct 3, 2023

Left some more review comments on the parent pull.

@fjahr
Copy link
Contributor Author

fjahr commented Oct 4, 2023

The handling of timeouts in feature_assumeutxo was moved out into #28586

@fanquake
Copy link
Member

fanquake commented Oct 4, 2023

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.

Copy link
Contributor

@ryanofsky ryanofsky left a 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

src/rpc/blockchain.cpp Outdated Show resolved Hide resolved
@ryanofsky
Copy link
Contributor

ryanofsky commented Oct 4, 2023

re: #28562 (comment)

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.

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 4, 2023

🐙 This pull request conflicts with the target branch and needs rebase.

achow101 added a commit to bitcoin-core/gui that referenced this pull request Oct 5, 2023
… 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
@Sjors
Copy link
Member

Sjors commented Oct 6, 2023

Can you give this a rebase? I think 952f037 can be dropped after #28590?

@fanquake fanquake added this to the 26.0 milestone Oct 6, 2023
Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 0b2c93b modulo dropping commit 952f037 and its related comment.

src/rpc/blockchain.cpp Outdated Show resolved Hide resolved
src/init.cpp Outdated Show resolved Hide resolved
@DrahtBot DrahtBot requested a review from Sjors October 6, 2023 14:33
Copy link
Contributor

@ryanofsky ryanofsky left a 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

src/init.cpp Outdated Show resolved Hide resolved
@fjahr
Copy link
Contributor Author

fjahr commented Oct 6, 2023

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.

@DrahtBot DrahtBot removed the CI failed label Oct 6, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 6, 2023
… 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)
Copy link
Contributor

@ryanofsky ryanofsky left a 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.

@fanquake fanquake merged commit 38f4b0d into bitcoin:master Oct 7, 2023
16 checks passed
// 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.
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@maflcko maflcko Oct 10, 2023

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.

Copy link
Contributor Author

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.

Copy link
Member

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;

Copy link
Member

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

Copy link
Member

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

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 10, 2023
… 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)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 11, 2023
… 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)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 12, 2023
… 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)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 12, 2023
… 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)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 12, 2023
… 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)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Oct 12, 2023
… 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)
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Oct 13, 2023
…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
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Oct 13, 2023
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Feb 23, 2024
… 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)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Feb 23, 2024
… 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants