mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
[net processing] Only send a getheaders for one block in an INV
Headers-first is the primary method of announcement on the network. If a node fell back sending blocks by inv, it's probably for a re-org. The final block hash provided should be the highest, so send a getheaders and then fetch the blocks we need to catch up.
This commit is contained in:
parent
8da1e43b63
commit
746736639e
1 changed files with 14 additions and 10 deletions
|
@ -2420,6 +2420,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
|
||||||
|
|
||||||
uint32_t nFetchFlags = GetFetchFlags(pfrom);
|
uint32_t nFetchFlags = GetFetchFlags(pfrom);
|
||||||
const auto current_time = GetTime<std::chrono::microseconds>();
|
const auto current_time = GetTime<std::chrono::microseconds>();
|
||||||
|
uint256* best_block{nullptr};
|
||||||
|
|
||||||
for (CInv &inv : vInv)
|
for (CInv &inv : vInv)
|
||||||
{
|
{
|
||||||
|
@ -2436,17 +2437,14 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
|
||||||
if (inv.type == MSG_BLOCK) {
|
if (inv.type == MSG_BLOCK) {
|
||||||
UpdateBlockAvailability(pfrom->GetId(), inv.hash);
|
UpdateBlockAvailability(pfrom->GetId(), inv.hash);
|
||||||
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) {
|
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) {
|
||||||
// We used to request the full block here, but since headers-announcements are now the
|
// Headers-first is the primary method of announcement on
|
||||||
// primary method of announcement on the network, and since, in the case that a node
|
// the network. If a node fell back to sending blocks by inv,
|
||||||
// fell back to inv we probably have a reorg which we should get the headers for first,
|
// it's probably for a re-org. The final block hash
|
||||||
// we now only provide a getheaders response here. When we receive the headers, we will
|
// provided should be the highest, so send a getheaders and
|
||||||
// then ask for the blocks we need.
|
// then fetch the blocks we need to catch up.
|
||||||
connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETHEADERS, ::ChainActive().GetLocator(pindexBestHeader), inv.hash));
|
best_block = &inv.hash;
|
||||||
LogPrint(BCLog::NET, "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->GetId());
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
pfrom->AddInventoryKnown(inv);
|
pfrom->AddInventoryKnown(inv);
|
||||||
if (fBlocksOnly) {
|
if (fBlocksOnly) {
|
||||||
LogPrint(BCLog::NET, "transaction (%s) inv sent in violation of protocol, disconnecting peer=%d\n", inv.hash.ToString(), pfrom->GetId());
|
LogPrint(BCLog::NET, "transaction (%s) inv sent in violation of protocol, disconnecting peer=%d\n", inv.hash.ToString(), pfrom->GetId());
|
||||||
|
@ -2457,6 +2455,12 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (best_block != nullptr) {
|
||||||
|
connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::GETHEADERS, ::ChainActive().GetLocator(pindexBestHeader), *best_block));
|
||||||
|
LogPrint(BCLog::NET, "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, best_block->ToString(), pfrom->GetId());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue