Skip to content

A missing AssumeUTXO snapshot base header causes a startup null dereference #37071

Backlog

Description

@l0rinc

Startup checks the snapshot's base hash against the AssumeUTXO chain parameters, but not whether the local block index contains that header. If the block index is lost while a snapshot chainstate remains, startup dereferences the missing entry and crashes with a segmentation fault on every restart, without recovery guidance.

Reproducer
diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py
index fa9466f2d8..1732e87a26 100755
--- a/test/functional/feature_assumeutxo.py
+++ b/test/functional/feature_assumeutxo.py
@@ -10,6 +10,7 @@ The assumeutxo value generated and used here is committed to in
 `CRegTestParams::m_assumeutxo_data` in `src/kernel/chainparams.cpp`.
 """
 import contextlib
+import shutil
 
 from dataclasses import dataclass
 from test_framework.blocktools import (
@@ -391,6 +392,20 @@ class AssumeutxoTest(BitcoinTestFramework):
 
         assert not (node.datadir_path / node.chain / "chainstate_snapshot").exists()
 
+    def test_block_index_missing_base_block(self):
+        self.log.info("Test that a snapshot base block missing from the block index crashes startup")
+        node = self.nodes[2]
+        # This node still runs on a snapshot-based chainstate at this point.
+        assert (node.chain_path / "chainstate_snapshot").exists()
+
+        node.stop_node()
+        # Deleting the block index is a common remedy for block index corruption. The freshly
+        # created index then no longer contains the block the snapshot chainstate is based on.
+        shutil.rmtree(node.blocks_path / "index")
+
+        node.start()
+        node.wait_until_stopped(expected_ret_code=-11)  # TODO: Explain how to recover instead of crashing on the missing base block
+
     def run_test(self):
         """
         Bring up two (disconnected) nodes, mine some new blocks on the first,
@@ -811,6 +826,8 @@ class AssumeutxoTest(BitcoinTestFramework):
 
         self.test_sync_to_most_work_chain_after_background_validation()
 
+        self.test_block_index_missing_base_block()
+
 @dataclass
 class Block:
     hash: str

The direct fix would be to reject the missing header and explain how to rebuild the index or discard the snapshot, but given that this persisted dependency disappears with snapshot loading, 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