-
-
Notifications
You must be signed in to change notification settings - Fork 250
fix(account-tree-controller): prevent :account{Added,Removed}
if init
has not been called yet
#6717
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(account-tree-controller): prevent :account{Added,Removed}
if init
has not been called yet
#6717
Conversation
… has not been called yet
391c05b
to
5077f36
Compare
@metamaskbot publish-preview |
@metamaskbot publish-preview |
054c4dd
to
33a5889
Compare
packages/account-tree-controller/src/AccountTreeController.test.ts
Outdated
Show resolved
Hide resolved
|
||
### Fixed | ||
|
||
- Prevent `:account{Added,Removed}` to used if `init` has not been called yet ([#6717](https://github.com/MetaMask/core/pull/6717)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm writing this comment last, and writing the other comments before made me realize that this might be a breaking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be seen as a breaking change in terms of behavior, but I actually think the current behavior is not valid either 😅
Also, "we" are the consumer the AccountsController
and clients don't really have control over those :account{Added,Removed}
event strictly speaking. I think it's implied that init
has to be called before being able to use the tree anyway.
Lastly, making this a "true breaking change" would quickly bubble up to other controllers, while the public interface remains the same.
But I get your point and I'm on a fence here 😅 for simplicity, I'd would just treat it as a fix (given it does not require any change as of now from any consumers).
Would that be ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with all your points! Thanks for elaborating ❤️ Yep that'd be alright with me!
Co-authored-by: Mathieu Artu <mathieu.artu@consensys.net>
Explanation
I initially thought calling
init
implicitly would solve some issues, but it actually adds one when it comes to automatically migrating accounts from v1 state.In the clients we usually use the tree like so:
The
updateAccounts
part re-creates the list of internal accounts and potentially migrate them if needed (in the case of BIP-44, this is needed to inject theoptions.entropy
for those accounts).If a
KeyingController:stateChange
happens beforeupdateAccounts
, this might trigger some:accountAdded
event, but some accounts might not have been automatically migrated yet (sinceupdateAccounts
has not been called at this point). Thus, this can lead theAccountTreeController
to misuse those accounts and put them in wrong wallet (like older HD accounts had notoptions.entropy
objects, thus they are not considered BIP-44 accounts yet).To avoid such issues (which seems to mainly happen for E2E), we wait for
init
to have been called explicitly.In anyway, calling
updateAccounts
right beforeinit
would make sure that the list of accounts is up-to-date AND migrated.References
Checklist