From 6b73c9a87d9bdcf3fac09b5de2c6f28dcfd5237f Mon Sep 17 00:00:00 2001 From: JoeGruff Date: Tue, 29 Oct 2024 10:56:37 +0900 Subject: [PATCH] spv: Accept cfilters from more peers. 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. --- spv/backend.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spv/backend.go b/spv/backend.go index ca6ff64c1..7988e2b03 100644 --- a/spv/backend.go +++ b/spv/backend.go @@ -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 } } @@ -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 {