Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,340 Lines • ▼ Show 20 Lines | return pindex->IsValid(BlockValidity::SCRIPTS) && | ||||
(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, BanMan *banman, | PeerLogicValidation::PeerLogicValidation(CConnman *connmanIn, BanMan *banman, | ||||
CScheduler &scheduler) | CScheduler &scheduler, | ||||
: connman(connmanIn), m_banman(banman), m_stale_tip_check_time(0) { | ChainstateManager &chainman) | ||||
: connman(connmanIn), m_banman(banman), m_chainman(chainman), | |||||
m_stale_tip_check_time(0) { | |||||
// Initialize global variables that cannot be constructed at startup. | // Initialize global variables that cannot be constructed at startup. | ||||
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001)); | recentRejects.reset(new CRollingBloomFilter(120000, 0.000001)); | ||||
const Consensus::Params &consensusParams = Params().GetConsensus(); | const Consensus::Params &consensusParams = Params().GetConsensus(); | ||||
// Stale tip checking and peer eviction are on two different timers, but we | // Stale tip checking and peer eviction are on two different timers, but we | ||||
// don't want them to get out of sync due to drift in the scheduler, so we | // don't want them to get out of sync due to drift in the scheduler, so we | ||||
// combine them in one function and schedule at the quicker (peer-eviction) | // combine them in one function and schedule at the quicker (peer-eviction) | ||||
// timer. | // timer. | ||||
▲ Show 20 Lines • Show All 1,124 Lines • ▼ Show 20 Lines | static void ProcessGetCFCheckPt(CNode &pfrom, CDataStream &vRecv, | ||||
CSerializedNetMsg msg = CNetMsgMaker(pfrom.GetSendVersion()) | CSerializedNetMsg msg = CNetMsgMaker(pfrom.GetSendVersion()) | ||||
.Make(NetMsgType::CFCHECKPT, filter_type_ser, | .Make(NetMsgType::CFCHECKPT, filter_type_ser, | ||||
stop_index->GetBlockHash(), headers); | stop_index->GetBlockHash(), headers); | ||||
connman.PushMessage(&pfrom, std::move(msg)); | connman.PushMessage(&pfrom, std::move(msg)); | ||||
} | } | ||||
bool ProcessMessage(const Config &config, CNode &pfrom, | bool ProcessMessage(const Config &config, CNode &pfrom, | ||||
const std::string &msg_type, CDataStream &vRecv, | const std::string &msg_type, CDataStream &vRecv, | ||||
int64_t nTimeReceived, CConnman &connman, BanMan *banman, | int64_t nTimeReceived, ChainstateManager &chainman, | ||||
CConnman &connman, BanMan *banman, | |||||
const std::atomic<bool> &interruptMsgProc) { | const std::atomic<bool> &interruptMsgProc) { | ||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", | LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", | ||||
SanitizeString(msg_type), vRecv.size(), pfrom.GetId()); | SanitizeString(msg_type), vRecv.size(), pfrom.GetId()); | ||||
if (gArgs.IsArgSet("-dropmessagestest") && | if (gArgs.IsArgSet("-dropmessagestest") && | ||||
GetRand(gArgs.GetArg("-dropmessagestest", 0)) == 0) { | GetRand(gArgs.GetArg("-dropmessagestest", 0)) == 0) { | ||||
LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); | LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 1,013 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::CMPCTBLOCK) { | ||||
// treatment as a header message. | // treatment as a header message. | ||||
fRevertToHeaderProcessing = true; | fRevertToHeaderProcessing = true; | ||||
} | } | ||||
} | } | ||||
} // cs_main | } // cs_main | ||||
if (fProcessBLOCKTXN) { | if (fProcessBLOCKTXN) { | ||||
return ProcessMessage(config, pfrom, NetMsgType::BLOCKTXN, | return ProcessMessage(config, pfrom, NetMsgType::BLOCKTXN, | ||||
blockTxnMsg, nTimeReceived, connman, banman, | blockTxnMsg, nTimeReceived, chainman, connman, | ||||
interruptMsgProc); | banman, interruptMsgProc); | ||||
} | } | ||||
if (fRevertToHeaderProcessing) { | if (fRevertToHeaderProcessing) { | ||||
// Headers received from HB compact block peers are permitted to be | // Headers received from HB compact block peers are permitted to be | ||||
// relayed before full validation (see BIP 152), so we don't want to | // relayed before full validation (see BIP 152), so we don't want to | ||||
// disconnect the peer if the header turns out to be for an invalid | // disconnect the peer if the header turns out to be for an invalid | ||||
// block. Note that if a peer tries to build on an invalid chain, | // block. Note that if a peer tries to build on an invalid chain, | ||||
// that will be detected and the peer will be banned. | // that will be detected and the peer will be banned. | ||||
▲ Show 20 Lines • Show All 793 Lines • ▼ Show 20 Lines | if (!msg.m_valid_checksum) { | ||||
connman->DisconnectNode(pfrom->addr); | connman->DisconnectNode(pfrom->addr); | ||||
return fMoreWork; | return fMoreWork; | ||||
} | } | ||||
// Process message | // Process message | ||||
bool fRet = false; | bool fRet = false; | ||||
try { | try { | ||||
fRet = ProcessMessage(config, *pfrom, msg_type, vRecv, msg.m_time, | fRet = ProcessMessage(config, *pfrom, msg_type, vRecv, msg.m_time, | ||||
*connman, m_banman, interruptMsgProc); | m_chainman, *connman, m_banman, interruptMsgProc); | ||||
if (interruptMsgProc) { | if (interruptMsgProc) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!pfrom->vRecvGetData.empty()) { | if (!pfrom->vRecvGetData.empty()) { | ||||
fMoreWork = true; | fMoreWork = true; | ||||
} | } | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
▲ Show 20 Lines • Show All 950 Lines • Show Last 20 Lines |