Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 2,828 Lines • ▼ Show 20 Lines | else if (strCommand == NetMsgType::CMPCTBLOCK && !fImporting && !fReindex) { | ||||
// If we got here, we were able to optimistically reconstruct a | // If we got here, we were able to optimistically reconstruct a | ||||
// block that is in flight from some other peer. | // block that is in flight from some other peer. | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
mapBlockSource.emplace(pblock->GetHash(), | mapBlockSource.emplace(pblock->GetHash(), | ||||
std::make_pair(pfrom->GetId(), false)); | std::make_pair(pfrom->GetId(), false)); | ||||
} | } | ||||
bool fNewBlock = false; | bool fNewBlock = false; | ||||
ProcessNewBlock(config, pblock, true, &fNewBlock); | // Setting fForceProcessing to true means that we bypass some of | ||||
// our anti-DoS protections in AcceptBlock, which filters | |||||
// unrequested blocks that might be trying to waste our resources | |||||
// (eg disk space). Because we only try to reconstruct blocks when | |||||
// we're close to caught up (via the CanDirectFetch() requirement | |||||
// above, combined with the behavior of not requesting blocks until | |||||
// we have a chain with at least nMinimumChainWork), and we ignore | |||||
// compact blocks with less work than our tip, it is safe to treat | |||||
// reconstructed compact blocks as having been requested. | |||||
ProcessNewBlock(config, pblock, /*fForceProcessing=*/true, | |||||
&fNewBlock); | |||||
if (fNewBlock) { | if (fNewBlock) { | ||||
pfrom->nLastBlockTime = GetTime(); | pfrom->nLastBlockTime = GetTime(); | ||||
} | } | ||||
// hold cs_main for CBlockIndex::IsValid() | // hold cs_main for CBlockIndex::IsValid() | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (pindex->IsValid(BlockValidity::TRANSACTIONS)) { | if (pindex->IsValid(BlockValidity::TRANSACTIONS)) { | ||||
// Clear download state for this block, which is in process from | // Clear download state for this block, which is in process from | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | else if (strCommand == NetMsgType::BLOCKTXN && !fImporting && | ||||
std::make_pair(pfrom->GetId(), false)); | std::make_pair(pfrom->GetId(), false)); | ||||
} | } | ||||
} // Don't hold cs_main when we call into ProcessNewBlock | } // Don't hold cs_main when we call into ProcessNewBlock | ||||
if (fBlockRead) { | if (fBlockRead) { | ||||
bool fNewBlock = false; | bool fNewBlock = false; | ||||
// Since we requested this block (it was in mapBlocksInFlight), | // Since we requested this block (it was in mapBlocksInFlight), | ||||
// force it to be processed, even if it would not be a candidate for | // force it to be processed, even if it would not be a candidate for | ||||
// new tip (missing previous block, chain not long enough, etc) | // new tip (missing previous block, chain not long enough, etc) | ||||
ProcessNewBlock(config, pblock, true, &fNewBlock); | // This bypasses some anti-DoS logic in AcceptBlock (eg to prevent | ||||
// disk-space attacks), but this should be safe due to the | |||||
// protections in the compact block handler -- see related comment | |||||
// in compact block optimistic reconstruction handling. | |||||
ProcessNewBlock(config, pblock, /*fForceProcessing=*/true, | |||||
&fNewBlock); | |||||
if (fNewBlock) { | if (fNewBlock) { | ||||
pfrom->nLastBlockTime = GetTime(); | pfrom->nLastBlockTime = GetTime(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Ignore headers received while importing | // Ignore headers received while importing | ||||
else if (strCommand == NetMsgType::HEADERS && !fImporting && !fReindex) { | else if (strCommand == NetMsgType::HEADERS && !fImporting && !fReindex) { | ||||
▲ Show 20 Lines • Show All 1,305 Lines • Show Last 20 Lines |