@@ -2420,6 +2420,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
2420
2420
2421
2421
uint32_t nFetchFlags = GetFetchFlags (pfrom);
2422
2422
const auto current_time = GetTime<std::chrono::microseconds>();
2423
+ uint256* best_block{nullptr };
2423
2424
2424
2425
for (CInv &inv : vInv)
2425
2426
{
@@ -2436,17 +2437,14 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
2436
2437
if (inv.type == MSG_BLOCK) {
2437
2438
UpdateBlockAvailability (pfrom->GetId (), inv.hash );
2438
2439
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count (inv.hash )) {
2439
- // We used to request the full block here, but since headers-announcements are now the
2440
- // primary method of announcement on the network, and since, in the case that a node
2441
- // fell back to inv we probably have a reorg which we should get the headers for first,
2442
- // we now only provide a getheaders response here. When we receive the headers, we will
2443
- // then ask for the blocks we need.
2444
- connman->PushMessage (pfrom, msgMaker.Make (NetMsgType::GETHEADERS, ::ChainActive ().GetLocator (pindexBestHeader), inv.hash ));
2445
- LogPrint (BCLog::NET, " getheaders (%d) %s to peer=%d\n " , pindexBestHeader->nHeight , inv.hash .ToString (), pfrom->GetId ());
2440
+ // Headers-first is the primary method of announcement on
2441
+ // the network. If a node fell back to sending blocks by inv,
2442
+ // it's probably for a re-org. The final block hash
2443
+ // provided should be the highest, so send a getheaders and
2444
+ // then fetch the blocks we need to catch up.
2445
+ best_block = &inv.hash ;
2446
2446
}
2447
- }
2448
- else
2449
- {
2447
+ } else {
2450
2448
pfrom->AddInventoryKnown (inv);
2451
2449
if (fBlocksOnly ) {
2452
2450
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
2457
2455
}
2458
2456
}
2459
2457
}
2458
+
2459
+ if (best_block != nullptr ) {
2460
+ connman->PushMessage (pfrom, msgMaker.Make (NetMsgType::GETHEADERS, ::ChainActive ().GetLocator (pindexBestHeader), *best_block));
2461
+ LogPrint (BCLog::NET, " getheaders (%d) %s to peer=%d\n " , pindexBestHeader->nHeight , best_block->ToString (), pfrom->GetId ());
2462
+ }
2463
+
2460
2464
return true ;
2461
2465
}
2462
2466
0 commit comments