From 1b22c883dc26fba418cbb6661e942ee4805fb9b7 Mon Sep 17 00:00:00 2001 From: Jono Prest Date: Fri, 25 Oct 2024 14:40:08 +0200 Subject: [PATCH] Fix double handling of start after pre-registration Revert fixed change --- .../codegen/src/globalState/GlobalState.res | 87 ++++++++++--------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/codegenerator/cli/templates/static/codegen/src/globalState/GlobalState.res b/codegenerator/cli/templates/static/codegen/src/globalState/GlobalState.res index add259251..0700ef8d7 100644 --- a/codegenerator/cli/templates/static/codegen/src/globalState/GlobalState.res +++ b/codegenerator/cli/templates/static/codegen/src/globalState/GlobalState.res @@ -652,50 +652,57 @@ let actionReducer = (state: t, action: action) => { ], ) | StartIndexingAfterPreRegister => - Logging.info("Starting indexing after pre-registration") let {config, chainManager, loadLayer} = state - let chainFetchers = chainManager.chainFetchers->ChainMap.map(cf => { - let { - chainConfig, - logger, - fetchState: {startBlock, endBlock, maxAddrInPartition}, - dynamicContractPreRegistration, - } = cf - - ChainFetcher.make( - ~dynamicContractRegistrations=dynamicContractPreRegistration->Option.mapWithDefault( - [], - Js.Dict.values, - ), - ~chainConfig, - ~lastBlockScannedHashes=ReorgDetection.LastBlockScannedHashes.empty( - ~confirmedBlockThreshold=chainConfig.confirmedBlockThreshold, - ), - ~staticContracts=chainConfig->ChainFetcher.getStaticContracts, - ~startBlock, - ~endBlock, - ~dbFirstEventBlockNumber=None, - ~latestProcessedBlock=None, - ~logger, - ~timestampCaughtUpToHeadOrEndblock=None, - ~numEventsProcessed=0, - ~numBatchesFetched=0, - ~processingFilters=None, - ~maxAddrInPartition, - ~dynamicContractPreRegistration=None, - ) - }) - let chainManager: ChainManager.t = { - chainFetchers, - arbitraryEventQueue: [], - isInReorgThreshold: false, - isUnorderedMultichainMode: chainManager.isUnorderedMultichainMode, - } + //Protect against handling this action twice. It should only be handled once + //when the pre registration is done + if ChainManager.isPreRegisteringDynamicContracts(chainManager) { + Logging.info("Starting indexing after pre-registration") + let chainFetchers = chainManager.chainFetchers->ChainMap.map(cf => { + let { + chainConfig, + logger, + fetchState: {startBlock, endBlock, maxAddrInPartition}, + dynamicContractPreRegistration, + } = cf + + ChainFetcher.make( + ~dynamicContractRegistrations=dynamicContractPreRegistration->Option.mapWithDefault( + [], + Js.Dict.values, + ), + ~chainConfig, + ~lastBlockScannedHashes=ReorgDetection.LastBlockScannedHashes.empty( + ~confirmedBlockThreshold=chainConfig.confirmedBlockThreshold, + ), + ~staticContracts=chainConfig->ChainFetcher.getStaticContracts, + ~startBlock, + ~endBlock, + ~dbFirstEventBlockNumber=None, + ~latestProcessedBlock=None, + ~logger, + ~timestampCaughtUpToHeadOrEndblock=None, + ~numEventsProcessed=0, + ~numBatchesFetched=0, + ~processingFilters=None, + ~maxAddrInPartition, + ~dynamicContractPreRegistration=None, + ) + }) + + let chainManager: ChainManager.t = { + chainFetchers, + arbitraryEventQueue: [], + isInReorgThreshold: false, + isUnorderedMultichainMode: chainManager.isUnorderedMultichainMode, + } - let freshState = make(~config, ~chainManager, ~loadLayer) + let freshState = make(~config, ~chainManager, ~loadLayer) - (freshState, [NextQuery(CheckAllChains)]) + (freshState, [NextQuery(CheckAllChains)]) + } else { + (state, []) + } | SuccessExit => { Logging.info("exiting with success") NodeJsLocal.process->NodeJsLocal.exitWithCode(Success)