Fast Avalanche P-Chain & L1 Subnet Indexer
Install ClickHouse natively or with Docker. ClickHouse Cloud is untested and might work, but not recommended.
Installation guide: https://clickhouse.com/docs/install
ClickHouse must be configured to use UTC timezone.
For Docker installations:
- Modify
/etc/clickhouse-server/config.xmlinside the container and add:<timezone>UTC</timezone>
- Or set environment variable when running container:
docker run -e TZ=UTC clickhouse/clickhouse-server
For native installations:
- Edit
/etc/clickhouse-server/config.xmland add<timezone>UTC</timezone>under the<clickhouse>section
For local development, running ClickHouse without a password is recommended.
If you need password authentication (for user default and database default):
export CLICKHOUSE_PASSWORD=your_passwordThe application will pick up this environment variable automatically.
Quick connection test:
clickhouse-client "select 1"This should execute without any additional arguments or password prompts.
Edit config.json to configure your blockchain ingestion:
[
{
"chainID": 43114,
"rpcURL": "http://localhost:9650/ext/bc/C/rpc",
"startBlock": 69600000,
"fetchBatchSize": 400,
"maxConcurrency": 100
}
]chainID(required): Chain identifier (e.g., 43114 for Avalanche C-Chain)rpcURL(required): Replace this with your actual RPC endpoint URLstartBlock(optional): Block number to start ingestion from on first run. If omitted, starts from block 1. On subsequent runs, always resumes from the last synced block (watermark)fetchBatchSize(optional): Number of blocks to fetch in each batch. Default: 400maxConcurrency(optional): Maximum concurrent RPC requests. Default: 100
You can configure multiple chains by adding more objects to the array.
This is the primary command you'll use. It starts the continuous ingestion process that syncs blockchain data into ClickHouse:
go run . ingestThe ingester will:
- Create all necessary tables automatically
- Resume from the last synced block
- Continuously fetch and process new blocks
- Calculate metrics on schedule when enough data is ingested
Display ClickHouse table sizes and disk usage statistics:
go run . sizeThis shows:
- All tables with row counts and sizes in MB
- RPC cache directory sizes
Drop calculated/derived tables (keeps raw data and watermark):
go run . wipeTo drop ALL tables including raw data:
go run . wipe --allQuery your ingested data directly from the command line:
# Query hourly ICM sent messages
clickhouse-client "SELECT period, value FROM icm_sent_hour LIMIT 10"
# Query raw blocks
clickhouse-client "SELECT block_number, block_time, hex(hash) as hash, hex(parent_hash) as parent_hash, gas_used, gas_limit FROM raw_blocks ORDER BY block_number DESC LIMIT 5"
# Query raw transactions
clickhouse-client "SELECT block_number, transaction_index, hex(hash) as hash, hex(\`from\`) as from, hex(to) as to, value, gas_used FROM raw_txs LIMIT 10"
# Count total transactions
clickhouse-client "SELECT count() FROM raw_txs"
# Check sync status
clickhouse-client "SELECT * FROM sync_watermark"For a GUI interface, connect to ClickHouse using DBeaver:
- Install DBeaver and add a ClickHouse connection
- Connection settings:
- Protocol: HTTP
- Host:
localhost - Port:
8123(default HTTP port) - Database:
default - User:
default - Password: (leave empty if no password set)
DBeaver provides a rich interface for exploring tables, writing queries, and visualizing results.
The system supports three types of indexers:
- Granular Metrics (time-based) -
sql/metrics/- Hour/day/week/month aggregations - Batched Incremental (block-based) -
sql/incremental/batched/- Runs max once per 5 minutes - Immediate Incremental (block-based) -
sql/incremental/immediate/- Runs every batch with 0.9s spacing
For detailed information about granular metrics, see: sql/metrics/README.md
- Raw Tables: Store blockchain data as-is (
raw_blocks,raw_txs,raw_traces,raw_logs) - Indexer Runner: One per chain, processes three types of indexers:
- Granular Metrics: Time-based aggregations (hour/day/week/month)
- Batched Incremental: Block-based indexers, throttled to 5min intervals
- Immediate Incremental: Block-based indexers, run every batch (0.9s spacing)
- Watermarks: Track progress per indexer in
indexer_watermarkstable - RPC Cache: Local disk cache to speed up resync (will be removed in production)
Connection issues:
- Verify ClickHouse is running and available without password:
clickhouse-client "SELECT 1" - Check timezone configuration with:
clickhouse-client "SELECT timezone()"(has to be UTC) - Ensure port 9000 (native) or 8123 (HTTP) is accessible
RPC Performance:
- Adjust
maxConcurrencyif your RPC endpoint has rate limits - Reduce
fetchBatchSizeif you see no visual progress
Data issues:
- Use
wipeto reset calculated tables while keeping raw data - Check
sync_watermarktable to see ingestion progress - Review logs for any RPC errors or connection issues
~ # clickhouse-client "show tables"
# Raw data tables
raw_blocks
raw_logs
raw_traces
raw_txs
# Watermark tables
indexer_watermarks
sync_watermark
# Incremental indexers
address_on_chain
# Granular metrics (hour/day/week/month)
active_addresses_{granularity}
active_senders_{granularity}
avg_gas_price_{granularity}
avg_gps_{granularity}
avg_tps_{granularity}
contracts_{granularity}
cumulative_addresses_{granularity}
cumulative_contracts_{granularity}
cumulative_deployers_{granularity}
cumulative_tx_count_{granularity}
deployers_{granularity}
fees_paid_{granularity}
gas_used_{granularity}
icm_received_{granularity}
icm_sent_{granularity}
icm_total_{granularity}
max_gas_price_{granularity}
max_gps_{granularity}
max_tps_{granularity}
tx_count_{granularity}Note: Each {granularity} metric creates 4 tables (one per granularity: hour, day, week, month)