Skip to content

Eth balance snapshot - #4605

Open
Tomasvrba wants to merge 4 commits into
BitBoxSwiss:masterfrom
Tomasvrba:eth-balance-snapshot
Open

Tomasvrba wants to merge 4 commits into
BitBoxSwiss:masterfrom
Tomasvrba:eth-balance-snapshot

Conversation

@Tomasvrba

Copy link
Copy Markdown
Collaborator

Fix negative balances after Send all. Separate balance and block-number requests could observe different blocks, causing a confirmed outgoing transaction to be deducted from a balance that already included the debit.

  • Fetch the block number, ETH balances, and ERC20 balances together in one Multicall3 request per chain, keeping balance updates and outgoing transaction reconciliation consistent.
  • Use the same snapshot for active-account probes.
  • Refresh again after 30 seconds when a synced account’s balance changes so transaction history can catch up.
  • Retry failed snapshots after 30 seconds, with increasing delays capped at five minutes.
  • Update tests and mocks for snapshots, partial failures, probes, and outgoing transaction consistency.

@Tomasvrba
Tomasvrba requested a review from a team as a code owner November 16, 2026 06:29
@benma

benma commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Please target master instead of the release branch - It will not make it in time. It is not a regression introduced in 4.53 right?

@Tomasvrba

Copy link
Copy Markdown
Collaborator Author

Please target master instead of the release branch - It will not make it in time. It is not a regression introduced in 4.53 right?

No, it's not, it's a pre-existing bug, but @strmci discovered it during release testing I believe.
Ok, will switch it to master

The displayed balance is the on-chain balance minus pending outgoing
amounts. The updater fetched the block number, then the balances, and
checked outgoing transactions at that block number. Etherscan answers
eth_call and balancemulti at the latest block regardless of the
requested block, and its backends can be a block or more apart. A
transaction mined in between was already missing from the balance but
still counted as pending, so it was subtracted twice. After sending
the whole balance, the account showed a negative balance until the
next poll.

Read the block number together with all native and ERC20 balances in
a single Multicall3 eth_call and check outgoing transactions at the
block it returns, so both describe the same chain state. Multicall3
is deployed at the same address on mainnet and Sepolia.
Use the same Multicall3 read as the full update.
Etherscan can report a new balance before it has indexed the
transaction. The transaction then only appeared with the next poll,
up to five minutes later. The active account probe already refreshed
again after 30 seconds. Do that for every update that changes the
on-chain balance of a synced account, so it also covers the update
after sending and the periodic poll. It stops by itself once the
balance no longer changes.
When the block number and balances cannot be read, no account of that
chain is updated. Retry after 30 seconds instead of waiting for the
next poll, doubling the delay up to the poll interval while it keeps
failing.
@Tomasvrba
Tomasvrba force-pushed the eth-balance-snapshot branch from d8b378a to 26167a9 Compare November 17, 2026 21:56
@Tomasvrba
Tomasvrba changed the base branch from release-v4.53.0 to master November 17, 2026 22:14
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