From 153794adb02b46f2bef216d9d9cb1252b10e160a Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 10 Nov 2017 16:55:31 -0800 Subject: [PATCH 1/2] routing/router: sets bestHeight before filtering chain This commit alters the behavior of the router's logic on startup, ensuring that the chain view is filtered using the router's latest prune height. Before, the chain was filtered using the bestHeight variable, which was uninitialized, benignly forcing a rescan from genesis. In tracking down this, we realized that we should actually be using the prune height, as this is representative of the channel view loaded from disk. The best height/hash are now only used during startup to determine if we are out of sync. --- routing/router.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/routing/router.go b/routing/router.go index 5ebaae9e..19cd7e12 100644 --- a/routing/router.go +++ b/routing/router.go @@ -273,6 +273,18 @@ func (r *ChannelRouter) Start() error { r.newBlocks = r.cfg.ChainView.FilteredBlocks() r.staleBlocks = r.cfg.ChainView.DisconnectedBlocks() + _, pruneHeight, err := r.cfg.Graph.PruneTip() + if err != nil { + switch { + // If the graph has never been pruned, or hasn't fully been + // created yet, then we don't treat this as an explicit error. + case err == channeldb.ErrGraphNeverPruned: + case err == channeldb.ErrGraphNotFound: + default: + return err + } + } + // Before we perform our manual block pruning, we'll construct and // apply a fresh chain filter to the active FilteredChainView instance. // We do this before, as otherwise we may miss on-chain events as the @@ -281,8 +293,9 @@ func (r *ChannelRouter) Start() error { if err != nil && err != channeldb.ErrGraphNoEdgesFound { return err } + log.Infof("Filtering chain using %v channels active", len(channelView)) - err = r.cfg.ChainView.UpdateFilter(channelView, r.bestHeight) + err = r.cfg.ChainView.UpdateFilter(channelView, pruneHeight) if err != nil { return err } @@ -331,6 +344,7 @@ func (r *ChannelRouter) syncGraphWithChain() error { return err } r.bestHeight = uint32(bestHeight) + pruneHash, pruneHeight, err := r.cfg.Graph.PruneTip() if err != nil { switch { From e62bb0319d487d7b9f2dbdda31559dace30970bb Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 10 Nov 2017 16:59:37 -0800 Subject: [PATCH 2/2] routing/chainview/btcd: makes rescan logging statement print to trace --- routing/chainview/btcd.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/routing/chainview/btcd.go b/routing/chainview/btcd.go index 04c4ce84..48b0260f 100644 --- a/routing/chainview/btcd.go +++ b/routing/chainview/btcd.go @@ -366,12 +366,12 @@ func (b *BtcdFilteredChainView) chainFilterer() { continue } - // If no block was returned from the rescan, - // it means no maching transactions were found. + // If no block was returned from the rescan, it + // means no matching transactions were found. if len(rescanned) != 1 { - log.Debugf("no matching block found "+ - "for rescan of hash %v", - blockHash) + log.Tracef("rescan of block %v at "+ + "height=%d yielded no "+ + "transactions", blockHash, i) continue } decoded, err := decodeJSONBlock(