From 1f781ea4317173b523ccf629252eb4c04699bd09 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Fri, 13 Dec 2019 16:07:53 -0800 Subject: [PATCH] discovery: use inclusive range in FilterChannelRange FilterChannelRange takes an inclusive range, so it was possible for us to return channels for an additional block that was not requested. --- discovery/syncer.go | 3 ++- discovery/syncer_test.go | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/discovery/syncer.go b/discovery/syncer.go index 9edb02be..b7dd07f8 100644 --- a/discovery/syncer.go +++ b/discovery/syncer.go @@ -814,8 +814,9 @@ func (g *GossipSyncer) replyChanRangeQuery(query *lnwire.QueryChannelRange) erro // Next, we'll consult the time series to obtain the set of known // channel ID's that match their query. startBlock := query.FirstBlockHeight + endBlock := startBlock + query.NumBlocks - 1 channelRange, err := g.cfg.channelSeries.FilterChannelRange( - query.ChainHash, startBlock, startBlock+query.NumBlocks, + query.ChainHash, startBlock, endBlock, ) if err != nil { return err diff --git a/discovery/syncer_test.go b/discovery/syncer_test.go index 60ba3d5f..9ca2f331 100644 --- a/discovery/syncer_test.go +++ b/discovery/syncer_test.go @@ -709,10 +709,12 @@ func TestGossipSyncerReplyChanRangeQuery(t *testing.T) { // Next, we'll craft a query to ask for all the new chan ID's after // block 100. - const startingBlockHeight int = 100 + const startingBlockHeight = 100 + const numBlocks = 50 + const endingBlockHeight = startingBlockHeight + numBlocks - 1 query := &lnwire.QueryChannelRange{ FirstBlockHeight: uint32(startingBlockHeight), - NumBlocks: 50, + NumBlocks: uint32(numBlocks), } // We'll then launch a goroutine to reply to the query with a set of 5 @@ -744,8 +746,11 @@ func TestGossipSyncerReplyChanRangeQuery(t *testing.T) { return case filterReq := <-chanSeries.filterRangeReqs: // We should be querying for block 100 to 150. - if filterReq.startHeight != 100 && filterReq.endHeight != 150 { - errCh <- fmt.Errorf("wrong height range: %v", spew.Sdump(filterReq)) + if filterReq.startHeight != startingBlockHeight && + filterReq.endHeight != endingBlockHeight { + + errCh <- fmt.Errorf("wrong height range: %v", + spew.Sdump(filterReq)) return }