Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 2,604 Lines • ▼ Show 20 Lines | do { | ||||
} | } | ||||
// A parked chain can be unparked if it has twice as much PoW | // A parked chain can be unparked if it has twice as much PoW | ||||
// accumulated as the main chain has since the fork block. | // accumulated as the main chain has since the fork block. | ||||
CBlockIndex const *pindexExtraPow = pindexTip; | CBlockIndex const *pindexExtraPow = pindexTip; | ||||
arith_uint256 requiredWork = pindexTip->nChainWork; | arith_uint256 requiredWork = pindexTip->nChainWork; | ||||
switch (pindexTip->nHeight - pindexFork->nHeight) { | switch (pindexTip->nHeight - pindexFork->nHeight) { | ||||
// Limit the penality for depth 1, 2 and 3 to half a block | // Limit the penality for depth 1, 2 and 3 to half a block | ||||
// worth of work to ensure we don't fork accidentaly. | // worth of work to ensure we don't fork accidentally. | ||||
case 3: | case 3: | ||||
case 2: | case 2: | ||||
pindexExtraPow = pindexExtraPow->pprev; | pindexExtraPow = pindexExtraPow->pprev; | ||||
// FALLTHROUGH | // FALLTHROUGH | ||||
case 1: { | case 1: { | ||||
const arith_uint256 deltaWork = | const arith_uint256 deltaWork = | ||||
pindexExtraPow->nChainWork - pindexFork->nChainWork; | pindexExtraPow->nChainWork - pindexFork->nChainWork; | ||||
requiredWork += (deltaWork >> 1); | requiredWork += (deltaWork >> 1); | ||||
▲ Show 20 Lines • Show All 358 Lines • ▼ Show 20 Lines | bool CChainState::PreciousBlock(const Config &config, CValidationState &state, | ||||
// We can't keep reducing the counter if somebody really wants to | // We can't keep reducing the counter if somebody really wants to | ||||
// call preciousblock 2**31-1 times on the same set of tips... | // call preciousblock 2**31-1 times on the same set of tips... | ||||
nBlockReverseSequenceId--; | nBlockReverseSequenceId--; | ||||
} | } | ||||
// In case this was parked, unpark it. | // In case this was parked, unpark it. | ||||
UnparkBlock(pindex); | UnparkBlock(pindex); | ||||
// Make sure it is added to the candidate list if apropriate. | // Make sure it is added to the candidate list if appropriate. | ||||
if (pindex->IsValid(BlockValidity::TRANSACTIONS) && pindex->nChainTx) { | if (pindex->IsValid(BlockValidity::TRANSACTIONS) && pindex->nChainTx) { | ||||
setBlockIndexCandidates.insert(pindex); | setBlockIndexCandidates.insert(pindex); | ||||
PruneBlockIndexCandidates(); | PruneBlockIndexCandidates(); | ||||
} | } | ||||
} | } | ||||
return ActivateBestChain(config, state); | return ActivateBestChain(config, state); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | if (pindexNew->pprev == nullptr || pindexNew->pprev->nChainTx) { | ||||
// Recursively process any descendant blocks that now may be eligible to | // Recursively process any descendant blocks that now may be eligible to | ||||
// be connected. | // be connected. | ||||
while (!queue.empty()) { | while (!queue.empty()) { | ||||
CBlockIndex *pindex = queue.front(); | CBlockIndex *pindex = queue.front(); | ||||
queue.pop_front(); | queue.pop_front(); | ||||
pindex->nChainTx = | pindex->nChainTx = | ||||
(pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx; | (pindex->pprev ? pindex->pprev->nChainTx : 0) + pindex->nTx; | ||||
if (pindex->nSequenceId == 0) { | if (pindex->nSequenceId == 0) { | ||||
// We assign a sequence is when transaction are recieved to | // We assign a sequence is when transaction are received to | ||||
// prevent a miner from being able to broadcast a block but not | // prevent a miner from being able to broadcast a block but not | ||||
// its content. However, a sequence id may have been set | // its content. However, a sequence id may have been set | ||||
// manually, for instance via PreciousBlock, in which case, we | // manually, for instance via PreciousBlock, in which case, we | ||||
// don't need to assign one. | // don't need to assign one. | ||||
pindex->nSequenceId = nBlockSequenceId++; | pindex->nSequenceId = nBlockSequenceId++; | ||||
} | } | ||||
if (chainActive.Tip() == nullptr || | if (chainActive.Tip() == nullptr || | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/** | /** | ||||
* Return true if the provided block header is valid. | * Return true if the provided block header is valid. | ||||
* Only verify PoW if blockValidationOptions is configured to do so. | * Only verify PoW if blockValidationOptions is configured to do so. | ||||
* This allows validation of headers on which the PoW hasn't been done. | * This allows validation of headers on which the PoW hasn't been done. | ||||
* For example: to validate template handed to mining software. | * For example: to validate template handed to mining software. | ||||
* Do not call this for any check that depends on the context. | * Do not call this for any check that depends on the context. | ||||
* For context-dependant calls, see ContextualCheckBlockHeader. | * For context-dependent calls, see ContextualCheckBlockHeader. | ||||
*/ | */ | ||||
static bool CheckBlockHeader( | static bool CheckBlockHeader( | ||||
const Config &config, const CBlockHeader &block, CValidationState &state, | const Config &config, const CBlockHeader &block, CValidationState &state, | ||||
BlockValidationOptions validationOptions = BlockValidationOptions()) { | BlockValidationOptions validationOptions = BlockValidationOptions()) { | ||||
// Check proof of work matches claimed amount | // Check proof of work matches claimed amount | ||||
if (validationOptions.shouldValidatePoW() && | if (validationOptions.shouldValidatePoW() && | ||||
!CheckProofOfWork(block.GetHash(), block.nBits, config)) { | !CheckProofOfWork(block.GetHash(), block.nBits, config)) { | ||||
return state.DoS(50, false, REJECT_INVALID, "high-hash", false, | return state.DoS(50, false, REJECT_INVALID, "high-hash", false, | ||||
▲ Show 20 Lines • Show All 296 Lines • ▼ Show 20 Lines | static bool ContextualCheckBlock(const Config &config, const CBlock &block, | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
/** | /** | ||||
* If the provided block header is valid, add it to the block index. | * If the provided block header is valid, add it to the block index. | ||||
* | * | ||||
* Returns true if the block is succesfully added to the block index. | * Returns true if the block is successfully added to the block index. | ||||
*/ | */ | ||||
bool CChainState::AcceptBlockHeader(const Config &config, | bool CChainState::AcceptBlockHeader(const Config &config, | ||||
const CBlockHeader &block, | const CBlockHeader &block, | ||||
CValidationState &state, | CValidationState &state, | ||||
CBlockIndex **ppindex) { | CBlockIndex **ppindex) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
▲ Show 20 Lines • Show All 1,907 Lines • Show Last 20 Lines |