Skip to content

Failed AssumeUTXO snapshot activation leaves shared block-index metadata changed #37078

Backlog

Description

@l0rinc

PopulateAndValidateSnapshot() changes shared block-index fields before ActivateSnapshot() has finished. If activation later fails (as when writing base_blockhash fails), the snapshot chainstate is discarded but the base block keeps its snapshot transaction count and the modified entries remain dirty. With block-index checks enabled, the next connected block then aborts the node in CheckBlockIndex().

Reproducer
diff --git a/src/test/validation_chainstate_tests.cpp b/src/test/validation_chainstate_tests.cpp
index d8fb378171..b841f3aac7 100644
--- a/src/test/validation_chainstate_tests.cpp
+++ b/src/test/validation_chainstate_tests.cpp
@@ -173,4 +173,19 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
     BOOST_CHECK_EQUAL(curr_tip, get_notify_tip());
 }
 
+BOOST_FIXTURE_TEST_CASE(failed_snapshot_activation_changes_block_index, TestChain100Setup)
+{
+    ChainstateManager& chainman{*Assert(m_node.chainman)};
+    mineBlocks(10);
+    CBlockIndex* base{WITH_LOCK(::cs_main, return chainman.ActiveTip())};
+
+    BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot(this, [&](AutoFile&, node::SnapshotMetadata&) {
+        fs::create_directories(chainman.m_options.datadir / "chainstate_snapshot" / node::SNAPSHOT_BLOCKHASH_FILENAME);
+    }, /*reset_chainstate=*/true));
+
+    LOCK(::cs_main);
+    BOOST_CHECK(chainman.CurrentChainstate().SnapshotBase() == nullptr);
+    BOOST_CHECK_NE(base->m_chain_tx_count, 0); // TODO: Leave the shared block index unchanged after a failed activation
+}
+
 BOOST_AUTO_TEST_SUITE_END()

The direct fix would be to apply the shared block-index changes only after activation succeeds, but given that AssumeUTXO fixes haven't attracted much review, I'm proposing to remove AssumeUTXO entirely in #36598 instead.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions