Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 928 Lines • ▼ Show 20 Lines | |||||
////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////// | ||||
// | // | ||||
// blockchain -> download logic notification | // blockchain -> download logic notification | ||||
// | // | ||||
// To prevent fingerprinting attacks, only send blocks/headers outside of the | // To prevent fingerprinting attacks, only send blocks/headers outside of the | ||||
// active chain if they are no more than a month older (both in time, and in | // active chain if they are no more than a month older (both in time, and in | ||||
// best equivalent proof of work) than the best header chain we know about. | // best equivalent proof of work) than the best header chain we know about and | ||||
static bool StaleBlockRequestAllowed(const CBlockIndex *pindex, | // we fully-validated them at some point. | ||||
static bool BlockRequestAllowed(const CBlockIndex *pindex, | |||||
const Consensus::Params &consensusParams) { | const Consensus::Params &consensusParams) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
return (pindexBestHeader != nullptr) && | if (chainActive.Contains(pindex)) { | ||||
return true; | |||||
} | |||||
return pindex->IsValid(BlockValidity::SCRIPTS) && | |||||
(pindexBestHeader != nullptr) && | |||||
(pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() < | (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() < | ||||
STALE_RELAY_AGE_LIMIT) && | STALE_RELAY_AGE_LIMIT) && | ||||
(GetBlockProofEquivalentTime(*pindexBestHeader, *pindex, | (GetBlockProofEquivalentTime(*pindexBestHeader, *pindex, | ||||
*pindexBestHeader, consensusParams) < | *pindexBestHeader, consensusParams) < | ||||
STALE_RELAY_AGE_LIMIT); | STALE_RELAY_AGE_LIMIT); | ||||
} | } | ||||
PeerLogicValidation::PeerLogicValidation(CConnman *connmanIn, | PeerLogicValidation::PeerLogicValidation(CConnman *connmanIn, | ||||
▲ Show 20 Lines • Show All 318 Lines • ▼ Show 20 Lines | while (it != pfrom->vRecvGetData.end()) { | ||||
std::shared_ptr<const CBlock> a_recent_block; | std::shared_ptr<const CBlock> a_recent_block; | ||||
{ | { | ||||
LOCK(cs_most_recent_block); | LOCK(cs_most_recent_block); | ||||
a_recent_block = most_recent_block; | a_recent_block = most_recent_block; | ||||
} | } | ||||
CValidationState dummy; | CValidationState dummy; | ||||
ActivateBestChain(config, dummy, a_recent_block); | ActivateBestChain(config, dummy, a_recent_block); | ||||
} | } | ||||
if (chainActive.Contains(mi->second)) { | send = BlockRequestAllowed(mi->second, consensusParams); | ||||
send = true; | |||||
} else { | |||||
send = mi->second->IsValid(BlockValidity::SCRIPTS) && | |||||
StaleBlockRequestAllowed(mi->second, | |||||
consensusParams); | |||||
if (!send) { | if (!send) { | ||||
LogPrintf("%s: ignoring request from peer=%i for " | LogPrintf("%s: ignoring request from peer=%i for old " | ||||
"old block that isn't in the main " | "block that isn't in the main chain\n", | ||||
"chain\n", | |||||
__func__, pfrom->GetId()); | __func__, pfrom->GetId()); | ||||
} | } | ||||
} | } | ||||
} | |||||
// Disconnect node in case we have reached the outbound limit | // Disconnect node in case we have reached the outbound limit | ||||
// for serving historical blocks. | // for serving historical blocks. | ||||
// Never disconnect whitelisted nodes. | // Never disconnect whitelisted nodes. | ||||
if (send && connman->OutboundTargetReached(true) && | if (send && connman->OutboundTargetReached(true) && | ||||
(((pindexBestHeader != nullptr) && | (((pindexBestHeader != nullptr) && | ||||
(pindexBestHeader->GetBlockTime() - | (pindexBestHeader->GetBlockTime() - | ||||
mi->second->GetBlockTime() > | mi->second->GetBlockTime() > | ||||
▲ Show 20 Lines • Show All 1,049 Lines • ▼ Show 20 Lines | else if (strCommand == NetMsgType::GETHEADERS) { | ||||
if (locator.IsNull()) { | if (locator.IsNull()) { | ||||
// If locator is null, return the hashStop block | // If locator is null, return the hashStop block | ||||
BlockMap::iterator mi = mapBlockIndex.find(hashStop); | BlockMap::iterator mi = mapBlockIndex.find(hashStop); | ||||
if (mi == mapBlockIndex.end()) { | if (mi == mapBlockIndex.end()) { | ||||
return true; | return true; | ||||
} | } | ||||
pindex = (*mi).second; | pindex = (*mi).second; | ||||
if (!chainActive.Contains(pindex) && | if (!BlockRequestAllowed(pindex, chainparams.GetConsensus())) { | ||||
!StaleBlockRequestAllowed(pindex, chainparams.GetConsensus())) { | |||||
LogPrintf("%s: ignoring request from peer=%i for old block " | LogPrintf("%s: ignoring request from peer=%i for old block " | ||||
"header that isn't in the main chain\n", | "header that isn't in the main chain\n", | ||||
__func__, pfrom->GetId()); | __func__, pfrom->GetId()); | ||||
return true; | return true; | ||||
} | } | ||||
} else { | } else { | ||||
// Find the last block the caller has in the main chain | // Find the last block the caller has in the main chain | ||||
pindex = FindForkInGlobalIndex(chainActive, locator); | pindex = FindForkInGlobalIndex(chainActive, locator); | ||||
▲ Show 20 Lines • Show All 1,915 Lines • Show Last 20 Lines |