Skip to content

Conversation

ccharly
Copy link
Contributor

@ccharly ccharly commented Sep 18, 2025

Explanation

Derive next address instead of creating the account entirely (which triggers :accountAdded and adds side-effects for this temporary account).

References

N/A

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@ccharly
Copy link
Contributor Author

ccharly commented Sep 18, 2025

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-tree-controller": "0.16.1-preview-988ea6d",
  "@metamask-previews/accounts-controller": "33.1.0-preview-988ea6d",
  "@metamask-previews/address-book-controller": "6.1.1-preview-988ea6d",
  "@metamask-previews/announcement-controller": "7.0.3-preview-988ea6d",
  "@metamask-previews/app-metadata-controller": "1.0.0-preview-988ea6d",
  "@metamask-previews/approval-controller": "7.1.3-preview-988ea6d",
  "@metamask-previews/assets-controllers": "75.2.0-preview-988ea6d",
  "@metamask-previews/base-controller": "8.4.0-preview-988ea6d",
  "@metamask-previews/bridge-controller": "43.1.0-preview-988ea6d",
  "@metamask-previews/bridge-status-controller": "43.1.0-preview-988ea6d",
  "@metamask-previews/build-utils": "3.0.3-preview-988ea6d",
  "@metamask-previews/chain-agnostic-permission": "1.1.1-preview-988ea6d",
  "@metamask-previews/composable-controller": "11.0.0-preview-988ea6d",
  "@metamask-previews/controller-utils": "11.14.0-preview-988ea6d",
  "@metamask-previews/delegation-controller": "0.7.0-preview-988ea6d",
  "@metamask-previews/earn-controller": "7.0.0-preview-988ea6d",
  "@metamask-previews/eip-5792-middleware": "1.1.0-preview-988ea6d",
  "@metamask-previews/eip1193-permission-middleware": "1.0.0-preview-988ea6d",
  "@metamask-previews/ens-controller": "17.0.1-preview-988ea6d",
  "@metamask-previews/error-reporting-service": "2.0.0-preview-988ea6d",
  "@metamask-previews/eth-json-rpc-provider": "4.1.8-preview-988ea6d",
  "@metamask-previews/foundryup": "1.0.1-preview-988ea6d",
  "@metamask-previews/gas-fee-controller": "24.0.0-preview-988ea6d",
  "@metamask-previews/gator-permissions-controller": "0.1.0-preview-988ea6d",
  "@metamask-previews/json-rpc-engine": "10.0.3-preview-988ea6d",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-988ea6d",
  "@metamask-previews/keyring-controller": "23.1.0-preview-988ea6d",
  "@metamask-previews/logging-controller": "6.0.4-preview-988ea6d",
  "@metamask-previews/message-manager": "12.0.2-preview-988ea6d",
  "@metamask-previews/messenger": "0.3.0-preview-988ea6d",
  "@metamask-previews/multichain-account-service": "0.9.0-preview-988ea6d",
  "@metamask-previews/multichain-api-middleware": "1.0.0-preview-988ea6d",
  "@metamask-previews/multichain-network-controller": "0.12.0-preview-988ea6d",
  "@metamask-previews/multichain-transactions-controller": "5.0.0-preview-988ea6d",
  "@metamask-previews/name-controller": "8.0.3-preview-988ea6d",
  "@metamask-previews/network-controller": "24.1.0-preview-988ea6d",
  "@metamask-previews/network-enablement-controller": "1.1.0-preview-988ea6d",
  "@metamask-previews/notification-services-controller": "18.1.0-preview-988ea6d",
  "@metamask-previews/permission-controller": "11.0.6-preview-988ea6d",
  "@metamask-previews/permission-log-controller": "4.0.0-preview-988ea6d",
  "@metamask-previews/phishing-controller": "13.1.0-preview-988ea6d",
  "@metamask-previews/polling-controller": "14.0.0-preview-988ea6d",
  "@metamask-previews/preferences-controller": "19.0.0-preview-988ea6d",
  "@metamask-previews/profile-sync-controller": "25.0.0-preview-988ea6d",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-988ea6d",
  "@metamask-previews/remote-feature-flag-controller": "1.7.0-preview-988ea6d",
  "@metamask-previews/sample-controllers": "1.0.0-preview-988ea6d",
  "@metamask-previews/seedless-onboarding-controller": "4.0.0-preview-988ea6d",
  "@metamask-previews/selected-network-controller": "24.0.0-preview-988ea6d",
  "@metamask-previews/shield-controller": "0.1.2-preview-988ea6d",
  "@metamask-previews/signature-controller": "33.0.0-preview-988ea6d",
  "@metamask-previews/subscription-controller": "0.1.0-preview-988ea6d",
  "@metamask-previews/token-search-discovery-controller": "3.3.0-preview-988ea6d",
  "@metamask-previews/transaction-controller": "60.4.0-preview-988ea6d",
  "@metamask-previews/user-operation-controller": "39.0.0-preview-988ea6d"
}

groupIndex,
});
assert(
addressFromGroupIndex === address,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remind me if the addresses are all lowercase or are they normalized?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We usually use lowercase for EVM yes. But I'm pretty sure it's bit of a mix today... I just know that most people re-sanitize their addresses before using them.

JFYI, I just re-used the same code than here:

@ccharly ccharly marked this pull request as ready for review September 18, 2025 14:13
@ccharly ccharly requested review from a team as code owners September 18, 2025 14:13
@ccharly
Copy link
Contributor Author

ccharly commented Sep 18, 2025

@metamaskbot publish-preview

@hmalik88
Copy link
Contributor

hmalik88 commented Sep 18, 2025

Hmm, my PR removes the accountAdded handler entirely for the service so that wouldn't be an issue anymore for the service. Is this necessary for the AccountTreeController as well? Wouldn't we be able to just call the keyring and make sure that the address is in the keyring before reacting to it in the AccountTreeController event handler?

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-tree-controller": "0.16.1-preview-8cfb0d7",
  "@metamask-previews/accounts-controller": "33.1.0-preview-8cfb0d7",
  "@metamask-previews/address-book-controller": "6.1.1-preview-8cfb0d7",
  "@metamask-previews/announcement-controller": "7.0.3-preview-8cfb0d7",
  "@metamask-previews/app-metadata-controller": "1.0.0-preview-8cfb0d7",
  "@metamask-previews/approval-controller": "7.1.3-preview-8cfb0d7",
  "@metamask-previews/assets-controllers": "75.2.0-preview-8cfb0d7",
  "@metamask-previews/base-controller": "8.4.0-preview-8cfb0d7",
  "@metamask-previews/bridge-controller": "43.1.0-preview-8cfb0d7",
  "@metamask-previews/bridge-status-controller": "43.1.0-preview-8cfb0d7",
  "@metamask-previews/build-utils": "3.0.3-preview-8cfb0d7",
  "@metamask-previews/chain-agnostic-permission": "1.1.1-preview-8cfb0d7",
  "@metamask-previews/composable-controller": "11.0.0-preview-8cfb0d7",
  "@metamask-previews/controller-utils": "11.14.0-preview-8cfb0d7",
  "@metamask-previews/delegation-controller": "0.7.0-preview-8cfb0d7",
  "@metamask-previews/earn-controller": "7.0.0-preview-8cfb0d7",
  "@metamask-previews/eip-5792-middleware": "1.1.0-preview-8cfb0d7",
  "@metamask-previews/eip1193-permission-middleware": "1.0.0-preview-8cfb0d7",
  "@metamask-previews/ens-controller": "17.0.1-preview-8cfb0d7",
  "@metamask-previews/error-reporting-service": "2.0.0-preview-8cfb0d7",
  "@metamask-previews/eth-json-rpc-provider": "4.1.8-preview-8cfb0d7",
  "@metamask-previews/foundryup": "1.0.1-preview-8cfb0d7",
  "@metamask-previews/gas-fee-controller": "24.0.0-preview-8cfb0d7",
  "@metamask-previews/gator-permissions-controller": "0.1.0-preview-8cfb0d7",
  "@metamask-previews/json-rpc-engine": "10.0.3-preview-8cfb0d7",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-8cfb0d7",
  "@metamask-previews/keyring-controller": "23.1.0-preview-8cfb0d7",
  "@metamask-previews/logging-controller": "6.0.4-preview-8cfb0d7",
  "@metamask-previews/message-manager": "12.0.2-preview-8cfb0d7",
  "@metamask-previews/messenger": "0.3.0-preview-8cfb0d7",
  "@metamask-previews/multichain-account-service": "0.9.0-preview-8cfb0d7",
  "@metamask-previews/multichain-api-middleware": "1.0.0-preview-8cfb0d7",
  "@metamask-previews/multichain-network-controller": "0.12.0-preview-8cfb0d7",
  "@metamask-previews/multichain-transactions-controller": "5.0.0-preview-8cfb0d7",
  "@metamask-previews/name-controller": "8.0.3-preview-8cfb0d7",
  "@metamask-previews/network-controller": "24.1.0-preview-8cfb0d7",
  "@metamask-previews/network-enablement-controller": "1.1.0-preview-8cfb0d7",
  "@metamask-previews/notification-services-controller": "18.1.0-preview-8cfb0d7",
  "@metamask-previews/permission-controller": "11.0.6-preview-8cfb0d7",
  "@metamask-previews/permission-log-controller": "4.0.0-preview-8cfb0d7",
  "@metamask-previews/phishing-controller": "13.1.0-preview-8cfb0d7",
  "@metamask-previews/polling-controller": "14.0.0-preview-8cfb0d7",
  "@metamask-previews/preferences-controller": "19.0.0-preview-8cfb0d7",
  "@metamask-previews/profile-sync-controller": "25.0.0-preview-8cfb0d7",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-8cfb0d7",
  "@metamask-previews/remote-feature-flag-controller": "1.7.0-preview-8cfb0d7",
  "@metamask-previews/sample-controllers": "1.0.0-preview-8cfb0d7",
  "@metamask-previews/seedless-onboarding-controller": "4.0.0-preview-8cfb0d7",
  "@metamask-previews/selected-network-controller": "24.0.0-preview-8cfb0d7",
  "@metamask-previews/shield-controller": "0.1.2-preview-8cfb0d7",
  "@metamask-previews/signature-controller": "33.0.0-preview-8cfb0d7",
  "@metamask-previews/subscription-controller": "0.1.0-preview-8cfb0d7",
  "@metamask-previews/token-search-discovery-controller": "3.3.0-preview-8cfb0d7",
  "@metamask-previews/transaction-controller": "60.4.0-preview-8cfb0d7",
  "@metamask-previews/user-operation-controller": "39.0.0-preview-8cfb0d7"
}

@ccharly
Copy link
Contributor Author

ccharly commented Sep 18, 2025

Hmm, my PR removes the accountAdded handler entirely for the service so that wouldn't be an issue anymore for the service. Is this necessary for the AccountTreeController as well? Wouldn't we be able to just call the keyring and make sure that the address is in the keyring before reacting to it in the AccountTreeController event handler?

Well indeed, this will fix it for the service (with your PR), but the account-tree-controller still reacts to :accountAdded (as well as some other controllers potentially).

My initial idea was to "consume" the wallets/groups from the service in the account-tree-controller:

This was working ok, but since (in my PR), the service still relies on :accountAdded there were some other side effects sometimes.

So I guess, combining #6646 and your future PR could have solved that issue.

Nevertheless, I still think that temporary creating the account is not the right pattern here, we just want to "peek" the next address and check for activity and THEN create the account if we have to.

So all in all, we might want to combine all 3 PRs 😄

@hmalik88
Copy link
Contributor

Hmm, my PR removes the accountAdded handler entirely for the service so that wouldn't be an issue anymore for the service. Is this necessary for the AccountTreeController as well? Wouldn't we be able to just call the keyring and make sure that the address is in the keyring before reacting to it in the AccountTreeController event handler?

Well indeed, this will fix it for the service (with your PR), but the account-tree-controller still reacts to :accountAdded (as well as some other controllers potentially).

My initial idea was to "consume" the wallets/groups from the service in the account-tree-controller:

This was working ok, but since (in my PR), the service still relies on :accountAdded there were some other side effects sometimes.

So I guess, combining #6646 and your future PR could have solved that issue.

Nevertheless, I still think that temporary creating the account is not the right pattern here, we just want to "peek" the next address and check for activity and THEN create the account if we have to.

So all in all, we might want to combine all 3 PRs 😄

Ok that makes sense, no issue on my end then with this PR 🙂

@ccharly ccharly enabled auto-merge (squash) September 18, 2025 15:09
Co-authored-by: Daniel Rocha <68558152+danroc@users.noreply.github.com>
cursor[bot]

This comment was marked as outdated.

Copy link
Contributor

@danroc danroc left a comment

Choose a reason for hiding this comment

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

LGTM

@ccharly ccharly merged commit 05b39bc into main Sep 18, 2025
239 checks passed
@ccharly ccharly deleted the fix/multichain-account-service-evm-peek-address branch September 18, 2025 15:44
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.

3 participants