Skip to content

Commit

Permalink
spv: Accept cfilters from more peers.
Browse files Browse the repository at this point in the history
If initial sync takes longer than six blocks and peers have not changed,
sync will hand at ninety-nine percent unable to get cfilters for the
last few blocks. Also accept cfilters from a peer that gave us headers
at or above the desired height in this case.
  • Loading branch information
JoeGruffins committed Nov 1, 2024
1 parent 15a67d7 commit 6b73c9a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions spv/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ func pickForGetCfilters(lastHeaderHeight int32) func(rp *p2p.RemotePeer) bool {
// blocks are generated while performing the sync, therefore
// the initial advertised peer height would be lower than the
// last header height. Therefore, accept peers that are
// close, but not quite at the tip.
return rp.InitialHeight() >= lastHeaderHeight-6
// close, but not quite at the tip. It's possible that sync
// until now took longer than six blocks. In that case get
// cfilters from a peer that gave us headers.
return rp.InitialHeight() >= lastHeaderHeight-6 || rp.LastHeight() >= lastHeaderHeight
}
}

Expand Down Expand Up @@ -118,7 +120,6 @@ func (s *Syncer) cfiltersV2FromNodes(ctx context.Context, nodes []*wallet.BlockN
}

cnet := s.wallet.ChainParams().Net

// Split fetching into batches of a max size.
const cfilterBatchSize = wire.MaxCFiltersV2PerBatch
if len(nodes) > cfilterBatchSize {
Expand Down

0 comments on commit 6b73c9a

Please sign in to comment.