Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
| Show First 20 Lines • Show All 3,516 Lines • ▼ Show 20 Lines | const int64_t nLockTimeCutoff = (flags & LOCKTIME_MEDIAN_TIME_PAST) | ||||
| : GetAdjustedTime(); | : GetAdjustedTime(); | ||||
| return ContextualCheckTransaction(config, tx, state, nBlockHeight, | return ContextualCheckTransaction(config, tx, state, nBlockHeight, | ||||
| nLockTimeCutoff); | nLockTimeCutoff); | ||||
| } | } | ||||
| bool ContextualCheckBlock(const Config &config, const CBlock &block, | bool ContextualCheckBlock(const Config &config, const CBlock &block, | ||||
| CValidationState &state, | CValidationState &state, | ||||
| const Consensus::Params &consensusParams, | |||||
| const CBlockIndex *pindexPrev) { | const CBlockIndex *pindexPrev) { | ||||
| const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1; | const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1; | ||||
| const Consensus::Params &consensusParams = | |||||
| config.GetChainParams().GetConsensus(); | |||||
| // Start enforcing BIP113 (Median Time Past) using versionbits logic. | // Start enforcing BIP113 (Median Time Past) using versionbits logic. | ||||
| int nLockTimeFlags = 0; | int nLockTimeFlags = 0; | ||||
| if (VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_CSV, | if (VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_CSV, | ||||
| versionbitscache) == THRESHOLD_ACTIVE) { | versionbitscache) == THRESHOLD_ACTIVE) { | ||||
| nLockTimeFlags |= LOCKTIME_MEDIAN_TIME_PAST; | nLockTimeFlags |= LOCKTIME_MEDIAN_TIME_PAST; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | if (!fRequested) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| if (fNewBlock) { | if (fNewBlock) { | ||||
| *fNewBlock = true; | *fNewBlock = true; | ||||
| } | } | ||||
| const CChainParams &chainparams = config.GetChainParams(); | |||||
| if (!CheckBlock(config, block, state) || | if (!CheckBlock(config, block, state) || | ||||
| !ContextualCheckBlock(config, block, state, chainparams.GetConsensus(), | !ContextualCheckBlock(config, block, state, pindex->pprev)) { | ||||
| pindex->pprev)) { | |||||
| if (state.IsInvalid() && !state.CorruptionPossible()) { | if (state.IsInvalid() && !state.CorruptionPossible()) { | ||||
| pindex->nStatus |= BLOCK_FAILED_VALID; | pindex->nStatus |= BLOCK_FAILED_VALID; | ||||
| setDirtyBlockIndex.insert(pindex); | setDirtyBlockIndex.insert(pindex); | ||||
| } | } | ||||
| return error("%s: %s (block %s)", __func__, FormatStateMessage(state), | return error("%s: %s (block %s)", __func__, FormatStateMessage(state), | ||||
| block.GetHash().ToString()); | block.GetHash().ToString()); | ||||
| } | } | ||||
| // Header is valid/has work, merkle tree and segwit merkle tree are | // Header is valid/has work, merkle tree and segwit merkle tree are | ||||
| // good...RELAY NOW (but if it does not build on our best tip, let the | // good...RELAY NOW (but if it does not build on our best tip, let the | ||||
| // SendMessages loop relay it) | // SendMessages loop relay it) | ||||
| if (!IsInitialBlockDownload() && chainActive.Tip() == pindex->pprev) { | if (!IsInitialBlockDownload() && chainActive.Tip() == pindex->pprev) { | ||||
| GetMainSignals().NewPoWValidBlock(pindex, pblock); | GetMainSignals().NewPoWValidBlock(pindex, pblock); | ||||
| } | } | ||||
| int nHeight = pindex->nHeight; | int nHeight = pindex->nHeight; | ||||
| const CChainParams &chainparams = config.GetChainParams(); | |||||
| // Write block to history file | // Write block to history file | ||||
| try { | try { | ||||
| unsigned int nBlockSize = | unsigned int nBlockSize = | ||||
| ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION); | ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION); | ||||
| CDiskBlockPos blockPos; | CDiskBlockPos blockPos; | ||||
| if (dbp != nullptr) { | if (dbp != nullptr) { | ||||
| blockPos = *dbp; | blockPos = *dbp; | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | if (!ContextualCheckBlockHeader(config, block, state, pindexPrev, | ||||
| GetAdjustedTime())) { | GetAdjustedTime())) { | ||||
| return error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, | return error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, | ||||
| FormatStateMessage(state)); | FormatStateMessage(state)); | ||||
| } | } | ||||
| if (!CheckBlock(config, block, state, fCheckPOW, fCheckMerkleRoot)) { | if (!CheckBlock(config, block, state, fCheckPOW, fCheckMerkleRoot)) { | ||||
| return error("%s: Consensus::CheckBlock: %s", __func__, | return error("%s: Consensus::CheckBlock: %s", __func__, | ||||
| FormatStateMessage(state)); | FormatStateMessage(state)); | ||||
| } | } | ||||
| if (!ContextualCheckBlock(config, block, state, chainparams.GetConsensus(), | if (!ContextualCheckBlock(config, block, state, pindexPrev)) { | ||||
| pindexPrev)) { | |||||
| return error("%s: Consensus::ContextualCheckBlock: %s", __func__, | return error("%s: Consensus::ContextualCheckBlock: %s", __func__, | ||||
| FormatStateMessage(state)); | FormatStateMessage(state)); | ||||
| } | } | ||||
| if (!ConnectBlock(config, block, state, &indexDummy, viewNew, chainparams, | if (!ConnectBlock(config, block, state, &indexDummy, viewNew, chainparams, | ||||
| true)) { | true)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,287 Lines • Show Last 20 Lines | |||||