Skip to content

Commit

Permalink
wallet: make sure the bucket is not nil to avoid panic
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed Nov 12, 2024
1 parent 321c0f3 commit 58426bc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions wallet/chainntfns.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package wallet

import (
"bytes"
"errors"
"fmt"
"time"

"github.com/btcsuite/btcd/chaincfg/chainhash"
Expand All @@ -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()

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 58426bc

Please sign in to comment.