From ceb454aa16752a387c775459f208f0dd41d5e387 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Mon, 23 Mar 2020 09:49:51 +0200 Subject: [PATCH] neutrinonotify: use batch for historical confirmations. This commit introduces an optimization for the chain scanning used in historical confirmations notifications. It now uses batch request instead of requesting filters one by one. --- chainntnfs/neutrinonotify/neutrino.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/chainntnfs/neutrinonotify/neutrino.go b/chainntnfs/neutrinonotify/neutrino.go index dfe6fca3..771c4b86 100644 --- a/chainntnfs/neutrinonotify/neutrino.go +++ b/chainntnfs/neutrinonotify/neutrino.go @@ -523,11 +523,18 @@ func (n *NeutrinoNotifier) historicalConfDetails(confRequest chainntnfs.ConfRequ scanHeight, err) } - // With the hash computed, we can now fetch the basic filter - // for this height. + // With the hash computed, we can now fetch the basic filter for this + // height. Since the range of required items is known we avoid + // roundtrips by requesting a batched response and save bandwidth by + // limiting the max number of items per batch. Since neutrino populates + // its underline filters cache with the batch response, the next call + // will execute a network query only once per batch and not on every + // iteration. regFilter, err := n.p2pNode.GetCFilter( *blockHash, wire.GCSFilterRegular, neutrino.NumRetries(5), + neutrino.OptimisticReverseBatch(), + neutrino.MaxBatchSize(int64(scanHeight-startHeight+1)), ) if err != nil { return nil, fmt.Errorf("unable to retrieve regular filter for "+