Skip to content

Event indexing: on-chain topics, new indexer service, optimized storage, filtering API, archiving, and query performance monitoring#138

Merged
LaGodxy merged 3 commits intoMettaChain:mainfrom
Abidoyesimze:feature/event-indexing-and-indexer
Mar 30, 2026
Merged

Event indexing: on-chain topics, new indexer service, optimized storage, filtering API, archiving, and query performance monitoring#138
LaGodxy merged 3 commits intoMettaChain:mainfrom
Abidoyesimze:feature/event-indexing-and-indexer

Conversation

@Abidoyesimze
Copy link
Copy Markdown
Contributor

closes #88

Summary

Implements efficient, queryable event indexing end-to-end.
Adds missing #[ink(topic)] where helpful, introduces a Rust indexer service with Postgres storage and composite indexes, filtering REST API, Prometheus metrics, and an archiving script.
Updates docker-compose to run the full stack locally (node, Postgres, indexer).

Scope of Changes

On-chain events
contracts/staking/src/lib.rs: StakingConfigUpdated fields min_stake and reward_rate_bps are now #[ink(topic)] for off-chain filtering.
Off-chain indexer

New crate indexer/ (added to workspace):

indexer/src/ingest.rs: Subscribes to finalized blocks; records Contracts::ContractEmitted; enriches topics with emitting contract address.
indexer/src/db.rs: Postgres schema + efficient indexes; insert and filtered query functions.
indexer/src/api.rs: GET /events with filters and pagination; GET /contracts; GET /health; GET /metrics.
indexer/src/main.rs: Axum 0.7 server; Prometheus metrics; feature-gated ingestor (builds without subxt unless --features ingest).
indexer/README.md: Setup, API, metrics, archiving guidance.
Dockerfile.indexer: Multi-stage build; ingestor enabled in container via --features ingest.

Storage & archiving

Table contract_events with narrow, append-only rows and composite indexes:
Columns: block_number, block_hash, block_timestamp, contract, payload_hex, optional event_type, topics[].
Indexes: by block desc, time desc, (contract, time), (event_type, time), GIN on topics.
scripts/archive-events.sh: Moves events older than N days to events_archive.
Ops
docker-compose.yml: Adds indexer service connected to substrate-node and postgres.
Workspace updated to include indexer crate.

Acceptance Criteria Mapping

Implement event indexing for efficient querying: Done (indexer+DB+indexes).
Add event filtering capabilities: Done (/events supports contract, event_type, topic, from_ts, to_ts, from_block, to_block, limit, offset).
Optimize event storage layout: Done (narrow schema, composite/GIN indexes).
Create event archiving strategy: Done (archive-events.sh; README guidance for partitioning/Parquet).
Add event query performance monitoring: Done (/metrics via Prometheus).

…e with Postgres-backed storage, filtering API, metrics, and archiving; wire docker-compose; fix CI clippy issues across workspace
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 28, 2026

@Abidoyesimze Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@LaGodxy
Copy link
Copy Markdown
Contributor

LaGodxy commented Mar 30, 2026

@Abidoyesimze resolve conflicts and fix the CI.

@LaGodxy LaGodxy merged commit a8185ed into MettaChain:main Mar 30, 2026
15 of 16 checks passed
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.

Inefficient Event Storage

2 participants