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