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:
parent
fd8aa5d541
commit
a9847c28b6
1 changed files with 23 additions and 17 deletions
|
@ -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"
|
||||||
|
@ -122,17 +121,17 @@ 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.connectBlock(tx, wtxmgr.BlockMeta(n))
|
return w.connectBlock(tx, wtxmgr.BlockMeta(n))
|
||||||
})
|
})
|
||||||
notificationName = "blockconnected"
|
notificationName = "block connected"
|
||||||
case chain.BlockDisconnected:
|
case chain.BlockDisconnected:
|
||||||
err = walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error {
|
err = walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error {
|
||||||
return w.disconnectBlock(tx, wtxmgr.BlockMeta(n))
|
return w.disconnectBlock(tx, wtxmgr.BlockMeta(n))
|
||||||
})
|
})
|
||||||
notificationName = "blockdisconnected"
|
notificationName = "block disconnected"
|
||||||
case chain.RelevantTx:
|
case chain.RelevantTx:
|
||||||
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 {
|
||||||
|
@ -149,13 +148,13 @@ func (w *Wallet) handleChainNotifications() {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
notificationName = "filteredblockconnected"
|
notificationName = "filtered block connected"
|
||||||
|
|
||||||
// The following require some database maintenance, but also
|
// The following require some database maintenance, but also
|
||||||
// need to be reported to the wallet's rescan goroutine.
|
// need to be reported to the wallet's rescan goroutine.
|
||||||
case *chain.RescanProgress:
|
case *chain.RescanProgress:
|
||||||
err = catchUpHashes(w, chainClient, n.Height)
|
err = catchUpHashes(w, chainClient, n.Height)
|
||||||
notificationName = "rescanprogress"
|
notificationName = "rescan progress"
|
||||||
select {
|
select {
|
||||||
case w.rescanNotifications <- n:
|
case w.rescanNotifications <- n:
|
||||||
case <-w.quitChan():
|
case <-w.quitChan():
|
||||||
|
@ -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 == "blockconnected" &&
|
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
|
||||||
|
|
Loading…
Reference in a new issue