fix(api/history): include coin_queue in balance read - #168
Merged
Conversation
…rfaces as 50k delta `balance_from_account_blob` previously read only `Account.balance`, which is the *settled* balance after sends. The mint and receive paths push the credited coin into `coin_queue` without touching the `balance` field — `Account::get_balance()` is the only call that sums both. Reading just `balance` here made every first-mint history row collapse to `new_balance = 0, prev_balance = 0, amount = 0`, so the wire item reported `amount = 0` for a 50_000-sat credit. The existing unit test masked this because its fixture set `a.balance = 5_000` directly, a shape no production caller produces on the mint or receive path. That test now documents that it pins the settled-balance variant (a valid post-send shape), and a new sibling test `history_row_to_item_balance_from_coin_queue_only` in `account_node_tests` walks the real mint flow (`execute_send_coins` + `receive_coin`) to pin the previously- uncovered queue-only case end to end — including a direct assertion on `balance_from_account_blob` itself. E2E (api_remote::history_after_mint_records_mint_row) flagged this against dev-api on PR #166 (Release develop->main).
TaprootFreak
marked this pull request as ready for review
June 1, 2026 20:41
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.
Problem
api_remote::history_after_mint_records_mint_rowfails against dev-apion PR #166 (Release: develop -> main):
/api/historyreturnsitems[0].amount = 0for the first mint of afresh address, where the wire contract is the credited amount.
Root cause
router::balance_from_account_blobreads onlyAccount.balance— thesettled balance after sends. The mint / receive paths push the credited
coin into
coin_queuewithout touchingbalance;Account::get_balance()is the only call that sums both. So
history_row_to_itemcomputednew_balance = 0, prev_balance = 0, amount = 0for every mint row.The existing unit test fixture set
a.balancedirectly, which noproduction write path produces on the mint or receive path — that hid
the gap until the E2E suite ran against a real
commit_mint_txwrite.Fix
balance_from_account_blob: deserialize, then sumbalance + Σ coin_queue.amount(mirrorsAccount::get_balance()).saturating_addon the untrusted-blob summands.history_row_to_item_handles_first_row_with_no_prev_data: docs-only — clarifies that it pins the settled-balance variant (still a valid post-send shape) and points to the queue-only sibling test.history_row_to_item_balance_from_coin_queue_onlyinaccount_node_tests: walks the real mint flow (execute_send_coins+receive_coin) and asserts bothbalance_from_account_blobdirectly and the end-to-endhistory_row_to_itemoutput.No wire-shape change, no schema change, no migration.
Verification
cargo fmt --all -- --check: cleancargo clippy -p node -p shared -- -D warnings: cleancargo build -p node: cleanUnblocks
PR #166 (Release develop -> main).