Skip to content

Commit 931684b

Browse files
committed
validation: fix ActivateSnapshot to use hardcoded nChainTx
This fixes an oversight from the move of nChainTx from the user-supplied snapshot metadata into the hardcoded assumeutxo chainparams. Since the nChainTx is now unused in the metadata, it should be removed in a future commit.
1 parent 773f8c1 commit 931684b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/node/utxo_snapshot.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class SnapshotMetadata
2424

2525
//! Necessary to "fake" the base nChainTx so that we can estimate progress during
2626
//! initial block download for the assumeutxo chainstate.
27+
//!
28+
//! TODO: this is unused and should be removed.
2729
unsigned int m_nchaintx = 0;
2830

2931
SnapshotMetadata() { }

src/test/validation_chainstatemanager_tests.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup)
233233

234234
// Mine 10 more blocks, putting at us height 110 where a valid assumeutxo value can
235235
// be found.
236+
constexpr int snapshot_height = 110;
236237
mineBlocks(10);
237238
initial_size += 10;
238239
initial_total_coins += 10;
@@ -265,14 +266,31 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup)
265266
metadata.m_base_blockhash = uint256::ONE;
266267
}));
267268

268-
BOOST_REQUIRE(CreateAndActivateUTXOSnapshot(m_node, m_path_root));
269+
constexpr int bad_nchaintx = 9999;
270+
271+
BOOST_REQUIRE(CreateAndActivateUTXOSnapshot(
272+
m_node, m_path_root, [](CAutoFile& auto_infile, SnapshotMetadata& metadata) {
273+
// Provide an nChainTx that differs from the hardcoded one.
274+
//
275+
// Ultimately this malleation check should be removed when we remove
276+
// the now-unnecessary nChainTx from the user-specified snapshot metadata.
277+
metadata.m_nchaintx = bad_nchaintx;
278+
}));
269279

270280
// Ensure our active chain is the snapshot chainstate.
271281
BOOST_CHECK(!chainman.ActiveChainstate().m_from_snapshot_blockhash.IsNull());
272282
BOOST_CHECK_EQUAL(
273283
chainman.ActiveChainstate().m_from_snapshot_blockhash,
274284
*chainman.SnapshotBlockhash());
275285

286+
const AssumeutxoData& au_data = *ExpectedAssumeutxo(snapshot_height, ::Params());
287+
const CBlockIndex* tip = chainman.ActiveTip();
288+
289+
// Ensure that, despite a bad nChainTx value being in the snapshot, activation
290+
// uses the hardcoded value from chainparams.
291+
BOOST_CHECK_EQUAL(tip->nChainTx, au_data.nChainTx);
292+
BOOST_CHECK(tip->nChainTx != bad_nchaintx);
293+
276294
// To be checked against later when we try loading a subsequent snapshot.
277295
uint256 loaded_snapshot_blockhash{*chainman.SnapshotBlockhash()};
278296

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5346,7 +5346,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
53465346
}
53475347

53485348
assert(index);
5349-
index->nChainTx = metadata.m_nchaintx;
5349+
index->nChainTx = au_data.nChainTx;
53505350
snapshot_chainstate.setBlockIndexCandidates.insert(snapshot_start_block);
53515351

53525352
LogPrintf("[snapshot] validated snapshot (%.2f MB)\n",

0 commit comments

Comments
 (0)