Skip to content

AssumeUTXO snapshot base invalidated during loadtxoutset can still be activated #37056

Backlog

Description

@l0rinc

loadtxoutset rejects an invalid snapshot base before loading the coins, but doesn't check again before activating the snapshot. If the base is invalidated while the coins load, the snapshot is still activated on the invalid block and stays active after restart.

Reproducer
diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py
index fa9466f2d8..2d3ee1b126 100755
--- a/test/functional/feature_assumeutxo.py
+++ b/test/functional/feature_assumeutxo.py
@@ -10,6 +10,8 @@ The assumeutxo value generated and used here is committed to in
 `CRegTestParams::m_assumeutxo_data` in `src/kernel/chainparams.cpp`.
 """
 import contextlib
+import os
+import threading
 
 from dataclasses import dataclass
 from test_framework.blocktools import (
@@ -370,6 +372,39 @@ class AssumeutxoTest(BitcoinTestFramework):
         self.log.info("Snapshot node should reorg to the most-work chain without the snapshot block")
         self.sync_blocks(nodes=(snapshot_node, forking_node))
 
+    def test_snapshot_base_invalidated_during_load(self, snapshot):
+        n0 = self.nodes[0]
+        node = self.nodes[3]
+        self.log.info("Test that a snapshot base invalidated during population is still activated")
+        assert_equal(node.getblockcount(), START_HEIGHT)
+
+        with open(snapshot['path'], 'rb') as f:
+            snapshot_data = f.read()
+        metadata_size = 51  # magic, version, network magic, base hash and coin count
+        fifo_path = os.path.join(self.options.tmpdir, "snapshot.fifo")
+        os.mkfifo(fifo_path)
+
+        loader = threading.Thread(target=node.create_new_rpc_connection().loadtxoutset, args=(fifo_path,))
+        loader.start()
+        with open(fifo_path, 'wb') as fifo:
+            with node.assert_debug_log(["[snapshot] loading"], timeout=30):
+                fifo.write(snapshot_data[:metadata_size])
+                fifo.flush()
+            node.invalidateblock(snapshot['base_hash'])
+            assert any(tip['hash'] == snapshot['base_hash'] and
+                       tip['status'] == 'invalid' for tip in node.getchaintips())
+            fifo.write(snapshot_data[metadata_size:])
+        loader.join()
+
+        assert_equal(node.getblockcount(), SNAPSHOT_BASE_HEIGHT)
+        self.restart_node(node.index, extra_args=self.extra_args[node.index])
+        assert_equal(node.getblockcount(), SNAPSHOT_BASE_HEIGHT)
+
+        # Discard the snapshot so later tests can reuse the node.
+        self.restart_node(node.index, extra_args=["-reindex", *self.extra_args[node.index]])
+        for height in range(START_HEIGHT + 1, SNAPSHOT_BASE_HEIGHT + 1):
+            node.submitheader(n0.getblock(n0.getblockhash(height), 0))
+
     def assert_only_network_limited_service(self, node):
         node_services = node.getnetworkinfo()['localservicesnames']
         assert 'NETWORK' not in node_services
@@ -464,6 +499,8 @@ class AssumeutxoTest(BitcoinTestFramework):
         for n in self.nodes:
             assert_equal(n.getblockchaininfo()["headers"], SNAPSHOT_BASE_HEIGHT)
 
+        self.test_snapshot_base_invalidated_during_load(dump_output)
+
         assert_equal(n0.getblockchaininfo()["blocks"], SNAPSHOT_BASE_HEIGHT)
 
         def check_dump_output(output):

The direct fix would be to recheck the base before the snapshot updates the block index (completing #30267), 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