Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,871 Lines • ▼ Show 20 Lines | static void ProcessGetBlockData(const Config &config, CNode &pfrom, | ||||
} | } | ||||
const CNetMsgMaker msgMaker(pfrom.GetCommonVersion()); | const CNetMsgMaker msgMaker(pfrom.GetCommonVersion()); | ||||
// Disconnect node in case we have reached the outbound limit for serving | // Disconnect node in case we have reached the outbound limit for serving | ||||
// historical blocks. | // historical blocks. | ||||
if (send && connman.OutboundTargetReached(true) && | if (send && connman.OutboundTargetReached(true) && | ||||
(((pindexBestHeader != nullptr) && | (((pindexBestHeader != nullptr) && | ||||
(pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > | (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > | ||||
HISTORICAL_BLOCK_AGE)) || | HISTORICAL_BLOCK_AGE)) || | ||||
inv.type == MSG_FILTERED_BLOCK) && | inv.IsMsgFilteredBlk()) && | ||||
// nodes with the download permission may exceed target | // nodes with the download permission may exceed target | ||||
!pfrom.HasPermission(PF_DOWNLOAD)) { | !pfrom.HasPermission(PF_DOWNLOAD)) { | ||||
LogPrint(BCLog::NET, | LogPrint(BCLog::NET, | ||||
"historical block serving limit reached, disconnect peer=%d\n", | "historical block serving limit reached, disconnect peer=%d\n", | ||||
pfrom.GetId()); | pfrom.GetId()); | ||||
// disconnect node | // disconnect node | ||||
pfrom.fDisconnect = true; | pfrom.fDisconnect = true; | ||||
Show All 28 Lines | if (send && pindex->nStatus.hasData()) { | ||||
} 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, consensusParams)) { | 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.IsMsgBlk()) { | ||||
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.IsMsgFilteredBlk()) { | ||||
bool sendMerkleBlock = false; | bool sendMerkleBlock = false; | ||||
CMerkleBlock merkleBlock; | CMerkleBlock merkleBlock; | ||||
if (pfrom.m_tx_relay != nullptr) { | if (pfrom.m_tx_relay != nullptr) { | ||||
LOCK(pfrom.m_tx_relay->cs_filter); | LOCK(pfrom.m_tx_relay->cs_filter); | ||||
if (pfrom.m_tx_relay->pfilter) { | if (pfrom.m_tx_relay->pfilter) { | ||||
sendMerkleBlock = true; | sendMerkleBlock = true; | ||||
merkleBlock = | merkleBlock = | ||||
CMerkleBlock(*pblock, *pfrom.m_tx_relay->pfilter); | CMerkleBlock(*pblock, *pfrom.m_tx_relay->pfilter); | ||||
Show All 16 Lines | if (send && pindex->nStatus.hasData()) { | ||||
for (PairType &pair : merkleBlock.vMatchedTxn) { | for (PairType &pair : merkleBlock.vMatchedTxn) { | ||||
connman.PushMessage( | connman.PushMessage( | ||||
&pfrom, msgMaker.Make(NetMsgType::TX, | &pfrom, msgMaker.Make(NetMsgType::TX, | ||||
*pblock->vtx[pair.first])); | *pblock->vtx[pair.first])); | ||||
} | } | ||||
} | } | ||||
// else | // else | ||||
// no response | // no response | ||||
} else if (inv.type == MSG_CMPCT_BLOCK) { | } else if (inv.IsMsgCmpctBlk()) { | ||||
// If a peer is asking for old blocks, we're almost guaranteed they | // If a peer is asking for old blocks, we're almost guaranteed they | ||||
// won't have a useful mempool to match against a compact block, and | // won't have a useful mempool to match against a compact block, and | ||||
// we don't feel like constructing the object for them, so instead | // we don't feel like constructing the object for them, so instead | ||||
// we respond with the full, non-compact block. | // we respond with the full, non-compact block. | ||||
int nSendFlags = 0; | int nSendFlags = 0; | ||||
if (CanDirectFetch(consensusParams) && | if (CanDirectFetch(consensusParams) && | ||||
pindex->nHeight >= | pindex->nHeight >= | ||||
::ChainActive().Height() - MAX_CMPCTBLOCK_DEPTH) { | ::ChainActive().Height() - MAX_CMPCTBLOCK_DEPTH) { | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | while (it != pfrom.vRecvGetData.end() && it->IsMsgTx()) { | ||||
vNotFound.push_back(inv); | vNotFound.push_back(inv); | ||||
} | } | ||||
} | } | ||||
// Only process one BLOCK item per call, since they're uncommon and can be | // Only process one BLOCK item per call, since they're uncommon and can be | ||||
// expensive to process. | // expensive to process. | ||||
if (it != pfrom.vRecvGetData.end() && !pfrom.fPauseSend) { | if (it != pfrom.vRecvGetData.end() && !pfrom.fPauseSend) { | ||||
const CInv &inv = *it++; | const CInv &inv = *it++; | ||||
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || | if (inv.IsGenBlkMsg()) { | ||||
inv.type == MSG_CMPCT_BLOCK) { | |||||
ProcessGetBlockData(config, pfrom, inv, connman, interruptMsgProc); | ProcessGetBlockData(config, pfrom, inv, connman, interruptMsgProc); | ||||
} | } | ||||
// else: If the first item on the queue is an unknown type, we erase it | // else: If the first item on the queue is an unknown type, we erase it | ||||
// and continue processing the queue on the next call. | // and continue processing the queue on the next call. | ||||
} | } | ||||
pfrom.vRecvGetData.erase(pfrom.vRecvGetData.begin(), it); | pfrom.vRecvGetData.erase(pfrom.vRecvGetData.begin(), it); | ||||
▲ Show 20 Lines • Show All 995 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::INV) { | ||||
const auto current_time = GetTime<std::chrono::microseconds>(); | const auto current_time = GetTime<std::chrono::microseconds>(); | ||||
std::optional<BlockHash> best_block; | std::optional<BlockHash> best_block; | ||||
for (CInv &inv : vInv) { | for (CInv &inv : vInv) { | ||||
if (interruptMsgProc) { | if (interruptMsgProc) { | ||||
return; | return; | ||||
} | } | ||||
if (inv.type == MSG_BLOCK) { | if (inv.IsMsgBlk()) { | ||||
bool fAlreadyHave = AlreadyHaveBlock(BlockHash(inv.hash)); | bool fAlreadyHave = AlreadyHaveBlock(BlockHash(inv.hash)); | ||||
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", | LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", | ||||
inv.ToString(), fAlreadyHave ? "have" : "new", | inv.ToString(), fAlreadyHave ? "have" : "new", | ||||
pfrom.GetId()); | pfrom.GetId()); | ||||
const BlockHash hash{inv.hash}; | const BlockHash hash{inv.hash}; | ||||
UpdateBlockAvailability(pfrom.GetId(), hash); | UpdateBlockAvailability(pfrom.GetId(), hash); | ||||
if (!fAlreadyHave && !fImporting && !fReindex && | if (!fAlreadyHave && !fImporting && !fReindex && | ||||
▲ Show 20 Lines • Show All 2,493 Lines • Show Last 20 Lines |