Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PostIndex Handler Support and Enhance CosmosEvent with Event Source Context #304

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jorgecuesta
Copy link

Description

This PR introduces two main updates:

  1. PostIndex Handler Support:

    • Added support for processing PostIndex handlers, enabling post-processing after the indexing of block, transaction, and other related data.
    • A new CosmosHandlerKind.PostIndex handler was introduced alongside its respective validations and runtime handling in both @subql/types-cosmos and relevant runtime logic.
    • Filter conditions, validation classes (like PostIndexHandler), and utility functions (e.g., isPostIndexHandlerProcessor) have been added to properly process PostIndex logic.
  2. Enhanced CosmosEvent with Event Sources:

    • Extended the CosmosEvent interface by introducing an additional kind property to explicitly define the source of each event, such as BeginBlock, EndBlock, FinalizeBlock, Transaction, or Message.
    • Updated event generation logic to include kind during the wrapping of events. This provides better contextualization of events tied to specific parts of the block lifecycle or transaction processing.

Key Changes:

  • @subql/types-cosmos:

    • Added a new CosmosHandlerKind.PostIndex type to define PostIndex handlers.
    • Extended CosmosEvent to include the CosmosEventKind enum and kind property for distinguishing event sources.
    • PostIndex handlers were added to the type structures where applicable.
  • Common Cosmos Module:

    • Added PostIndexHandler class within models.ts to validate and map PostIndex handlers from the configuration.
    • Introduced the filter handling logic for PostIndex in utils.ts.
  • Indexer Logic in Node:

    • Enhanced performance for message and event indexing by building maps (msgsTxMap, evntsTxMap) to efficiently group and access events or messages without redundant filtering.
    • Implemented the postIndexHook method inside the IndexerManager, triggering "PostIndex" handlers on the consolidated block.
  • Event Wrapping & Context Handling:

    • Updated the wrapBlockEvents, wrapTxEvents, and others to assign the corresponding CosmosEventKind to each event properly.

This change also addresses inefficiencies in filtering messages and events for each transaction by introducing maps to avoid redundant iterations over already-processed objects.

Fix Details:

This PR indirectly resolves issues related to filtering non-msg-index attributes, particularly events triggered outside of regular messages or transactions (e.g., BeginBlock, EndBlock, FinalizeBlock, and Transaction-only events). For example:

  • Events without msg_index (such as fee, tips, or other external events) are now properly processed due to the inclusion of evntsTxMap.nonMsg.

Fixes # (specific issue reference, if applicable).


Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update.

Checklist

  • I have tested locally.
  • I have performed a self-review of my changes.
  • Updated any relevant documentation.
  • Linked to any relevant issues.
  • I have added tests relevant to my changes.
  • Any dependent changes have been merged and published in downstream modules.
  • My code is up to date with the base branch.
  • I have updated relevant changelogs. We suggest using chan.

@yoozo yoozo requested a review from stwiname January 16, 2025 03:25
…d events

Introduces new handlers and utilities for batch processing, enhancing efficiency when handling multiple Cosmos entities at once. Updated relevant models, filters, and indexer logic to accommodate these batch handlers. This improves the flexibility and performance of Cosmos data processing.
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.

1 participant