mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-13 11:25:02 -05:00
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.
This commit is contained in:
parent
773f8c1a7d
commit
931684b24a
3 changed files with 22 additions and 2 deletions
|
@ -24,6 +24,8 @@ public:
|
||||||
|
|
||||||
//! Necessary to "fake" the base nChainTx so that we can estimate progress during
|
//! Necessary to "fake" the base nChainTx so that we can estimate progress during
|
||||||
//! initial block download for the assumeutxo chainstate.
|
//! initial block download for the assumeutxo chainstate.
|
||||||
|
//!
|
||||||
|
//! TODO: this is unused and should be removed.
|
||||||
unsigned int m_nchaintx = 0;
|
unsigned int m_nchaintx = 0;
|
||||||
|
|
||||||
SnapshotMetadata() { }
|
SnapshotMetadata() { }
|
||||||
|
|
|
@ -233,6 +233,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup)
|
||||||
|
|
||||||
// Mine 10 more blocks, putting at us height 110 where a valid assumeutxo value can
|
// Mine 10 more blocks, putting at us height 110 where a valid assumeutxo value can
|
||||||
// be found.
|
// be found.
|
||||||
|
constexpr int snapshot_height = 110;
|
||||||
mineBlocks(10);
|
mineBlocks(10);
|
||||||
initial_size += 10;
|
initial_size += 10;
|
||||||
initial_total_coins += 10;
|
initial_total_coins += 10;
|
||||||
|
@ -265,7 +266,16 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup)
|
||||||
metadata.m_base_blockhash = uint256::ONE;
|
metadata.m_base_blockhash = uint256::ONE;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
BOOST_REQUIRE(CreateAndActivateUTXOSnapshot(m_node, m_path_root));
|
constexpr int bad_nchaintx = 9999;
|
||||||
|
|
||||||
|
BOOST_REQUIRE(CreateAndActivateUTXOSnapshot(
|
||||||
|
m_node, m_path_root, [](CAutoFile& auto_infile, SnapshotMetadata& metadata) {
|
||||||
|
// Provide an nChainTx that differs from the hardcoded one.
|
||||||
|
//
|
||||||
|
// Ultimately this malleation check should be removed when we remove
|
||||||
|
// the now-unnecessary nChainTx from the user-specified snapshot metadata.
|
||||||
|
metadata.m_nchaintx = bad_nchaintx;
|
||||||
|
}));
|
||||||
|
|
||||||
// Ensure our active chain is the snapshot chainstate.
|
// Ensure our active chain is the snapshot chainstate.
|
||||||
BOOST_CHECK(!chainman.ActiveChainstate().m_from_snapshot_blockhash.IsNull());
|
BOOST_CHECK(!chainman.ActiveChainstate().m_from_snapshot_blockhash.IsNull());
|
||||||
|
@ -273,6 +283,14 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup)
|
||||||
chainman.ActiveChainstate().m_from_snapshot_blockhash,
|
chainman.ActiveChainstate().m_from_snapshot_blockhash,
|
||||||
*chainman.SnapshotBlockhash());
|
*chainman.SnapshotBlockhash());
|
||||||
|
|
||||||
|
const AssumeutxoData& au_data = *ExpectedAssumeutxo(snapshot_height, ::Params());
|
||||||
|
const CBlockIndex* tip = chainman.ActiveTip();
|
||||||
|
|
||||||
|
// Ensure that, despite a bad nChainTx value being in the snapshot, activation
|
||||||
|
// uses the hardcoded value from chainparams.
|
||||||
|
BOOST_CHECK_EQUAL(tip->nChainTx, au_data.nChainTx);
|
||||||
|
BOOST_CHECK(tip->nChainTx != bad_nchaintx);
|
||||||
|
|
||||||
// To be checked against later when we try loading a subsequent snapshot.
|
// To be checked against later when we try loading a subsequent snapshot.
|
||||||
uint256 loaded_snapshot_blockhash{*chainman.SnapshotBlockhash()};
|
uint256 loaded_snapshot_blockhash{*chainman.SnapshotBlockhash()};
|
||||||
|
|
||||||
|
|
|
@ -5346,7 +5346,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(index);
|
assert(index);
|
||||||
index->nChainTx = metadata.m_nchaintx;
|
index->nChainTx = au_data.nChainTx;
|
||||||
snapshot_chainstate.setBlockIndexCandidates.insert(snapshot_start_block);
|
snapshot_chainstate.setBlockIndexCandidates.insert(snapshot_start_block);
|
||||||
|
|
||||||
LogPrintf("[snapshot] validated snapshot (%.2f MB)\n",
|
LogPrintf("[snapshot] validated snapshot (%.2f MB)\n",
|
||||||
|
|
Loading…
Add table
Reference in a new issue