Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,498 Lines • ▼ Show 20 Lines | inline static void SendBlockTransactions(const CBlock &block, | ||||
const BlockTransactionsRequest &req, | const BlockTransactionsRequest &req, | ||||
CNode *pfrom, CConnman *connman) { | CNode *pfrom, CConnman *connman) { | ||||
BlockTransactions resp(req); | BlockTransactions resp(req); | ||||
for (size_t i = 0; i < req.indices.size(); i++) { | for (size_t i = 0; i < req.indices.size(); i++) { | ||||
if (req.indices[i] >= block.vtx.size()) { | if (req.indices[i] >= block.vtx.size()) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
Misbehaving(pfrom, 100, "out-of-bound-tx-index"); | Misbehaving(pfrom, 100, "out-of-bound-tx-index"); | ||||
LogPrintf( | LogPrintf( | ||||
"Peer %d sent us a getblocktxn with out-of-bounds tx indices", | "Peer %d sent us a getblocktxn with out-of-bounds tx indices\n", | ||||
pfrom->GetId()); | pfrom->GetId()); | ||||
return; | return; | ||||
} | } | ||||
resp.txn[i] = block.vtx[req.indices[i]]; | resp.txn[i] = block.vtx[req.indices[i]]; | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CNetMsgMaker msgMaker(pfrom->GetSendVersion()); | const CNetMsgMaker msgMaker(pfrom->GetSendVersion()); | ||||
int nSendFlags = 0; | int nSendFlags = 0; | ||||
▲ Show 20 Lines • Show All 843 Lines • ▼ Show 20 Lines | else if (strCommand == NetMsgType::GETBLOCKTXN) { | ||||
SendBlockTransactions(*recent_block, req, pfrom, connman); | SendBlockTransactions(*recent_block, req, pfrom, connman); | ||||
return true; | return true; | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CBlockIndex *pindex = LookupBlockIndex(req.blockhash); | const CBlockIndex *pindex = LookupBlockIndex(req.blockhash); | ||||
if (!pindex || !pindex->nStatus.hasData()) { | if (!pindex || !pindex->nStatus.hasData()) { | ||||
LogPrint(BCLog::NET, | LogPrint( | ||||
"Peer %d sent us a getblocktxn for a block we don't have", | BCLog::NET, | ||||
"Peer %d sent us a getblocktxn for a block we don't have\n", | |||||
pfrom->GetId()); | pfrom->GetId()); | ||||
return true; | return true; | ||||
} | } | ||||
if (pindex->nHeight < chainActive.Height() - MAX_BLOCKTXN_DEPTH) { | if (pindex->nHeight < chainActive.Height() - MAX_BLOCKTXN_DEPTH) { | ||||
// If an older block is requested (should never happen in practice, | // If an older block is requested (should never happen in practice, | ||||
// but can happen in tests) send a block response instead of a | // but can happen in tests) send a block response instead of a | ||||
// blocktxn response. Sending a full block response instead of a | // blocktxn response. Sending a full block response instead of a | ||||
// small blocktxn response is preferable in the case where a peer | // small blocktxn response is preferable in the case where a peer | ||||
// might maliciously send lots of getblocktxn requests to trigger | // might maliciously send lots of getblocktxn requests to trigger | ||||
// expensive disk reads, because it will require the peer to | // expensive disk reads, because it will require the peer to | ||||
// actually receive all the data read from disk over the network. | // actually receive all the data read from disk over the network. | ||||
LogPrint(BCLog::NET, | LogPrint(BCLog::NET, | ||||
"Peer %d sent us a getblocktxn for a block > %i deep", | "Peer %d sent us a getblocktxn for a block > %i deep\n", | ||||
pfrom->GetId(), MAX_BLOCKTXN_DEPTH); | pfrom->GetId(), MAX_BLOCKTXN_DEPTH); | ||||
CInv inv; | CInv inv; | ||||
inv.type = MSG_BLOCK; | inv.type = MSG_BLOCK; | ||||
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; | ||||
▲ Show 20 Lines • Show All 1,988 Lines • Show Last 20 Lines |