Skip to content

Commit 9819db4

Browse files
committed
validation: move nChainTx assert down in CheckBlockIndex
There is a designated section meant for the actual consistency checks, marked by a comment.
1 parent 033477d commit 9819db4

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/validation.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4862,16 +4862,6 @@ void ChainstateManager::CheckBlockIndex()
48624862
CBlockIndex* pindexFirstAssumeValid = nullptr; // Oldest ancestor of pindex which has BLOCK_ASSUMED_VALID
48634863
while (pindex != nullptr) {
48644864
nNodes++;
4865-
// Make sure nChainTx sum is correctly computed.
4866-
unsigned int prev_chain_tx = pindex->pprev ? pindex->pprev->nChainTx : 0;
4867-
assert((pindex->nChainTx == pindex->nTx + prev_chain_tx)
4868-
// Transaction may be completely unset - happens if only the header was accepted but the block hasn't been processed.
4869-
|| (pindex->nChainTx == 0 && pindex->nTx == 0)
4870-
// nChainTx may be unset, but nTx set (if a block has been accepted, but one of its predecessors hasn't been processed yet)
4871-
|| (pindex->nChainTx == 0 && prev_chain_tx == 0 && pindex->pprev)
4872-
// Transaction counts prior to snapshot are unknown.
4873-
|| pindex->IsAssumedValid());
4874-
48754865
if (pindexFirstAssumeValid == nullptr && pindex->nStatus & BLOCK_ASSUMED_VALID) pindexFirstAssumeValid = pindex;
48764866
if (pindexFirstInvalid == nullptr && pindex->nStatus & BLOCK_FAILED_VALID) pindexFirstInvalid = pindex;
48774867
if (pindexFirstMissing == nullptr && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
@@ -4954,6 +4944,15 @@ void ChainstateManager::CheckBlockIndex()
49544944
// Checks for not-invalid blocks.
49554945
assert((pindex->nStatus & BLOCK_FAILED_MASK) == 0); // The failed mask cannot be set for blocks without invalid parents.
49564946
}
4947+
// Make sure nChainTx sum is correctly computed.
4948+
unsigned int prev_chain_tx = pindex->pprev ? pindex->pprev->nChainTx : 0;
4949+
assert((pindex->nChainTx == pindex->nTx + prev_chain_tx)
4950+
// Transaction may be completely unset - happens if only the header was accepted but the block hasn't been processed.
4951+
|| (pindex->nChainTx == 0 && pindex->nTx == 0)
4952+
// nChainTx may be unset, but nTx set (if a block has been accepted, but one of its predecessors hasn't been processed yet)
4953+
|| (pindex->nChainTx == 0 && prev_chain_tx == 0 && pindex->pprev)
4954+
// Transaction counts prior to snapshot are unknown.
4955+
|| pindex->IsAssumedValid());
49574956
// Chainstate-specific checks on setBlockIndexCandidates
49584957
for (auto c : GetAll()) {
49594958
if (c->m_chain.Tip() == nullptr) continue;

0 commit comments

Comments
 (0)