Skip to content

Commit bac6fca

Browse files
sdaftuarlaanwj
authored andcommitted
Set nSequenceId when a block is fully linked
Also adds a test to CheckBlockIndex Conflicts: src/main.cpp Rebased-From: c1ecee8 Github-Pull: bitcoin#6010
1 parent 3a70613 commit bac6fca

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,10 +2319,6 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl
23192319
pindexNew->nUndoPos = 0;
23202320
pindexNew->nStatus |= BLOCK_HAVE_DATA;
23212321
pindexNew->RaiseValidity(BLOCK_VALID_TRANSACTIONS);
2322-
{
2323-
LOCK(cs_nBlockSequenceId);
2324-
pindexNew->nSequenceId = nBlockSequenceId++;
2325-
}
23262322
setDirtyBlockIndex.insert(pindexNew);
23272323

23282324
if (pindexNew->pprev == NULL || pindexNew->pprev->nChainTx) {
@@ -2335,6 +2331,10 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl
23352331
CBlockIndex *pindex = queue.front();
23362332
queue.pop_front();
23372333
pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx;
2334+
{
2335+
LOCK(cs_nBlockSequenceId);
2336+
pindex->nSequenceId = nBlockSequenceId++;
2337+
}
23382338
if (chainActive.Tip() == NULL || !setBlockIndexCandidates.value_comp()(pindex, chainActive.Tip())) {
23392339
setBlockIndexCandidates.insert(pindex);
23402340
}
@@ -3272,6 +3272,11 @@ void static CheckBlockIndex()
32723272
assert(pindex->GetBlockHash() == Params().HashGenesisBlock()); // Genesis block's hash must match.
32733273
assert(pindex == chainActive.Genesis()); // The current active chain's genesis block must be this block.
32743274
}
3275+
// HAVE_DATA is equivalent to VALID_TRANSACTIONS and equivalent to nTx > 0 (we stored the number of transactions in the block)
3276+
assert(!(pindex->nStatus & BLOCK_HAVE_DATA) == (pindex->nTx == 0));
3277+
assert(((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_TRANSACTIONS) == (pindex->nTx > 0));
3278+
if (pindex->nChainTx == 0) assert(pindex->nSequenceId == 0); // nSequenceId can't be set for blocks that aren't linked
3279+
// All parents having data is equivalent to all parents being VALID_TRANSACTIONS, which is equivalent to nChainTx being set.
32753280
assert((pindexFirstMissing != NULL) == (pindex->nChainTx == 0)); // nChainTx == 0 is used to signal that all parent block's transaction data is available.
32763281
assert(pindex->nHeight == nHeight); // nHeight must be consistent.
32773282
assert(pindex->pprev == NULL || pindex->nChainWork >= pindex->pprev->nChainWork); // For every block except the genesis block, the chainwork must be larger than the parent's.

0 commit comments

Comments
 (0)