Skip to content

Commit

Permalink
Update sync state and raw events regardless of handler registration
Browse files Browse the repository at this point in the history
  • Loading branch information
JonoPrest committed Nov 6, 2024
1 parent b4b2894 commit 01d6240
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,13 @@ module EventFunctions = {
| None => () //No need to run contract registration
}

let latestProcessedBlocks = EventProcessing.EventsProcessed.makeEmpty(~config)

switch handlerRegister->Types.HandlerTypes.Register.getLoaderHandler {
| Some(loaderHandler) =>
switch await eventBatchQueueItem->EventProcessing.runEventHandler(
~inMemoryStore,
~loadLayer,
~loaderHandler,
~logger,
~latestProcessedBlocks,
~config,
~isInReorgThreshold=false,
) {
| Ok(_) => ()
Expand Down
46 changes: 23 additions & 23 deletions codegenerator/cli/templates/static/codegen/src/EventProcessing.res
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,15 @@ let runEventHandler = (
~loaderHandler: Types.HandlerTypes.loaderHandler<_>,
~inMemoryStore,
~logger,
~latestProcessedBlocks,
~loadLayer,
~config: Config.t,
~isInReorgThreshold,
) => {
open ErrorHandling.ResultPropogateEnv
runAsyncEnv(async () => {
let contextEnv = ContextEnv.make(~eventBatchQueueItem, ~logger)
let {loader, handler} = loaderHandler

//Include the load just before handler
//Include the load in time before handler
let timeBeforeHandler = Hrtime.makeTimer()

let loaderReturn =
Expand Down Expand Up @@ -298,45 +296,47 @@ let runEventHandler = (
~decimalPlaces=4,
)
}
eventBatchQueueItem->updateEventSyncState(
~inMemoryStore,
~isPreRegisteringDynamicContracts=false,
)
if config.enableRawEvents {
eventBatchQueueItem->addEventToRawEvents(~inMemoryStore)
}
latestProcessedBlocks
->EventsProcessed.updateEventsProcessed(
~chain=eventBatchQueueItem.chain,
~blockNumber=eventBatchQueueItem.blockNumber,
)
->Ok
Ok()
}
})
}

let runHandler = (
let runHandler = async (
eventBatchQueueItem: Types.eventBatchQueueItem,
~latestProcessedBlocks,
~inMemoryStore,
~logger,
~loadLayer,
~config,
~config: Config.t,
~isInReorgThreshold,
) => {
switch eventBatchQueueItem.handlerRegister->Types.HandlerTypes.Register.getLoaderHandler {
let result = switch eventBatchQueueItem.handlerRegister->Types.HandlerTypes.Register.getLoaderHandler {
| Some(loaderHandler) =>
eventBatchQueueItem->runEventHandler(
await eventBatchQueueItem->runEventHandler(
~loaderHandler,
~latestProcessedBlocks,
~inMemoryStore,
~logger,
~loadLayer,
~config,
~isInReorgThreshold,
)
| None => Ok(latestProcessedBlocks)->Promise.resolve
| None => Ok()
}

result->Result.map(() => {
eventBatchQueueItem->updateEventSyncState(
~inMemoryStore,
~isPreRegisteringDynamicContracts=false,
)

if config.enableRawEvents {
eventBatchQueueItem->addEventToRawEvents(~inMemoryStore)
}

latestProcessedBlocks->EventsProcessed.updateEventsProcessed(
~chain=eventBatchQueueItem.chain,
~blockNumber=eventBatchQueueItem.blockNumber,
)
})
}

let addToUnprocessedBatch = (
Expand Down
5 changes: 1 addition & 4 deletions scenarios/test_codegen/test/Mock_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ let inMemoryStore = InMemoryStore.make()

describe("E2E Mock Event Batch", () => {
Async.before(async () => {
let config = RegisterHandlers.registerAllHandlers()
DbStub.setGravatarDb(~gravatar=MockEntities.gravatarEntity1)
DbStub.setGravatarDb(~gravatar=MockEntities.gravatarEntity2)
// EventProcessing.processEventBatch(MockEvents.eventBatch)
Expand All @@ -17,14 +16,12 @@ describe("E2E Mock Event Batch", () => {
| Some(loaderHandler) =>
await eventBatchQueueItem->EventProcessing.runEventHandler(
~loaderHandler,
~latestProcessedBlocks=EventProcessing.EventsProcessed.makeEmpty(~config),
~inMemoryStore,
~logger=Logging.logger,
~loadLayer,
~config,
~isInReorgThreshold=false,
)
| None => Ok(EventProcessing.EventsProcessed.makeEmpty(~config))
| None => Ok()
}
}

Expand Down

0 comments on commit 01d6240

Please sign in to comment.