From 485d8f043d5b8769e0b085673a6beaa9c017cede Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 29 Mar 2022 17:52:25 +0200 Subject: [PATCH 1/2] btcwallet: always make sure default scopes exist If new default scopes are added to the underlying btcwallet implementation, then they aren't automatically created for _existing_ wallets, only for new ones. So on startup we need to make sure all scopes are present. --- lnwallet/btcwallet/btcwallet.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 0cb6b5ad3..41bec9410 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -324,6 +324,34 @@ func (b *BtcWallet) Start() error { } } + // Because we might add new "default" key scopes over time, they are + // created correctly for new wallets. Existing wallets don't + // automatically add them, we need to do that manually now. + for _, scope := range waddrmgr.DefaultKeyScopes { + _, err := b.wallet.Manager.FetchScopedKeyManager(scope) + if waddrmgr.IsError(err, waddrmgr.ErrScopeNotFound) { + // The default scope wasn't found, that probably means + // it was added recently and older wallets don't know it + // yet. Let's add it now. + addrSchema := waddrmgr.ScopeAddrMap[scope] + err := walletdb.Update( + b.db, func(tx walletdb.ReadWriteTx) error { + addrmgrNs := tx.ReadWriteBucket( + waddrmgrNamespaceKey, + ) + + _, err := b.wallet.Manager.NewScopedKeyManager( + addrmgrNs, scope, addrSchema, + ) + return err + }, + ) + if err != nil { + return err + } + } + } + scope, err := b.wallet.Manager.FetchScopedKeyManager(b.chainKeyScope) if err != nil { // If the scope hasn't yet been created (it wouldn't been From 28a99fc2a279afb90357eb7c34b11a9847a13f5e Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 29 Mar 2022 18:11:39 +0200 Subject: [PATCH 2/2] docs: add release notes --- docs/release-notes/release-notes-0.15.0.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/release-notes/release-notes-0.15.0.md b/docs/release-notes/release-notes-0.15.0.md index 24ecd3f53..14e74678e 100644 --- a/docs/release-notes/release-notes-0.15.0.md +++ b/docs/release-notes/release-notes-0.15.0.md @@ -68,6 +68,10 @@ then watch it on chain. Taproot script spends are also supported through the * [Fixed a bug that would cause lnd to be unable to parse certain PSBT blobs](https://github.com/lightningnetwork/lnd/pull/6383). +* [Fixed a bug in the `btcwallet` that caused an error to be shown for + `lncli walletbalance` in existing wallets after upgrading to + Taproot](https://github.com/lightningnetwork/lnd/pull/6379). + ## Misc * [An example systemd service file](https://github.com/lightningnetwork/lnd/pull/6033)