Set nSequenceId when a block is fully linked
Also adds a test to CheckBlockIndex
Conflicts:
src/main.cpp
Rebased-From: c1ecee8f72
Github-Pull: #6010
This commit is contained in:
parent
3a70613398
commit
bac6fca3c9
13
src/main.cpp
13
src/main.cpp
|
@ -2319,10 +2319,6 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl
|
||||||
pindexNew->nUndoPos = 0;
|
pindexNew->nUndoPos = 0;
|
||||||
pindexNew->nStatus |= BLOCK_HAVE_DATA;
|
pindexNew->nStatus |= BLOCK_HAVE_DATA;
|
||||||
pindexNew->RaiseValidity(BLOCK_VALID_TRANSACTIONS);
|
pindexNew->RaiseValidity(BLOCK_VALID_TRANSACTIONS);
|
||||||
{
|
|
||||||
LOCK(cs_nBlockSequenceId);
|
|
||||||
pindexNew->nSequenceId = nBlockSequenceId++;
|
|
||||||
}
|
|
||||||
setDirtyBlockIndex.insert(pindexNew);
|
setDirtyBlockIndex.insert(pindexNew);
|
||||||
|
|
||||||
if (pindexNew->pprev == NULL || pindexNew->pprev->nChainTx) {
|
if (pindexNew->pprev == NULL || pindexNew->pprev->nChainTx) {
|
||||||
|
@ -2335,6 +2331,10 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl
|
||||||
CBlockIndex *pindex = queue.front();
|
CBlockIndex *pindex = queue.front();
|
||||||
queue.pop_front();
|
queue.pop_front();
|
||||||
pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx;
|
pindex->nChainTx = (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx;
|
||||||
|
{
|
||||||
|
LOCK(cs_nBlockSequenceId);
|
||||||
|
pindex->nSequenceId = nBlockSequenceId++;
|
||||||
|
}
|
||||||
if (chainActive.Tip() == NULL || !setBlockIndexCandidates.value_comp()(pindex, chainActive.Tip())) {
|
if (chainActive.Tip() == NULL || !setBlockIndexCandidates.value_comp()(pindex, chainActive.Tip())) {
|
||||||
setBlockIndexCandidates.insert(pindex);
|
setBlockIndexCandidates.insert(pindex);
|
||||||
}
|
}
|
||||||
|
@ -3272,6 +3272,11 @@ void static CheckBlockIndex()
|
||||||
assert(pindex->GetBlockHash() == Params().HashGenesisBlock()); // Genesis block's hash must match.
|
assert(pindex->GetBlockHash() == Params().HashGenesisBlock()); // Genesis block's hash must match.
|
||||||
assert(pindex == chainActive.Genesis()); // The current active chain's genesis block must be this block.
|
assert(pindex == chainActive.Genesis()); // The current active chain's genesis block must be this block.
|
||||||
}
|
}
|
||||||
|
// HAVE_DATA is equivalent to VALID_TRANSACTIONS and equivalent to nTx > 0 (we stored the number of transactions in the block)
|
||||||
|
assert(!(pindex->nStatus & BLOCK_HAVE_DATA) == (pindex->nTx == 0));
|
||||||
|
assert(((pindex->nStatus & BLOCK_VALID_MASK) >= BLOCK_VALID_TRANSACTIONS) == (pindex->nTx > 0));
|
||||||
|
if (pindex->nChainTx == 0) assert(pindex->nSequenceId == 0); // nSequenceId can't be set for blocks that aren't linked
|
||||||
|
// All parents having data is equivalent to all parents being VALID_TRANSACTIONS, which is equivalent to nChainTx being set.
|
||||||
assert((pindexFirstMissing != NULL) == (pindex->nChainTx == 0)); // nChainTx == 0 is used to signal that all parent block's transaction data is available.
|
assert((pindexFirstMissing != NULL) == (pindex->nChainTx == 0)); // nChainTx == 0 is used to signal that all parent block's transaction data is available.
|
||||||
assert(pindex->nHeight == nHeight); // nHeight must be consistent.
|
assert(pindex->nHeight == nHeight); // nHeight must be consistent.
|
||||||
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.
|
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.
|
||||||
|
|
Loading…
Reference in New Issue