Skip to content

Commit 19ce3d4

Browse files
fjahralfonsoromanz
andcommitted
assumeutxo: Check snapshot base block is not marked invalid
Co-authored-by: Alfonso Roman Zubeldia <alfonsoromanz24@gmail.com>
1 parent 80315c0 commit 19ce3d4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/validation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5677,6 +5677,11 @@ util::Result<void> ChainstateManager::ActivateSnapshot(
56775677
base_blockhash.ToString())};
56785678
}
56795679

5680+
bool start_block_invalid = snapshot_start_block->nStatus & BLOCK_FAILED_MASK;
5681+
if (start_block_invalid) {
5682+
return util::Error{strprintf(_("The base block header (%s) is part of an invalid chain."), base_blockhash.ToString())};
5683+
}
5684+
56805685
if (Assert(m_active_chainstate->GetMempool())->size() > 0) {
56815686
return util::Error{_("Can't activate a snapshot when mempool not empty.")};
56825687
}

test/functional/feature_assumeutxo.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ def test_snapshot_with_less_work(self, dump_output_path):
205205
assert_raises_rpc_error(-32603, "Unable to load UTXO snapshot", node.loadtxoutset, dump_output_path)
206206
self.restart_node(0, extra_args=self.extra_args[0])
207207

208+
def test_snapshot_block_invalidated(self, dump_output_path):
209+
self.log.info("Test snapshot is not loaded when base block is invalid.")
210+
node = self.nodes[0]
211+
# We are testing the case where the base block is invalidated itself
212+
# and also the case where one of its parents is invalidated.
213+
for height in [SNAPSHOT_BASE_HEIGHT, SNAPSHOT_BASE_HEIGHT - 1]:
214+
block_hash = node.getblockhash(height)
215+
node.invalidateblock(block_hash)
216+
assert_equal(node.getblockcount(), height - 1)
217+
msg = "Unable to load UTXO snapshot: The base block header (3bb7ce5eba0be48939b7a521ac1ba9316afee2c7bada3a0cca24188e6d7d96c0) is part of an invalid chain."
218+
assert_raises_rpc_error(-32603, msg, node.loadtxoutset, dump_output_path)
219+
node.reconsiderblock(block_hash)
220+
208221
def run_test(self):
209222
"""
210223
Bring up two (disconnected) nodes, mine some new blocks on the first,
@@ -291,6 +304,7 @@ def run_test(self):
291304
self.test_invalid_snapshot_scenarios(dump_output['path'])
292305
self.test_invalid_chainstate_scenarios()
293306
self.test_invalid_file_path()
307+
self.test_snapshot_block_invalidated(dump_output['path'])
294308

295309
self.log.info(f"Loading snapshot into second node from {dump_output['path']}")
296310
loaded = n1.loadtxoutset(dump_output['path'])

0 commit comments

Comments
 (0)