Fix reorg threshold state with start block - #470
Conversation
| it( | ||
| "Returns false when we just started the indexer and it has currentBlockHeight=0, while start block is more than 0 + reorg threshold", |
There was a problem hiding this comment.
This test was returning true
There was a problem hiding this comment.
Was the first test passing the assertion?
| item.earliestEvent->FetchState.queueItemIsInReorgThreshold( | ||
| ~heighestBlockBelowThreshold=ChainMap.get( | ||
| fetchStatesMap, | ||
| a.chain, |
There was a problem hiding this comment.
a.chain instead of item.chain is another bug I've found
| } else { | ||
| false | ||
| let queueItemIsInReorgThreshold = (queueItem: queueItem, ~currentBlockHeight, ~heighestBlockBelowThreshold) => { | ||
| if currentBlockHeight === 0 { |
There was a problem hiding this comment.
Compared to the first fix I use currentBlockHeight now instead of heighestBlockBelowThreshold. This way chains with height less than reorg threshold will work correctly - relevant for our tests
| dispatchAction(SetIsInReorgThreshold(true)) | ||
| let batch = | ||
| state.chainManager->ChainManager.createBatch( | ||
| ~maxBatchSize=state.maxBatchSize, | ||
| ~onlyBelowReorgThreshold=false, | ||
| ) | ||
| await handleBatch(batch) |
There was a problem hiding this comment.
This is not really needed for the indexer execution, but it makes lifecycle more predictable and fixes Rollback_test.res. Without the change rollback in the test happens before we processed events in the reorg threshold.
| GlobalState.NextQuery(CheckAllChains), | ||
| ProcessEventBatch, |
There was a problem hiding this comment.
This is a change caused by handleBatch, since we now handle reaching the reorg threshold inside of ProcessEventBatch itself without redispatching it in the case when there are no items to process before threshold.
| // Keep only the first chain | ||
| let config = Config.make( | ||
| ~shouldRollbackOnReorg=false, | ||
| ~shouldSaveFullHistory=false, | ||
| ~isUnorderedMultichainMode=false, | ||
| ~chains=config.chainMap | ||
| ->ChainMap.entries | ||
| ->Array.keepMap(((chain, config)) => | ||
| chain == RollbackMultichain_test.Mock.Chain1.chain ? Some(config) : None | ||
| ), | ||
| ~enableRawEvents=false, | ||
| ~entities=config.entities->Obj.magic, | ||
| ) |
There was a problem hiding this comment.
This one and a few other tests randomly broke after the fix. It is caused by them having shouldRollbackOnReorg enabled. The chain we are testing gets some height and considered to be in the reorg threshold, while other chains stay at block 0 and have in reorg threshold as false. To fix this I remove other chains from the tests which we don't use.
| if isInReorgThreshold { | ||
| Logging.info("Reorg threshold reached") | ||
| } | ||
| ({...state, chainManager: {...state.chainManager, isInReorgThreshold}}, [ProcessEventBatch]) |
There was a problem hiding this comment.
Is it sure that we never get into a deadlock where ProcessEventBatch doesn't get dispatched again?
It caused
Reorg threshold reachedhappening earlier than it should have been.