Skip to content

Conversation

@xavier-brochard
Copy link
Contributor

@xavier-brochard xavier-brochard commented Oct 28, 2025

When creating an account, we save it in 2 different places:

  • first in the snap state
  • then in the MetaMask state

If the first succeeds, but the second fails, we need to rollback the first (by removing the account from the snap's state) to ensure consistency across both states.

This was already supported, but the flow was faulty in some cases. This fixes this faulty flow.


Note

Ensure createAccount persists to state before notifying the client and rolls back state if AccountCreated event emission fails, with tests covering the rollback.

  • Core (SolanaKeyring):
    • Adjust createAccount flow to:
      • Build keyringAccount earlier and save keyringAccounts.{id} before notifying the client.
      • Wrap emitEvent(KeyringEvent.AccountCreated, ...) with rollback logic that calls #deleteAccountFromState(id) on failure and rethrows.
    • Remove unconditional state cleanup in the outer catch; rollback now occurs only when client notification fails.
  • Tests:
    • Add test to assert rollback by verifying three deleteKey calls when emitEvent rejects in createAccount (state consistency).

Written by Cursor Bugbot for commit dcc4170. This will update automatically on new commits. Configure here.

@sonarqubecloud
Copy link

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.

2 participants