chainntnfs: rewind chain on missed disconnected blocks

If the chain backend misses telling the notifier about a series of disconnected blocks, the notifier is now able to disconnect the tip to its new best block.
This commit is contained in:
Valentine Wallace
2018-08-09 00:05:29 -07:00
parent a5e1cf9c97
commit cbf1799c40
4 changed files with 88 additions and 35 deletions

View File

@@ -327,23 +327,24 @@ out:
case chain.BlockDisconnected:
if item.Height != b.bestBlock.Height {
chainntnfs.Log.Warnf("Received blocks "+
"out of order: current height="+
"%d, disconnected height=%d",
bestHeight, item.Height)
continue
chainntnfs.Log.Infof("Missed disconnected" +
"blocks, attempting to catch up")
}
chainntnfs.Log.Infof("Block disconnected from "+
"main chain: height=%v, sha=%v",
item.Height, item.Hash)
err := b.txConfNotifier.DisconnectTip(
uint32(item.Height))
newBestBlock, err := chainntnfs.RewindChain(
b.chainConn, b.txConfNotifier,
b.bestBlock, item.Height-1,
)
if err != nil {
chainntnfs.Log.Error(err)
chainntnfs.Log.Errorf("Unable to rewind chain "+
"from height %d to height %d: %v",
b.bestBlock.Height, item.Height-1, err)
}
// Set the bestBlock here in case a chain
// rewind partially completed.
b.bestBlock = newBestBlock
case chain.RelevantTx:
b.handleRelevantTx(item, b.bestBlock.Height)
}