routing: ensure that new blocks connected monotonically increase in height

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.
This commit is contained in:
Olaoluwa Osuntokun 2017-12-05 17:44:10 -08:00
parent ffd6b65ec1
commit 455568279b
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -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)