From 90a0744ae4fafdcfebf1535c39263c57942cc86c Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Tue, 24 Mar 2020 16:23:41 -0700 Subject: [PATCH] chain: batch filter fetches for neutrino chain client This greatly speeds up wallet recovery with a neutrino backend, as we'll avoid unnecessary round trips for each block filter fetch. --- chain/neutrino.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/chain/neutrino.go b/chain/neutrino.go index 71ef800..28987f7 100644 --- a/chain/neutrino.go +++ b/chain/neutrino.go @@ -199,6 +199,11 @@ func (s *NeutrinoClient) FilterBlocks( // the filter returns a positive match, the full block is then requested // and scanned for addresses using the block filterer. for i, blk := range req.Blocks { + // TODO(wilmer): Investigate why polling it still necessary + // here. While testing, I ran into a few instances where the + // filter was not retrieved, leading to a panic. This should not + // happen in most cases thanks to the query logic revamp within + // Neutrino, but it seems there's still an uncovered edge case. filter, err := s.pollCFilter(&blk.Hash) if err != nil { return nil, err @@ -312,7 +317,9 @@ func (s *NeutrinoClient) pollCFilter(hash *chainhash.Hash) (*gcs.Filter, error) time.Sleep(100 * time.Millisecond) } - filter, err = s.CS.GetCFilter(*hash, wire.GCSFilterRegular) + filter, err = s.CS.GetCFilter( + *hash, wire.GCSFilterRegular, neutrino.OptimisticBatch(), + ) if err != nil { count++ continue