From 0c134a8cb32e595afa336bd3c11d2af61b19c319 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 8 Jun 2017 23:10:46 -0700 Subject: [PATCH] routing/chainview: if the chain filter is empty, don't fetch the cfilter --- routing/chainview/neutrino.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/routing/chainview/neutrino.go b/routing/chainview/neutrino.go index c4c594d1..49f129bf 100644 --- a/routing/chainview/neutrino.go +++ b/routing/chainview/neutrino.go @@ -250,12 +250,21 @@ func (c *CfFilteredChainView) FilterBlock(blockHash *chainhash.Hash) (*FilteredB Height: blockHeight, } + // If we don't have any items within our current chain filter, then we + // can exit early as we don't need to fetch the filter. + c.filterMtx.RLock() + numPoints := len(c.chainFilter) + c.filterMtx.RUnlock() + if numPoints == 0 { + return filteredBlock, nil + } + // Next, using the block, hash, we'll fetch the compact filter for this // block. We only require the regular filter as we're just looking for // outpoint that have been spent. filter, err := c.p2pNode.GetCFilter(*blockHash, false) if err != nil { - return filteredBlock, err + return nil, err } // Before we can match the filter, we'll need to map each item in our