mirror of
https://github.com/dogecoin/dogecoin.git
synced 2026-01-31 10:30:52 +00:00
p2p: 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. Backported from: 74673663 Original Author: John Newbery <john@johnnewbery.com>
This commit is contained in:
parent
962b0205f4
commit
3e64e6f226
@ -1741,6 +1741,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||
|
||||
uint32_t nFetchFlags = GetFetchFlags(pfrom, chainActive.Tip(), chainparams.GetConsensus(chainActive.Height()));
|
||||
int64_t current_time = GetMockableTimeMicros();
|
||||
uint256* best_block{nullptr};
|
||||
|
||||
std::vector<CInv> vToFetch;
|
||||
|
||||
@ -1761,14 +1762,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||
if (inv.type == MSG_BLOCK) {
|
||||
UpdateBlockAvailability(pfrom->GetId(), 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
|
||||
// primary method of announcement on the network, and since, in the case that a node
|
||||
// fell back to inv we probably have a reorg which we should get the headers for first,
|
||||
// we now only provide a getheaders response here. When we receive the headers, we will
|
||||
// then ask for the blocks we need.
|
||||
// Dogecoin: We force this check, in case we're only connected to nodes that send invs
|
||||
RequestHeadersFrom(pfrom, connman, pindexBestHeader, inv.hash, true);
|
||||
LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id);
|
||||
// Headers-first is the primary method of announcement on
|
||||
// the network. If a node fell back to 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.
|
||||
best_block = &inv.hash;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1782,6 +1781,13 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||
|
||||
}
|
||||
|
||||
if (best_block != nullptr) {
|
||||
// Dogecoin: allow header requests from inv to be non-serial by
|
||||
// forcing the request, to be able to get split chaintips quickly.
|
||||
RequestHeadersFrom(pfrom, connman, pindexBestHeader, *best_block, true /* force */);
|
||||
LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, best_block->ToString(), pfrom->id);
|
||||
}
|
||||
|
||||
if (!vToFetch.empty())
|
||||
connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::GETDATA, vToFetch));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user