Skip to content

fix(api/history): include coin_queue in balance read - #168

Merged
TaprootFreak merged 1 commit into
stagingfrom
fix/history-include-coin-queue
Jun 1, 2026
Merged

fix(api/history): include coin_queue in balance read#168
TaprootFreak merged 1 commit into
stagingfrom
fix/history-include-coin-queue

Conversation

@TaprootFreak

Copy link
Copy Markdown
Contributor

Problem

api_remote::history_after_mint_records_mint_row fails against dev-api
on PR #166 (Release: develop -> main):

assertion `left == right` failed
  left: Number(0)
 right: 50000

/api/history returns items[0].amount = 0 for the first mint of a
fresh address, where the wire contract is the credited amount.

Root cause

router::balance_from_account_blob reads only Account.balance — the
settled balance after sends. The mint / receive paths push the credited
coin into coin_queue without touching balance; Account::get_balance()
is the only call that sums both. So history_row_to_item computed
new_balance = 0, prev_balance = 0, amount = 0 for every mint row.

The existing unit test fixture set a.balance directly, which no
production write path produces on the mint or receive path — that hid
the gap until the E2E suite ran against a real commit_mint_tx write.

Fix

  • balance_from_account_blob: deserialize, then sum balance + Σ coin_queue.amount (mirrors Account::get_balance()). saturating_add on 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.
  • New test history_row_to_item_balance_from_coin_queue_only in account_node_tests: walks the real mint flow (execute_send_coins + receive_coin) and asserts both balance_from_account_blob directly and the end-to-end history_row_to_item output.

No wire-shape change, no schema change, no migration.

Verification

  • cargo fmt --all -- --check: clean
  • cargo clippy -p node -p shared -- -D warnings: clean
  • cargo build -p node: clean
  • Heavy tests deferred to CI.

Unblocks

PR #166 (Release develop -> main).

…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
TaprootFreak marked this pull request as ready for review June 1, 2026 20:41
@TaprootFreak
TaprootFreak merged commit 206bf87 into staging Jun 1, 2026
4 checks passed
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.

1 participant