Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-deterministic behaviour for custom accounts #7565

Merged
merged 4 commits into from
Jun 15, 2023

Conversation

Torakushi
Copy link
Contributor

This PR fixes: #7265

  1. fix non-deterministic behaviour for custom accounts with same name but different key scopes (ListAccounts/LookupAccount)

  2. Forbid users to create a custom account if the name is already used

Steps to Test

This PR was tested, here are the steps to test:

  1. -> You will need to cherry-pick the two first commit (otherwise the 3rd commit will prevent you from create 2 custom accounts with the same name). Then import 2 accounts (different key scope but same name) and check if ListAccounts returns the 2 accounts (and not only one as before)

  2. -> Now, you can include the 3rd commit, check that you cant import 2 accounts with the same name anymore

// newAccountNotFoundError returns an error indicating that the manager didn't
// find the specific account. This error is used to be compatible with the old
// 'LookupAccount' behaviour previously used.
func newAccountNotFoundError(name string) error {
Copy link
Contributor Author

@Torakushi Torakushi Apr 3, 2023

Choose a reason for hiding this comment

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

I used this particular error to be compatible with the old error returned by LookupAccount in the same case.

If this compatibility is not important, I will create a generic error like
var errAccountNotFound

lnwallet/btcwallet/psbt.go Show resolved Hide resolved
@Torakushi
Copy link
Contributor Author

it looks like that a 30m timeout was added to the travis build:
GOMEMLIMIT=500MiB GOARM=7 GOARCH=arm GOOS=linux travis_wait 30 make itest-parallel backend=bitcoind

Making the travis build failed (timeout)

I've seen this behaviour in other PRs (example: https://app.travis-ci.com/github/lightningnetwork/lnd/builds/261768324)

@Torakushi Torakushi marked this pull request as ready for review April 4, 2023 10:09
@Roasbeef Roasbeef requested a review from sputn1ck April 6, 2023 00:24
@guggero guggero self-requested a review April 11, 2023 20:01
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Thank you very much for the fix!
Did a first pass and things look pretty good. Will do some manual testing during the next pass.

lnwallet/btcwallet/btcwallet.go Outdated Show resolved Hide resolved
lnwallet/btcwallet/btcwallet.go Outdated Show resolved Hide resolved
lnwallet/btcwallet/psbt.go Outdated Show resolved Hide resolved
lnwallet/btcwallet/psbt.go Show resolved Hide resolved
itest/lnd_wallet_import_test.go Outdated Show resolved Hide resolved
itest/lnd_wallet_import_test.go Outdated Show resolved Hide resolved
lnwallet/btcwallet/btcwallet.go Show resolved Hide resolved
docs/release-notes/release-notes-0.16.0.md Outdated Show resolved Hide resolved
@Torakushi
Copy link
Contributor Author

Torakushi commented Apr 12, 2023

Thank you very much for the fix!

My pleasure 👍 sorry it took so long!

Will do some manual testing during the next pass.

Thank you @guggero!

@guggero guggero self-requested a review April 19, 2023 16:32
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Great work, only a couple of nits left.

@saubyk can we prioritize for the 0.17 milestone please?

lnwallet/btcwallet/btcwallet.go Outdated Show resolved Hide resolved
lnwallet/btcwallet/psbt.go Outdated Show resolved Hide resolved
cmd/lncli/walletrpc_active.go Outdated Show resolved Hide resolved
lnwallet/btcwallet/btcwallet.go Show resolved Hide resolved
docs/release-notes/release-notes-0.16.1.md Outdated Show resolved Hide resolved
@lightninglabs-deploy
Copy link

@sputn1ck: review reminder

@Torakushi
Copy link
Contributor Author

Torakushi commented Jun 6, 2023

Don't really know why a test is failing after the rebase

--- FAIL: TestLightningWallet/btcwallet/neutrino:reorg_wallet_balance (14.97s)
        test_interface.go:2162: unable to sync wallet: timeout after 30s

As well Travis job is failing (weird error), I will check tomorrow!

@guggero
Copy link
Collaborator

guggero commented Jun 6, 2023

Looks like that failure is independent. Some tests unfortunately are still flaky.

@Torakushi
Copy link
Contributor Author

Indeed flaky tests :)

In theory, it should be only one custom account with a given name. However,
due to a lack of check, users could have created custom accounts with various
key scopes. In that case, ListAccounts has to list all these accounts.
In theory, it should be only one custom account with a given name. However,
users could have created custom accounts with various key scopes. In that case,
'LookupAccount' has a non deterministic behaviour. To fix that, we browse
through all key scopes (deterministically) and return the first account we found.
Currently, a user can create a custom account with various key scopes.
This is not a desired behaviour.
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🚈

@Roasbeef Roasbeef added this pull request to the merge queue Jun 15, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 15, 2023
@saubyk
Copy link
Collaborator

saubyk commented Jun 15, 2023

Concept Ack

@Roasbeef Roasbeef merged commit 453fbb3 into lightningnetwork:master Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accounting bug fix wallet The wallet (lnwallet) which LND uses
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: returned (wallet) account is not deterministic if there are various scopes for the same account name
5 participants