diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index 5ee9a619..cdc2f816 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -300,6 +300,7 @@ out: chainntnfs.Log.Warnf("Received blocks out of order: "+ "current height=%d, new height=%d", currentHeight, update.blockHeight) + continue } currentHeight = update.blockHeight @@ -321,22 +322,24 @@ out: if err != nil { chainntnfs.Log.Error(err) } - } else { - if update.blockHeight != currentHeight { - chainntnfs.Log.Warnf("Received blocks out of order: "+ - "current height=%d, disconnected height=%d", - currentHeight, update.blockHeight) - } + continue + } - currentHeight = update.blockHeight - 1 + if update.blockHeight != currentHeight { + chainntnfs.Log.Warnf("Received blocks out of order: "+ + "current height=%d, disconnected height=%d", + currentHeight, update.blockHeight) + continue + } - chainntnfs.Log.Infof("Block disconnected from main chain: "+ - "height=%v, sha=%v", update.blockHeight, update.blockHash) + currentHeight = update.blockHeight - 1 - err := b.txConfNotifier.DisconnectTip(uint32(update.blockHeight)) - if err != nil { - chainntnfs.Log.Error(err) - } + chainntnfs.Log.Infof("Block disconnected from main chain: "+ + "height=%v, sha=%v", update.blockHeight, update.blockHash) + + err := b.txConfNotifier.DisconnectTip(uint32(update.blockHeight)) + if err != nil { + chainntnfs.Log.Error(err) } case item := <-b.txUpdates.ChanOut(): diff --git a/chainntnfs/neutrinonotify/neutrino.go b/chainntnfs/neutrinonotify/neutrino.go index 4bb29920..28d738e7 100644 --- a/chainntnfs/neutrinonotify/neutrino.go +++ b/chainntnfs/neutrinonotify/neutrino.go @@ -334,6 +334,8 @@ func (n *NeutrinoNotifier) notificationDispatcher() { chainntnfs.Log.Warnf("Received blocks out of order: "+ "current height=%d, new height=%d", n.bestHeight, update.height) + n.heightMtx.Unlock() + continue } n.bestHeight = update.height @@ -346,25 +348,29 @@ func (n *NeutrinoNotifier) notificationDispatcher() { if err != nil { chainntnfs.Log.Error(err) } - } else { - n.heightMtx.Lock() - if update.height != n.bestHeight { - chainntnfs.Log.Warnf("Received blocks out of order: "+ - "current height=%d, disconnected height=%d", - n.bestHeight, update.height) - } - - n.bestHeight = update.height - 1 - n.heightMtx.Unlock() - - chainntnfs.Log.Infof("Block disconnected from main chain: "+ - "height=%v, sha=%v", update.height, update.hash) - - err := n.txConfNotifier.DisconnectTip(update.height) - if err != nil { - chainntnfs.Log.Error(err) - } + continue } + + n.heightMtx.Lock() + if update.height != n.bestHeight { + chainntnfs.Log.Warnf("Received blocks out of order: "+ + "current height=%d, disconnected height=%d", + n.bestHeight, update.height) + n.heightMtx.Unlock() + continue + } + + n.bestHeight = update.height - 1 + n.heightMtx.Unlock() + + chainntnfs.Log.Infof("Block disconnected from main chain: "+ + "height=%v, sha=%v", update.height, update.hash) + + err := n.txConfNotifier.DisconnectTip(update.height) + if err != nil { + chainntnfs.Log.Error(err) + } + case err := <-n.rescanErr: chainntnfs.Log.Errorf("Error during rescan: %v", err)