perf(bifrost/bsc): skip eth_getBlockReceipts when logsBloom rules out observations

🔎 Visual review of 7474e33d: explainer, review flags and prompts to ask an AI about the change

Problem

The BSC scanner calls eth_getBlockReceipts for every block, but almost no block has anything THORChain needs from its receipts. A receipt only leads to an observation through a log emitted by a router, or a tx to or from a vault. In a 2,500-block sample from normal traffic, 7 blocks (0.28%) had a router log. Every node still makes the call for all the other blocks, which is about 2.2 calls per second at tip and more while catching up.

TRON solved the same problem with a vault gate on tx fields. BSC can't use that alone. With EVMDisableContractWhitelist=1, a deposit can arrive through any contract: tx.To is that contract, and the vault appears only in the router's Deposit log. A gate on tx fields would silently miss those deposits.

Changes

  • gasPricesWithoutReceipts (new): on BSC, getTxIn calls this first and skips the receipts call only if all of these hold:
    • no active router from GetContracts is in the block's logsBloom
    • no tx is to a router, a whitelisted contract or a vault
    • no tx is from a vault
    • no tx is a transfer(address,uint256) to a vault
  • The bloom covers logs: only router logs are parsed, and a bloom has no false negatives, so a miss proves the block has no router log.
  • Tx fields cover the rest: this includes failed vault txs, which have no logs. Their status is still read from the receipt, because they fetch.
  • Anything it can't settle fetches as before: no routers known, no base fee, a fee cap under the base fee, an unrecoverable sender, or truncated transfer calldata.
  • Skipped blocks behave the same otherwise: they still clean up signed tx items, and they take gas prices from the txs and base fee, so updateGasPrice sees the same values. Blob txs stay excluded, as in getTxInOptimized.
  • txSender (new): reads the from that ethclient kept when decoding the block, falling back to signature recovery. Recovery was nearly all of the filter's cost. A cancelled context stops TransactionSender turning a cache miss into one RPC per tx.

Live comparison

I ran the filter and getTxInOptimized side by side on real BSC blocks. For every skipped block, the receipts path had to produce no observations and the same gas prices.

Blocks Count Skipped Fetched Missed observations Gas price mismatches
During the halt, low traffic 120 118 2 0 0
Before the halt, normal traffic 120 102 18 0 0
Blocks with real router logs 205 0 205 0 n/a (none skipped)
  • Router-log blocks: all 205 hit the bloom, and they produced 68 observations through the normal path.
  • Filter cost: median 0.30 ms and 0.53 ms per scanned block in the two sampled periods.
  • Reported senders: across 3,929 live txs, the cached from always hit and always matched signature recovery. The local block hash matched the server's on all 40 blocks checked, which the cache lookup depends on.
  • False positives: these follow how many bloom bits are set, so busier blocks will skip less. The low-traffic blocks had about 690 of 2,048 bits set, and the normal-traffic blocks about 1,030.

Tests

receipts_gate_test.go adds 15 tests, including a deposit through an unknown contract, a failed vault tx, a second active router, and a block with no reported senders making no extra RPC calls. I broke the implementation 22 different ways, one at a time, and the tests caught each one.

Not covered

  • Real TSS module: tss-lib-private isn't available to me, so I ran the evm package against a local stub of it that isn't in this branch. shared/evm tests and everything TSS-related did not run, so CI needs to confirm those.
  • Some observation types on live blocks: the sample had no direct vault sends, no vault txs without router logs, and no direct ERC20 inbounds. Those are covered by unit tests only.
  • Non-standard tokens: direct ERC20 transfers are detected from calldata, while ParseDirectERC20TransferLogs reads logs. A token whose Transfer log names a different recipient than its calldata could be skipped.
  • Scan speed: I haven't measured the effect on real scan rates, so this MR claims fewer calls, not a specific speedup.
Edited by Huginn Ai

Merge request reports

Loading
Loading