Skip to content

fix: Indexing a fresh local chain from block 0 caused an integer underflow due to left-to-right evaluation.#78

Open
sonny-campbell wants to merge 1 commit into
evstack:mainfrom
sonny-campbell:bugfix/indexer-underflow
Open

fix: Indexing a fresh local chain from block 0 caused an integer underflow due to left-to-right evaluation.#78
sonny-campbell wants to merge 1 commit into
evstack:mainfrom
sonny-campbell:bugfix/indexer-underflow

Conversation

@sonny-campbell
Copy link
Copy Markdown

@sonny-campbell sonny-campbell commented May 13, 2026

I was trying to test the indexer using a local chain on anvil. I ran into the following error:

2026-05-13T13:15:50.707433Z  INFO atlas_server::indexer::indexer: starting fetch workers workers=4 rpc_batch_size=20

thread 'tokio-rt-worker' (464933) panicked at crates/atlas-server/src/indexer/indexer.rs:473:31:
attempt to subtract with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Steps to reproduce:

  1. Set up .env for local test chain
DATABASE_URL=postgres://atlas:atlas@localhost:5432/atlas

RPC_URL=http://localhost:8545

CHAIN_NAME="Devnet"

everything else is defaults... 
  1. docker compose down -v
  2. docker compose up -d postgres
  3. anvil --host 127.0.0.1 --port 8545 --block-time 2 --chain-id 31337 --accounts 10 --balance 10000
  4. just backend-run

This would always throw the underflow error the first time I run. On running just backend-run a second time, it seems to start working as expected.

On the first run it looks like end_block is always equal to batch_size - 1 causing an underflow due to it being subtracted before the + 1

Summary by CodeRabbit

  • Chores
    • Internal code optimization with no user-facing changes.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3679eb1b-c022-4aad-8341-6a0dc6a4d471

📥 Commits

Reviewing files that changed from the base of the PR and between 6d5de9b and 30a0677.

📒 Files selected for processing (1)
  • backend/crates/atlas-server/src/indexer/indexer.rs

📝 Walkthrough

Walkthrough

The batch completion logging statement reorders the arithmetic expression for calculating start_block from end_block - batch_size + 1 to end_block + 1 - batch_size. Both expressions are mathematically equivalent; no logic or behavior changed.

Changes

Batch Completion Logging Expression

Layer / File(s) Summary
Logging expression reorder
backend/crates/atlas-server/src/indexer/indexer.rs
The tracing::info! log at line 473 reorders the start_block arithmetic from end_block - batch_size + 1 to end_block + 1 - batch_size, preserving the computed value.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested reviewers

  • tac0turtle

Poem

🐰 A sprightly hop through arithmetic's dance,
Where block numbers twirl in a rearranged trance,
The sum stays the same, yet the order's so neat,
Like carrots rearranged on a mathematically sweet treat! 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the fix for an integer underflow bug in the indexer caused by arithmetic operator precedence when processing a fresh chain starting at block 0.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant