Skip to content

AssumeUTXO snapshot activation can abort when a transaction arrives during loading #37076

Backlog

Description

@l0rinc

loadtxoutset checks that the mempool is empty, then releases cs_main while it loads the snapshot.
A transaction accepted in that interval leaves the mempool nonempty when AddChainstate() asserts the opposite, aborting the node.

Reproducer

The node aborts on the empty-mempool assertion in AddChainstate(), so the final check fails.

diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py
index fa9466f2d8..65cba8e172 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 (
@@ -207,6 +209,24 @@ class AssumeutxoTest(BitcoinTestFramework):
 
         self.restart_node(2, extra_args=self.extra_args[2])
 
+    def test_mempool_arrival_during_load(self, snapshot_path):
+        node = self.nodes[2]
+        with open(snapshot_path, "rb") as f:
+            snapshot = f.read()
+        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.busy_wait_for_debug_log([b"[snapshot] loading"]):
+                fifo.write(snapshot[:51])
+                fifo.flush()
+            node.sendrawtransaction(MiniWallet(node).create_self_transfer()["hex"])
+            fifo.write(snapshot[51:])
+        loader.join()
+        assert node.process.poll() is None  # TODO: A transaction arriving during loading must not abort activation
+
     def test_invalid_file_path(self):
         self.log.info("Test bitcoind should fail when file path is invalid.")
         node = self.nodes[0]
@@ -511,6 +531,7 @@ class AssumeutxoTest(BitcoinTestFramework):
         assert_equal(n0.getblockchaininfo()["blocks"], FINAL_HEIGHT)
 
         self.test_snapshot_with_less_work(dump_output['path'])
+        self.test_mempool_arrival_during_load(dump_output['path'])
         self.test_invalid_mempool_state(dump_output['path'])
         self.test_invalid_snapshot_scenarios(dump_output['path'])
         self.test_invalid_chainstate_scenarios()

A narrow fix could block mempool admission during loading (as closed #36346 proposed) or recheck the mempool before activation. Both add snapshot-specific mempool handling, so 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