Skip to content

fix(bfa): scan FundsIn logs from the asset genesis in bounded ranges - #108

Merged
gofman8 merged 2 commits into
devfrom
fix/bfa-funds-in-log-range
Oct 7, 2026
Merged

gofman8 merged 2 commits into
devfrom
fix/bfa-funds-in-log-range

Conversation

@nklyy

@nklyy nklyy commented Oct 7, 2026 •

Copy link
Copy Markdown

Problem

BFA receive validation fetched every Bridge FundsIn log with eth_getLogs(fromBlock 0x0, toBlock latest). The public Arbitrum One RPC now refuses ranges over 10M blocks (-32602 query spans N blocks ... only 10000000 are allowed). So every BFA receive fails, and the transfer stays WaitingCounterparty with the error only in RefreshedTransfer.failure.

Fix

EthClient::funds_in_logs_since(contract, genesis_ts) replaces the full scan:

  1. It reads the head (eth_blockNumber).
  2. It binary-searches the first block mined at or after the asset genesis timestamp minus one day (eth_getBlockByNumber, about 29 calls on Arbitrum One).
  3. It scans from that block to the head in ranges of at most 10M blocks. When the node answers with a JSON-RPC error, it halves the range down to 1000 blocks. Transport errors are not retried.

Starting at the genesis drops nothing a mint can use: a mint OpId commits to the contract id, so no FundsIn naming it can be older than the genesis. The one-day slack covers issuer clock skew. Fewer events can only make the cea check stricter, never looser.

The get_logs / client_version JSON-RPC plumbing is merged into one call helper. client_version sends the same request as before.

This is a quick patch until we migrate to upstream rgb-lib.

Tests

  • Unit tests for the binary search (bounds, equal timestamps, past the head) and for the chunked scan (contiguous ranges, halving the range actually sent, giving up at the floor, no retry on transport errors, empty range).
  • An end-to-end mock RPC test for the whole lookup.
  • Manually against the live arb1 RPC and the dev Bridge (0xc7faf6fa…): both FundsIn logs of 2026-10-06 were found in about 5 s, where the old query is refused.
  • cargo clippy in all four CI feature sets.

nklyy added 2 commits October 6, 2026 15:23
bridge-smart-contracts #174 indexes rgbOpId in FundsIn. The parser now
takes the OpId from topic2 (big-endian uint256) and the amount from the
only data word; the old layout no longer decodes. The test bridge
contract indexes it too.
BFA receive validation asked eth_getLogs for every FundsIn from block 0.
The public Arbitrum One RPC now refuses ranges over 10M blocks, so every
BFA receive stayed WaitingCounterparty. The scan now starts at the first
block mined a day before the asset genesis (found by a binary search on
block timestamps) and runs to the head in ranges of at most 10M blocks,
halving a range the node refuses. Fewer events can only make validation
stricter, so the later start loosens nothing.
@nklyy
nklyy changed the base branch from fix/funds-in-indexed-opid to dev October 7, 2026 08:27
@nklyy nklyy closed this Oct 7, 2026
@nklyy nklyy reopened this Oct 7, 2026
@gofman8
gofman8 merged commit 04b4b14 into dev Oct 7, 2026
23 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.

2 participants