Skip to content

get_asset_balance: count a colored witness receive once - #27

Closed
darkhorse-core wants to merge 1 commit into
UTEXO-Protocol:devfrom
RGB-Launchpad:fix/witness-receive-counted-once
Closed

darkhorse-core wants to merge 1 commit into
UTEXO-Protocol:devfrom
RGB-Launchpad:fix/witness-receive-counted-once

Conversation

@darkhorse-core

Copy link
Copy Markdown

get_asset_balance counts a witness receive waiting for confirmations twice in future.

What happens. A wallet with a settled balance of 1000 receives 500 through a witness
invoice. While the transfer waits for confirmations, future reads 2000 instead of 1500.

Why. The pending amount exists to cover transfers whose allocations are not on a TXO yet.
Once a receive has been colored its allocation is already part of txos_allocations, so adding
the transfer's requested_assignment on top counts the same amount a second time.

Fix. Asset transfers that already carry a Receive coloring are skipped when the pending
amounts are summed.

The added test covers both sides, with the allocation colored and without.
cargo test --lib database::memory_db passes: 48 tests, 0 failures.

Branched from dev at 2610d4a.

A witness receive waiting for confirmations was counted twice in `future`: once
through the allocation already recorded on its output, and once more through the
transfer's requested assignment. With a settled balance of 1000 and an incoming
500, `future` reported 2000.

The pending amount exists to cover transfers whose allocations are not on a TXO
yet. Once a receive has been colored its allocation is already part of
`txos_allocations`, so adding the requested assignment on top counts the same
amount a second time. Asset transfers that already have a `Receive` coloring are
now skipped there.

The added test covers both sides, with the allocation colored and without.
@darkhorse-core

Copy link
Copy Markdown
Author

Friendly ping — is there anything we can add to make this easier to review (more tests, a reproducer against the published package, a different shape for the fix)? Happy to adjust.

For context: we hit this while running a browser wallet on the published WASM bindings, where a colored witness receive was counted twice and the displayed balance inflated.

@RGB-Launchpad RGB-Launchpad closed this by deleting the head repository Oct 16, 2026
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.

2 participants