OpenZeppelin / OpenZeppelin/Event-Scanner

fix: Using Block Hash for `from_block`: Handle Unlikely Edge Case that a Reorg Happens Between Scanner Being Started and The First Logs Being Fetched

Open
#193 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement type: refactor
Dominant language
Rust
Stars
19
Forks
7
Avg merge
2h 15m
Merged PRs (30d)
4

Description

Becomes relevant after #178 is implemented.

NOTE: since the scanner normalizes from/to blocks, i.e. the client can set to_block to be lower than from_block, when we refer to from_block in this issue, we refer to the block with the lower block number post-normalization.

Current logic is to get the block number associated with the configured from/to block hash at scanner.start, to reduce the chance of a reorg removing the block with the configured hash.

There's an edge case though, where the block hash is set to a non-finalized block and a reorg happens between the scanner being started and the first logs are fetched, meaning by the time the scanner uses the block number previously associated with the block hash that was set, it has already been reorged, and the client would be getting logs from an unrelated, post-reorg block at the same block number.

This edge case is extremely unlikely, but to still address it requires that the event scanner perform a one-time check after the first time it fetches logs that the start block it used has the same hash as the one the client set. After that initial check, the scanner would rely on the existing reorg handling logic.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the scanner.start flow and the first log-fetch operation, then trace the existing reorg handling logic. The work is done when the scanner performs the described one-time check that the start block's hash still matches the configured hash before relying on normal reorg handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
blockchain
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.