wallet: improve error logging for unsuccessful notification handling

If a block arrives while the wallet is rescanning, users would be shown
a log message that is confusing and not very helpful.
This commit is contained in:
Wilmer Paulino 2019-05-20 16:29:41 -07:00
parent fd8aa5d541
commit a9847c28b6
No known key found for this signature in database
GPG key ID: 6DF57B9F9514972F

View file

@ -7,7 +7,6 @@ package wallet
import (
"bytes"
"fmt"
"strings"
"time"
"github.com/btcsuite/btcd/chaincfg/chainhash"
@ -132,7 +131,7 @@ func (w *Wallet) handleChainNotifications() {
err = walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error {
return w.addRelevantTx(tx, n.TxRecord, n.Block)
})
notificationName = "recvtx/redeemingtx"
notificationName = "relevant transaction"
case chain.FilteredBlockConnected:
// Atomically update for the whole block.
if len(n.RelevantTxs) > 0 {
@ -163,7 +162,7 @@ func (w *Wallet) handleChainNotifications() {
}
case *chain.RescanFinished:
err = catchUpHashes(w, chainClient, n.Height)
notificationName = "rescanprogress"
notificationName = "rescan finished"
w.SetChainSynced(true)
select {
case w.rescanNotifications <- n:
@ -172,17 +171,24 @@ func (w *Wallet) handleChainNotifications() {
}
}
if err != nil {
// On out-of-sync blockconnected notifications, only
// send a debug message.
errStr := "Failed to process consensus server " +
"notification (name: `%s`, detail: `%v`)"
// If we received a block connected notification
// while rescanning, then we can ignore logging
// the error as we'll properly catch up once we
// process the RescanFinished notification.
if notificationName == "block connected" &&
strings.Contains(err.Error(),
"couldn't get hash from database") {
log.Debugf(errStr, notificationName, err)
} else {
log.Errorf(errStr, notificationName, err)
waddrmgr.IsError(err, waddrmgr.ErrBlockNotFound) &&
!w.ChainSynced() {
log.Debugf("Received block connected "+
"notification for height %v "+
"while rescanning",
n.(chain.BlockConnected).Height)
continue
}
log.Errorf("Unable to process chain backend "+
"%v notification: %v", notificationName,
err)
}
case <-w.quit:
return