Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
CChainState stores and provides an API to update our local knowledge of the current best chain and header tree. More...
Public Member Functions | |
bool | LoadBlockIndex (const Consensus::Params &consensus_params, CBlockTreeDB &blocktree) |
bool | ActivateBestChain (CValidationState &state, const CChainParams &chainparams, std::shared_ptr< const CBlock > pblock) |
Make the best chain active, in multiple steps. More... | |
bool | AcceptBlockHeader (const CBlockHeader &block, CValidationState &state, const CChainParams &chainparams, CBlockIndex **ppindex) |
bool | AcceptBlock (const std::shared_ptr< const CBlock > &pblock, CValidationState &state, const CChainParams &chainparams, CBlockIndex **ppindex, bool fRequested, const CDiskBlockPos *dbp, bool *fNewBlock) |
Store block on disk. More... | |
DisconnectResult | DisconnectBlock (const CBlock &block, const CBlockIndex *pindex, CCoinsViewCache &view) |
Undo the effects of this block (with given index) on the UTXO set represented by coins. More... | |
bool | ConnectBlock (const CBlock &block, CValidationState &state, CBlockIndex *pindex, CCoinsViewCache &view, const CChainParams &chainparams, bool fJustCheck=false) |
Apply the effects of this block (with given index) on the UTXO set represented by coins. More... | |
bool | DisconnectTip (CValidationState &state, const CChainParams &chainparams, DisconnectedBlockTransactions *disconnectpool) |
Disconnect chainActive's tip. More... | |
bool | PreciousBlock (CValidationState &state, const CChainParams ¶ms, CBlockIndex *pindex) |
bool | InvalidateBlock (CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex) |
bool | ResetBlockFailureFlags (CBlockIndex *pindex) |
bool | ReplayBlocks (const CChainParams ¶ms, CCoinsView *view) |
bool | RewindBlockIndex (const CChainParams ¶ms) |
bool | LoadGenesisBlock (const CChainParams &chainparams) |
bool | AddGenesisBlock (const CChainParams &chainparams, const CBlock &block, CValidationState &state) |
void | PruneBlockIndexCandidates () |
Delete all entries in setBlockIndexCandidates that are worse than the current tip. More... | |
void | UnloadBlockIndex () |
Public Attributes | |
CChain | chainActive |
BlockMap | mapBlockIndex |
PrevBlockMap | mapPrevBlockIndex |
std::multimap< CBlockIndex *, CBlockIndex * > | mapBlocksUnlinked |
CBlockIndex * | pindexBestInvalid = nullptr |
Private Member Functions | |
bool | ActivateBestChainStep (CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindexMostWork, const std::shared_ptr< const CBlock > &pblock, bool &fInvalidFound, ConnectTrace &connectTrace) |
Try to make some progress towards making pindexMostWork the active block. More... | |
bool | ConnectTip (CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindexNew, const std::shared_ptr< const CBlock > &pblock, ConnectTrace &connectTrace, DisconnectedBlockTransactions &disconnectpool) |
Connect a new block to chainActive. More... | |
CBlockIndex * | AddToBlockIndex (const CBlockHeader &block, enum BlockStatus nStatus=BLOCK_VALID_TREE) |
CBlockIndex * | InsertBlockIndex (const uint256 &hash) |
Create a new block index entry for a given block hash. More... | |
void | CheckBlockIndex (const Consensus::Params &consensusParams) |
void | InvalidBlockFound (CBlockIndex *pindex, const CValidationState &state) |
CBlockIndex * | FindMostWorkChain () |
Return the tip of the chain with the most work in it, that isn't known to be invalid (it's however far from certain to be valid). More... | |
bool | ReceivedBlockTransactions (const CBlock &block, CValidationState &state, CBlockIndex *pindexNew, const CDiskBlockPos &pos) |
Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS). More... | |
bool | RollforwardBlock (const CBlockIndex *pindex, CCoinsViewCache &inputs, const CChainParams ¶ms) |
Apply the effects of a block on the utxo cache, ignoring that it may already have been applied. More... | |
Private Attributes | |
std::set< CBlockIndex *, CBlockIndexWorkComparator > | setBlockIndexCandidates |
The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS (for itself and all ancestors) and as good as our current tip or better. More... | |
CCriticalSection | cs_nBlockSequenceId |
Every received block is assigned a unique and increasing identifier, so we know which one to give priority in case of a fork. More... | |
int32_t | nBlockSequenceId = 1 |
Blocks loaded from disk are assigned id 0, so start the counter at 1. More... | |
int32_t | nBlockReverseSequenceId = -1 |
Decreasing counter (used by subsequent preciousblock calls). More... | |
arith_uint256 | nLastPreciousChainwork = 0 |
chainwork for the last block that preciousblock has been applied to. More... | |
std::set< CBlockIndex * > | g_failed_blocks |
In order to efficiently track invalidity of headers, we keep the set of blocks which we tried to connect and found to be invalid here (ie which were set to BLOCK_FAILED_VALID since the last restart). More... | |
Detailed Description
CChainState stores and provides an API to update our local knowledge of the current best chain and header tree.
It generally provides access to the current block tree, as well as functions to provide new data, which it will appropriately validate and incorporate in its state as necessary.
Eventually, the API here is targeted at being exposed externally as a consumable libconsensus library, so any functions added must only call other class member functions, pure functions in other parts of the consensus library, callbacks via the validation interface, or read/write-to-disk functions (eventually this will also be via callbacks).
Definition at line 117 of file validation.cpp.
Member Function Documentation
◆ AcceptBlock()
bool CChainState::AcceptBlock | ( | const std::shared_ptr< const CBlock > & | pblock, |
CValidationState & | state, | ||
const CChainParams & | chainparams, | ||
CBlockIndex ** | ppindex, | ||
bool | fRequested, | ||
const CDiskBlockPos * | dbp, | ||
bool * | fNewBlock | ||
) |
Store block on disk.
If dbp is non-nullptr, the file is known to already reside on disk
Definition at line 3722 of file validation.cpp.
References AcceptBlockHeader(), AssertLockHeld(), BLOCK_FAILED_VALID, BLOCK_HAVE_DATA, chainActive, CheckBlock(), CheckBlockIndex(), ContextualCheckBlock(), CValidationState::CorruptionPossible(), cs_main, CValidationState::Error(), error(), FLUSH_STATE_NONE, FlushStateToDisk(), FormatStateMessage(), CChainParams::GetConsensus(), GetMainSignals(), CChain::Height(), IsInitialBlockDownload(), CValidationState::IsInvalid(), CDiskBlockPos::IsNull(), MIN_BLOCKS_TO_KEEP, CBlockIndex::nChainWork, CMainSignals::NewPoWValidBlock(), CBlockIndex::nHeight, nMinimumChainWork, CBlockIndex::nStatus, CBlockIndex::nTx, CBlockIndex::pprev, ReceivedBlockTransactions(), SaveBlockToDisk(), strprintf, and CChain::Tip().
Referenced by LoadExternalBlockFile(), LoadGenesisBlock(), and ProcessNewBlock().
◆ AcceptBlockHeader()
bool CChainState::AcceptBlockHeader | ( | const CBlockHeader & | block, |
CValidationState & | state, | ||
const CChainParams & | chainparams, | ||
CBlockIndex ** | ppindex | ||
) |
Definition at line 3603 of file validation.cpp.
References CMainSignals::AcceptedBlockHeader(), AddToBlockIndex(), AssertLockHeld(), BLOCK_CONFLICT_CHAINLOCK, BLOCK_FAILED_CHILD, BLOCK_FAILED_MASK, BLOCK_FAILED_VALID, BLOCK_VALID_SCRIPTS, llmq::chainLocksHandler, CheckBlockHeader(), CheckBlockIndex(), ContextualCheckBlockHeader(), cs_main, CValidationState::DoS(), error(), FormatStateMessage(), g_failed_blocks, GetAdjustedTime(), CChainParams::GetConsensus(), CBlockHeader::GetHash(), GetMainSignals(), Consensus::Params::hashGenesisBlock, CBlockHeader::hashPrevBlock, CValidationState::Invalid(), mapBlockIndex, CBlockIndex::nStatus, CBlockIndex::pprev, REJECT_INVALID, and base_blob< BITS >::ToString().
Referenced by AcceptBlock(), and ProcessNewBlockHeaders().
◆ ActivateBestChain()
bool CChainState::ActivateBestChain | ( | CValidationState & | state, |
const CChainParams & | chainparams, | ||
std::shared_ptr< const CBlock > | pblock | ||
) |
Make the best chain active, in multiple steps.
The result is either failure or an activated best chain. pblock is either nullptr or a pointer to a block that is already loaded (to avoid loading it again from disk).
Definition at line 2981 of file validation.cpp.
References ActivateBestChainStep(), AssertLockNotHeld, CMainSignals::BlockConnected(), chainActive, CheckBlockIndex(), cs_main, DEFAULT_STOPATHEIGHT, CChain::FindFork(), FindMostWorkChain(), FLUSH_STATE_PERIODIC, FlushStateToDisk(), gArgs, ArgsManager::GetArg(), CBlockIndex::GetBlockHash(), ConnectTrace::GetBlocksConnected(), CChainParams::GetConsensus(), GetMainSignals(), IsInitialBlockDownload(), LOCK, mempool, CBlockIndex::nHeight, CClientUIInterface::NotifyBlockTip, ShutdownRequested(), StartShutdown(), CMainSignals::SynchronousUpdatedBlockTip(), SyncWithValidationInterfaceQueue(), CChain::Tip(), uiInterface, and CMainSignals::UpdatedBlockTip().
Referenced by ActivateBestChain(), PreciousBlock(), and ProcessNewBlock().
◆ ActivateBestChainStep()
|
private |
Try to make some progress towards making pindexMostWork the active block.
pblock is either nullptr or a pointer to a CBlock corresponding to pindexMostWork.
Definition at line 2873 of file validation.cpp.
References AssertLockHeld(), chainActive, CTxMemPool::check(), CheckForkWarningConditions(), CheckForkWarningConditionsOnNewFork(), ConnectTip(), CValidationState::CorruptionPossible(), cs_main, DisconnectTip(), CChain::FindFork(), CBlockIndex::GetAncestor(), InvalidChainFound(), CValidationState::IsInvalid(), mempool, CBlockIndex::nChainWork, CBlockIndex::nHeight, pcoinsTip, CBlockIndex::pprev, PruneBlockIndexCandidates(), reverse_iterate(), CChain::Tip(), and UpdateMempoolForReorg().
Referenced by ActivateBestChain().
◆ AddGenesisBlock()
bool CChainState::AddGenesisBlock | ( | const CChainParams & | chainparams, |
const CBlock & | block, | ||
CValidationState & | state | ||
) |
Definition at line 4527 of file validation.cpp.
References AddToBlockIndex(), error(), CDiskBlockPos::IsNull(), ReceivedBlockTransactions(), and SaveBlockToDisk().
Referenced by LoadGenesisBlock().
◆ AddToBlockIndex()
|
private |
Definition at line 3222 of file validation.cpp.
References BLOCK_VALID_MASK, BLOCK_VALID_TREE, GetBlockProof(), CBlockHeader::GetHash(), CBlockHeader::hashPrevBlock, mapBlockIndex, mapPrevBlockIndex, CBlockIndex::nChainWork, CBlockIndex::nSequenceId, pindexBestHeader, and CBlockIndex::RaiseValidity().
Referenced by AcceptBlockHeader(), and AddGenesisBlock().
◆ CheckBlockIndex()
|
private |
Definition at line 4694 of file validation.cpp.
References BLOCK_FAILED_MASK, BLOCK_FAILED_VALID, BLOCK_HAVE_DATA, BLOCK_HAVE_UNDO, BLOCK_VALID_CHAIN, BLOCK_VALID_MASK, BLOCK_VALID_SCRIPTS, BLOCK_VALID_TRANSACTIONS, BLOCK_VALID_TREE, chainActive, cs_main, fCheckBlockIndex, fHavePruned, CChain::Genesis(), CBlockIndex::GetBlockHash(), Consensus::Params::hashGenesisBlock, CChain::Height(), LOCK, mapBlockIndex, mapBlocksUnlinked, CBlockIndex::nChainTx, CBlockIndex::nChainWork, CBlockIndex::nHeight, CBlockIndex::nSequenceId, CBlockIndex::nStatus, CBlockIndex::nTx, CBlockIndex::pprev, CBlockIndex::pskip, setBlockIndexCandidates, and CChain::Tip().
Referenced by AcceptBlock(), AcceptBlockHeader(), and ActivateBestChain().
◆ ConnectBlock()
bool CChainState::ConnectBlock | ( | const CBlock & | block, |
CValidationState & | state, | ||
CBlockIndex * | pindex, | ||
CCoinsViewCache & | view, | ||
const CChainParams & | chainparams, | ||
bool | fJustCheck = false |
||
) |
Apply the effects of this block (with given index) on the UTXO set represented by coins.
Validity checks that depend on the UTXO set are also done; ConnectBlock() can fail if those validity checks fail (among other reasons).
DASH: Check superblock start
END DASH
Definition at line 1983 of file validation.cpp.
References CCoinsViewCache::AccessCoin(), CCheckQueueControl< T >::Add(), AssertLockHeld(), prevector< N, T, Size, Diff >::begin(), BCLog::BENCHMARK, Consensus::Params::BIP34Hash, Consensus::Params::BIP34Height, BLOCK_VALID_SCRIPTS, llmq::chainLocksHandler, CheckBlock(), CheckInputs(), Consensus::CheckTxInputs(), cs_main, Consensus::DEPLOYMENT_CSV, Consensus::Params::DIP0001Height, Consensus::Params::DIP0003Height, CValidationState::DoS(), prevector< N, T, Size, Diff >::end(), error(), evoDb, fAddressIndex, flags, FormatStateMessage(), fSpentIndex, fTimestampIndex, CBlockIndex::GetAncestor(), CCoinsViewCache::GetBestBlock(), CBlockIndex::GetBlockHash(), GetBlockProofEquivalentTime(), GetBlockScriptFlags(), GetBlockSubsidy(), llmq::CInstantSendManager::GetConflictingLock(), CChainParams::GetConsensus(), CBlockHeader::GetHash(), CTransaction::GetHash(), GetTimeMicros(), GetTransactionSigOpCount(), llmq::CChainLocksHandler::HasConflictingChainLock(), COutPoint::hash, Hash160(), hashAssumeValid, Consensus::Params::hashGenesisBlock, CCoinsViewCache::HaveCoin(), IsBlockPayeeValid(), IsBlockValueValid(), CTransaction::IsCoinBase(), base_blob< BITS >::IsNull(), CScript::IsPayToPublicKey(), CScript::IsPayToPublicKeyHash(), CScript::IsPayToScriptHash(), CSporkManager::IsSporkActive(), CBlockIndex::IsValid(), LOCK, LOCKTIME_VERIFY_SEQUENCE, LogPrint, LogPrintf, mapBlockIndex, MaxBlockSigOps(), MICRO, MILLI, MoneyRange(), COutPoint::n, CBlockIndex::nBits, nBlocksTotal, CBlockIndex::nChainWork, Coin::nHeight, CBlockIndex::nHeight, nMinimumChainWork, nScriptCheckThreads, Consensus::Params::nSuperblockStartBlock, Consensus::Params::nSuperblockStartHash, CBlockIndex::nTime, nTimeCallbacks, nTimeCheck, nTimeConnect, nTimeDashSpecific, nTimeForks, nTimeIndex, nTimeISFilter, nTimePayeeValid, nTimeProcessSpecial, nTimeSubsidy, nTimeValueValid, nTimeVerify, CTxOut::nValue, Coin::out, Params(), pblocktree, CBlockIndex::phashBlock, pindexBestHeader, CBlockIndex::pprev, CTxIn::prevout, ProcessSpecialTxsInBlock(), llmq::quorumInstantSendManager, CBlockIndex::RaiseValidity(), REJECT_INVALID, llmq::CInstantSendManager::RemoveChainLockConflictingLock(), scriptcheckqueue, CTxOut::scriptPubKey, SequenceLocks(), SerializeHash(), CCoinsViewCache::SetBestBlock(), base_blob< BITS >::SetNull(), SPORK_3_INSTANTSEND_BLOCK_FILTERING, sporkManager, THRESHOLD_ACTIVE, base_blob< BITS >::ToString(), uint256S(), UpdateCoins(), versionbitscache, VersionBitsState(), CTransaction::vin, CTransaction::vout, CBlock::vtx, CBlockUndo::vtxundo, CCheckQueueControl< T >::Wait(), WriteTxIndexDataForBlock(), and WriteUndoDataForBlock().
Referenced by ConnectTip(), TestBlockValidity(), and CVerifyDB::VerifyDB().
◆ ConnectTip()
|
private |
Connect a new block to chainActive.
pblock is either nullptr or a pointer to a CBlock corresponding to pindexNew, to bypass loading it again from disk.
The block is added to connectTrace if connection succeeds.
Definition at line 2741 of file validation.cpp.
References BCLog::BENCHMARK, CMainSignals::BlockChecked(), ConnectTrace::BlockConnected(), chainActive, ConnectBlock(), error(), evoDb, FLUSH_STATE_IF_NEEDED, FlushStateToDisk(), FormatStateMessage(), CBlockIndex::GetBlockHash(), CChainParams::GetConsensus(), GetMainSignals(), GetTimeMicros(), InvalidBlockFound(), CValidationState::IsInvalid(), LogPrint, mempool, MICRO, MILLI, nBlocksTotal, CBlockIndex::nHeight, nTimeChainState, nTimeConnectTotal, nTimeFlush, nTimePostConnect, nTimeReadFromDisk, nTimeTotal, pcoinsTip, CBlockIndex::pprev, ReadBlockFromDisk(), CTxMemPool::removeForBlock(), DisconnectedBlockTransactions::removeForBlock(), CChain::SetTip(), CChain::Tip(), base_blob< BITS >::ToString(), UpdateTip(), and CBlock::vtx.
Referenced by ActivateBestChainStep().
◆ DisconnectBlock()
DisconnectResult CChainState::DisconnectBlock | ( | const CBlock & | block, |
const CBlockIndex * | pindex, | ||
CCoinsViewCache & | view | ||
) |
Undo the effects of this block (with given index) on the UTXO set represented by coins.
When FAILED is returned, view is left in an indeterminate state.
Definition at line 1631 of file validation.cpp.
References CCoinsViewCache::AccessCoin(), ApplyTxInUndo(), prevector< N, T, Size, Diff >::begin(), Consensus::Params::DIP0003Height, DISCONNECT_FAILED, DISCONNECT_OK, DISCONNECT_UNCLEAN, prevector< N, T, Size, Diff >::end(), error(), evoDb, fAddressIndex, Coin::fCoinBase, fSpentIndex, CBlockIndex::GetBlockHash(), CChainParams::GetConsensus(), CTransaction::GetHash(), COutPoint::hash, Hash160(), CTransaction::IsCoinBase(), CScript::IsPayToPublicKey(), CScript::IsPayToPublicKeyHash(), CScript::IsPayToScriptHash(), COutPoint::n, Coin::nHeight, CBlockIndex::nHeight, CTxOut::nValue, Coin::out, Params(), pblocktree, CBlockIndex::pprev, CTxIn::prevout, CTxOut::scriptPubKey, CCoinsViewCache::SetBestBlock(), CCoinsViewCache::SpendCoin(), UndoSpecialTxsInBlock(), CTransaction::vin, CTransaction::vout, CTxUndo::vprevout, CBlock::vtx, and CBlockUndo::vtxundo.
Referenced by DisconnectTip(), ReplayBlocks(), and CVerifyDB::VerifyDB().
◆ DisconnectTip()
bool CChainState::DisconnectTip | ( | CValidationState & | state, |
const CChainParams & | chainparams, | ||
DisconnectedBlockTransactions * | disconnectpool | ||
) |
Disconnect chainActive's tip.
After calling, the mempool will be in an inconsistent state, with transactions from disconnected blocks being added to disconnectpool. You should make the mempool consistent again by calling UpdateMempoolForReorg. with cs_main held.
If disconnectpool is nullptr, then no disconnected transactions are added to disconnectpool (note that the caller is responsible for mempool consistency in any case).
Definition at line 2615 of file validation.cpp.
References DisconnectedBlockTransactions::addTransaction(), BCLog::BENCHMARK, CMainSignals::BlockDisconnected(), chainActive, DISCONNECT_OK, DisconnectBlock(), DisconnectedBlockTransactions::DynamicMemoryUsage(), error(), evoDb, FLUSH_STATE_IF_NEEDED, FlushStateToDisk(), CBlockIndex::GetBlockHash(), CChainParams::GetConsensus(), GetMainSignals(), GetTimeMicros(), LogPrint, MAX_DISCONNECTED_TX_POOL_SIZE, mempool, MILLI, pcoinsTip, CBlockIndex::pprev, DisconnectedBlockTransactions::queuedTx, ReadBlockFromDisk(), DisconnectedBlockTransactions::removeEntry(), CTxMemPool::removeRecursive(), REORG, CChain::SetTip(), CChain::Tip(), base_blob< BITS >::ToString(), and UpdateTip().
Referenced by ActivateBestChainStep(), and InvalidateBlock().
◆ FindMostWorkChain()
|
private |
Return the tip of the chain with the most work in it, that isn't known to be invalid (it's however far from certain to be valid).
Definition at line 2803 of file validation.cpp.
References BLOCK_FAILED_CHILD, BLOCK_FAILED_MASK, BLOCK_HAVE_DATA, chainActive, CChain::Contains(), mapBlocksUnlinked, CBlockIndex::nChainTx, CBlockIndex::nChainWork, CBlockIndex::nHeight, CBlockIndex::nStatus, pindexBestInvalid, CBlockIndex::pprev, and setBlockIndexCandidates.
Referenced by ActivateBestChain().
◆ InsertBlockIndex()
|
private |
Create a new block index entry for a given block hash.
Definition at line 4070 of file validation.cpp.
References base_blob< BITS >::IsNull(), and mapBlockIndex.
◆ InvalidateBlock()
bool CChainState::InvalidateBlock | ( | CValidationState & | state, |
const CChainParams & | chainparams, | ||
CBlockIndex * | pindex | ||
) |
Definition at line 3108 of file validation.cpp.
References AssertLockHeld(), BLOCK_FAILED_CHILD, BLOCK_FAILED_VALID, BLOCK_VALID_TRANSACTIONS, chainActive, CChain::Contains(), cs_main, DisconnectTip(), g_failed_blocks, GetMainSignals(), InvalidChainFound(), IsInitialBlockDownload(), mapBlockIndex, CClientUIInterface::NotifyBlockTip, CBlockIndex::nStatus, pindexBestHeader, pindexBestInvalid, CBlockIndex::pprev, setBlockIndexCandidates, CMainSignals::SynchronousUpdatedBlockTip(), CChain::Tip(), uiInterface, CMainSignals::UpdatedBlockTip(), and UpdateMempoolForReorg().
Referenced by InvalidateBlock().
◆ InvalidBlockFound()
|
private |
Definition at line 1361 of file validation.cpp.
References BLOCK_FAILED_VALID, CValidationState::CorruptionPossible(), g_failed_blocks, InvalidChainFound(), CBlockIndex::nStatus, and setBlockIndexCandidates.
Referenced by ConnectTip().
◆ LoadBlockIndex()
bool CChainState::LoadBlockIndex | ( | const Consensus::Params & | consensus_params, |
CBlockTreeDB & | blocktree | ||
) |
Definition at line 4088 of file validation.cpp.
References BLOCK_FAILED_CHILD, BLOCK_FAILED_MASK, BLOCK_VALID_TRANSACTIONS, BLOCK_VALID_TREE, CBlockIndex::BuildSkip(), CBlockIndex::GetBlockHash(), GetBlockProof(), CBlockIndex::IsValid(), CBlockTreeDB::LoadBlockIndexGuts(), mapBlockIndex, mapBlocksUnlinked, mapPrevBlockIndex, CBlockIndex::nChainTx, CBlockIndex::nChainWork, CBlockIndex::nHeight, CBlockIndex::nStatus, CBlockIndex::nTime, CBlockIndex::nTimeMax, CBlockIndex::nTx, pindexBestHeader, pindexBestInvalid, CBlockIndex::pprev, and setBlockIndexCandidates.
Referenced by LoadBlockIndexDB().
◆ LoadGenesisBlock()
bool CChainState::LoadGenesisBlock | ( | const CChainParams & | chainparams | ) |
Definition at line 4538 of file validation.cpp.
References AcceptBlock(), AddGenesisBlock(), CheckBlock(), cs_main, CBaseChainParams::DEVNET, CChainParams::DevNetGenesisBlock(), error(), CChainParams::GenesisBlock(), CChainParams::GetConsensus(), CBlockHeader::GetHash(), LOCK, mapBlockIndex, and CChainParams::NetworkIDString().
Referenced by LoadGenesisBlock().
◆ PreciousBlock()
bool CChainState::PreciousBlock | ( | CValidationState & | state, |
const CChainParams & | params, | ||
CBlockIndex * | pindex | ||
) |
Definition at line 3076 of file validation.cpp.
References ActivateBestChain(), BLOCK_VALID_TRANSACTIONS, chainActive, cs_main, CBlockIndex::IsValid(), LOCK, nBlockReverseSequenceId, CBlockIndex::nChainTx, CBlockIndex::nChainWork, nLastPreciousChainwork, CBlockIndex::nSequenceId, PruneBlockIndexCandidates(), setBlockIndexCandidates, and CChain::Tip().
Referenced by PreciousBlock().
◆ PruneBlockIndexCandidates()
void CChainState::PruneBlockIndexCandidates | ( | ) |
Delete all entries in setBlockIndexCandidates that are worse than the current tip.
Definition at line 2858 of file validation.cpp.
References chainActive, setBlockIndexCandidates, and CChain::Tip().
Referenced by ActivateBestChainStep(), LoadChainTip(), and PreciousBlock().
◆ ReceivedBlockTransactions()
|
private |
Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS).
Definition at line 3267 of file validation.cpp.
References BLOCK_HAVE_DATA, BLOCK_VALID_TRANSACTIONS, chainActive, cs_nBlockSequenceId, LOCK, mapBlocksUnlinked, nBlockSequenceId, CBlockIndex::nChainTx, CBlockIndex::nDataPos, CDiskBlockPos::nFile, CBlockIndex::nFile, CDiskBlockPos::nPos, CBlockIndex::nSequenceId, CBlockIndex::nStatus, CBlockIndex::nTx, CBlockIndex::nUndoPos, CBlockIndex::pprev, CBlockIndex::RaiseValidity(), setBlockIndexCandidates, CChain::Tip(), and CBlock::vtx.
Referenced by AcceptBlock(), and AddGenesisBlock().
◆ ReplayBlocks()
bool CChainState::ReplayBlocks | ( | const CChainParams & | params, |
CCoinsView * | view | ||
) |
Definition at line 4378 of file validation.cpp.
References _(), cs_main, DISCONNECT_FAILED, DisconnectBlock(), error(), evoDb, CCoinsViewCache::Flush(), CBlockIndex::GetAncestor(), CBlockIndex::GetBlockHash(), CChainParams::GetConsensus(), CCoinsView::GetHeadBlocks(), LastCommonAncestor(), LOCK, LogPrintf, mapBlockIndex, CBlockIndex::nHeight, CBlockIndex::pprev, ReadBlockFromDisk(), RollforwardBlock(), CCoinsViewCache::SetBestBlock(), CClientUIInterface::ShowProgress, base_blob< BITS >::ToString(), and uiInterface.
Referenced by ReplayBlocks().
◆ ResetBlockFailureFlags()
bool CChainState::ResetBlockFailureFlags | ( | CBlockIndex * | pindex | ) |
Definition at line 3184 of file validation.cpp.
References AssertLockHeld(), BLOCK_FAILED_MASK, BLOCK_VALID_TRANSACTIONS, chainActive, cs_main, g_failed_blocks, mapBlockIndex, CBlockIndex::nHeight, CBlockIndex::nStatus, pindexBestInvalid, CBlockIndex::pprev, setBlockIndexCandidates, and CChain::Tip().
Referenced by ResetBlockFailureFlags().
◆ RewindBlockIndex()
bool CChainState::RewindBlockIndex | ( | const CChainParams & | params | ) |
◆ RollforwardBlock()
|
private |
Apply the effects of a block on the utxo cache, ignoring that it may already have been applied.
Definition at line 4351 of file validation.cpp.
References AddCoins(), error(), FormatStateMessage(), CBlockIndex::GetBlockHash(), CChainParams::GetConsensus(), CBlockIndex::nHeight, CTxIn::prevout, ProcessSpecialTxsInBlock(), ReadBlockFromDisk(), CCoinsViewCache::SpendCoin(), base_blob< BITS >::ToString(), and CBlock::vtx.
Referenced by ReplayBlocks().
◆ UnloadBlockIndex()
void CChainState::UnloadBlockIndex | ( | ) |
Definition at line 4455 of file validation.cpp.
References g_failed_blocks, nBlockSequenceId, and setBlockIndexCandidates.
Referenced by UnloadBlockIndex().
Member Data Documentation
◆ chainActive
CChain CChainState::chainActive |
Definition at line 159 of file validation.cpp.
Referenced by AcceptBlock(), ActivateBestChain(), ActivateBestChainStep(), CheckBlockIndex(), ConnectTip(), DisconnectTip(), FindMostWorkChain(), InvalidateBlock(), PreciousBlock(), PruneBlockIndexCandidates(), ReceivedBlockTransactions(), and ResetBlockFailureFlags().
◆ cs_nBlockSequenceId
|
private |
Every received block is assigned a unique and increasing identifier, so we know which one to give priority in case of a fork.
Definition at line 130 of file validation.cpp.
Referenced by ReceivedBlockTransactions().
◆ g_failed_blocks
|
private |
In order to efficiently track invalidity of headers, we keep the set of blocks which we tried to connect and found to be invalid here (ie which were set to BLOCK_FAILED_VALID since the last restart).
We can then walk this set and check if a new header is a descendant of something in this set, preventing us from having to walk mapBlockIndex when we try to connect a bad block and fail.
While this is more complicated than marking everything which descends from an invalid block as invalid at the time we discover it to be invalid, doing so would require walking all of mapBlockIndex to find all descendants. Since this case should be very rare, keeping track of all BLOCK_FAILED_VALID blocks in a set should be just fine and work just as well.
Because we already walk mapBlockIndex in height-order at startup, we go ahead and mark descendants of invalid blocks as FAILED_CHILD at that time, instead of putting things in this set.
Definition at line 156 of file validation.cpp.
Referenced by AcceptBlockHeader(), InvalidateBlock(), InvalidBlockFound(), ResetBlockFailureFlags(), and UnloadBlockIndex().
◆ mapBlockIndex
BlockMap CChainState::mapBlockIndex |
Definition at line 160 of file validation.cpp.
Referenced by AcceptBlockHeader(), AddToBlockIndex(), CheckBlockIndex(), ConnectBlock(), InsertBlockIndex(), InvalidateBlock(), LoadBlockIndex(), LoadGenesisBlock(), ReplayBlocks(), and ResetBlockFailureFlags().
◆ mapBlocksUnlinked
std::multimap<CBlockIndex*, CBlockIndex*> CChainState::mapBlocksUnlinked |
Definition at line 162 of file validation.cpp.
Referenced by CheckBlockIndex(), FindMostWorkChain(), LoadBlockIndex(), and ReceivedBlockTransactions().
◆ mapPrevBlockIndex
PrevBlockMap CChainState::mapPrevBlockIndex |
Definition at line 161 of file validation.cpp.
Referenced by AddToBlockIndex(), and LoadBlockIndex().
◆ nBlockReverseSequenceId
|
private |
Decreasing counter (used by subsequent preciousblock calls).
Definition at line 134 of file validation.cpp.
Referenced by PreciousBlock().
◆ nBlockSequenceId
|
private |
Blocks loaded from disk are assigned id 0, so start the counter at 1.
Definition at line 132 of file validation.cpp.
Referenced by ReceivedBlockTransactions(), and UnloadBlockIndex().
◆ nLastPreciousChainwork
|
private |
chainwork for the last block that preciousblock has been applied to.
Definition at line 136 of file validation.cpp.
Referenced by PreciousBlock().
◆ pindexBestInvalid
CBlockIndex* CChainState::pindexBestInvalid = nullptr |
Definition at line 163 of file validation.cpp.
Referenced by FindMostWorkChain(), InvalidateBlock(), LoadBlockIndex(), and ResetBlockFailureFlags().
◆ setBlockIndexCandidates
|
private |
The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS (for itself and all ancestors) and as good as our current tip or better.
Entries may be failed, though, and pruning nodes may be missing the data for the block.
Definition at line 124 of file validation.cpp.
Referenced by CheckBlockIndex(), FindMostWorkChain(), InvalidateBlock(), InvalidBlockFound(), LoadBlockIndex(), PreciousBlock(), PruneBlockIndexCandidates(), ReceivedBlockTransactions(), ResetBlockFailureFlags(), and UnloadBlockIndex().
The documentation for this class was generated from the following file:
- src/validation.cpp