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

Keyring cache clear #129

Merged
merged 8 commits into from
Mar 4, 2022
Merged

Keyring cache clear #129

merged 8 commits into from
Mar 4, 2022

Conversation

jpuri
Copy link
Contributor

@jpuri jpuri commented Feb 14, 2022

No description provided.

@jpuri jpuri requested a review from a team as a code owner February 14, 2022 16:54
@adonesky1
Copy link
Contributor

Going through this flow again, I think we can/should clean up in a slightly different way perhaps.

So as you've put it here we call clearKeyrings first, then we call persistKeyrings and all that it does is set this.password to the user input password, it does not persist anything to the vault field in state because - having just cleared the keyrings array - there are no keyrings in the keyrings array to enter the map loop on line 528.

Then we enter createFirstKeyTree which also calls clearKeyrings before doing anything else (repeating the first step).

I'm not seeing why we shouldn't just skip straight to the createFirstKeyTree call as the first method call in this chain:

 createNewVaultAndKeychain (password) {
     return this.createFirstKeyTree()
      .then(this.persistAllKeyrings.bind(this, password))
      .then(this.setUnlocked.bind(this))
      .then(this.fullUpdate.bind(this))
  }

@jpuri @Gudahtt @danjm am I misreading this?

@Gudahtt
Copy link
Member

Gudahtt commented Feb 24, 2022

@adonesky1 That does seem better to me, except that setting a password is required before calling createFirstKeyTree. persistAllKeyrings needs to have a password set, and that's called within createFirstKeyTree.

Perhaps the password could be passed into createFirstKeyTree, and from there to persistAllKeyrings. That should work, and it would prevent the duplicate call to clearKeyrings.

@jpuri
Copy link
Contributor Author

jpuri commented Feb 25, 2022

@adonesky1 , @Gudahtt : I spent more time looking at the code, change suggested above will require changing method addNewKeyring at https://github.com/MetaMask/KeyringController/blob/main/index.js#L198, we need to pass password to the method which will be in-turn passed in call to persistAllKeyrings.

This method is called from other places also, thus I would avoid making this change, please suggest.

@adonesky1
Copy link
Contributor

adonesky1 commented Feb 28, 2022

@jpuri could we just pass the password to createFirstKeyTree and then set it first thing:

createFirstKeyTree(password) {
    this.password = password;
    this.clearKeyrings();
    return this.addNewKeyring('HD Key Tree', { numberOfAccounts: 1 })
      .then((keyring) => {
        return keyring.getAccounts();
      })
      .then(([firstAccount]) => {
        if (!firstAccount) {
          throw new Error('KeyringController - No account found on keychain.');
        }
        const hexAccount = normalizeAddress(firstAccount);
        this.emit('newVault', hexAccount);
        return null;
      });
  }

then we don't need to change the function signature of addNewKeyring?

So createNewVaultAndKeychain would be:

createNewVaultAndKeychain(password) {
    return this.createFirstKeyTree(password)
      .then(this.persistAllKeyrings.bind(this, password))
      .then(this.setUnlocked.bind(this))
      .then(this.fullUpdate.bind(this));
  }

I believe this resolves the flow/duplication issues without needing to drastic a change?

cc @Gudahtt @danjm

@jpuri
Copy link
Contributor Author

jpuri commented Mar 1, 2022

@adonesky1 : I just updated the PR please check.

@adonesky1
Copy link
Contributor

@jpuri looks like there's a lint issue.

@Gudahtt can you provide feedback on the approach I've suggested here?

index.js Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
jpuri and others added 2 commits March 3, 2022 23:13
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM!

@jpuri jpuri merged commit f461389 into main Mar 4, 2022
@jpuri jpuri deleted the keyring_cache_clear branch March 4, 2022 07:07
@adonesky1 adonesky1 mentioned this pull request Apr 22, 2022
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.

3 participants