Visible transfers are counted twice: every one emits Balances::Transfer and Wormhole::NativeTransferred #42

Closed
opened 2026-10-06 14:41:31 +00:00 by grenade · 1 comment
Owner

Why

Found while building #39's bridge view: the bridge custody account's page reports received 312,003.992 QTC across 28 receipts. The real figures are 156,001.996 across 14, exactly half.

Every visible transfer on this chain emits two events with the same payload. Counted on production, 2026-10-06:

Events
Balances::Transfer 193,691
...of which have a Wormhole::NativeTransferred in the same extrinsic, with the same from, to and amount 193,686
Wormhole::NativeTransferred with a visible sender 193,687
Wormhole::NativeTransferred in total (the rest have the hidden 0x0101… sender: rewards and exits) 415,340

Three queries add the two event types together, so they count every visible transfer twice:

  • Store::account_flows: each account page's sent, received, sends, receipts.
  • Store::flows_for: the distribution table on /:chain/network: sent on and the counts behind it.
  • Store::wormhole_routes: the visible-sender rows on /:chain/wormhole, i.e. Utility::batch_all, Balances::transfer_allow_death and the like.

Distinct counts (recipients, senders) are unaffected, because a duplicate is the same pair. Sums and counts of transfers are doubled. Hidden-sender rows (rewards, exits) are correct, because those only ever emit NativeTransferred. CLAUDE.md's route table quotes some of the doubled counts.

Fix

  • Count each transfer once: every NativeTransferred, plus a Balances::Transfer only when no identical NativeTransferred sits beside it in the same extrinsic. That keeps the five unmatched Balances::Transfer events rather than discarding them.
  • Correct the figures CLAUDE.md quotes from the doubled routes.
## Why Found while building #39's bridge view: the bridge custody account's page reports `received` **312,003.992 QTC across 28 receipts**. The real figures are **156,001.996 across 14**, exactly half. **Every visible transfer on this chain emits two events with the same payload.** Counted on production, 2026-10-06: | | Events | |---|---| | `Balances::Transfer` | 193,691 | | ...of which have a `Wormhole::NativeTransferred` in the same extrinsic, with the same `from`, `to` and `amount` | **193,686** | | `Wormhole::NativeTransferred` with a visible sender | 193,687 | | `Wormhole::NativeTransferred` in total (the rest have the hidden `0x0101…` sender: rewards and exits) | 415,340 | Three queries add the two event types together, so they count every visible transfer twice: - **`Store::account_flows`:** each account page's `sent`, `received`, `sends`, `receipts`. - **`Store::flows_for`:** the distribution table on `/:chain/network`: `sent on` and the counts behind it. - **`Store::wormhole_routes`:** the visible-sender rows on `/:chain/wormhole`, i.e. `Utility::batch_all`, `Balances::transfer_allow_death` and the like. Distinct counts (recipients, senders) are unaffected, because a duplicate is the same pair. Sums and counts of transfers are doubled. Hidden-sender rows (rewards, exits) are correct, because those only ever emit `NativeTransferred`. CLAUDE.md's route table quotes some of the doubled counts. ## Fix - Count each transfer once: every `NativeTransferred`, plus a `Balances::Transfer` only when no identical `NativeTransferred` sits beside it in the same extrinsic. That keeps the five unmatched `Balances::Transfer` events rather than discarding them. - Correct the figures CLAUDE.md quotes from the doubled routes.
Author
Owner

2026-10-06: correction, CLAUDE.md's route table is not doubled

The issue body says CLAUDE.md quotes some of the doubled counts. It doesn't. Recomputed on production with the fix applied, over blocks ≤ 42,400, Utility::batch_all gives 15,530 visible transfers. The table says 15,303. A doubled figure would be about twice the true one, not slightly below it. The table must have been measured from Wormhole::NativeTransferred alone, most likely before Balances::Transfer was indexed, so it is left as it stands.

The fix itself is checked on production data for the bridge custody account. The old query gives received 372,003.992 over 30 receipts; the fixed one 186,001.996 over 15, exactly half. Custody has received 30,000 QTC more since the figure in the issue body was taken.

## 2026-10-06: correction, CLAUDE.md's route table is not doubled The issue body says CLAUDE.md quotes some of the doubled counts. **It doesn't.** Recomputed on production with the fix applied, over blocks ≤ 42,400, `Utility::batch_all` gives **15,530** visible transfers. The table says 15,303. A doubled figure would be about twice the true one, not slightly below it. The table must have been measured from `Wormhole::NativeTransferred` alone, most likely before `Balances::Transfer` was indexed, so it is left as it stands. The fix itself is checked on production data for the bridge custody account. The old query gives `received` **372,003.992 over 30 receipts**; the fixed one **186,001.996 over 15**, exactly half. Custody has received 30,000 QTC more since the figure in the issue body was taken.
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: blackbeard/observer#42