Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | |||||
static constexpr unsigned int MAX_FEEFILTER_CHANGE_DELAY = 5 * 60; | static constexpr unsigned int MAX_FEEFILTER_CHANGE_DELAY = 5 * 60; | ||||
// Internal stuff | // Internal stuff | ||||
namespace { | namespace { | ||||
/** Number of nodes with fSyncStarted. */ | /** Number of nodes with fSyncStarted. */ | ||||
int nSyncStarted GUARDED_BY(cs_main) = 0; | int nSyncStarted GUARDED_BY(cs_main) = 0; | ||||
/** | /** | ||||
* Sources of received blocks, saved to be able to send them reject messages or | * Sources of received blocks, saved to be able to punish them when processing | ||||
* ban them when processing happens afterwards. | * happens afterwards. | ||||
* Set mapBlockSource[hash].second to false if the node should not be punished | * Set mapBlockSource[hash].second to false if the node should not be punished | ||||
* if the block is invalid. | * if the block is invalid. | ||||
*/ | */ | ||||
std::map<BlockHash, std::pair<NodeId, bool>> mapBlockSource GUARDED_BY(cs_main); | std::map<BlockHash, std::pair<NodeId, bool>> mapBlockSource GUARDED_BY(cs_main); | ||||
/** | /** | ||||
* Filter for transactions that were recently rejected by AcceptToMemoryPool. | * Filter for transactions that were recently rejected by AcceptToMemoryPool. | ||||
* These are not rerequested until the chain tip changes, at which point the | * These are not rerequested until the chain tip changes, at which point the | ||||
▲ Show 20 Lines • Show All 3,208 Lines • ▼ Show 20 Lines | if (strCommand == NetMsgType::BLOCKTXN) { | ||||
// 3. the block is otherwise invalid (eg invalid coinbase, | // 3. the block is otherwise invalid (eg invalid coinbase, | ||||
// block is too big, too many legacy sigops, etc). | // block is too big, too many legacy sigops, etc). | ||||
// So if CheckBlock failed, #3 is the only possibility. | // So if CheckBlock failed, #3 is the only possibility. | ||||
// Under BIP 152, we don't DoS-ban unless proof of work is | // Under BIP 152, we don't DoS-ban unless proof of work is | ||||
// invalid (we don't require all the stateless checks to have | // invalid (we don't require all the stateless checks to have | ||||
// been run). This is handled below, so just treat this as | // been run). This is handled below, so just treat this as | ||||
// though the block was successfully read, and rely on the | // though the block was successfully read, and rely on the | ||||
// handling in ProcessNewBlock to ensure the block index is | // handling in ProcessNewBlock to ensure the block index is | ||||
// updated, reject messages go out, etc. | // updated, etc. | ||||
// it is now an empty pointer | // it is now an empty pointer | ||||
MarkBlockAsReceived(resp.blockhash); | MarkBlockAsReceived(resp.blockhash); | ||||
fBlockRead = true; | fBlockRead = true; | ||||
// mapBlockSource is only used for sending reject messages and | // mapBlockSource is used for potentially punishing peers and | ||||
// DoS scores, so the race between here and cs_main in | // updating which peers send us compact blocks, so the race | ||||
// ProcessNewBlock is fine. BIP 152 permits peers to relay | // between here and cs_main in ProcessNewBlock is fine. | ||||
// compact blocks after validating the header only; we should | // BIP 152 permits peers to relay compact blocks after | ||||
// not punish peers if the block turns out to be invalid. | // validating the header only; we should not punish peers | ||||
// if the block turns out to be invalid. | |||||
mapBlockSource.emplace(resp.blockhash, | mapBlockSource.emplace(resp.blockhash, | ||||
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 | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | if (strCommand == NetMsgType::BLOCK) { | ||||
bool forceProcessing = pfrom->HasPermission(PF_NOBAN) && | bool forceProcessing = pfrom->HasPermission(PF_NOBAN) && | ||||
!::ChainstateActive().IsInitialBlockDownload(); | !::ChainstateActive().IsInitialBlockDownload(); | ||||
const BlockHash hash = pblock->GetHash(); | const BlockHash hash = pblock->GetHash(); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
// Also always process if we requested the block explicitly, as we | // Also always process if we requested the block explicitly, as we | ||||
// may need it even though it is not a candidate for a new best tip. | // may need it even though it is not a candidate for a new best tip. | ||||
forceProcessing |= MarkBlockAsReceived(hash); | forceProcessing |= MarkBlockAsReceived(hash); | ||||
// mapBlockSource is only used for sending reject messages and DoS | // mapBlockSource is only used for punishing peers and setting | ||||
// scores, so the race between here and cs_main in ProcessNewBlock | // which peers send us compact blocks, so the race between here and | ||||
// is fine. | // cs_main in ProcessNewBlock is fine. | ||||
mapBlockSource.emplace(hash, std::make_pair(pfrom->GetId(), true)); | mapBlockSource.emplace(hash, std::make_pair(pfrom->GetId(), true)); | ||||
} | } | ||||
bool fNewBlock = false; | bool fNewBlock = false; | ||||
ProcessNewBlock(config, pblock, forceProcessing, &fNewBlock); | ProcessNewBlock(config, pblock, forceProcessing, &fNewBlock); | ||||
if (fNewBlock) { | if (fNewBlock) { | ||||
pfrom->nLastBlockTime = GetTime(); | pfrom->nLastBlockTime = GetTime(); | ||||
} else { | } else { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
▲ Show 20 Lines • Show All 1,510 Lines • Show Last 20 Lines |