Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 1,630 Lines • ▼ Show 20 Lines | bool CChainState::ConnectBlock(const Config &config, const CBlock &block, | ||||
CValidationState &state, CBlockIndex *pindex, | CValidationState &state, CBlockIndex *pindex, | ||||
CCoinsViewCache &view, bool fJustCheck) { | CCoinsViewCache &view, bool fJustCheck) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
assert(pindex); | assert(pindex); | ||||
assert(*pindex->phashBlock == block.GetHash()); | assert(*pindex->phashBlock == block.GetHash()); | ||||
int64_t nTimeStart = GetTimeMicros(); | int64_t nTimeStart = GetTimeMicros(); | ||||
// Check it again in case a previous version let a bad block in | // Check it again in case a previous version let a bad block in | ||||
// NOTE: We don't currently (re-)invoke ContextualCheckBlock() or | |||||
// ContextualCheckBlockHeader() here. This means that if we add a new | |||||
// consensus rule that is enforced in one of those two functions, then we | |||||
// may have let in a block that violates the rule prior to updating the | |||||
// software, and we would NOT be enforcing the rule here. Fully solving | |||||
// upgrade from one software version to the next after a consensus rule | |||||
// change is potentially tricky and issue-specific (see RewindBlockIndex() | |||||
// for one general approach that was used for BIP 141 deployment). | |||||
// Also, currently the rule against blocks more than 2 hours in the future | |||||
// is enforced in ContextualCheckBlockHeader(); we wouldn't want to | |||||
// re-enforce that rule here (at least until we make it impossible for | |||||
// GetAdjustedTime() to go backward). | |||||
BlockValidationOptions validationOptions = | BlockValidationOptions validationOptions = | ||||
BlockValidationOptions(!fJustCheck, !fJustCheck); | BlockValidationOptions(!fJustCheck, !fJustCheck); | ||||
if (!CheckBlock(config, block, state, validationOptions)) { | if (!CheckBlock(config, block, state, validationOptions)) { | ||||
return error("%s: Consensus::CheckBlock: %s", __func__, | return error("%s: Consensus::CheckBlock: %s", __func__, | ||||
FormatStateMessage(state)); | FormatStateMessage(state)); | ||||
} | } | ||||
// Verify that the view's current state corresponds to the previous block | // Verify that the view's current state corresponds to the previous block | ||||
▲ Show 20 Lines • Show All 1,877 Lines • ▼ Show 20 Lines | bool CheckBlock(const Config &config, const CBlock &block, | ||||
return true; | return true; | ||||
} | } | ||||
/** | /** | ||||
* Context-dependent validity checks. | * Context-dependent validity checks. | ||||
* By "context", we mean only the previous block headers, but not the UTXO | * By "context", we mean only the previous block headers, but not the UTXO | ||||
* set; UTXO-related validity checks are done in ConnectBlock(). | * 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 ContextualCheckBlockHeader(const Config &config, | static bool ContextualCheckBlockHeader(const Config &config, | ||||
const CBlockHeader &block, | const CBlockHeader &block, | ||||
CValidationState &state, | CValidationState &state, | ||||
const CBlockIndex *pindexPrev, | const CBlockIndex *pindexPrev, | ||||
int64_t nAdjustedTime) { | int64_t nAdjustedTime) { | ||||
assert(pindexPrev != nullptr); | assert(pindexPrev != nullptr); | ||||
const int nHeight = pindexPrev->nHeight + 1; | const int nHeight = pindexPrev->nHeight + 1; | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if ((block.nVersion < 2 && nHeight >= consensusParams.BIP34Height) || | ||||
false, REJECT_OBSOLETE, | false, REJECT_OBSOLETE, | ||||
strprintf("bad-version(0x%08x)", block.nVersion), | strprintf("bad-version(0x%08x)", block.nVersion), | ||||
strprintf("rejected nVersion=0x%08x block", block.nVersion)); | strprintf("rejected nVersion=0x%08x block", block.nVersion)); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
/** | |||||
* 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! | |||||
*/ | |||||
bool ContextualCheckTransactionForCurrentBlock(const Config &config, | bool ContextualCheckTransactionForCurrentBlock(const Config &config, | ||||
const CTransaction &tx, | const CTransaction &tx, | ||||
CValidationState &state, | CValidationState &state, | ||||
int flags) { | int flags) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
// By convention a negative value for flags indicates that the current | // By convention a negative value for flags indicates that the current | ||||
// network-enforced consensus rules should be used. In a future soft-fork | // network-enforced consensus rules should be used. In a future soft-fork | ||||
▲ Show 20 Lines • Show All 2,051 Lines • Show Last 20 Lines |