…elector` transaction volume spike by not passing `trace` into `getAggregatedBalanceForAccount` cp-13.40.0 (#44449)
## Motivation
`AggregatedBalanceSelector` accounts for [91% of all Sentry transaction
roots](https://metamask.sentry.io/explore/traces/?aggregateField=%7B%22groupBy%22%3A%22transaction%22%7D&aggregateField=%7B%22yAxes%22%3A%5B%22count%28span.duration%29%22%5D%7D&environment=production&mode=aggregate&project=273505&sort=-count%28span.duration%29&statsPeriod=7d&query=is_transaction%3Atrue),
and is growing as 13.38+ adoption climbs. Accepted transaction volume is
holding at approximately 36M per week against a 3.2M per week pre-spike
baseline.
`ui/selectors/assets.ts` forwards `traceAsControllerCallback` into
`getAggregatedBalanceForAccount` through the `assets.balance-utils`
helpers. That function runs inside a Redux selector, so it recomputes
per account group on every relevant state change and re-render. Each
computation emits a forced transaction root (`span.op: custom`), with no
sample gate.
The same callback was removed from `assets-controller-init.ts` in
#43213. That fix covered the controller entry point. The selector entry
point, introduced by the same upstream changeset
([MetaMask/core#8310](MetaMask/core#8310)), was
not covered, and reached production in 13.38.0 via #43635.
`AggregatedBalanceSelector` is the only one of the seven traces added by
core#8310 that is still emitting. The other six route through the
controller callback removed in #43213 and are already at zero, so this
call site closes core#8310 entirely.
## Description
This commit removes `traceAsControllerCallback` from the two call sites
in `ui/selectors/assets.ts` that forward it into the unified balance
selectors, along with the now-unused import.
The optional `trace` parameters are also removed from
`aggregateGroupBalance`, `calculateBalanceForAllWallets`, and
`calculateBalanceChangeForAccountGroup` in
`ui/selectors/assets.balance-utils.ts`. Leaving them in place would
allow the callback to be reintroduced by supplying a single argument,
which is how it arrived in the first place. The test that asserted trace
forwarding is inverted into a regression test asserting no trace is
passed.
## Test plan
- [x] `eslint` passes on all three touched files
- [x] `tsc --noEmit` reports no errors in the touched files
- [x] `ui/selectors/assets.test.ts` and
`ui/selectors/assets.balance-utils.test.ts` pass (71 tests)
- [ ] After release, [`AggregatedBalanceSelector`
volume](https://metamask.sentry.io/explore/traces/?aggregateField=%7B%22groupBy%22%3A%22release%22%7D&aggregateField=%7B%22yAxes%22%3A%5B%22count%28span.duration%29%22%5D%7D&environment=production&mode=aggregate&project=273505&sort=-count%28span.duration%29&statsPeriod=30d&query=transaction%3AAggregatedBalanceSelector)
drops to approximately zero on the fixed release
## Changelog
CHANGELOG entry: null
## References
Fixes #44447
Related: #43211, #43213, #43370,
[MetaMask/core#8310](MetaMask/core#8310)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Observability-only change; balance math and selector inputs are
unchanged aside from omitting the optional trace argument.
>
> **Overview**
> Stops **Sentry transaction roots** from `AggregatedBalanceSelector` by
no longer forwarding `traceAsControllerCallback` into unified wallet and
account-group balance calculations.
>
> `ui/selectors/assets.ts` drops the trace import and stops passing a
callback into `calculateBalanceForAllWallets` and
`calculateBalanceChangeForAccountGroup` when assets-unify state is
enabled. In `assets.balance-utils.ts`, optional `trace` parameters are
removed end-to-end so `getAggregatedBalanceForAccount` is never given a
trace callback from this Redux path (which recomputes per group on every
relevant state change). The unit test now asserts the 7th argument to
the aggregator stays **undefined** instead of expecting trace
forwarding.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
c781a10. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
AggregatedBalanceSelectortransaction volume spike by not passingtraceintogetAggregatedBalanceForAccountcp-13.40.0 (fix(sentry): ResolveAggregatedBalanceSelectortransaction volume spike by not passingtraceintogetAggregatedBalanceForAccountcp-13.40.0 #44449)Motivation
AggregatedBalanceSelectoraccounts for 91% of all Sentry transactionroots,
and is growing as 13.38+ adoption climbs. Accepted transaction volume is
holding at approximately 36M per week against a 3.2M per week pre-spike
baseline.
ui/selectors/assets.tsforwardstraceAsControllerCallbackintogetAggregatedBalanceForAccountthrough theassets.balance-utilshelpers. That function runs inside a Redux selector, so it recomputes
per account group on every relevant state change and re-render. Each
computation emits a forced transaction root (
span.op: custom), with nosample gate.
The same callback was removed from
assets-controller-init.tsin#43213. That fix covered the controller entry point. The selector entry
point, introduced by the same upstream changeset
(MetaMask/core#8310), was
not covered, and reached production in 13.38.0 via #43635.
AggregatedBalanceSelectoris the only one of the seven traces added bycore#8310 that is still emitting. The other six route through the
controller callback removed in #43213 and are already at zero, so this
call site closes core#8310 entirely.
Description
This commit removes
traceAsControllerCallbackfrom the two call sitesin
ui/selectors/assets.tsthat forward it into the unified balanceselectors, along with the now-unused import.
The optional
traceparameters are also removed fromaggregateGroupBalance,calculateBalanceForAllWallets, andcalculateBalanceChangeForAccountGroupinui/selectors/assets.balance-utils.ts. Leaving them in place wouldallow the callback to be reintroduced by supplying a single argument,
which is how it arrived in the first place. The test that asserted trace
forwarding is inverted into a regression test asserting no trace is
passed.
Test plan
eslintpasses on all three touched filestsc --noEmitreports no errors in the touched filesui/selectors/assets.test.tsandui/selectors/assets.balance-utils.test.tspass (71 tests)AggregatedBalanceSelectorvolume
drops to approximately zero on the fixed release
Changelog
CHANGELOG entry: null
References
Fixes #44447
Related: #43211, #43213, #43370,
MetaMask/core#8310
Note
Low Risk
Observability-only change; balance math and selector inputs are
unchanged aside from omitting the optional trace argument.
Overview
Stops Sentry transaction roots from
AggregatedBalanceSelectorbyno longer forwarding
traceAsControllerCallbackinto unified wallet andaccount-group balance calculations.
ui/selectors/assets.tsdrops the trace import and stops passing acallback into
calculateBalanceForAllWalletsandcalculateBalanceChangeForAccountGroupwhen assets-unify state isenabled. In
assets.balance-utils.ts, optionaltraceparameters areremoved end-to-end so
getAggregatedBalanceForAccountis never given atrace callback from this Redux path (which recomputes per group on every
relevant state change). The unit test now asserts the 7th argument to
the aggregator stays undefined instead of expecting trace
forwarding.
Reviewed by Cursor Bugbot for commit
c781a10. Bugbot is set up for automated
code reviews on this repo. Configure
here.