From 2d25bae7bce8d28290b6f1eff59c2880a2b9ed14 Mon Sep 17 00:00:00 2001 From: Calvin Kim Date: Tue, 29 Oct 2024 14:07:37 +0900 Subject: [PATCH] netsync: ignore tx invs when we're not current During ibd sometimes we may ban our sync peers because we're attempting to fetch some txs that may already been confirmed and don't exist in the mempool anymore. Since we shouldn't be fetching txs anyways when we're not current, this commit changes the handleInvMsg logic to ignore tx invs if the node is not caught up to the tip. Fixes #1984 --- netsync/manager.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/netsync/manager.go b/netsync/manager.go index 3215a86aced..f81361d9dc8 100644 --- a/netsync/manager.go +++ b/netsync/manager.go @@ -1171,6 +1171,11 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) { peer.UpdateLastAnnouncedBlock(&invVects[lastBlock].Hash) } + // Ignore inventory when we're in headers-first mode. + if sm.headersFirstMode { + return + } + // Ignore invs from peers that aren't the sync if we are not current. // Helps prevent fetching a mass of orphans. if peer != sm.syncPeer && !sm.current() { @@ -1201,15 +1206,20 @@ func (sm *SyncManager) handleInvMsg(imsg *invMsg) { continue } + // Ingore txs when we're not current as we can't verify them + // and they'll just go in the orphan pool. + if iv.Type == wire.InvTypeWitnessTx || + iv.Type == wire.InvTypeTx { + + if !sm.current() { + continue + } + } + // Add the inventory to the cache of known inventory // for the peer. peer.AddKnownInventory(iv) - // Ignore inventory when we're in headers-first mode. - if sm.headersFirstMode { - continue - } - // Request the inventory if we don't already have it. haveInv, err := sm.haveInventory(iv) if err != nil {