Skip to content

Commit 2bc6332

Browse files
committed
Merge pull request #6010
c1ecee8 Set nSequenceId when a block is fully linked (Suhas Daftuar)
2 parents 6a0bcb8 + c1ecee8 commit 2bc6332

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,10 +2350,6 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl
23502350
pindexNew->nUndoPos = 0;
23512351
pindexNew->nStatus |= BLOCK_HAVE_DATA;
23522352
pindexNew->RaiseValidity(BLOCK_VALID_TRANSACTIONS);
2353-
{
2354-
LOCK(cs_nBlockSequenceId);
2355-
pindexNew->nSequenceId = nBlockSequenceId++;
2356-
}
23572353
setDirtyBlockIndex.insert(pindexNew);
23582354

23592355
if (pindexNew->pprev == NULL || pindexNew->pprev->nChainTx) {
@@ -2366,6 +2362,10 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl
23662362
CBlockIndex *pindex = queue.front();
23672363
queue.pop_front();
23682364
pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx;
2365+
{
2366+
LOCK(cs_nBlockSequenceId);
2367+
pindex->nSequenceId = nBlockSequenceId++;
2368+
}
23692369
if (chainActive.Tip() == NULL || !setBlockIndexCandidates.value_comp()(pindex, chainActive.Tip())) {
23702370
setBlockIndexCandidates.insert(pindex);
23712371
}
@@ -3282,6 +3282,7 @@ void static CheckBlockIndex()
32823282
// HAVE_DATA is equivalent to VALID_TRANSACTIONS and equivalent to nTx > 0 (we stored the number of transactions in the block)
32833283
assert(!(pindex->nStatus & BLOCK_HAVE_DATA) == (pindex->nTx == 0));
32843284
assert(((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_TRANSACTIONS) == (pindex->nTx > 0));
3285+
if (pindex->nChainTx == 0) assert(pindex->nSequenceId == 0); // nSequenceId can't be set for blocks that aren't linked
32853286
// All parents having data is equivalent to all parents being VALID_TRANSACTIONS, which is equivalent to nChainTx being set.
32863287
assert((pindexFirstMissing != NULL) == (pindex->nChainTx == 0)); // nChainTx == 0 is used to signal that all parent block's transaction data is available.
32873288
assert((pindexFirstNotTransactionsValid != NULL) == (pindex->nChainTx == 0));

0 commit comments

Comments
 (0)