Skip to content

fix(api): round account-summary activity.total_fee_tao to rao precision#2352

Merged
JSONbored merged 2 commits into
JSONbored:mainfrom
joaovictor91123:fix/account-activity-fee-rounding-2351
Jun 29, 2026
Merged

fix(api): round account-summary activity.total_fee_tao to rao precision#2352
JSONbored merged 2 commits into
JSONbored:mainfrom
joaovictor91123:fix/account-activity-fee-rounding-2351

Conversation

@joaovictor91123

Copy link
Copy Markdown
Contributor

Summary

  • GET /api/v1/accounts/{ss58} and the MCP get_account tool (both share loadAccountSummary in src/account-events.mjs) reported activity.total_fee_tao straight from a D1 SUM(fee_tao) aggregate, unrounded — so summing many REAL fee cells leaked accumulated IEEE-754 float noise (e.g. 0.30000000000000004).
  • Every other TAO sum in the codebase rounds to rao precision (9 dp) to prevent exactly this. The same signer-total-fee value is already rounded via toTao in buildChainSigners (/chain/signers) and buildChainFees (/chain/fees); the account-summary path was the one that was missed, so the endpoints disagreed on the precision of the same number.

Fixes #2351

What Changed

  • src/account-events.mjs: added a null-preserving toTaoOrNull helper (rounds to 9 dp, keeps null for the cold-store aggregate) and used it for activity.total_fee_tao in formatAccountActivity. Mirrors toTao in src/chain-analytics.mjs; null-preserving because the activity aggregate is null (not 0) on a cold store. No schema/contract change — same field, same type, just without the float tail.
  • tests/account-events.test.mjs: added a regression test asserting a noisy sum (0.1 + 0.2) rounds to 0.3, a sub-rao tail is rounded to 9 dp, and an absent aggregate stays null.

Registry Safety

  • No secrets, PATs, wallet data, private dashboards, private URLs, or validator-local state.
  • Generated artifacts were produced by repo scripts, not hand-edited.
  • R2-only/high-churn detail artifacts are not committed.
  • Public API/OpenAPI/schema changes are intentional and documented. (None — behaviour-only fix; the field type is unchanged.)

Validation

  • npm run check (lint clean; format check passes on CI's LF checkout)
  • npm run worker:test (tests/account-events.test.mjs: 45 passed, incl. new regression test)
  • git diff --check

The account-summary signing-activity aggregate (loadAccountSummary, shared by
the REST /accounts/{ss58} route and the MCP get_account tool) reported
activity.total_fee_tao straight from a D1 SUM(fee_tao) without rounding, so the
payload leaked accumulated IEEE-754 float noise (e.g. 0.30000000000000004).
Every other TAO sum in the codebase rounds to rao precision (9 dp) for exactly
this reason -- the same signer-total-fee value is rounded via toTao in
buildChainSigners (/chain/signers) and buildChainFees (/chain/fees). Round it in
formatAccountActivity too (null-preserving, since the aggregate is null on a
cold store), so the same fee reads identically across endpoints.

Fixes JSONbored#2351
@gittensory-orb

gittensory-orb Bot commented Jun 29, 2026

Copy link
Copy Markdown

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-06-29 23:23:07 UTC

2 files · 1 AI reviewer · no blockers · readiness 73/100 · CI green · clean

⏸️ Suggested Action - Manual Review

  • Touches a maintainer-blocked path — held for manual review

Review summary
The change rounds account-summary activity.total_fee_tao to 9 decimal places at the formatter boundary while preserving null for missing aggregates and nulling invalid numeric input. The implementation is correctly scoped, keeps the public field shape unchanged, and the added regression test covers noisy sums, sub-precision tails, null, and nonnumeric input. No schema or generated artifact update is needed for this behavior-only precision fix.

Nits — 5 non-blocking
  • src/account-events.mjs:83: The helper comment repeats PR context and endpoint comparisons; shorten it to the local invariant that TAO aggregates are rounded to 9 decimal places while preserving null.
  • tests/account-events.test.mjs:307: The regression test is useful but slightly broad for one case; splitting invalid-input behavior from rounding behavior would make future failures easier to diagnose.
  • src/account-events.mjs:83: Consider consolidating this helper with the existing TAO rounding helpers in nearby analytics modules when precision handling is next touched, so the 9-decimal invariant stays centralized.
  • Readiness score is below the configured threshold — Use the readiness panel as advisory maintainer context; the score does not block this PR.
  • Touches a maintainer-blocked path — held for manual review — A maintainer must review and merge this change.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ✅ Linked #2351
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ❌ 5/25 Preflight is holding this PR; address the blocker before review.
Contributor workload ✅ 10/10 Author activity: 37 registered-repo PR(s), 19 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor joaovictor91123; Gittensor profile; 37 PR(s), 0 issue(s).
Gate result ⚠️ Not blocking Advisory; not blocking this PR.
Review context
  • Author: joaovictor91123
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository registration is not available in the local Gittensory cache.
  • Public profile languages: not available
  • Official Gittensor activity: 37 PR(s), 0 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Fix the blocker.
  • Triage stale or unlinked PRs.
  • Refresh registry data or choose a registered active repo.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@gittensory-orb gittensory-orb Bot added gittensor Gittensor contributor context gittensor:bug Bug labels Jun 29, 2026
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.47%. Comparing base (9d5b154) to head (965092e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2352   +/-   ##
=======================================
  Coverage   95.46%   95.47%           
=======================================
  Files          61       61           
  Lines        9777     9788   +11     
  Branches     3634     3637    +3     
=======================================
+ Hits         9334     9345   +11     
  Misses         70       70           
  Partials      373      373           
Files with missing lines Coverage Δ
src/account-events.mjs 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored JSONbored merged commit 7e482a9 into JSONbored:main Jun 29, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Bug gittensor Gittensor contributor context

Development

Successfully merging this pull request may close these issues.

bug(api): account-summary activity.total_fee_tao leaks SUM float noise (not rounded to rao like the chain fee endpoints)

2 participants