feat: optimize Transaction Pay amount quote latency#9543
Draft
pedronfigueiredo wants to merge 3 commits into
Draft
feat: optimize Transaction Pay amount quote latency#9543pedronfigueiredo wants to merge 3 commits into
pedronfigueiredo wants to merge 3 commits into
Conversation
10 tasks
d284b3c to
732f0f7
Compare
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.
Explanation
Context
Updating the amount of a Money Account deposit currently fans one logical user action out through multiple nested transaction updates, parent calldata rebuilds, gas/simulation preparation, controller publications, and quote generations. In the reference iOS simulator trace, Update/Done to an executable quote took 8.503 seconds:
Relay is a third-party request and its latency varies independently. The client-controlled portions are therefore the primary optimization target.
What this PR changes
This proof of concept adds generic controller foundations for an explicit, coherent amount-update-and-quote pipeline.
TransactionController
beginAtomicBatchUpdateto apply required assets and all nested calldata updates in one canonical state publication.TransactionPayController
updateAmount, backed by a consumer-providedprepareTransactionAmountcallback, so transaction-specific amount conversion and calldata construction remain outside the generic controller.The result is one coherent revision, one local preparation generation, and one quote generation for the standard path rather than intermediate revisions repeatedly triggering work.
Why start with Money Account deposits?
Money Account deposits are a useful first adopter because they expose the amplification clearly: an amount change updates both approval and deposit calldata, requires
previewDeposit, and then feeds Transaction Pay and EIP-7702/delegation preparation. The flow is narrow enough to validate behind a Mobile feature flag while retaining the legacy path as a kill switch.The APIs in this PR are intentionally not Money Account-specific.
TransactionControlleraccepts generic required assets and nested transaction updates, whileTransactionPayControllerdelegates transaction-specific preparation to an injected callback. Other Transaction Pay flows can adopt the same orchestration later once their patch completeness, strategy semantics, and freshness requirements are validated.Benchmark result
A follow-up React Native DevTools trace used the same inferred Update/Done and executable-commit anchors:
The Relay request regressed by 1.011 seconds in the second sample even though this PR does not optimize the Relay backend. Treating Relay as the same 4.108-second contribution in both traces gives a normalized PoC total of 6,426.691 ms, a 2,075.840 ms / 24.4% end-to-end improvement. Client-controlled time fell from 4,394.591 ms to 2,318.751 ms, a 47.2% reduction.
Structural trace evidence supports the client improvement:
eth_estimateGascallsThese are two individual simulator traces, not production p50/p95 measurements. Relay latency should continue to be reported separately and old/new runs should be alternated over multiple samples.
Correctness and rollout constraints
Future work
Validation
yarn workspace @metamask/transaction-controller run jest --no-coverage src/TransactionController.test.ts --runInBand— 249 passedyarn workspace @metamask/transaction-pay-controller run jest --no-coverage src/TransactionPayController.test.ts src/strategy/relay/relay-quotes.test.ts src/utils/quotes.test.ts --runInBand— 260 passedyarn changelog:validatepasses.References
28e517a73d33db3aa63470f9bc55bdbb47fc61060b09227dce3c5df2d4ae13a9e80c86da8913924a228627627d851ab75965174a30c7607cee1416917aa2c34fChecklist