Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Set password sooner to avoid redundant persistance #154

Merged
merged 1 commit into from
Nov 7, 2022

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Nov 7, 2022

The vault password is now always set in the method responsible for creating the vault. Previously it was set when the vault was persisted, or when the first keyring was created. This led to redundant calls to persist the keyrings, just to achieve the side-effect of setting the password.

This change eliminates those redundant calls, and a few more that had no obvious purpose.

Note that the password is also set on unlock, and that has not changed here.

@@ -752,7 +743,7 @@ class KeyringController extends EventEmitter {
forgetKeyring(keyring) {
if (keyring.forgetDevice) {
keyring.forgetDevice();
this.persistAllKeyrings.bind(this)();
Copy link
Member Author

Choose a reason for hiding this comment

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

This .bind was redundant, as we're calling persistAllKeyrings on this anyway. So it's a no-op.

await this.persistAllKeyrings(password);
this.password = password;

await this.createFirstKeyTree();
Copy link
Member Author

Choose a reason for hiding this comment

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

createFirstKeyTree only modifies this.keyrings via addNewKeyring, which calls persistAllKeyrings internally after adding the keyring. That's why the persistAllKeyrings call was eliminated here.


await this.persistAllKeyrings(password);
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm guessing this call was primarily meant to set the password, so it has been removed.

It did have another functional impact, in that it ensured the clearKeyrings operation was reflected in the vault, in case the attempt to create a new vault fails. But... that situation is not anticipated. At this point we have validated that the SRP is valid, and the password is text, so there aren't any more additional failure conditions.

Moreover; leaving an existing vault in state isn't an awful end result to encountering an unexpected error. If anything it might aid with recovery, if we do somehow end up accidentally bricking the wallet with an update.

@@ -130,8 +131,6 @@ class KeyringController extends EventEmitter {
if (!firstAccount) {
throw new Error('KeyringController - First Account not found.');
}

await this.persistAllKeyrings(password);
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed because the last time this.keyrings is modified is within addNewKeyring, which calls persistAllKeyrings internally.

@Gudahtt Gudahtt marked this pull request as ready for review November 7, 2022 20:42
@Gudahtt Gudahtt requested a review from a team as a code owner November 7, 2022 20:42
The vault password is now always set in the method responsible for
creating the vault. Previously it was set when the vault was persisted,
or when the first keyring was created. This led to redundant calls to
persist the keyrings, just to achieve the side-effect of setting the
password.

This change eliminates those redundant calls, and a few more that had
no obvious purpose.

Note that the password is also set on unlock, and that has not changed
here.
@Gudahtt Gudahtt force-pushed the set-password-when-creating-vault branch from 5905de9 to eb3b986 Compare November 7, 2022 21:30
Copy link
Contributor

@darkwing darkwing left a comment

Choose a reason for hiding this comment

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

This makes sense!

@Gudahtt Gudahtt merged commit 5c0ef4c into main Nov 7, 2022
@Gudahtt Gudahtt deleted the set-password-when-creating-vault branch November 7, 2022 21:50
Gudahtt added a commit that referenced this pull request Nov 7, 2022
* origin/main:
  Set password sooner to avoid redundant persistance (#154)
  Ensure newly created vaults are unlocked (#155)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants