From 455568279bd792cc71f5c5e8b1856473513a36cb Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 5 Dec 2017 17:44:10 -0800 Subject: [PATCH] routing: ensure that new blocks connected monotonically increase in height MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes an existing bug within the ChannelRouter. Prior to this commit, if the chain view skipped blocks or for some reason we had a gap in blocks delivered, then we would simply accept them. This had the potential to cause us to miss on-chain channel closure events. To remedy this, we won’t process any blocks whose heights aren’t *strictly* increasing. A longer term fix would be to have the ChainView take a block height, and re-dispatch any notifications from that height to the current height. --- routing/router.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/routing/router.go b/routing/router.go index a112670c..882efaa4 100644 --- a/routing/router.go +++ b/routing/router.go @@ -593,6 +593,19 @@ func (r *ChannelRouter) networkHandler() { return } + // We'll ensure that any new blocks received attach + // directly to the end of our main chain. If not, then + // we've somehow missed some blocks. We don't process + // this block as otherwise, we may miss on-chain + // events. + currentHeight := atomic.LoadUint32(&r.bestHeight) + if chainUpdate.Height != currentHeight+1 { + log.Errorf("out of order block: expecting "+ + "height=%v, got height=%v", currentHeight+1, + chainUpdate.Height) + continue + } + // Once a new block arrives, we update our running // track of the height of the chain tip. blockHeight := uint32(chainUpdate.Height)