From 01d6240b7d248148492917c7eddde07c4ab623be Mon Sep 17 00:00:00 2001 From: Jono Prest Date: Tue, 5 Nov 2024 12:58:21 +0200 Subject: [PATCH] Update sync state and raw events regardless of handler registration --- .../dynamic/codegen/src/TestHelpers.res.hbs | 4 -- .../static/codegen/src/EventProcessing.res | 46 +++++++++---------- scenarios/test_codegen/test/Mock_test.res | 5 +- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/codegenerator/cli/templates/dynamic/codegen/src/TestHelpers.res.hbs b/codegenerator/cli/templates/dynamic/codegen/src/TestHelpers.res.hbs index b7c4ecb87..3bc55fd17 100644 --- a/codegenerator/cli/templates/dynamic/codegen/src/TestHelpers.res.hbs +++ b/codegenerator/cli/templates/dynamic/codegen/src/TestHelpers.res.hbs @@ -140,8 +140,6 @@ 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( @@ -149,8 +147,6 @@ module EventFunctions = { ~loadLayer, ~loaderHandler, ~logger, - ~latestProcessedBlocks, - ~config, ~isInReorgThreshold=false, ) { | Ok(_) => () diff --git a/codegenerator/cli/templates/static/codegen/src/EventProcessing.res b/codegenerator/cli/templates/static/codegen/src/EventProcessing.res index bc7823818..c8b7574b5 100644 --- a/codegenerator/cli/templates/static/codegen/src/EventProcessing.res +++ b/codegenerator/cli/templates/static/codegen/src/EventProcessing.res @@ -255,9 +255,7 @@ let runEventHandler = ( ~loaderHandler: Types.HandlerTypes.loaderHandler<_>, ~inMemoryStore, ~logger, - ~latestProcessedBlocks, ~loadLayer, - ~config: Config.t, ~isInReorgThreshold, ) => { open ErrorHandling.ResultPropogateEnv @@ -265,7 +263,7 @@ let runEventHandler = ( 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 = @@ -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 = ( diff --git a/scenarios/test_codegen/test/Mock_test.res b/scenarios/test_codegen/test/Mock_test.res index c7c85d5e1..648f1a422 100644 --- a/scenarios/test_codegen/test/Mock_test.res +++ b/scenarios/test_codegen/test/Mock_test.res @@ -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) @@ -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() } }