Add PostIndex Handler Support and Enhance CosmosEvent with Event Source Context #304
+406
−49
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.
Description
This PR introduces two main updates:
PostIndex Handler Support:
CosmosHandlerKind.PostIndex
handler was introduced alongside its respective validations and runtime handling in both@subql/types-cosmos
and relevant runtime logic.PostIndexHandler
), and utility functions (e.g.,isPostIndexHandlerProcessor
) have been added to properly processPostIndex
logic.Enhanced
CosmosEvent
with Event Sources:CosmosEvent
interface by introducing an additionalkind
property to explicitly define the source of each event, such asBeginBlock
,EndBlock
,FinalizeBlock
,Transaction
, orMessage
.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
:CosmosHandlerKind.PostIndex
type to define PostIndex handlers.CosmosEvent
to include theCosmosEventKind
enum andkind
property for distinguishing event sources.Common Cosmos Module:
PostIndexHandler
class withinmodels.ts
to validate and map PostIndex handlers from the configuration.utils.ts
.Indexer Logic in Node:
msgsTxMap
,evntsTxMap
) to efficiently group and access events or messages without redundant filtering.postIndexHook
method inside theIndexerManager
, triggering "PostIndex" handlers on the consolidated block.Event Wrapping & Context Handling:
wrapBlockEvents
,wrapTxEvents
, and others to assign the correspondingCosmosEventKind
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
, andTransaction
-only events). For example:msg_index
(such asfee
,tips
, or other external events) are now properly processed due to the inclusion ofevntsTxMap.nonMsg
.Fixes # (specific issue reference, if applicable).
Type of change
Checklist