Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,243 Lines • ▼ Show 20 Lines | auto pushfunc = [&addr, &best, nRelayNodes, &insecure_rand] { | ||||
for (unsigned int i = 0; i < nRelayNodes && best[i].first != 0; i++) { | for (unsigned int i = 0; i < nRelayNodes && best[i].first != 0; i++) { | ||||
best[i].second->PushAddress(addr, insecure_rand); | best[i].second->PushAddress(addr, insecure_rand); | ||||
} | } | ||||
}; | }; | ||||
connman->ForEachNodeThen(std::move(sortfunc), std::move(pushfunc)); | connman->ForEachNodeThen(std::move(sortfunc), std::move(pushfunc)); | ||||
} | } | ||||
void static ProcessGetBlockData(const Config &config, CNode *pfrom, | static void ProcessGetBlockData(const Config &config, CNode *pfrom, | ||||
const CInv &inv, CConnman *connman, | const CInv &inv, CConnman *connman, | ||||
const std::atomic<bool> &interruptMsgProc) { | const std::atomic<bool> &interruptMsgProc) { | ||||
const Consensus::Params &consensusParams = | const Consensus::Params &consensusParams = | ||||
config.GetChainParams().GetConsensus(); | config.GetChainParams().GetConsensus(); | ||||
bool send = false; | bool send = false; | ||||
std::shared_ptr<const CBlock> a_recent_block; | std::shared_ptr<const CBlock> a_recent_block; | ||||
std::shared_ptr<const CBlockHeaderAndShortTxIDs> a_recent_compact_block; | std::shared_ptr<const CBlockHeaderAndShortTxIDs> a_recent_compact_block; | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | static void ProcessGetBlockData(const Config &config, CNode *pfrom, | ||||
if (send && pindex->nStatus.hasData()) { | if (send && pindex->nStatus.hasData()) { | ||||
std::shared_ptr<const CBlock> pblock; | std::shared_ptr<const CBlock> pblock; | ||||
if (a_recent_block && | if (a_recent_block && | ||||
a_recent_block->GetHash() == pindex->GetBlockHash()) { | a_recent_block->GetHash() == pindex->GetBlockHash()) { | ||||
pblock = a_recent_block; | pblock = a_recent_block; | ||||
} else { | } else { | ||||
// Send block from disk | // Send block from disk | ||||
std::shared_ptr<CBlock> pblockRead = std::make_shared<CBlock>(); | std::shared_ptr<CBlock> pblockRead = std::make_shared<CBlock>(); | ||||
if (!ReadBlockFromDisk(*pblockRead, pindex, config)) { | if (!ReadBlockFromDisk(*pblockRead, pindex, consensusParams)) { | ||||
assert(!"cannot load block from disk"); | assert(!"cannot load block from disk"); | ||||
} | } | ||||
pblock = pblockRead; | pblock = pblockRead; | ||||
} | } | ||||
if (inv.type == MSG_BLOCK) { | if (inv.type == MSG_BLOCK) { | ||||
connman->PushMessage(pfrom, | connman->PushMessage(pfrom, | ||||
msgMaker.Make(NetMsgType::BLOCK, *pblock)); | msgMaker.Make(NetMsgType::BLOCK, *pblock)); | ||||
} else if (inv.type == MSG_FILTERED_BLOCK) { | } else if (inv.type == MSG_FILTERED_BLOCK) { | ||||
▲ Show 20 Lines • Show All 1,028 Lines • ▼ Show 20 Lines | else if (strCommand == NetMsgType::GETBLOCKTXN) { | ||||
inv.hash = req.blockhash; | inv.hash = req.blockhash; | ||||
pfrom->vRecvGetData.push_back(inv); | pfrom->vRecvGetData.push_back(inv); | ||||
// The message processing loop will go around again (without | // The message processing loop will go around again (without | ||||
// pausing) and we'll respond then (without cs_main) | // pausing) and we'll respond then (without cs_main) | ||||
return true; | return true; | ||||
} | } | ||||
CBlock block; | CBlock block; | ||||
bool ret = ReadBlockFromDisk(block, pindex, config); | bool ret = ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()); | ||||
assert(ret); | assert(ret); | ||||
SendBlockTransactions(block, req, pfrom, connman); | SendBlockTransactions(block, req, pfrom, connman); | ||||
} | } | ||||
else if (strCommand == NetMsgType::GETHEADERS) { | else if (strCommand == NetMsgType::GETHEADERS) { | ||||
CBlockLocator locator; | CBlockLocator locator; | ||||
uint256 hashStop; | uint256 hashStop; | ||||
▲ Show 20 Lines • Show All 1,557 Lines • ▼ Show 20 Lines | // | ||||
pto, | pto, | ||||
msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, | msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, | ||||
cmpctblock)); | cmpctblock)); | ||||
fGotBlockFromCache = true; | fGotBlockFromCache = true; | ||||
} | } | ||||
} | } | ||||
if (!fGotBlockFromCache) { | if (!fGotBlockFromCache) { | ||||
CBlock block; | CBlock block; | ||||
bool ret = ReadBlockFromDisk(block, pBestIndex, config); | bool ret = | ||||
ReadBlockFromDisk(block, pBestIndex, consensusParams); | |||||
assert(ret); | assert(ret); | ||||
CBlockHeaderAndShortTxIDs cmpctblock(block); | CBlockHeaderAndShortTxIDs cmpctblock(block); | ||||
connman->PushMessage( | connman->PushMessage( | ||||
pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, | pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, | ||||
cmpctblock)); | cmpctblock)); | ||||
} | } | ||||
state.pindexBestHeaderSent = pBestIndex; | state.pindexBestHeaderSent = pBestIndex; | ||||
} else if (state.fPreferHeaders) { | } else if (state.fPreferHeaders) { | ||||
▲ Show 20 Lines • Show All 402 Lines • Show Last 20 Lines |