Skip to content

Commit

Permalink
Fix double handling of start after pre-registration
Browse files Browse the repository at this point in the history
  • Loading branch information
JonoPrest committed Oct 25, 2024
1 parent 4932a66 commit 2b58601
Showing 1 changed file with 50 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 freshState = make(~config, ~chainManager, ~loadLayer)
let chainManager: ChainManager.t = {
chainFetchers,
arbitraryEventQueue: [],
isInReorgThreshold: false,
isUnorderedMultichainMode: chainManager.isUnorderedMultichainMode,
}

(freshState, [NextQuery(CheckAllChains)])
let freshState = make(~config, ~chainManager, ~loadLayer)

(freshState, [NextQuery(CheckAllChains)])
} else {
(state, [])
}
| SuccessExit => {
Logging.info("exiting with success")
NodeJsLocal.process->NodeJsLocal.exitWithCode(Success)
Expand Down Expand Up @@ -958,16 +965,11 @@ let injectedTaskReducer = (
}
| ProcessEventBatch =>
if !state.currentlyProcessingBatch && !isRollingBack(state) {
//Allows us to process events all the way up until we hit the reorg threshold
//across all chains before starting to capture entity history
let onlyBelowReorgThreshold = if state.config->Config.shouldRollbackOnReorg {
state.chainManager.isInReorgThreshold ? false : true
} else {
false
}
switch state.chainManager->ChainManager.createBatch(
~maxBatchSize=state.maxBatchSize,
~onlyBelowReorgThreshold,
//Allows us to process events all the way up until we hit the reorg threshold
//across all chains before starting to capture entity history
~onlyBelowReorgThreshold=state.chainManager.isInReorgThreshold ? false : true,
) {
| {isInReorgThreshold, val: Some({batch, fetchStatesMap, arbitraryEventQueue})} =>
dispatchAction(SetCurrentlyProcessing(true))
Expand Down

0 comments on commit 2b58601

Please sign in to comment.