@@ -3135,7 +3135,7 @@ namespace Consensus {
3135
3135
{
3136
3136
outOverflow = true;
3137
3137
}
3138
-
3138
+
3139
3139
if (outOverflow || ReserveValueIn < reserveValueOut)
3140
3140
{
3141
3141
fprintf(stderr,"overflow or spentheight.%d reservevaluein: %s\nis less than out: %s\n", nSpendHeight,
@@ -8806,7 +8806,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
8806
8806
8807
8807
LOCK(cs_main);
8808
8808
8809
- std::vector<CInv> vToFetch ;
8809
+ const uint256* best_block{nullptr} ;
8810
8810
8811
8811
for (unsigned int nInv = 0; nInv < vInv.size(); nInv++)
8812
8812
{
@@ -8820,29 +8820,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
8820
8820
if (inv.type == MSG_BLOCK) {
8821
8821
UpdateBlockAvailability(pfrom->GetId(), inv.hash);
8822
8822
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) {
8823
- // First request the headers preceding the announced block. In the normal fully-synced
8824
- // case where a new block is announced that succeeds the current tip (no reorganization),
8825
- // there are no such headers.
8826
- // Secondly, and only when we are close to being synced, we request the announced block directly,
8827
- // to avoid an extra round-trip. Note that we must *first* ask for the headers, so by the
8828
- // time the block arrives, the header chain leading up to it is already validated. Not
8829
- // doing this will result in the received block being rejected as an orphan in case it is
8830
- // not a direct successor.
8831
- pfrom->PushMessage (" getheaders" , chainActive.GetLocator (pindexBestHeader), inv.hash );
8832
- CNodeState *nodestate = State (pfrom->GetId ());
8833
-
8834
- if (chainActive.Tip ()->GetBlockTime () > GetAdjustedTime () - (ConnectedChains.ThisChain ().blockTime * 20 ) &&
8835
- nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
8836
- vToFetch.push_back (inv);
8837
- // Mark block as in flight already, even though the actual "getdata" message only goes out
8838
- // later (within the same cs_main lock, though).
8839
- MarkBlockAsInFlight (pfrom->GetId (), inv.hash , chainparams.GetConsensus ());
8840
- }
8841
- LogPrint (" net" , " getheaders (%d) %s to peer=%d\n " , pindexBestHeader->GetHeight (), inv.hash .ToString (), pfrom->id );
8823
+ // Headers-first is the primary method of announcement on
8824
+ // the network. If a node fell back to sending blocks by inv,
8825
+ // it's probably for a re-org. The final block hash
8826
+ // provided should be the highest, so send a getheaders and
8827
+ // then fetch the blocks we need to catch up.
8828
+ best_block = &inv.hash;
8842
8829
}
8843
- }
8844
- else
8845
- {
8830
+ } else {
8846
8831
pfrom->AddKnownWTxId(WTxId(inv.hash));
8847
8832
if (fBlocksOnly)
8848
8833
LogPrint("net", "transaction (%s) inv sent in violation of protocol peer=%d\n", inv.hash.ToString(), pfrom->id);
@@ -8856,8 +8841,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
8856
8841
}
8857
8842
}
8858
8843
8859
- if (!vToFetch.empty ())
8860
- pfrom->PushMessage (" getdata" , vToFetch);
8844
+ if (best_block != nullptr) {
8845
+ pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexBestHeader), *best_block);
8846
+ LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->GetHeight(), best_block->ToString(), pfrom->id);
8847
+ }
8861
8848
}
8862
8849
8863
8850
@@ -9125,7 +9112,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
9125
9112
LogPrint("mempool", "%s from peer=%d %s was not accepted into the memory pool: %s\n", tx.GetHash().ToString(),
9126
9113
pfrom->id, pfrom->cleanSubVer,
9127
9114
state.GetRejectReason());
9128
-
9115
+
9129
9116
bool sendReject = true;
9130
9117
if (state.GetRejectReason() == "bad-txns-inputs-spent" && nDoS <= 1)
9131
9118
{
0 commit comments