Conversation
… update arrives before account is in state Previously, `#handleOnAccountBalancesUpdated` would silently drop balance updates if `state.balances[accountId]` had not yet been populated (i.e. the key was absent). This caused a race condition where a Snap could send balances before `updateBalance` had created the entry, leaving the account with no persisted balance. The handler now initializes the entry with `??=` before merging, consistent with every other code path in the controller that writes to `state.balances`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously,
#handleOnAccountBalancesUpdatedwould silently drop balance updates ifstate.balances[accountId]had not yet been populated (i.e. the key was absent). This caused a race condition where a Snap could send balances beforeupdateBalancehad created the entry, leaving the account with no persisted balance.The handler now initializes the entry with
??=before merging, consistent with every other code path in the controller that writes tostate.balances.Explanation
References
Checklist
Note
Low Risk
Small, localized state-update change with added test coverage; low chance of unintended side effects beyond persisting previously-dropped balance updates.
Overview
Fixes a race in
MultichainBalancesControllerwhere balances published viaAccountsController:accountBalancesUpdatedcould be ignored ifstate.balances[accountId]was not yet initialized.The handler now always initializes
state.balances[accountId]before merging updates, and adds a unit test covering the “event arrives before state entry exists” case; theassets-controllerschangelog is updated accordingly.Reviewed by Cursor Bugbot for commit d31c0f8. Bugbot is set up for automated code reviews on this repo. Configure here.