From 58426bc7b33ab92c83da301702c2850618bdf26d Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Mon, 4 Nov 2024 17:19:32 +0800 Subject: [PATCH] wallet: make sure the bucket is not nil to avoid panic --- wallet/chainntfns.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wallet/chainntfns.go b/wallet/chainntfns.go index a902fcd4bf..4d8b823517 100644 --- a/wallet/chainntfns.go +++ b/wallet/chainntfns.go @@ -6,6 +6,8 @@ package wallet import ( "bytes" + "errors" + "fmt" "time" "github.com/btcsuite/btcd/chaincfg/chainhash" @@ -24,6 +26,9 @@ const ( birthdayBlockDelta = 2 * time.Hour ) +// ErrEmptyBucket is used when an expected bucket is not found in the database. +var ErrEmptyBucket = errors.New("empty waddrmgr bucket") + func (w *Wallet) handleChainNotifications() { defer w.wg.Done() @@ -242,6 +247,9 @@ func (w *Wallet) handleChainNotifications() { // the passed block. func (w *Wallet) connectBlock(dbtx walletdb.ReadWriteTx, b wtxmgr.BlockMeta) error { addrmgrNs := dbtx.ReadWriteBucket(waddrmgrNamespaceKey) + if addrmgrNs == nil { + return fmt.Errorf("%w: empty waddrmgr bucket", ErrEmptyBucket) + } bs := waddrmgr.BlockStamp{ Height: b.Height,