Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 1,710 Lines • ▼ Show 20 Lines | |||||
* done; ConnectBlock() can fail if those validity checks fail (among other | * done; ConnectBlock() can fail if those validity checks fail (among other | ||||
* reasons). | * reasons). | ||||
*/ | */ | ||||
bool CChainState::ConnectBlock(const Config &config, const CBlock &block, | 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); | ||||
// pindex->phashBlock can be null if called by | assert(*pindex->phashBlock == block.GetHash()); | ||||
// CreateNewBlock/TestBlockValidity | |||||
assert((pindex->phashBlock == nullptr) || | |||||
(*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 | ||||
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)); | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | bool CChainState::ConnectBlock(const Config &config, const CBlock &block, | ||||
// http://r6.ca/blog/20120206T005236Z.html for more information. This logic | // http://r6.ca/blog/20120206T005236Z.html for more information. This logic | ||||
// is not necessary for memory pool transactions, as AcceptToMemoryPool | // is not necessary for memory pool transactions, as AcceptToMemoryPool | ||||
// already refuses previously-known transaction ids entirely. This rule was | // already refuses previously-known transaction ids entirely. This rule was | ||||
// originally applied to all blocks with a timestamp after March 15, 2012, | // originally applied to all blocks with a timestamp after March 15, 2012, | ||||
// 0:00 UTC. Now that the whole chain is irreversibly beyond that time it is | // 0:00 UTC. Now that the whole chain is irreversibly beyond that time it is | ||||
// applied to all blocks except the two in the chain that violate it. This | // applied to all blocks except the two in the chain that violate it. This | ||||
// prevents exploiting the issue against nodes during their initial block | // prevents exploiting the issue against nodes during their initial block | ||||
// download. | // download. | ||||
bool fEnforceBIP30 = (!pindex->phashBlock) || // Enforce on CreateNewBlock | bool fEnforceBIP30 = !((pindex->nHeight == 91842 && | ||||
// invocations which don't | |||||
// have a hash. | |||||
!((pindex->nHeight == 91842 && | |||||
pindex->GetBlockHash() == | pindex->GetBlockHash() == | ||||
uint256S("0x00000000000a4d0a398161ffc163c503763" | uint256S("0x00000000000a4d0a398161ffc163c503763" | ||||
"b1f4360639393e0e4c8e300e0caec")) || | "b1f4360639393e0e4c8e300e0caec")) || | ||||
(pindex->nHeight == 91880 && | (pindex->nHeight == 91880 && | ||||
pindex->GetBlockHash() == | pindex->GetBlockHash() == | ||||
uint256S("0x00000000000743f190a18c5577a3c2d2a1f" | uint256S("0x00000000000743f190a18c5577a3c2d2a1f" | ||||
"610ae9601ac046a38084ccb7cd721"))); | "610ae9601ac046a38084ccb7cd721"))); | ||||
▲ Show 20 Lines • Show All 2,320 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
bool TestBlockValidity(const Config &config, CValidationState &state, | bool TestBlockValidity(const Config &config, CValidationState &state, | ||||
const CBlock &block, CBlockIndex *pindexPrev, | const CBlock &block, CBlockIndex *pindexPrev, | ||||
BlockValidationOptions validationOptions) { | BlockValidationOptions validationOptions) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
assert(pindexPrev && pindexPrev == chainActive.Tip()); | assert(pindexPrev && pindexPrev == chainActive.Tip()); | ||||
CCoinsViewCache viewNew(pcoinsTip.get()); | CCoinsViewCache viewNew(pcoinsTip.get()); | ||||
uint256 block_hash(block.GetHash()); | |||||
CBlockIndex indexDummy(block); | CBlockIndex indexDummy(block); | ||||
indexDummy.pprev = pindexPrev; | indexDummy.pprev = pindexPrev; | ||||
indexDummy.nHeight = pindexPrev->nHeight + 1; | indexDummy.nHeight = pindexPrev->nHeight + 1; | ||||
indexDummy.phashBlock = &block_hash; | |||||
// NOTE: CheckBlockHeader is called by CheckBlock | // NOTE: CheckBlockHeader is called by CheckBlock | ||||
if (!ContextualCheckBlockHeader(config, block, state, pindexPrev, | 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)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,563 Lines • Show Last 20 Lines |