From 9fd9234d869018dbdfd311e76fec3587b3f98c21 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 8 Jul 2022 13:29:19 +0200 Subject: [PATCH 1/3] lnwallet: don't create BIP044 key scope by default With a change in #6379 we made sure that all default scopes are added to the the wallet. Unfortunately this included the BIP044 key scope that our wallet doesn't really use. This breaks the remote signing setup because we don't export the account of the BIP044 scope and therefore run into an issue on the watch-only side when attempting to create the wallet. --- lnwallet/btcwallet/btcwallet.go | 75 ++++++++++++--------------------- 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index c92823cb8..5fd6614a7 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -70,6 +70,14 @@ var ( InternalAddrType: waddrmgr.WitnessPubKey, } + // LndDefaultKeyScopes is the list of default key scopes that lnd adds + // to its wallet. + LndDefaultKeyScopes = []waddrmgr.KeyScope{ + waddrmgr.KeyScopeBIP0049Plus, + waddrmgr.KeyScopeBIP0084, + waddrmgr.KeyScopeBIP0086, + } + // errNoImportedAddrGen is an error returned when a new address is // requested for the default imported account within the wallet. errNoImportedAddrGen = errors.New("addresses cannot be generated for " + @@ -333,7 +341,7 @@ 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 { + for _, scope := range LndDefaultKeyScopes { _, err := b.wallet.Manager.FetchScopedKeyManager(scope) if waddrmgr.IsError(err, waddrmgr.ErrScopeNotFound) { // The default scope wasn't found, that probably means @@ -615,29 +623,16 @@ func (b *BtcWallet) ListAccounts(name string, if name == lnwallet.DefaultAccountName || name == waddrmgr.ImportedAddrAccountName { - a1, err := b.wallet.AccountPropertiesByName( - waddrmgr.KeyScopeBIP0049Plus, name, - ) - if err != nil { - return nil, err + for _, defaultScope := range LndDefaultKeyScopes { + a, err := b.wallet.AccountPropertiesByName( + defaultScope, name, + ) + if err != nil { + return nil, err + } + res = append(res, a) } - res = append(res, a1) - a2, err := b.wallet.AccountPropertiesByName( - waddrmgr.KeyScopeBIP0084, name, - ) - if err != nil { - return nil, err - } - res = append(res, a2) - - a3, err := b.wallet.AccountPropertiesByName( - waddrmgr.KeyScopeBIP0086, name, - ) - if err != nil { - return nil, err - } - res = append(res, a3) break } @@ -668,34 +663,18 @@ func (b *BtcWallet) ListAccounts(name string, // Neither of the filters were provided, so return all accounts for our // supported key scopes. case name == "" && keyScope == nil: - accounts, err := b.wallet.Accounts(waddrmgr.KeyScopeBIP0049Plus) - if err != nil { - return nil, err - } - for _, account := range accounts.Accounts { - account := account - res = append(res, &account.AccountProperties) + for _, defaultScope := range LndDefaultKeyScopes { + accounts, err := b.wallet.Accounts(defaultScope) + if err != nil { + return nil, err + } + for _, account := range accounts.Accounts { + account := account + res = append(res, &account.AccountProperties) + } } - accounts, err = b.wallet.Accounts(waddrmgr.KeyScopeBIP0084) - if err != nil { - return nil, err - } - for _, account := range accounts.Accounts { - account := account - res = append(res, &account.AccountProperties) - } - - accounts, err = b.wallet.Accounts(waddrmgr.KeyScopeBIP0086) - if err != nil { - return nil, err - } - for _, account := range accounts.Accounts { - account := account - res = append(res, &account.AccountProperties) - } - - accounts, err = b.wallet.Accounts(waddrmgr.KeyScope{ + accounts, err := b.wallet.Accounts(waddrmgr.KeyScope{ Purpose: keychain.BIP0043Purpose, Coin: b.cfg.CoinType, }) From 989648b7ec124704161a5568b6e183e5182c7471 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 8 Jul 2022 14:30:04 +0200 Subject: [PATCH 2/3] itest: fix timeout in sign_psbt test --- lntest/itest/lnd_psbt_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lntest/itest/lnd_psbt_test.go b/lntest/itest/lnd_psbt_test.go index f4434bfc1..0a4b5f76a 100644 --- a/lntest/itest/lnd_psbt_test.go +++ b/lntest/itest/lnd_psbt_test.go @@ -468,7 +468,7 @@ func testPsbtChanFundingSingleStep(net *lntest.NetworkHarness, t *harnessTest) { // Everything we do here should be done within a second or two, so we // can just keep a single timeout context around for all calls. - ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) + ctxt, cancel := context.WithTimeout(ctxb, 2*defaultTimeout) defer cancel() args := nodeArgsForCommitType(lnrpc.CommitmentType_ANCHORS) @@ -1019,8 +1019,6 @@ func runSignPsbtSegWitV1ScriptSpend(t *harnessTest, func runFundAndSignPsbt(t *harnessTest, net *lntest.NetworkHarness, alice *lntest.HarnessNode) { - // Everything we do here should be done within a second or two, so we - // can just keep a single timeout context around for all calls. ctxb := context.Background() ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) defer cancel() @@ -1042,6 +1040,8 @@ func runFundAndSignPsbt(t *harnessTest, net *lntest.NetworkHarness, } for _, addrType := range spendAddrTypes { + ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) + // First, spend all the coins in the wallet to an address of the // given type so that UTXO will be picked when funding a PSBT. sendAllCoinsToAddrType(ctxt, t, net, alice, addrType) @@ -1057,6 +1057,8 @@ func runFundAndSignPsbt(t *harnessTest, net *lntest.NetworkHarness, // is calling FinalizePsbt directly, also works for this address // type. assertPsbtFundSignSpend(ctxt, t, net, alice, fundOutputs, true) + + cancel() } } From d365babe2533ffd1d2c2db8af4c84b171cca4966 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 8 Jul 2022 13:34:18 +0200 Subject: [PATCH 3/3] docs: add release notes --- docs/release-notes/release-notes-0.15.1.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/release-notes-0.15.1.md b/docs/release-notes/release-notes-0.15.1.md index 477394d41..ea41d4742 100644 --- a/docs/release-notes/release-notes-0.15.1.md +++ b/docs/release-notes/release-notes-0.15.1.md @@ -65,7 +65,11 @@ * [The HtlcSwitch now waits for a ChannelLink to stop before replacing it. This fixes a race condition.](https://github.com/lightningnetwork/lnd/pull/6642) -* [Integration tests now always run with nodes never deleting failed payments](https://github.com/lightningnetwork/lnd/pull/6712). +* [Integration tests now always run with nodes never deleting failed + payments](https://github.com/lightningnetwork/lnd/pull/6712). + +* [Fixes a key scope issue preventing new remote signing setups to be created + with `v0.15.0-beta`](https://github.com/lightningnetwork/lnd/pull/6714). ## Code Health