From 91b0e9cae54b371813f05a6be5fa7b541d0d9411 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 24 Aug 2018 17:58:02 -0700 Subject: [PATCH] chainntnfs/txconfnotifier: commit conf hints before notifying --- chainntnfs/txconfnotifier.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/chainntnfs/txconfnotifier.go b/chainntnfs/txconfnotifier.go index 14f150c44..0a9518516 100644 --- a/chainntnfs/txconfnotifier.go +++ b/chainntnfs/txconfnotifier.go @@ -452,6 +452,19 @@ func (tcn *TxConfNotifier) DisconnectTip(blockHeight uint32) error { tcn.currentHeight-- tcn.reorgDepth++ + // Rewind the height hint for all watched transactions. + var txs []chainhash.Hash + for tx := range tcn.confNotifications { + txs = append(txs, tx) + } + + err := tcn.hintCache.CommitConfirmHint(tcn.currentHeight, txs...) + if err != nil { + Log.Errorf("Unable to update confirm hint to %d for %v: %v", + tcn.currentHeight, txs, err) + return err + } + // We'll go through all of our watched transactions and attempt to drain // their notification channels to ensure sending notifications to the // clients is always non-blocking. @@ -515,20 +528,6 @@ func (tcn *TxConfNotifier) DisconnectTip(blockHeight uint32) error { } } - // Rewind the height hint for all watched transactions. - var txs []chainhash.Hash - for tx := range tcn.confNotifications { - txs = append(txs, tx) - } - - err := tcn.hintCache.CommitConfirmHint(tcn.currentHeight, txs...) - if err != nil { - // The error is not fatal, so we should not return an error to - // the caller. - Log.Errorf("Unable to update confirm hint to %d for %v: %v", - tcn.currentHeight, txs, err) - } - // Finally, we can remove the transactions we're currently watching that // were included in this block height. delete(tcn.txsByInitialHeight, blockHeight)