Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,355 Lines • ▼ Show 20 Lines | uint32_t GetFetchFlags(CNode *pfrom, const CBlockIndex *pprev, | ||||
uint32_t nFetchFlags = 0; | uint32_t nFetchFlags = 0; | ||||
return nFetchFlags; | return nFetchFlags; | ||||
} | } | ||||
inline static void SendBlockTransactions(const CBlock &block, | 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.indexes.size(); i++) { | for (size_t i = 0; i < req.indices.size(); i++) { | ||||
if (req.indexes[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", | ||||
pfrom->id); | pfrom->id); | ||||
return; | return; | ||||
} | } | ||||
resp.txn[i] = block.vtx[req.indexes[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; | ||||
connman.PushMessage(pfrom, | connman.PushMessage(pfrom, | ||||
msgMaker.Make(nSendFlags, NetMsgType::BLOCKTXN, resp)); | msgMaker.Make(nSendFlags, NetMsgType::BLOCKTXN, resp)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,012 Lines • ▼ Show 20 Lines | else if (strCommand == NetMsgType::CMPCTBLOCK && !fImporting && !fReindex) { | ||||
if (status == READ_STATUS_INVALID) { | if (status == READ_STATUS_INVALID) { | ||||
// Reset in-flight state in case of whitelist | // Reset in-flight state in case of whitelist | ||||
MarkBlockAsReceived(pindex->GetBlockHash()); | MarkBlockAsReceived(pindex->GetBlockHash()); | ||||
Misbehaving(pfrom, 100, "invalid-cmpctblk"); | Misbehaving(pfrom, 100, "invalid-cmpctblk"); | ||||
LogPrintf("Peer %d sent us invalid compact block\n", | LogPrintf("Peer %d sent us invalid compact block\n", | ||||
pfrom->id); | pfrom->id); | ||||
return true; | return true; | ||||
} else if (status == READ_STATUS_FAILED) { | } else if (status == READ_STATUS_FAILED) { | ||||
// Duplicate txindexes, the block is now in-flight, so | // Duplicate txindices, the block is now in-flight, so | ||||
// just request it. | // just request it. | ||||
std::vector<CInv> vInv(1); | std::vector<CInv> vInv(1); | ||||
vInv[0] = | vInv[0] = | ||||
CInv(MSG_BLOCK | | CInv(MSG_BLOCK | | ||||
GetFetchFlags(pfrom, pindex->pprev, | GetFetchFlags(pfrom, pindex->pprev, | ||||
chainparams.GetConsensus()), | chainparams.GetConsensus()), | ||||
cmpctblock.header.GetHash()); | cmpctblock.header.GetHash()); | ||||
connman.PushMessage( | connman.PushMessage( | ||||
pfrom, msgMaker.Make(NetMsgType::GETDATA, vInv)); | pfrom, msgMaker.Make(NetMsgType::GETDATA, vInv)); | ||||
return true; | return true; | ||||
} | } | ||||
BlockTransactionsRequest req; | BlockTransactionsRequest req; | ||||
for (size_t i = 0; i < cmpctblock.BlockTxCount(); i++) { | for (size_t i = 0; i < cmpctblock.BlockTxCount(); i++) { | ||||
if (!partialBlock.IsTxAvailable(i)) { | if (!partialBlock.IsTxAvailable(i)) { | ||||
req.indexes.push_back(i); | req.indices.push_back(i); | ||||
} | } | ||||
} | } | ||||
if (req.indexes.empty()) { | if (req.indices.empty()) { | ||||
// Dirty hack to jump to BLOCKTXN code (TODO: move | // Dirty hack to jump to BLOCKTXN code (TODO: move | ||||
// message handling into their own functions) | // message handling into their own functions) | ||||
BlockTransactions txn; | BlockTransactions txn; | ||||
txn.blockhash = cmpctblock.header.GetHash(); | txn.blockhash = cmpctblock.header.GetHash(); | ||||
blockTxnMsg << txn; | blockTxnMsg << txn; | ||||
fProcessBLOCKTXN = true; | fProcessBLOCKTXN = true; | ||||
} else { | } else { | ||||
req.blockhash = pindex->GetBlockHash(); | req.blockhash = pindex->GetBlockHash(); | ||||
▲ Show 20 Lines • Show All 1,411 Lines • Show Last 20 Lines |