Skip to content

Update sync state and raw events regardless of handler registration - #321

Merged
JonoPrest merged 1 commit into
mainfrom
jp/save-events-with-no-handler
Nov 6, 2024
Merged

Update sync state and raw events regardless of handler registration#321
JonoPrest merged 1 commit into
mainfrom
jp/save-events-with-no-handler

Conversation

@JonoPrest

Copy link
Copy Markdown
Collaborator

A quick one to close #282

This actually is a small bug for restarts in an edgecase described below, also I think it's an improvement.

Before this change, an event that doesn't have a handler registered (even if it has a contractRegister instead)

  1. does not count towards number of events processed on UI
  2. does not increment event sync state table (this should be atomic and it's what gets read on restarts)
  3. does not add the event to raw_events table (when it's configured to)

The edgecase bug this can cause is if the last event processed had only a contractRegister function. The event sync state will not increase and on a restart it would then include the event that had already been processed. There should be no crash or double processing though since it would only have a contractRegister function and this is already protected against double registrations.

@JonoPrest
JonoPrest requested a review from DZakh November 5, 2024 11:13
Comment on lines -301 to -313
eventBatchQueueItem->updateEventSyncState(
~inMemoryStore,
~isPreRegisteringDynamicContracts=false,
)
if config.enableRawEvents {
eventBatchQueueItem->addEventToRawEvents(~inMemoryStore)
}
latestProcessedBlocks
->EventsProcessed.updateEventsProcessed(
~chain=eventBatchQueueItem.chain,
~blockNumber=eventBatchQueueItem.blockNumber,
)
->Ok

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This get's moved lower down the call stack so that it's run whether or not a handler is registered

@DZakh DZakh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. It even makes the code cleaner 👍

| None => Ok()
}

result->Result.map(() => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably use if result->Result.isOk instead of Result.map. But this is really a preference which doesn't bring much benefits

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to return a mapped Ok value with the same Error if there is one.

@JonoPrest
JonoPrest force-pushed the jp/save-events-with-no-handler branch from 7320186 to 8f9f489 Compare November 6, 2024 08:05
@JonoPrest
JonoPrest merged commit 01d6240 into main Nov 6, 2024
@JonoPrest
JonoPrest deleted the jp/save-events-with-no-handler branch November 6, 2024 08:41
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.

Check if all the events from config.yaml are handled

2 participants