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: Fix -reindex before snapshot was validated #29726

Merged
merged 2 commits into from Apr 16, 2024

Conversation

mzumsande
Copy link
Contributor

In c711ca1 logic was introduced that -reindex and -reindex-chainstate will delete the snapshot chainstate.
This doesn't work currently, instead of deleting the snapshot chainstate the node crashes with an assert (this can be triggered by applying the added test commit on master).
Fix this, and another bug that would prevent the new active chainstate from having a mempool after -reindex has deleted the snapshot (also covered by the test).

This didn't work for two reasons:
1.) GetSnapshotCoinsDBPath() was used to retrieve the path.
    This requires coins_views to exist, but the initialisation only happens later
    (in CompleteChainstateInitialization) so the node hits an assert in
    CCoinsViewDB& CoinsDB() and crashes.

2.) The snapshot was already activated, so it has the mempool attached.
    Therefore, the mempool needs to be transferred back to the ibd
    chainstate before deleting the snapshot chainstate.
@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 25, 2024

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 fjahr, BrandonOdiwuor, hernanmarino, byaye

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

Copy link
Contributor

@BrandonOdiwuor BrandonOdiwuor left a comment

Choose a reason for hiding this comment

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

Concept ACK

Copy link
Contributor

@fjahr fjahr left a comment

Choose a reason for hiding this comment

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

tACK cfdef5c

Good catch! I could reproduce the crash and that the change here fixes this.

My suggested test extension can be pulled in here if you retouch or I can add it to one of my outstanding assumeutxo PRs as a small follow-up.

@@ -278,6 +275,18 @@ def check_tx_counts(final: bool) -> None:

assert_equal(n1.getblockchaininfo()["blocks"], SNAPSHOT_BASE_HEIGHT)

self.log.info(f"Check that restarting with -reindex will delete the snapshot chainstate")
self.restart_node(1, extra_args=['-reindex=1', *self.extra_args[1]])
Copy link
Contributor

@fjahr fjahr Mar 27, 2024

Choose a reason for hiding this comment

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

This only covers -reindex but not -reindex-chainstate. It's easily possible when using node 2 for the test instead which is not pruned: fjahr@38c5d80

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I took your suggestion (with a minor change to logging).

Copy link
Contributor

@BrandonOdiwuor BrandonOdiwuor left a comment

Choose a reason for hiding this comment

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

crACK cfdef5c

Co-authored-by: Fabian Jahr <fjahr@protonmail.com>
@mzumsande mzumsande force-pushed the 202403_assumeutxo_reindex_fix branch from cfdef5c to b7ba60f Compare March 28, 2024 17:24
@mzumsande
Copy link
Contributor Author

cfdef5c to b7ba60f: Included test coverage for -reindex-chainstate as suggested by @fjahr

@fjahr
Copy link
Contributor

fjahr commented Mar 29, 2024

re-ACK b7ba60f

Copy link
Contributor

@BrandonOdiwuor BrandonOdiwuor left a comment

Choose a reason for hiding this comment

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

re-ACK b7ba60f

@hernanmarino
Copy link
Contributor

crACK b7ba60f . Good fix

Copy link

@byaye byaye left a comment

Choose a reason for hiding this comment

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

Tested ACK b7ba60f

Test result before the fix
Screenshot 2024-04-12 at 17 34 14

Test result after the fix
Screenshot 2024-04-12 at 17 21 48

@ryanofsky ryanofsky merged commit 312f542 into bitcoin:master Apr 16, 2024
16 checks passed
@mzumsande mzumsande deleted the 202403_assumeutxo_reindex_fix branch April 16, 2024 18:13
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Apr 24, 2024
This didn't work for two reasons:
1.) GetSnapshotCoinsDBPath() was used to retrieve the path.
    This requires coins_views to exist, but the initialisation only happens later
    (in CompleteChainstateInitialization) so the node hits an assert in
    CCoinsViewDB& CoinsDB() and crashes.

2.) The snapshot was already activated, so it has the mempool attached.
    Therefore, the mempool needs to be transferred back to the ibd
    chainstate before deleting the snapshot chainstate.

Github-Pull: bitcoin#29726
Rebased-From: e57f951
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Apr 24, 2024
Co-authored-by: Fabian Jahr <fjahr@protonmail.com>

Github-Pull: bitcoin#29726
Rebased-From: b7ba60f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

7 participants