mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 11:57:28 -03:00
validation: move nChainTx assert down in CheckBlockIndex
There is a designated section meant for the actual consistency checks, marked by a comment.
This commit is contained in:
parent
033477dba6
commit
9819db4cca
1 changed files with 9 additions and 10 deletions
|
@ -4862,16 +4862,6 @@ void ChainstateManager::CheckBlockIndex()
|
|||
CBlockIndex* pindexFirstAssumeValid = nullptr; // Oldest ancestor of pindex which has BLOCK_ASSUMED_VALID
|
||||
while (pindex != nullptr) {
|
||||
nNodes++;
|
||||
// Make sure nChainTx sum is correctly computed.
|
||||
unsigned int prev_chain_tx = pindex->pprev ? pindex->pprev->nChainTx : 0;
|
||||
assert((pindex->nChainTx == pindex->nTx + prev_chain_tx)
|
||||
// Transaction may be completely unset - happens if only the header was accepted but the block hasn't been processed.
|
||||
|| (pindex->nChainTx == 0 && pindex->nTx == 0)
|
||||
// nChainTx may be unset, but nTx set (if a block has been accepted, but one of its predecessors hasn't been processed yet)
|
||||
|| (pindex->nChainTx == 0 && prev_chain_tx == 0 && pindex->pprev)
|
||||
// Transaction counts prior to snapshot are unknown.
|
||||
|| pindex->IsAssumedValid());
|
||||
|
||||
if (pindexFirstAssumeValid == nullptr && pindex->nStatus & BLOCK_ASSUMED_VALID) pindexFirstAssumeValid = pindex;
|
||||
if (pindexFirstInvalid == nullptr && pindex->nStatus & BLOCK_FAILED_VALID) pindexFirstInvalid = pindex;
|
||||
if (pindexFirstMissing == nullptr && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
|
||||
|
@ -4954,6 +4944,15 @@ void ChainstateManager::CheckBlockIndex()
|
|||
// Checks for not-invalid blocks.
|
||||
assert((pindex->nStatus & BLOCK_FAILED_MASK) == 0); // The failed mask cannot be set for blocks without invalid parents.
|
||||
}
|
||||
// Make sure nChainTx sum is correctly computed.
|
||||
unsigned int prev_chain_tx = pindex->pprev ? pindex->pprev->nChainTx : 0;
|
||||
assert((pindex->nChainTx == pindex->nTx + prev_chain_tx)
|
||||
// Transaction may be completely unset - happens if only the header was accepted but the block hasn't been processed.
|
||||
|| (pindex->nChainTx == 0 && pindex->nTx == 0)
|
||||
// nChainTx may be unset, but nTx set (if a block has been accepted, but one of its predecessors hasn't been processed yet)
|
||||
|| (pindex->nChainTx == 0 && prev_chain_tx == 0 && pindex->pprev)
|
||||
// Transaction counts prior to snapshot are unknown.
|
||||
|| pindex->IsAssumedValid());
|
||||
// Chainstate-specific checks on setBlockIndexCandidates
|
||||
for (auto c : GetAll()) {
|
||||
if (c->m_chain.Tip() == nullptr) continue;
|
||||
|
|
Loading…
Reference in a new issue