Skip to content

Set up ETH Tracker ​

Requirements ​

  • A Gnosis node with HTTP JSON-RPC and WebSocket. It must serve eth_getBlockReceipts and full blocks from chain.start_block to the tip. A gnosis-node host serves both on 8545 and 8546.
  • NATS with JetStream.
  • Go 1.26 to build from source, or Docker.

The tracker keeps its state in a BoltDB file at db/tracker_db, relative to the working directory. It needs no database server.

Start NATS ​

For development, run one NATS server with JetStream on port 4222:

sh
git clone https://github.com/cosmo-local-credit/eth-tracker.git
cd eth-tracker/dev
docker compose up -d

For production, deploy/nats/ has a three-node cluster, with one Compose file per host. Create the cluster Docker network on each host, then run docker compose -f deploy/nats/docker-compose-N.yaml up -d on host N. Set jetstream.stream_replicas to 3.

Configure ​

The tracker reads config.toml. Set -config to use another file. Environment variables with the TRACKER_ prefix override file values, with two underscores between section and key: TRACKER_CHAIN__RPC_ENDPOINT sets chain.rpc_endpoint. Separate list items with commas. A list with one item needs a trailing comma, such as nats://nats:4222,.

Chain ​

SettingWhat it controls
chain.rpc_endpointHTTP JSON-RPC URL for blocks, receipts and contract calls.
chain.ws_endpointWebSocket URL for new block heads. Required.
chain.chainid100 for Gnosis. Used to recover transaction senders.
chain.start_blockFirst block on the first run. 0 starts at the current tip. Ignored once db/tracker_db exists.
chain.pool_settlement_blockFirst block where POOL_SWAP is read from SwapSettlement instead of Swap. 0 reads Swap only.

Tracked contracts ​

The tracker only decodes logs from addresses it tracks. On first start it reads each registry in bootstrap.ge_registry. It tracks the registry's account, token and pool indexes, every entry in them, and each pool's quoter, token registry, fee policy and protocol fee controller. Later starts load the saved list and refresh it in the background.

SettingWhat it controls
bootstrap.ge_registryRegistry contracts to read. Required, even with a watchlist.
bootstrap.watchlistIf set, track only these addresses and skip the registries.
bootstrap.blacklistAddresses to stop tracking at startup.
bootstrap.contractsAddresses to always track, such as the ERC1967Factory.
bootstrap.custodial_registration_addressChecksummed address. register(address) calls to it publish CUSTODIAL_REGISTRATION instead of INDEX_ADD.

New vouchers, pools and Safes are tracked as their creation or registration events arrive.

JetStream ​

SettingWhat it controls
jetstream.endpointNATS URLs, as a TOML array. Unset means nats://127.0.0.1:4222.
jetstream.persist_duration_hrsHours the TRACKER stream keeps events.
jetstream.dedup_window_hrsHours JetStream drops duplicate message IDs. Keep it equal to persist_duration_hrs.
jetstream.stream_replicas1, or 3 for the cluster.
publisher.max_retriesPublish attempts per event.
publisher.circuit_breaker_thresholdConsecutive publish failures before publishing pauses.
publisher.circuit_breaker_timeout_sSeconds publishing stays paused.

WARNING

The example config.toml sets jetstream.endpoints. The tracker reads jetstream.endpoint, so rename the key before you point it at another NATS server.

Workers ​

SettingWhat it controls
api.addressListen address for /health, /stats and /metrics.
core.pool_sizeBlock workers. 0 means three per CPU.
core.batch_sizeMissing blocks queued per backfill scan.
core.max_block_retriesAttempts before a block moves to the dead-letter queue. Must be above zero.

Keep core.cache_type = "internal" and core.db_type = "bolt". core.reorg_depth_limit, jetstream.enable and redis.dsn are not read.

Run ​

From source:

sh
make build
./eth-tracker -config config.toml

With Docker, mount the config and a volume for the database:

sh
docker run -d --name eth-tracker \
  -v "$PWD/config.toml:/service/config.toml:ro" \
  -v tracker-db:/service/db \
  -p 5001:5001 \
  ghcr.io/cosmo-local-credit/eth-tracker:<tag>

On startup the tracker reads the registries, then catches up from chain.start_block to the tip. It follows new blocks only after the catch-up finishes. A first start with a cold cache can take several minutes before the first block.

Verify ​

sh
curl -s localhost:5001/health
curl -s localhost:5001/stats
nats stream info TRACKER
nats subscribe 'TRACKER.*'

/health returns {"nats":true,"syncer":true}, or HTTP 503 if either is false. /stats returns the latest block, queue size, active workers and the number of tracked addresses. The log prints block stats every 15 seconds.

Operate ​

  • A restart resumes after the last completed block.
  • A block that fails is retried up to core.max_block_retries times, then moved to the dead-letter queue. The backfill scan, which runs every minute, queues it again.
  • The tracker does not handle chain reorganizations.
  • To start again from another block, stop the tracker, delete db/tracker_db, set chain.start_block, and start it.
  • /metrics serves Go runtime metrics in Prometheus format.