Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 3,783 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::AVAPOLL && !fImporting && !fReindex && | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
for (unsigned int n = 0; n < nCount; n++) { | for (unsigned int n = 0; n < nCount; n++) { | ||||
CInv inv; | CInv inv; | ||||
vRecv >> inv; | vRecv >> inv; | ||||
uint32_t error = -1; | const auto insertVote = [&](uint32_t e) { | ||||
if (inv.type == MSG_BLOCK) { | votes.emplace_back(e, inv.hash); | ||||
auto blockIndex = LookupBlockIndex(BlockHash(inv.hash)); | }; | ||||
if (blockIndex) { | |||||
error = ::ChainActive().Contains(blockIndex) ? 0 : 1; | // Not a block. | ||||
if (inv.type != MSG_BLOCK) { | |||||
insertVote(-1); | |||||
continue; | |||||
} | |||||
// We have a block. | |||||
const CBlockIndex *pindex = | |||||
LookupBlockIndex(BlockHash(inv.hash)); | |||||
// Unknown block. | |||||
if (!pindex) { | |||||
insertVote(-1); | |||||
continue; | |||||
} | |||||
// Invalid block | |||||
if (pindex->nStatus.isInvalid()) { | |||||
insertVote(1); | |||||
continue; | |||||
} | |||||
// Parked block | |||||
if (pindex->nStatus.isOnParkedChain()) { | |||||
insertVote(2); | |||||
continue; | |||||
} | |||||
const CBlockIndex *pindexTip = ::ChainActive().Tip(); | |||||
const CBlockIndex *pindexFork = | |||||
LastCommonAncestor(pindex, pindexTip); | |||||
// Active block. | |||||
if (pindex == pindexFork) { | |||||
insertVote(0); | |||||
continue; | |||||
} | |||||
// Fork block. | |||||
if (pindexFork != pindexTip) { | |||||
insertVote(3); | |||||
continue; | |||||
} | } | ||||
// Missing block data. | |||||
if (!pindex->nStatus.hasData()) { | |||||
insertVote(-2); | |||||
continue; | |||||
} | } | ||||
votes.emplace_back(error, inv.hash); | // This block is built on top of the tip, we have the data, it | ||||
// is pending connection or rejection. | |||||
insertVote(-3); | |||||
} | } | ||||
} | } | ||||
// Send the query to the node. | // Send the query to the node. | ||||
g_avalanche->sendResponse( | g_avalanche->sendResponse( | ||||
&pfrom, avalanche::Response(round, cooldown, std::move(votes))); | &pfrom, avalanche::Response(round, cooldown, std::move(votes))); | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,434 Lines • Show Last 20 Lines |