Skip to content

Commit 312f542

Browse files
committed
Merge bitcoin/bitcoin#29726: assumeutxo: Fix -reindex before snapshot was validated
b7ba60f test: add coverage for -reindex and assumeutxo (Martin Zumsande) e57f951 init, validation: Fix -reindex option with an existing snapshot (Martin Zumsande) Pull request description: In c711ca1 logic was introduced that `-reindex` and `-reindex-chainstate` will delete the snapshot chainstate. This doesn't work currently, instead of deleting the snapshot chainstate the node crashes with an assert (this can be triggered by applying the added test commit on master). Fix this, and another bug that would prevent the new active chainstate from having a mempool after `-reindex` has deleted the snapshot (also covered by the test). ACKs for top commit: fjahr: re-ACK b7ba60f hernanmarino: crACK b7ba60f . Good fix BrandonOdiwuor: re-ACK b7ba60f byaye: Tested ACK b7ba60f Tree-SHA512: c168f36997d7677d590af37b10427870f5d30123abf1c76032a16661e486735373bfa7e049e6aca439526fbcb6d619f970bf9d042196c851bf058a75a32fafdc
2 parents c7567d9 + b7ba60f commit 312f542

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/validation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6142,13 +6142,14 @@ bool ChainstateManager::DeleteSnapshotChainstate()
61426142
Assert(m_snapshot_chainstate);
61436143
Assert(m_ibd_chainstate);
61446144

6145-
fs::path snapshot_datadir = GetSnapshotCoinsDBPath(*m_snapshot_chainstate);
6145+
fs::path snapshot_datadir = Assert(node::FindSnapshotChainstateDir(m_options.datadir)).value();
61466146
if (!DeleteCoinsDBFromDisk(snapshot_datadir, /*is_snapshot=*/ true)) {
61476147
LogPrintf("Deletion of %s failed. Please remove it manually to continue reindexing.\n",
61486148
fs::PathToString(snapshot_datadir));
61496149
return false;
61506150
}
61516151
m_active_chainstate = m_ibd_chainstate.get();
6152+
m_active_chainstate->m_mempool = m_snapshot_chainstate->m_mempool;
61526153
m_snapshot_chainstate.reset();
61536154
return true;
61546155
}

test/functional/feature_assumeutxo.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
1212
## Possible test improvements
1313
14-
- TODO: test what happens with -reindex and -reindex-chainstate before the
15-
snapshot is validated, and make sure it's deleted successfully.
16-
1714
Interesting test cases could be loading an assumeutxo snapshot file with:
1815
1916
- TODO: Valid hash but invalid snapshot file (bad coin height or
@@ -379,6 +376,17 @@ def check_tx_counts(final: bool) -> None:
379376
assert_equal(loaded['coins_loaded'], SNAPSHOT_BASE_HEIGHT)
380377
assert_equal(loaded['base_height'], SNAPSHOT_BASE_HEIGHT)
381378

379+
for reindex_arg in ['-reindex=1', '-reindex-chainstate=1']:
380+
self.log.info(f"Check that restarting with {reindex_arg} will delete the snapshot chainstate")
381+
self.restart_node(2, extra_args=[reindex_arg, *self.extra_args[2]])
382+
assert_equal(1, len(n2.getchainstates()["chainstates"]))
383+
for i in range(1, 300):
384+
block = n0.getblock(n0.getblockhash(i), 0)
385+
n2.submitheader(block)
386+
loaded = n2.loadtxoutset(dump_output['path'])
387+
assert_equal(loaded['coins_loaded'], SNAPSHOT_BASE_HEIGHT)
388+
assert_equal(loaded['base_height'], SNAPSHOT_BASE_HEIGHT)
389+
382390
normal, snapshot = n2.getchainstates()['chainstates']
383391
assert_equal(normal['blocks'], START_HEIGHT)
384392
assert_equal(normal.get('snapshot_blockhash'), None)

0 commit comments

Comments
 (0)