Changeset View
Changeset View
Standalone View
Standalone View
src/validation.h
Show First 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | bool ProcessNewBlockHeaders(const Config &config, | ||||
const std::vector<CBlockHeader> &block, | const std::vector<CBlockHeader> &block, | ||||
CValidationState &state, | CValidationState &state, | ||||
const CBlockIndex **ppindex = nullptr); | const CBlockIndex **ppindex = nullptr); | ||||
/** Check whether enough disk space is available for an incoming block */ | /** Check whether enough disk space is available for an incoming block */ | ||||
bool CheckDiskSpace(uint64_t nAdditionalBytes = 0); | bool CheckDiskSpace(uint64_t nAdditionalBytes = 0); | ||||
/** Open a block file (blk?????.dat) */ | /** Open a block file (blk?????.dat) */ | ||||
FILE *OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false); | FILE *OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false); | ||||
/** Open an undo file (rev?????.dat) */ | |||||
FILE *OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly = false); | |||||
/** Translation to a filesystem path */ | /** Translation to a filesystem path */ | ||||
fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix); | fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix); | ||||
/** Import blocks from an external file */ | /** Import blocks from an external file */ | ||||
bool LoadExternalBlockFile(const Config &config, FILE *fileIn, | bool LoadExternalBlockFile(const Config &config, FILE *fileIn, | ||||
CDiskBlockPos *dbp = nullptr); | CDiskBlockPos *dbp = nullptr); | ||||
/** Initialize a new block tree database + block data on disk */ | /** Initialize a new block tree database + block data on disk */ | ||||
bool InitBlockIndex(const Config &config); | bool InitBlockIndex(const Config &config); | ||||
/** Load the block tree and coins database from disk */ | /** Load the block tree and coins database from disk */ | ||||
Show All 28 Lines | bool ActivateBestChain( | ||||
std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>()); | std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>()); | ||||
Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams); | Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams); | ||||
/** Guess verification progress (as a fraction between 0.0=genesis and | /** Guess verification progress (as a fraction between 0.0=genesis and | ||||
* 1.0=current tip). */ | * 1.0=current tip). */ | ||||
double GuessVerificationProgress(const ChainTxData &data, CBlockIndex *pindex); | double GuessVerificationProgress(const ChainTxData &data, CBlockIndex *pindex); | ||||
/** | /** | ||||
* 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. | |||||
* | |||||
* @param[out] setFilesToPrune The set of file indices that can be unlinked | |||||
* will be returned | |||||
*/ | |||||
void FindFilesToPrune(std::set<int> &setFilesToPrune, | |||||
uint64_t nPruneAfterHeight); | |||||
/** | |||||
* Mark one block file as pruned. | * Mark one block file as pruned. | ||||
*/ | */ | ||||
void PruneOneBlockFile(const int fileNumber); | void PruneOneBlockFile(const int fileNumber); | ||||
/** | /** | ||||
* Actually unlink the specified files | * Actually unlink the specified files | ||||
*/ | */ | ||||
void UnlinkPrunedFiles(const std::set<int> &setFilesToPrune); | void UnlinkPrunedFiles(const std::set<int> &setFilesToPrune); | ||||
/** Create a new block index entry for a given block hash */ | /** Create a new block index entry for a given block hash */ | ||||
CBlockIndex *InsertBlockIndex(uint256 hash); | CBlockIndex *InsertBlockIndex(uint256 hash); | ||||
/** Flush all state, indexes and buffers to disk. */ | /** Flush all state, indexes and buffers to disk. */ | ||||
void FlushStateToDisk(); | void FlushStateToDisk(); | ||||
/** Prune block files and flush state to disk. */ | /** Prune block files and flush state to disk. */ | ||||
void PruneAndFlush(); | void PruneAndFlush(); | ||||
/** Prune block files up to a given height */ | /** Prune block files up to a given height */ | ||||
void PruneBlockFilesManual(int nPruneUpToHeight); | void PruneBlockFilesManual(int nPruneUpToHeight); | ||||
/** Check is UAHF has activated. */ | /** Check is UAHF has activated. */ | ||||
bool IsUAHFenabled(const Config &config, const CBlockIndex *pindexPrev); | bool IsUAHFenabled(const Config &config, const CBlockIndex *pindexPrev); | ||||
/** Check is DAA HF has activated. */ | /** Check is DAA HF has activated. */ | ||||
bool IsDAAEnabled(const Config &config, const CBlockIndex *pindexPrev); | bool IsDAAEnabled(const Config &config, const CBlockIndex *pindexPrev); | ||||
/** (try to) add transaction to memory pool | /** | ||||
* plTxnReplaced will be appended to with all transactions replaced from mempool | * (try to) add transaction to memory pool | ||||
* **/ | * plTxnReplaced will be appended to with all transactions replaced from | ||||
* mempool. | |||||
*/ | |||||
bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool, | bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool, | ||||
CValidationState &state, const CTransactionRef &tx, | CValidationState &state, const CTransactionRef &tx, | ||||
bool fLimitFree, bool *pfMissingInputs, | bool fLimitFree, bool *pfMissingInputs, | ||||
std::list<CTransactionRef> *plTxnReplaced = nullptr, | std::list<CTransactionRef> *plTxnReplaced = nullptr, | ||||
bool fOverrideMempoolLimit = false, | bool fOverrideMempoolLimit = false, | ||||
const Amount nAbsurdFee = Amount(0)); | const Amount nAbsurdFee = Amount(0)); | ||||
/** Convert CValidationState to a human-readable message for logging */ | /** Convert CValidationState to a human-readable message for logging */ | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | void swap(CScriptCheck &check) { | ||||
std::swap(error, check.error); | std::swap(error, check.error); | ||||
std::swap(txdata, check.txdata); | std::swap(txdata, check.txdata); | ||||
} | } | ||||
ScriptError GetScriptError() const { return error; } | ScriptError GetScriptError() const { return error; } | ||||
}; | }; | ||||
/** Functions for disk access for blocks */ | /** Functions for disk access for blocks */ | ||||
bool WriteBlockToDisk(const CBlock &block, CDiskBlockPos &pos, | |||||
const CMessageHeader::MessageMagic &messageStart); | |||||
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, | bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, | ||||
const Config &config); | const Config &config); | ||||
bool ReadBlockFromDisk(CBlock &block, const CBlockIndex *pindex, | bool ReadBlockFromDisk(CBlock &block, const CBlockIndex *pindex, | ||||
const Config &config); | const Config &config); | ||||
/** Functions for validating blocks and updating the block tree */ | /** Functions for validating blocks and updating the block tree */ | ||||
/** Context-independent validity checks */ | /** Context-independent validity checks */ | ||||
Show All 18 Lines | |||||
* See consensus/consensus.h for flag definitions. | * See consensus/consensus.h for flag definitions. | ||||
*/ | */ | ||||
bool ContextualCheckTransactionForCurrentBlock(const Config &config, | bool ContextualCheckTransactionForCurrentBlock(const Config &config, | ||||
const CTransaction &tx, | const CTransaction &tx, | ||||
CValidationState &state, | CValidationState &state, | ||||
int flags = -1); | int flags = -1); | ||||
/** | /** | ||||
* 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(). | |||||
*/ | |||||
bool ContextualCheckBlock(const Config &config, const CBlock &block, | |||||
CValidationState &state, | |||||
const Consensus::Params &consensusParams, | |||||
const CBlockIndex *pindexPrev); | |||||
/** | |||||
* Check a block is completely valid from start to finish (only works on top of | * Check a block is completely valid from start to finish (only works on top of | ||||
* our current best block, with cs_main held) | * our current best block, with cs_main held) | ||||
*/ | */ | ||||
bool TestBlockValidity(const Config &config, CValidationState &state, | bool TestBlockValidity(const Config &config, CValidationState &state, | ||||
const CBlock &block, CBlockIndex *pindexPrev, | const CBlock &block, CBlockIndex *pindexPrev, | ||||
bool fCheckPOW = true, bool fCheckMerkleRoot = true); | bool fCheckPOW = true, bool fCheckMerkleRoot = true); | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |