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 Mar 30, 2026
Conversation
…e with Postgres-backed storage, filtering API, metrics, and archiving; wire docker-compose; fix CI clippy issues across workspace
|
@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! 🚀 |
… cfg; minor clippy/test adjustments
Contributor
|
@Abidoyesimze resolve conflicts and fix the CI. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).