Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/registries/src/world_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use alloy::{
sol!(
/// The registry of World IDs. Each World ID is represented as a leaf in the Merkle tree.
#[allow(clippy::too_many_arguments)]
#[sol(rpc, ignore_unlinked)]
#[sol(rpc, ignore_unlinked, extra_derives(Debug, PartialEq, Eq))]
WorldIdRegistry,
"abi/WorldIDRegistryAbi.json"
);
Expand Down
2 changes: 1 addition & 1 deletion local-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ start_node() {
run_indexer_and_gateway() {
# remove the tree_cache_file as we have a new DB everytime we run local_setup
rm -f /tmp/tree.mmap
REGISTRY_ADDRESS=$world_id_registry RPC_URL=http://localhost:8545 WS_URL=ws://localhost:8545 DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres TREE_CACHE_FILE=/tmp/tree.mmap cargo run --release -p world-id-indexer -- --http --indexer > logs/world-id-indexer.log 2>&1 &
REGISTRY_ADDRESS=$world_id_registry RPC_URL=http://localhost:8545 DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres TREE_CACHE_FILE=/tmp/tree.mmap cargo run --release -p world-id-indexer -- --http --indexer > logs/world-id-indexer.log 2>&1 &
indexer_pid=$!
echo "started indexer with PID $indexer_pid"
wait_for_health 8080 "world-id-indexer" 300
Expand Down
2 changes: 0 additions & 2 deletions run-indexer-stage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ REGISTRY_ADDRESS="${REGISTRY_ADDRESS:-0x969947cFED008bFb5e3F32a25A1A2CDdf64d46fe
BATCH_SIZE="${BATCH_SIZE:-512}"
START_BLOCK="${START_BLOCK:-22827118}"
RPC_URL="${RPC_URL:-https://worldchain-mainnet.g.alchemy.com/public}"
WS_URL="${WS_URL:-wss://worldchain-mainnet.g.alchemy.com/public}"
DATABASE_URL="${DATABASE_URL:-postgres://postgres:postgres@localhost:5433/indexer_stage}"
TREE_CACHE_FILE="${TREE_CACHE_FILE:-$ROOT_DIR/tree-cache-stage.mmap}"
DB_NAME="${DB_NAME:-indexer_stage}"
Expand Down Expand Up @@ -69,7 +68,6 @@ env \
RUN_MODE="$RUN_MODE" \
DATABASE_URL="$DATABASE_URL" \
RPC_URL="$RPC_URL" \
WS_URL="$WS_URL" \
REGISTRY_ADDRESS="$REGISTRY_ADDRESS" \
START_BLOCK="$START_BLOCK" \
BATCH_SIZE="$BATCH_SIZE" \
Expand Down
5 changes: 4 additions & 1 deletion services/indexer/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres

# Indexer Config
RPC_URL=http://localhost:8545
WS_URL=ws://localhost:8545
REGISTRY_ADDRESS=0x0000000000000000000000000000000000000000
START_BLOCK=0
BATCH_SIZE=64
# Blocks to stay behind the chain head when polling (avoids ingesting reorg-prone unconfirmed blocks)
CONFIRMATIONS=8
# Seconds to wait between RPC poll cycles once caught up
POLL_INTERVAL_SECS=2

# HTTP Config
HTTP_ADDR=0.0.0.0:8080
Expand Down
3 changes: 2 additions & 1 deletion services/indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ publish = false

[dependencies]
world-id-services-common = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "sync"] }
backon = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["json"] }
telemetry-batteries = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions services/indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The indexer supports three run modes, selected via the `RUN_MODE` environment va

### Event Processing

The indexer connects to the chain via HTTP + WebSocket RPC. On startup it backfills from the last indexed block (or `START_BLOCK` if the DB is empty), then transitions to live WebSocket streaming.
The indexer connects to the chain via HTTP RPC and polls for events. On startup it backfills from the last indexed block (or `START_BLOCK` if the DB is empty), then keeps polling for newly confirmed logs. Only logs at or below the confirmed head (`chain_head - CONFIRMATIONS`) are ingested, so short-lived reorgs of unconfirmed blocks are never committed.

Events are processed through `EventsCommitter`, which:

Expand Down Expand Up @@ -65,12 +65,13 @@ This restart-on-reorg pattern — detect, rollback state, exit cleanly, re-initi
|---|---|---|
| `DATABASE_URL` | required | PostgreSQL connection string |
| `RPC_URL` | required | HTTP RPC endpoint |
| `WS_URL` | required | WebSocket RPC endpoint |
| `REGISTRY_ADDRESS` | required | `AccountRegistry` contract address |
| `TREE_CACHE_FILE` | required | Path to mmap-backed tree cache file |
| `RUN_MODE` | `both` | `both`, `indexer`, or `http` |
| `START_BLOCK` | `0` | Block to start indexing from if DB is empty |
| `BATCH_SIZE` | `64` | Blocks per RPC batch during backfill |
| `CONFIRMATIONS` | `8` | Blocks to stay behind the chain head when polling |
| `POLL_INTERVAL_SECS` | `2` | Seconds between RPC poll cycles once caught up |
| `TREE_DEPTH` | `30` | Merkle tree depth |
| `TREE_MAX_BLOCK_AGE` | `1000` | Blocks of per-leaf history kept for rollback |
| `HTTP_ADDR` | `0.0.0.0:8080` | Address for the HTTP server |
Expand Down
Loading
Loading