Skip to content

Conversation

guggero
Copy link
Contributor

@guggero guggero commented Jun 14, 2022

Fixes #372.
This commit fixes the issue that if the lnd node the trader client is
connected to was also restored from seed, it is starting at account key
derivation index 0. So when recovering accounts we need to make sure we
re-derive the right number of keys from the wallet in order to allow
properly creating new accounts with the recovered node.

Pull Request Checklist

  • LndServices minimum version has been updated if new lnd apis/fields are
    used.


log.Debugf("Account %s already has %d external keys (want "+
"minimum index %d), not deriving any keys",
poolAccountsPath, poolAccountsAccount.ExternalKeyCount,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess wallet.ListAccounts returns them in increasing order so we have the last one here?

https://github.com/btcsuite/btcwallet/blob/50ea8d1125561279f9c9af1e46bea16ca414b4a5/wallet/wallet.go#L2396

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it returns them in order, but there are more than 255 and we want one towards the back (key family 220).

}

log.Debugf("Derived next account key with index %d", key.Index)
if key.Index >= minimumIndex {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Do we want to end up with the last key being minimumIndex or the next one? Before we were comparing with poolAccountsAccount.ExternalKeyCount > minimumIndex

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above it's the key count while here it's the derived index. So the count is always one higher than the index. Added a comment above to make it a bit more clear.

Fixes #372.
This commit fixes the issue that if the lnd node the trader client is
connected to was also restored from seed, it is starting at account key
derivation index 0. So when recovering accounts we need to make sure we
re-derive the right number of keys from the wallet in order to allow
properly creating new accounts with the recovered node.
@guggero guggero force-pushed the bump-key-index-on-account-recovery branch from 94de789 to 1ba717c Compare June 15, 2022 11:23
@guggero guggero requested a review from bhandras June 15, 2022 11:25
Copy link
Member

@bhandras bhandras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, straightforward fix 💯

@guggero guggero merged commit 6ff0d43 into master Jun 15, 2022
@guggero guggero deleted the bump-key-index-on-account-recovery branch June 15, 2022 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to startup: account alraedy exists
3 participants