mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
assumeutxo: Get rid of faked nTx and nChainTx values
The `PopulateAndValidateSnapshot` function introduced in
f6e2da5fb7 from #19806 has been setting fake
`nTx` and `nChainTx` values that can show up in RPC results (see #29328) and
make `CBlockIndex` state hard to reason about, because it is difficult to know
whether the values are real or fake.
Revert to previous behavior of setting `nTx` and `nChainTx` to 0 when the
values are unknown, instead of faking them.
This commit fixes at least two assert failures in the (pindex->nChainTx ==
pindex->nTx + prev_chain_tx) check that would happen previously. Tests for
these failures are added separately in the next two commits.
Compatibility note: This change could result in -checkblockindex failures if a
snapshot was loaded by a previous version of Bitcoin Core and not fully
validated, because fake nTx values will have been saved to the block index. It
would be pretty easy to avoid these failures by adding some compatibility code
to `LoadBlockIndex` and changing `nTx` values from 1 to 0 when they are fake
(when `(pindex->nStatus & BLOCK_VALID_MASK) < BLOCK_VALID_TRANSACTIONS`), but a
little simpler not to worry about being compatible in this case.
This commit is contained in:
@@ -91,13 +91,16 @@ CreateAndActivateUTXOSnapshot(
|
||||
// these blocks instead
|
||||
CBlockIndex *pindex = orig_tip;
|
||||
while (pindex && pindex != chain.m_chain.Tip()) {
|
||||
pindex->nStatus &= ~BLOCK_HAVE_DATA;
|
||||
pindex->nStatus &= ~BLOCK_HAVE_UNDO;
|
||||
// We have to set the ASSUMED_VALID flag, because otherwise it
|
||||
// would not be possible to have a block index entry without HAVE_DATA
|
||||
// and with nTx > 0 (since we aren't setting the pruned flag);
|
||||
// see CheckBlockIndex().
|
||||
pindex->nStatus |= BLOCK_ASSUMED_VALID;
|
||||
// Remove all data and validity flags by just setting
|
||||
// BLOCK_VALID_TREE. Also reset transaction counts and sequence
|
||||
// ids that are set when blocks are received, to make test setup
|
||||
// more realistic and satisfy consistency checks in
|
||||
// CheckBlockIndex().
|
||||
assert(pindex->IsValid(BlockStatus::BLOCK_VALID_TREE));
|
||||
pindex->nStatus = BlockStatus::BLOCK_VALID_TREE;
|
||||
pindex->nTx = 0;
|
||||
pindex->nChainTx = 0;
|
||||
pindex->nSequenceId = 0;
|
||||
pindex = pindex->pprev;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user