Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 3,875 Lines • ▼ Show 20 Lines | if (isSameHeightAndMoreHonestlyMined) { | ||||
"diff=%d\n", | "diff=%d\n", | ||||
chainActive.Tip()->GetBlockHash().ToString(), | chainActive.Tip()->GetBlockHash().ToString(), | ||||
chainTipTimeDiff); | chainTipTimeDiff); | ||||
LogPrintf("New block timestamp-to-received-time difference: hash=%s, " | LogPrintf("New block timestamp-to-received-time difference: hash=%s, " | ||||
"diff=%d\n", | "diff=%d\n", | ||||
pindex->GetBlockHash().ToString(), newBlockTimeDiff); | pindex->GetBlockHash().ToString(), newBlockTimeDiff); | ||||
} | } | ||||
bool fHasMoreWork = | // New chain either has more work or is more honestly mined | ||||
bool chainTipShouldUpdate = | |||||
isSameHeightAndMoreHonestlyMined || | |||||
(chainActive.Tip() ? pindex->nChainWork > chainActive.Tip()->nChainWork | (chainActive.Tip() ? pindex->nChainWork > chainActive.Tip()->nChainWork | ||||
deadalnix: Please keep `fHasMoreWork` and then you can add:
bool chainTipShouldUpdate =… | |||||
: true); | : true); | ||||
if (chainTipShouldUpdate && isSameHeightAndMoreHonestlyMined) { | |||||
LogPrintf("More honestly broadcasted block will replace chaintip: %s\n", | |||||
pindex->GetBlockHash().ToString()); | |||||
} | |||||
// Blocks that are too out-of-order needlessly limit the effectiveness of | // Blocks that are too out-of-order needlessly limit the effectiveness of | ||||
// pruning, because pruning will not delete block files that contain any | // pruning, because pruning will not delete block files that contain any | ||||
// blocks which are too close in height to the tip. Apply this test | // blocks which are too close in height to the tip. Apply this test | ||||
// regardless of whether pruning is enabled; it should generally be safe to | // regardless of whether pruning is enabled; it should generally be safe to | ||||
// not process unrequested blocks. | // not process unrequested blocks. | ||||
bool fTooFarAhead = | bool fTooFarAhead = | ||||
(pindex->nHeight > int(chainActive.Height() + MIN_BLOCKS_TO_KEEP)); | (pindex->nHeight > int(chainActive.Height() + MIN_BLOCKS_TO_KEEP)); | ||||
Show All 11 Lines | static bool AcceptBlock(const Config &config, | ||||
// If we didn't ask for it: | // If we didn't ask for it: | ||||
if (!fRequested) { | if (!fRequested) { | ||||
// This is a previously-processed block that was pruned. | // This is a previously-processed block that was pruned. | ||||
if (pindex->nTx != 0) { | if (pindex->nTx != 0) { | ||||
return true; | return true; | ||||
} | } | ||||
// Don't process less-work chains. | // Don't process less-work chains. | ||||
deadalnixUnsubmitted Done Inline ActionsThis comment is invalid now. deadalnix: This comment is invalid now. | |||||
jasonbcoxAuthorUnsubmitted Done Inline ActionsIt's still valid because less-work is < not <=. It would have been more accurate in the past if it said same-or-less work. jasonbcox: It's still valid because less-work is < not <=. It would have been more accurate in the past if… | |||||
if (!fHasMoreWork) { | if (!chainTipShouldUpdate) { | ||||
return true; | return true; | ||||
} | } | ||||
// Block height is too high. | // Block height is too high. | ||||
if (fTooFarAhead) { | if (fTooFarAhead) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
Show All 11 Lines | if (!CheckBlock(config, block, state) || | ||||
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 and the merkle tree is good. | // Header is valid/has work and the merkle tree is good. | ||||
// Relay now, but if it does not build on our best tip, let the | // 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() && chainTipShouldUpdate) { | ||||
deadalnixUnsubmitted Done Inline ActionsConsidering this doesn't trigger when fHasMoreWork is true, then what ensures a reorg happens ? Is calling NewPoWValidBlock really the right thing to do ? After all, the chain we want to pick doesn't have more PoW behing it, just more accurate timestamps. deadalnix: Considering this doesn't trigger when `fHasMoreWork` is true, then what ensures a reorg happens… | |||||
jasonbcoxAuthorUnsubmitted Not Done Inline ActionsI think the naming here is confusing. This hooks into the net_processing code that announces new blocks. If this node receives a more honest block, I think it makes sense to announce that block ASAP or else we're encouraging the honest block to be orphaned by not sharing it with the network as fast as possible. jasonbcox: I think the naming here is confusing. This hooks into the net_processing code that announces… | |||||
GetMainSignals().NewPoWValidBlock(pindex, pblock); | GetMainSignals().NewPoWValidBlock(pindex, pblock); | ||||
} | } | ||||
int nHeight = pindex->nHeight; | int nHeight = pindex->nHeight; | ||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
// Write block to history file | // Write block to history file | ||||
try { | try { | ||||
▲ Show 20 Lines • Show All 1,575 Lines • Show Last 20 Lines |
Please keep fHasMoreWork and then you can add:
Keeping names for intermediate variable makes the code more readable.