Skip to content

feat(contracts): index contract creations + /contracts/{recent,pioneers,stats}#61

Merged
satyakwok merged 2 commits into
mainfrom
feat/contracts-indexing-phase2
Jun 8, 2026
Merged

feat(contracts): index contract creations + /contracts/{recent,pioneers,stats}#61
satyakwok merged 2 commits into
mainfrom
feat/contracts-indexing-phase2

Conversation

@satyakwok
Copy link
Copy Markdown
Member

@satyakwok satyakwok commented Jun 8, 2026

Why

Phase 2 of consolidating the testnet explorer onto a single indexer (indexer-rs). After #60 (stats/whale parity), the only remaining gap was the contract leaderboards — indexer-rs had no contract data at all. This adds it, so indexer-rs can fully replace the legacy indexer.

Changes

  • Migration 0004contracts table (address PK, first/last_seen_block, code_hash NULL, tx_count, created_tx_hash) + recent/pioneers indexes.
  • Detection — a tx with to_addr IS NULL is a contract creation; the created address = keccak(rlp(sender, nonce))[12:] (alloy Address::create), lowercased. Wired into both block-writer paths (single + batch).
  • History backfill — one-time, on boot, background; fills contracts from existing creation txs (no-op once populated, so cheap on every restart).
  • Routes/contracts/recent (newest), /contracts/pioneers (oldest), /contracts/stats (sortable, defaults newest). Shape {"contracts":[{rank,address,first_seen_block,last_seen_block,code_hash}]} — matches the frontend (res?.contracts ?? []; null code_hash renders "—").

code_hash stays NULL for now (UI handles it); an eth_getCode pass is a later enhancement.

Tests

  • CREATE-address known vector + bad-input rejection (block_writer).
  • Response shape (routes/contracts).
  • Smoke: fixture contract + /contracts/{recent,pioneers,stats} asserts (incl null code_hash).

Note

cargo-deny red is pre-existing (RUSTSEC-2026-0173 proc-macro-error2, repo-wide, unrelated).

Summary by CodeRabbit

  • New Features
    • New contract leaderboard endpoints: /contracts/recent, /contracts/pioneers, and /contracts/stats for contract ranking queries
    • Automatic contract-creation transaction detection and historical backfill for contract data
    • Performance improvements via indexes on contract creation timestamps

…rs,stats}

Phase 2 of explorer-indexer consolidation: indexer-rs now serves the contract
leaderboards the frontend expects, so it fully replaces the legacy indexer.

- Migration 0004: `contracts` table (address PK, first/last_seen_block,
  code_hash NULL, tx_count, created_tx_hash) + indexes for recent/pioneers.
- Detection: a tx with `to_addr IS NULL` is a contract creation; the created
  address is the CREATE address keccak(rlp(sender, nonce))[12:] (alloy), lower-
  cased. Wired into both block-writer paths (single + batch).
- One-time history backfill on boot (no-op once populated) fills `contracts`
  from existing creation txs — runs in the background so it never blocks sync.
- Routes `/contracts/recent` (newest), `/contracts/pioneers` (oldest),
  `/contracts/stats` (sortable list, defaults newest). Shape
  `{"contracts":[{rank,address,first_seen_block,last_seen_block,code_hash}]}`,
  matching the frontend (`res?.contracts ?? []`, null code_hash → "—").

code_hash stays NULL for now (the UI already handles it); an eth_getCode pass
is a later enhancement.

Tests: CREATE-address known vector + bad-input; response shape; smoke fixture
contract + /contracts/{recent,pioneers,stats} asserts.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 8, 2026

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces contract leaderboards across the full stack. A new contracts database table tracks contract-creation transactions (identified by null recipient addresses), with first/last-seen block numbers and an optional code hash. Block-write logic now detects contract creations, derives their CREATE addresses from sender and nonce, and upserts records atomically. A one-time backfill populates historical contracts. Three REST endpoints (/recent, /pioneers, /stats) serve ranked leaderboards with cached responses. Smoke tests verify endpoint contracts and response serialization.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Sentriscloud/indexer-rs#35: Modifies crates/sync/src/block_writer.rs batch write path (write_block_batch COPY backfill), directly related to the batch write transaction extension in this PR.
  • Sentriscloud/indexer-rs#37: Refactors batch_write_blocks function in the same module, overlapping with the contract-creation upsert logic added in this PR's batch write layer.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description lacks critical required sections from the template including Scope, Checks (build, test, format, slither, storage), Linked issue, and Deploy impact checkboxes. Add the missing template sections with appropriate checkboxes, test results, and deployment impact assessment to enable proper review and merge gating.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding contract creation indexing and three new API endpoints for contract leaderboards.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/contracts-indexing-phase2

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.

@satyakwok satyakwok merged commit d998d05 into main Jun 8, 2026
6 of 8 checks passed
@satyakwok satyakwok deleted the feat/contracts-indexing-phase2 branch June 8, 2026 04:17
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