mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-12 10:30:08 +01:00
Make nSequenceId init value constants
Make it easier to follow what the values come without having to go over the comments, plus easier to maintain
This commit is contained in:
parent
c8f5e6234f
commit
c7f9061d55
4 changed files with 16 additions and 10 deletions
|
@ -35,6 +35,9 @@ static constexpr int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60;
|
|||
* MAX_FUTURE_BLOCK_TIME.
|
||||
*/
|
||||
static constexpr int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME;
|
||||
//! Init values for CBlockIndex nSequenceId when loaded from disk
|
||||
static constexpr int32_t SEQ_ID_BEST_CHAIN_FROM_DISK = 0;
|
||||
static constexpr int32_t SEQ_ID_INIT_FROM_DISK = 1;
|
||||
|
||||
/**
|
||||
* Maximum gap between node time and block time used
|
||||
|
@ -191,9 +194,9 @@ public:
|
|||
uint32_t nNonce{0};
|
||||
|
||||
//! (memory only) Sequential id assigned to distinguish order in which blocks are received.
|
||||
//! Initialized to 1 when loading blocks from disk, except for blocks belonging to the best chain
|
||||
//! which overwrite it to 0.
|
||||
int32_t nSequenceId{1};
|
||||
//! Initialized to SEQ_ID_INIT_FROM_DISK{1} when loading blocks from disk, except for blocks
|
||||
//! belonging to the best chain which overwrite it to SEQ_ID_BEST_CHAIN_FROM_DISK{0}.
|
||||
int32_t nSequenceId{SEQ_ID_INIT_FROM_DISK};
|
||||
|
||||
//! (memory only) Maximum nTime in the chain up to and including this block.
|
||||
unsigned int nTimeMax{0};
|
||||
|
|
|
@ -215,7 +215,7 @@ CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block, CBlockInde
|
|||
// We assign the sequence id to blocks only when the full data is available,
|
||||
// to avoid miners withholding blocks but broadcasting headers, to get a
|
||||
// competitive advantage.
|
||||
pindexNew->nSequenceId = 1;
|
||||
pindexNew->nSequenceId = SEQ_ID_INIT_FROM_DISK;
|
||||
|
||||
pindexNew->phashBlock = &((*mi).first);
|
||||
BlockMap::iterator miPrev = m_block_index.find(block.hashPrevBlock);
|
||||
|
|
|
@ -4724,7 +4724,7 @@ bool Chainstate::LoadChainTip()
|
|||
// to maintain a consistent best tip over reboots
|
||||
auto target = tip;
|
||||
while (target) {
|
||||
target->nSequenceId = 0;
|
||||
target->nSequenceId = SEQ_ID_BEST_CHAIN_FROM_DISK;
|
||||
target = target->pprev;
|
||||
}
|
||||
|
||||
|
@ -5379,7 +5379,9 @@ void ChainstateManager::CheckBlockIndex()
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!pindex->HaveNumChainTxs()) assert(pindex->nSequenceId <= 1); // nSequenceId can't be set higher than 1 for blocks that aren't linked (negative is used for preciousblock, 0 for active chain)
|
||||
// nSequenceId can't be set higher than SEQ_ID_INIT_FROM_DISK{1} for blocks that aren't linked
|
||||
// (negative is used for preciousblock, SEQ_ID_BEST_CHAIN_FROM_DISK{0} for active chain when loaded from disk)
|
||||
if (!pindex->HaveNumChainTxs()) assert(pindex->nSequenceId <= SEQ_ID_INIT_FROM_DISK);
|
||||
// VALID_TRANSACTIONS is equivalent to nTx > 0 for all nodes (whether or not pruning has occurred).
|
||||
// HAVE_DATA is only equivalent to nTx > 0 (or VALID_TRANSACTIONS) if no pruning has occurred.
|
||||
if (!m_blockman.m_have_pruned) {
|
||||
|
|
|
@ -1021,9 +1021,10 @@ public:
|
|||
* Every received block is assigned a unique and increasing identifier, so we
|
||||
* know which one to give priority in case of a fork.
|
||||
*/
|
||||
/** Blocks loaded from disk are assigned id 1 (0 if they belong to the best
|
||||
* chain loaded from disk), so start the counter at 2. **/
|
||||
int32_t nBlockSequenceId GUARDED_BY(::cs_main) = 2;
|
||||
/** Blocks loaded from disk are assigned id SEQ_ID_INIT_FROM_DISK{1}
|
||||
* (SEQ_ID_BEST_CHAIN_FROM_DISK{0} if they belong to the best chain loaded from disk),
|
||||
* so start the counter after that. **/
|
||||
int32_t nBlockSequenceId GUARDED_BY(::cs_main) = SEQ_ID_INIT_FROM_DISK + 1;
|
||||
/** Decreasing counter (used by subsequent preciousblock calls). */
|
||||
int32_t nBlockReverseSequenceId = -1;
|
||||
/** chainwork for the last block that preciousblock has been applied to. */
|
||||
|
@ -1034,7 +1035,7 @@ public:
|
|||
void ResetBlockSequenceCounters() EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
|
||||
{
|
||||
AssertLockHeld(::cs_main);
|
||||
nBlockSequenceId = 2;
|
||||
nBlockSequenceId = SEQ_ID_INIT_FROM_DISK + 1;
|
||||
nBlockReverseSequenceId = -1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue