Bitcoin
|
#include <validation.h>
#include <arith_uint256.h>
#include <chain.h>
#include <chainparams.h>
#include <checkqueue.h>
#include <consensus/consensus.h>
#include <consensus/merkle.h>
#include <consensus/tx_check.h>
#include <consensus/tx_verify.h>
#include <consensus/validation.h>
#include <cuckoocache.h>
#include <flatfile.h>
#include <hash.h>
#include <index/txindex.h>
#include <policy/fees.h>
#include <policy/policy.h>
#include <policy/settings.h>
#include <pow.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <random.h>
#include <reverse_iterator.h>
#include <script/script.h>
#include <script/sigcache.h>
#include <script/standard.h>
#include <shutdown.h>
#include <timedata.h>
#include <tinyformat.h>
#include <txdb.h>
#include <txmempool.h>
#include <ui_interface.h>
#include <uint256.h>
#include <undo.h>
#include <util/moneystr.h>
#include <util/rbf.h>
#include <util/strencodings.h>
#include <util/system.h>
#include <util/validation.h>
#include <validationinterface.h>
#include <warnings.h>
#include <future>
#include <sstream>
#include <string>
#include <boost/algorithm/string/replace.hpp>
#include <boost/thread.hpp>
Classes | |
class | WarningBitsConditionChecker |
struct | PerBlockConnectTrace |
class | ConnectTrace |
class | CMainCleanup |
Namespaces | |
anonymous_namespace{validation.cpp} | |
Macros | |
#define | MICRO 0.000001 |
#define | MILLI 0.001 |
Functions | |
CChainState & | ChainstateActive () |
CChain & | ChainActive () |
std::atomic_bool | fImporting (false) |
std::atomic_bool | fReindex (false) |
CBlockIndex * | LookupBlockIndex (const uint256 &hash) |
CBlockIndex * | FindForkInGlobalIndex (const CChain &chain, const CBlockLocator &locator) |
static void | FindFilesToPruneManual (std::set< int > &setFilesToPrune, int nManualPruneHeight) |
static void | FindFilesToPrune (std::set< int > &setFilesToPrune, uint64_t nPruneAfterHeight) |
bool | CheckInputs (const CTransaction &tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData &txdata, std::vector< CScriptCheck > *pvChecks=nullptr) |
static FILE * | OpenUndoFile (const FlatFilePos &pos, bool fReadOnly=false) |
static FlatFileSeq | BlockFileSeq () |
static FlatFileSeq | UndoFileSeq () |
bool | CheckFinalTx (const CTransaction &tx, int flags) |
bool | TestLockPointValidity (const LockPoints *lp) |
bool | CheckSequenceLocks (const CTxMemPool &pool, const CTransaction &tx, int flags, LockPoints *lp, bool useExistingLockPoints) |
static unsigned int | GetBlockScriptFlags (const CBlockIndex *pindex, const Consensus::Params &chainparams) |
static void | LimitMempoolSize (CTxMemPool &pool, size_t limit, unsigned long age) EXCLUSIVE_LOCKS_REQUIRED(pool.cs) |
static bool | IsCurrentForFeeEstimation () EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
static void | UpdateMempoolForReorg (DisconnectedBlockTransactions &disconnectpool, bool fAddToMempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main |
while (it !=disconnectpool.queuedTx.get< insertion_order >().rend()) | |
disconnectpool queuedTx | clear () |
mempool | UpdateTransactionsFromBlock (vHashUpdate) |
mempool | removeForReorg (pcoinsTip.get(), ::ChainActive().Tip() ->nHeight+1, STANDARD_LOCKTIME_VERIFY_FLAGS) |
LimitMempoolSize (mempool, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) *1000000, gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) *60 *60) | |
static bool | CheckInputsFromMempoolAndCache (const CTransaction &tx, CValidationState &state, const CCoinsViewCache &view, const CTxMemPool &pool, unsigned int flags, bool cacheSigStore, PrecomputedTransactionData &txdata) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
static bool | AcceptToMemoryPoolWorker (const CChainParams &chainparams, CTxMemPool &pool, CValidationState &state, const CTransactionRef &ptx, bool *pfMissingInputs, int64_t nAcceptTime, std::list< CTransactionRef > *plTxnReplaced, bool bypass_limits, const CAmount &nAbsurdFee, std::vector< COutPoint > &coins_to_uncache, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
static bool | AcceptToMemoryPoolWithTime (const CChainParams &chainparams, CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool *pfMissingInputs, int64_t nAcceptTime, std::list< CTransactionRef > *plTxnReplaced, bool bypass_limits, const CAmount nAbsurdFee, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
bool | AcceptToMemoryPool (CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced, bool bypass_limits, const CAmount nAbsurdFee, bool test_accept) |
bool | GetTransaction (const uint256 &hash, CTransactionRef &txOut, const Consensus::Params &consensusParams, uint256 &hashBlock, const CBlockIndex *const block_index) |
static bool | WriteBlockToDisk (const CBlock &block, FlatFilePos &pos, const CMessageHeader::MessageStartChars &messageStart) |
bool | ReadBlockFromDisk (CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams) |
bool | ReadBlockFromDisk (CBlock &block, const CBlockIndex *pindex, const Consensus::Params &consensusParams) |
bool | ReadRawBlockFromDisk (std::vector< uint8_t > &block, const FlatFilePos &pos, const CMessageHeader::MessageStartChars &message_start) |
bool | ReadRawBlockFromDisk (std::vector< uint8_t > &block, const CBlockIndex *pindex, const CMessageHeader::MessageStartChars &message_start) |
CAmount | GetBlockSubsidy (int nHeight, const Consensus::Params &consensusParams) |
BlockMap & | BlockIndex () |
static void | AlertNotify (const std::string &strMessage) |
static void | CheckForkWarningConditions () EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
static void | CheckForkWarningConditionsOnNewFork (CBlockIndex *pindexNewForkTip) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
static void | InvalidChainFound (CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
void | UpdateCoins (const CTransaction &tx, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight) |
void | UpdateCoins (const CTransaction &tx, CCoinsViewCache &inputs, int nHeight) |
int | GetSpendHeight (const CCoinsViewCache &inputs) |
void | InitScriptExecutionCache () |
static bool | UndoWriteToDisk (const CBlockUndo &blockundo, FlatFilePos &pos, const uint256 &hashBlock, const CMessageHeader::MessageStartChars &messageStart) |
bool | UndoReadFromDisk (CBlockUndo &blockundo, const CBlockIndex *pindex) |
static bool | AbortNode (const std::string &strMessage, const std::string &userMessage="", unsigned int prefix=0) |
static bool | AbortNode (CValidationState &state, const std::string &strMessage, const std::string &userMessage="", unsigned int prefix=0) |
int | ApplyTxInUndo (Coin &&undo, CCoinsViewCache &view, const COutPoint &out) |
static void | FlushBlockFile (bool fFinalize=false) |
static bool | FindUndoPos (CValidationState &state, int nFile, FlatFilePos &pos, unsigned int nAddSize) |
static bool | WriteUndoDataForBlock (const CBlockUndo &blockundo, CValidationState &state, CBlockIndex *pindex, const CChainParams &chainparams) |
void | ThreadScriptCheck (int worker_num) |
VersionBitsCache versionbitscache | GUARDED_BY (cs_main) |
int32_t | ComputeBlockVersion (const CBlockIndex *pindexPrev, const Consensus::Params ¶ms) |
static bool | IsScriptWitnessEnabled (const Consensus::Params ¶ms) |
static void | DoWarning (const std::string &strWarning) |
static void | AppendWarning (std::string &res, const std::string &warn) |
static void | UpdateTip (const CBlockIndex *pindexNew, const CChainParams &chainParams) |
static void | NotifyHeaderTip () LOCKS_EXCLUDED(cs_main) |
static void | LimitValidationInterfaceQueue () LOCKS_EXCLUDED(cs_main) |
bool | ActivateBestChain (CValidationState &state, const CChainParams &chainparams, std::shared_ptr< const CBlock > pblock) |
bool | PreciousBlock (CValidationState &state, const CChainParams ¶ms, CBlockIndex *pindex) |
bool | InvalidateBlock (CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex) |
void | ResetBlockFailureFlags (CBlockIndex *pindex) |
static bool | FindBlockPos (FlatFilePos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown=false) |
static bool | CheckBlockHeader (const CBlockHeader &block, CValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW=true) |
bool | CheckBlock (const CBlock &block, CValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW, bool fCheckMerkleRoot) |
bool | IsWitnessEnabled (const CBlockIndex *pindexPrev, const Consensus::Params ¶ms) |
bool | IsNullDummyEnabled (const CBlockIndex *pindexPrev, const Consensus::Params ¶ms) |
static int | GetWitnessCommitmentIndex (const CBlock &block) |
void | UpdateUncommittedBlockStructures (CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams) |
std::vector< unsigned char > | GenerateCoinbaseCommitment (CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams) |
static CBlockIndex * | GetLastCheckpoint (const CCheckpointData &data) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
Returns last CBlockIndex* that is a checkpoint. More... | |
static bool | ContextualCheckBlockHeader (const CBlockHeader &block, CValidationState &state, const CChainParams ¶ms, const CBlockIndex *pindexPrev, int64_t nAdjustedTime) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
static bool | ContextualCheckBlock (const CBlock &block, CValidationState &state, const Consensus::Params &consensusParams, const CBlockIndex *pindexPrev) |
bool | ProcessNewBlockHeaders (const std::vector< CBlockHeader > &headers, CValidationState &state, const CChainParams &chainparams, const CBlockIndex **ppindex, CBlockHeader *first_invalid) |
static FlatFilePos | SaveBlockToDisk (const CBlock &block, int nHeight, const CChainParams &chainparams, const FlatFilePos *dbp) |
bool | ProcessNewBlock (const CChainParams &chainparams, const std::shared_ptr< const CBlock > pblock, bool fForceProcessing, bool *fNewBlock) |
bool | TestBlockValidity (CValidationState &state, const CChainParams &chainparams, const CBlock &block, CBlockIndex *pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot) |
uint64_t | CalculateCurrentUsage () |
void | PruneOneBlockFile (const int fileNumber) |
void | UnlinkPrunedFiles (const std::set< int > &setFilesToPrune) |
void | PruneBlockFilesManual (int nManualPruneHeight) |
FILE * | OpenBlockFile (const FlatFilePos &pos, bool fReadOnly) |
fs::path | GetBlockPosFilename (const FlatFilePos &pos) |
static bool | LoadBlockIndexDB (const CChainParams &chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
bool | LoadChainTip (const CChainParams &chainparams) |
bool | ReplayBlocks (const CChainParams ¶ms, CCoinsView *view) |
bool | RewindBlockIndex (const CChainParams ¶ms) |
void | UnloadBlockIndex () |
bool | LoadBlockIndex (const CChainParams &chainparams) |
bool | LoadGenesisBlock (const CChainParams &chainparams) |
bool | LoadExternalBlockFile (const CChainParams &chainparams, FILE *fileIn, FlatFilePos *dbp) |
CBlockFileInfo * | GetBlockFileInfo (size_t n) |
ThresholdState | VersionBitsTipState (const Consensus::Params ¶ms, Consensus::DeploymentPos pos) |
BIP9Stats | VersionBitsTipStatistics (const Consensus::Params ¶ms, Consensus::DeploymentPos pos) |
int | VersionBitsTipStateSinceHeight (const Consensus::Params ¶ms, Consensus::DeploymentPos pos) |
bool | LoadMempool (CTxMemPool &pool) |
bool | DumpMempool (const CTxMemPool &pool) |
double | GuessVerificationProgress (const ChainTxData &data, const CBlockIndex *pindex) |
#define MICRO 0.000001 |
#define MILLI 0.001 |
|
static |
Abort with a message
|
static |
bool AcceptToMemoryPool | ( | CTxMemPool & | pool, |
CValidationState & | state, | ||
const CTransactionRef & | tx, | ||
bool * | pfMissingInputs, | ||
std::list< CTransactionRef > * | plTxnReplaced, | ||
bool | bypass_limits, | ||
const CAmount | nAbsurdFee, | ||
bool | test_accept = false |
||
) |
(try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions replaced from mempool
|
static |
(try to) add transaction to memory pool with a specified acceptance time
|
static |
[out] | coins_to_uncache | Return any outpoints which were not previously present in the coins cache, but were added as a result of validating the tx for mempool acceptance. This allows the caller to optionally remove the cache additions if the associated transaction ends up being rejected by the mempool. |
bool ActivateBestChain | ( | CValidationState & | state, |
const CChainParams & | chainparams, | ||
std::shared_ptr< const CBlock > | pblock = std::shared_ptr< const CBlock >() |
||
) |
Find the best known block, and make it the tip of the block chain
May not be called with cs_main held. May not be called in a validationinterface callback.
|
static |
|
static |
Private helper function that concatenates warning messages.
int ApplyTxInUndo | ( | Coin && | undo, |
CCoinsViewCache & | view, | ||
const COutPoint & | out | ||
) |
|
static |
BlockMap& BlockIndex | ( | ) |
uint64_t CalculateCurrentUsage | ( | ) |
BLOCK PRUNING CODE
CChain& ChainActive | ( | ) |
CChainState& ChainstateActive | ( | ) |
bool CheckBlock | ( | const CBlock & | block, |
CValidationState & | state, | ||
const Consensus::Params & | consensusParams, | ||
bool | fCheckPOW = true , |
||
bool | fCheckMerkleRoot = true |
||
) |
Functions for validating blocks and updating the block tree Context-independent validity checks
|
static |
bool CheckFinalTx | ( | const CTransaction & | tx, |
int | flags = -1 |
||
) |
Transaction validation functions Check if transaction will be final in the next block to be created.
Calls IsFinalTx() with current block height and appropriate block time.
See consensus/consensus.h for flag definitions.
|
static |
|
static |
bool CheckInputs | ( | const CTransaction & | tx, |
CValidationState & | state, | ||
const CCoinsViewCache & | inputs, | ||
bool | fScriptChecks, | ||
unsigned int | flags, | ||
bool | cacheSigStore, | ||
bool | cacheFullScriptStore, | ||
PrecomputedTransactionData & | txdata, | ||
std::vector< CScriptCheck > * | pvChecks | ||
) |
Check whether all inputs of this transaction are valid (no double spends, scripts & sigs, amounts) This does not modify the UTXO set.
If pvChecks is not nullptr, script checks are pushed onto it instead of being performed inline. Any script checks which are not necessary (eg due to script execution cache hits) are, obviously, not pushed onto pvChecks/run.
Setting cacheSigStore/cacheFullScriptStore to false will remove elements from the corresponding cache which are matched. This is useful for checking blocks where we will likely never need the cache entry again.
Note that we may set state.reason to NOT_STANDARD for extra soft-fork flags in flags, block-checking callers should probably reset it to CONSENSUS in such cases.
Non-static (and re-declared) in src/test/txvalidationcache_tests.cpp
|
static |
bool CheckSequenceLocks | ( | const CTxMemPool & | pool, |
const CTransaction & | tx, | ||
int | flags, | ||
LockPoints * | lp = nullptr , |
||
bool | useExistingLockPoints = false |
||
) |
Check if transaction will be BIP 68 final in the next block to be created.
Simulates calling SequenceLocks() with data from the tip of the current active chain. Optionally stores in LockPoints the resulting height and time calculated and the hash of the block needed for calculation or skips the calculation and uses the LockPoints passed in for evaluation. The LockPoints should not be considered valid if CheckSequenceLocks returns false.
See consensus/consensus.h for flag definitions.
disconnectpool queuedTx clear | ( | ) |
int32_t ComputeBlockVersion | ( | const CBlockIndex * | pindexPrev, |
const Consensus::Params & | params | ||
) |
Determine what nVersion a new block should use.
|
static |
NOTE: This function is not currently invoked by ConnectBlock(), so we should consider upgrade issues if we change which consensus rules are enforced in this function (eg by adding a new consensus rule). See comment in ConnectBlock(). Note that -reindex-chainstate skips the validation that happens here!
|
static |
Context-dependent validity checks. By "context", we mean only the previous block headers, but not the UTXO set; UTXO-related validity checks are done in ConnectBlock(). NOTE: This function is not currently invoked by ConnectBlock(), so we should consider upgrade issues if we change which consensus rules are enforced in this function (eg by adding a new consensus rule). See comment in ConnectBlock(). Note that -reindex-chainstate skips the validation that happens here!
|
static |
bool DumpMempool | ( | const CTxMemPool & | pool | ) |
Dump the mempool to disk.
std::atomic_bool fImporting | ( | false | ) |
|
static |
|
static |
Prune block and undo files (blk???.dat and undo???.dat) so that the disk space used is less than a user-defined target. The user sets the target (in MB) on the command line or in config file. This will be run on startup and whenever new space is allocated in a block or undo file, staying below the target. Changing back to unpruned requires a reindex (which in this case means the blockchain must be re-downloaded.)
Pruning functions are called from FlushStateToDisk when the global fCheckForPruning flag has been set. Block and undo files are deleted in lock-step (when blk00003.dat is deleted, so is rev00003.dat.) Pruning cannot take place until the longest chain is at least a certain length (100000 on mainnet, 1000 on testnet, 1000 on regtest). Pruning will never delete a block within a defined distance (currently 288) from the active chain's tip. The block index is updated by unsetting HAVE_DATA and HAVE_UNDO for any blocks that were stored in the deleted files. A db flag records the fact that at least some block files have been pruned.
[out] | setFilesToPrune | The set of file indices that can be unlinked will be returned |
|
static |
CBlockIndex* FindForkInGlobalIndex | ( | const CChain & | chain, |
const CBlockLocator & | locator | ||
) |
Find the last common block between the parameter chain and a locator.
|
static |
|
static |
std::atomic_bool fReindex | ( | false | ) |
std::vector<unsigned char> GenerateCoinbaseCommitment | ( | CBlock & | block, |
const CBlockIndex * | pindexPrev, | ||
const Consensus::Params & | consensusParams | ||
) |
Produce the necessary coinbase commitment for a block (modifies the hash, don't call for mined blocks).
CBlockFileInfo* GetBlockFileInfo | ( | size_t | n | ) |
Get block file info entry for one block file
fs::path GetBlockPosFilename | ( | const FlatFilePos & | pos | ) |
Translation to a filesystem path
|
static |
CAmount GetBlockSubsidy | ( | int | nHeight, |
const Consensus::Params & | consensusParams | ||
) |
|
static |
Returns last CBlockIndex* that is a checkpoint.
int GetSpendHeight | ( | const CCoinsViewCache & | inputs | ) |
Return the spend height, which is one more than the inputs.GetBestBlock(). While checking, GetBestBlock() refers to the parent block. (protected by cs_main) This is also true for mempool checks.
bool GetTransaction | ( | const uint256 & | hash, |
CTransactionRef & | txOut, | ||
const Consensus::Params & | consensusParams, | ||
uint256 & | hashBlock, | ||
const CBlockIndex *const | block_index | ||
) |
Return transaction in txOut, and if it was found inside a block, its hash is placed in hashBlock. If blockIndex is provided, the transaction is fetched from the corresponding block.
|
static |
VersionBitsCache versionbitscache GUARDED_BY | ( | cs_main | ) |
double GuessVerificationProgress | ( | const ChainTxData & | data, |
const CBlockIndex * | pindex | ||
) |
Guess how far we are in the verification process at the given block index require cs_main if pindex has not been validated yet (because nChainTx might be unset)
void InitScriptExecutionCache | ( | ) |
Initializes the script-execution cache
bool InvalidateBlock | ( | CValidationState & | state, |
const CChainParams & | chainparams, | ||
CBlockIndex * | pindex | ||
) |
Mark a block as invalid.
|
static |
|
static |
bool IsNullDummyEnabled | ( | const CBlockIndex * | pindexPrev, |
const Consensus::Params & | params | ||
) |
Check whether NULLDUMMY (BIP 147) has activated.
|
static |
bool IsWitnessEnabled | ( | const CBlockIndex * | pindexPrev, |
const Consensus::Params & | params | ||
) |
Check whether witness commitments are required for block.
|
static |
LimitMempoolSize | ( | mempool | , |
gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * | 1000000, | ||
gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) *60 * | 60 | ||
) |
|
static |
bool LoadBlockIndex | ( | const CChainParams & | chainparams | ) |
Load the block tree and coins database from disk, initializing state if we're running with -reindex.
|
static |
bool LoadChainTip | ( | const CChainParams & | chainparams | ) |
Update the chain tip based on database information.
bool LoadExternalBlockFile | ( | const CChainParams & | chainparams, |
FILE * | fileIn, | ||
FlatFilePos * | dbp = nullptr |
||
) |
Import blocks from an external file
bool LoadGenesisBlock | ( | const CChainParams & | chainparams | ) |
Ensures we have a genesis block in the block tree, possibly writing one to disk.
bool LoadMempool | ( | CTxMemPool & | pool | ) |
Load the mempool from disk.
CBlockIndex* LookupBlockIndex | ( | const uint256 & | hash | ) |
|
static |
FILE* OpenBlockFile | ( | const FlatFilePos & | pos, |
bool | fReadOnly = false |
||
) |
Open a block file (blk?????.dat)
|
static |
Open an undo file (rev?????.dat)
bool PreciousBlock | ( | CValidationState & | state, |
const CChainParams & | params, | ||
CBlockIndex * | pindex | ||
) |
Mark a block as precious and reorganize.
May not be called in a validationinterface callback.
bool ProcessNewBlock | ( | const CChainParams & | chainparams, |
const std::shared_ptr< const CBlock > | pblock, | ||
bool | fForceProcessing, | ||
bool * | fNewBlock | ||
) |
Process an incoming block. This only returns after the best known valid block is made active. Note that it does not, however, guarantee that the specific block passed to it has been checked for validity!
If you want to possibly get feedback on whether pblock is valid, you must install a CValidationInterface (see validationinterface.h) - this will have its BlockChecked method called whenever any block completes validation.
Note that we guarantee that either the proof-of-work is valid on pblock, or (and possibly also) BlockChecked will have been called.
May not be called in a validationinterface callback.
[in] | pblock | The block we want to process. |
[in] | fForceProcessing | Process this block even if unrequested; used for non-network block sources and whitelisted peers. |
[out] | fNewBlock | A boolean which is set to indicate if the block was first received via this call |
bool ProcessNewBlockHeaders | ( | const std::vector< CBlockHeader > & | block, |
CValidationState & | state, | ||
const CChainParams & | chainparams, | ||
const CBlockIndex ** | ppindex = nullptr , |
||
CBlockHeader * | first_invalid = nullptr |
||
) |
Process incoming block headers.
May not be called in a validationinterface callback.
[in] | block | The block headers themselves |
[out] | state | This may be set to an Error state if any error occurred processing them |
[in] | chainparams | The params for the chain we want to connect to |
[out] | ppindex | If set, the pointer will be set to point to the last new block index object for the given headers |
[out] | first_invalid | First header that fails validation, if one exists |
void PruneBlockFilesManual | ( | int | nManualPruneHeight | ) |
Prune block files up to a given height
void PruneOneBlockFile | ( | const int | fileNumber | ) |
Mark one block file as pruned.
bool ReadBlockFromDisk | ( | CBlock & | block, |
const FlatFilePos & | pos, | ||
const Consensus::Params & | consensusParams | ||
) |
Functions for disk access for blocks
bool ReadBlockFromDisk | ( | CBlock & | block, |
const CBlockIndex * | pindex, | ||
const Consensus::Params & | consensusParams | ||
) |
bool ReadRawBlockFromDisk | ( | std::vector< uint8_t > & | block, |
const FlatFilePos & | pos, | ||
const CMessageHeader::MessageStartChars & | message_start | ||
) |
bool ReadRawBlockFromDisk | ( | std::vector< uint8_t > & | block, |
const CBlockIndex * | pindex, | ||
const CMessageHeader::MessageStartChars & | message_start | ||
) |
mempool removeForReorg | ( | pcoinsTip. | get(), |
::ChainActive().Tip() ->nHeight+ | 1, | ||
STANDARD_LOCKTIME_VERIFY_FLAGS | |||
) |
bool ReplayBlocks | ( | const CChainParams & | params, |
CCoinsView * | view | ||
) |
Replay blocks that aren't fully applied to the database.
void ResetBlockFailureFlags | ( | CBlockIndex * | pindex | ) |
Remove invalidity status from a block and its descendants.
bool RewindBlockIndex | ( | const CChainParams & | params | ) |
When there are blocks in the active chain with missing data, rewind the chainstate and remove them from the block index
|
static |
Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk
bool TestBlockValidity | ( | CValidationState & | state, |
const CChainParams & | chainparams, | ||
const CBlock & | block, | ||
CBlockIndex * | pindexPrev, | ||
bool | fCheckPOW = true , |
||
bool | fCheckMerkleRoot = true |
||
) |
Check a block is completely valid from start to finish (only works on top of our current best block)
bool TestLockPointValidity | ( | const LockPoints * | lp | ) |
Test whether the LockPoints height and time are still valid on the current chain
void ThreadScriptCheck | ( | int | worker_num | ) |
Run an instance of the script checking thread
|
static |
bool UndoReadFromDisk | ( | CBlockUndo & | blockundo, |
const CBlockIndex * | pindex | ||
) |
|
static |
void UnlinkPrunedFiles | ( | const std::set< int > & | setFilesToPrune | ) |
Actually unlink the specified files
void UnloadBlockIndex | ( | ) |
Unload database information
void UpdateCoins | ( | const CTransaction & | tx, |
CCoinsViewCache & | inputs, | ||
CTxUndo & | txundo, | ||
int | nHeight | ||
) |
void UpdateCoins | ( | const CTransaction & | tx, |
CCoinsViewCache & | inputs, | ||
int | nHeight | ||
) |
Apply the effects of this transaction on the UTXO set represented by view
|
static |
|
static |
Check warning conditions and do some notifications on new chain tip set.
mempool UpdateTransactionsFromBlock | ( | vHashUpdate | ) |
void UpdateUncommittedBlockStructures | ( | CBlock & | block, |
const CBlockIndex * | pindexPrev, | ||
const Consensus::Params & | consensusParams | ||
) |
Update uncommitted block structures (currently: only the witness reserved value). This is safe for submitted blocks.
ThresholdState VersionBitsTipState | ( | const Consensus::Params & | params, |
Consensus::DeploymentPos | pos | ||
) |
Get the BIP9 state for a given deployment at the current tip.
int VersionBitsTipStateSinceHeight | ( | const Consensus::Params & | params, |
Consensus::DeploymentPos | pos | ||
) |
Get the block height at which the BIP9 deployment switched into the state for the block building on the current tip.
BIP9Stats VersionBitsTipStatistics | ( | const Consensus::Params & | params, |
Consensus::DeploymentPos | pos | ||
) |
Get the numerical statistics for the BIP9 state for a given deployment at the current tip.
while | ( | it ! | = disconnectpool.queuedTx.get<insertion_order>().rend() | ) |
|
static |
|
static |
CScript COINBASE_FLAGS |
Constant stuff for coinbase transactions we create:
void ::mempool cs |
RecursiveMutex cs_main |
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
This may also need to be locked when updating the transaction pool, e.g. on AcceptToMemoryPool. See CTxMemPool::cs comment for details.
The transaction pool has a separate lock to allow reading from it and the chainstate at the same time.
bool fCheckBlockIndex = false |
bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED |
CTxMemPool mempool & feeEstimator |
bool fHavePruned = false |
Pruning-related variables and constants True if any block files have ever been pruned.
bool fPruneMode = false |
True if we're running in -prune mode.
bool fRequireStandard = true |
uint256 g_best_block |
std::condition_variable g_best_block_cv |
Mutex g_best_block_mutex |
|
static |
uint256 hashAssumeValid |
Block hash whose ancestors we will assume to have valid scripts without checking them.
|
static |
auto it = disconnectpool.queuedTx.get<insertion_order>().rbegin() |
|
static |
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE) |
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation)
|
static |
size_t nCoinCacheUsage = 5000 * 300 |
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE |
If the tip is older than this (in seconds), the node is considered to be in initial block download.
arith_uint256 nMinimumChainWork |
Minimum work we will assume exists on some valid chain.
uint64_t nPruneTarget = 0 |
Number of MiB of block files that we're trying to stay below.
int nScriptCheckThreads = 0 |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
std::unique_ptr<CBlockTreeDB> pblocktree |
Global variable that points to the active block tree (protected by cs_main)
std::unique_ptr<CCoinsViewDB> pcoinsdbview |
Global variable that points to the coins database (protected by cs_main)
std::unique_ptr<CCoinsViewCache> pcoinsTip |
Global variable that points to the active CCoinsView (protected by cs_main)
|
static |
|
static |
CBlockIndex* pindexBestHeader = nullptr |
Best header we've seen so far (used for getheaders queries' starting points).
|
static |
|
static |
|
static |
std::vector<uint256> vHashUpdate |