Skip to content

Commit 1413378

Browse files
committed
backend: fix regression related to updating persisted accounts
It was supposed to only be applied to the accounts that belong to the current keystore, but 52bf446 added a regression and it was applied to all persisted accounts. The `setWatch()` thing can be removed - it was there before when the watchonly setting was global and accounts would need to be marked as `Watch` when the keystore is connected. After we moved it to be a keystore setting, it can only be enabled after connecting the keystore anyway in 'Manage accounts'.
1 parent 46e34b2 commit 1413378

File tree

3 files changed

+3
-39
lines changed

3 files changed

+3
-39
lines changed

backend/accounts.go

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,35 +1073,9 @@ func (backend *Backend) maybeAddP2TR(keystore keystore.Keystore, accounts []*con
10731073
// perform migrations, updates etc. We use it to add taproot subaccounts to Bitcoin accounts that
10741074
// were created (persisted) before the introduction of taproot support.
10751075
func (backend *Backend) updatePersistedAccounts(
1076-
keystore keystore.Keystore, accountsConfig *config.AccountsConfig) error {
1076+
keystore keystore.Keystore, accounts []*config.Account) error {
10771077

1078-
// setWatch, if the keystore Watchonly flag is enabled, sets the `Watch`
1079-
// flag to `true`, turning this account into a watch-only account.
1080-
setWatch := func() error {
1081-
rootFingerprint, err := keystore.RootFingerprint()
1082-
if err != nil {
1083-
return err
1084-
}
1085-
if !accountsConfig.IsKeystoreWatchonly(rootFingerprint) {
1086-
return nil
1087-
}
1088-
for _, account := range accountsConfig.Accounts {
1089-
// If the account was added in the background as part of scanning, we don't mark it
1090-
// watchonly. Otherwise the account would appear automatically once it received funds,
1091-
// even if it was not visible before and the keystore is never connected again.
1092-
if !account.HiddenBecauseUnused && account.Watch == nil {
1093-
t := true
1094-
account.Watch = &t
1095-
}
1096-
}
1097-
return nil
1098-
}
1099-
1100-
if err := setWatch(); err != nil {
1101-
return err
1102-
}
1103-
1104-
return backend.maybeAddP2TR(keystore, accountsConfig.Accounts)
1078+
return backend.maybeAddP2TR(keystore, accounts)
11051079
}
11061080

11071081
// The accountsAndKeystoreLock must be held when calling this function.

backend/accounts_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,16 +1381,6 @@ func TestWatchonly(t *testing.T) {
13811381
// Disable watchonly, all accounts disappear.
13821382
require.NoError(t, b.SetWatchonly(rootFingerprint, false))
13831383
checkShownAccountsLen(t, b, 0, 3)
1384-
1385-
// Re-enable watchonly - accounts do not show up yet.
1386-
require.NoError(t, b.SetWatchonly(rootFingerprint, true))
1387-
checkShownAccountsLen(t, b, 0, 3)
1388-
1389-
// Reconnecting the keystore brings back the watched accounts.
1390-
b.registerKeystore(ks)
1391-
checkShownAccountsLen(t, b, 3, 3)
1392-
b.DeregisterKeystore()
1393-
checkShownAccountsLen(t, b, 3, 3)
13941384
})
13951385

13961386
// Disable keystore's watchonly setting while keystore is connected does not make the accounts

backend/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ func (backend *Backend) registerKeystore(keystore keystore.Keystore) {
640640
// needed on the persisted accounts.
641641
accounts := backend.filterAccounts(accountsConfig, belongsToKeystore)
642642
if len(accounts) != 0 {
643-
return backend.updatePersistedAccounts(keystore, accountsConfig)
643+
return backend.updatePersistedAccounts(keystore, accounts)
644644
}
645645
return backend.persistDefaultAccountConfigs(keystore, accountsConfig)
646646
})

0 commit comments

Comments
 (0)