Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wildcard partition #392

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions codegenerator/cli/templates/static/codegen/src/Config.res
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ let shouldPreRegisterDynamicContracts = (chainConfig: chainConfig) => {
})
}

let hasWildcard = (chainConfig: chainConfig) => {
chainConfig.contracts->Array.some(contract => {
contract.events->Array.some(event => {
let module(Event) = event

let {isWildcard} =
Event.handlerRegister->Types.HandlerTypes.Register.getEventOptions

isWildcard
})
})
}

type historyFlag = FullHistory | MinHistory
type rollbackFlag = RollbackOnReorg | NoRollback
type historyConfig = {rollbackFlag: rollbackFlag, historyFlag: historyFlag}
Expand Down
4 changes: 2 additions & 2 deletions codegenerator/cli/templates/static/codegen/src/Index.res
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ let makeAppState = (globalState: GlobalState.t): EnvioInkApp.appState => {
globalState.chainManager.chainFetchers
->ChainMap.values
->Array.map(cf => {
let {numEventsProcessed, fetchState, numBatchesFetched} = cf
let {numEventsProcessed, partitionedFetchState, numBatchesFetched} = cf
let latestFetchedBlockNumber = PartitionedFetchState.getLatestFullyFetchedBlock(
fetchState,
partitionedFetchState,
).blockNumber
let hasProcessedToEndblock = cf->ChainFetcher.hasProcessedToEndblock
let currentBlockHeight =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type processingFilter = {
type addressToDynContractLookup = dict<TablesStatic.DynamicContractRegistry.t>
type t = {
logger: Pino.t,
fetchState: PartitionedFetchState.t,
partitionedFetchState: PartitionedFetchState.t,
sourceManager: SourceManager.t,
chainConfig: Config.chainConfig,
//The latest known block of the chain
Expand Down Expand Up @@ -51,22 +51,25 @@ let make = (
let module(ChainWorker) = chainConfig.chainWorker
logger->Logging.childInfo("Initializing ChainFetcher with " ++ ChainWorker.name ++ " worker")

let fetchState = PartitionedFetchState.make(
let isPreRegisteringDynamicContracts = dynamicContractPreRegistration->Option.isSome
let partitionedFetchState = PartitionedFetchState.make(
~maxAddrInPartition,
~staticContracts,
~dynamicContractRegistrations,
~startBlock,
~endBlock,
~isPreRegisteringDynamicContracts,
~hasWildcard=Config.hasWildcard(chainConfig),
~logger,
)

{
logger,
chainConfig,
sourceManager: SourceManager.make(~maxPartitionConcurrency=Env.maxPartitionConcurrency, ~logger),
sourceManager: SourceManager.make(~maxPartitionConcurrency=Env.maxPartitionConcurrency, ~endBlock, ~logger),
lastBlockScannedHashes,
currentBlockHeight: 0,
fetchState,
partitionedFetchState,
dbFirstEventBlockNumber,
latestProcessedBlock,
timestampCaughtUpToHeadOrEndblock,
Expand Down Expand Up @@ -303,7 +306,7 @@ let applyProcessingFilters = (
//any that meet the cleanup condition
let cleanUpProcessingFilters = (
processingFilters: array<processingFilter>,
~fetchState as {partitions}: PartitionedFetchState.t,
~partitionedFetchState as {partitions}: PartitionedFetchState.t,
) => {
switch processingFilters->Array.keep(processingFilter =>
partitions->Array.reduce(false, (accum, partition) => {
Expand Down Expand Up @@ -333,7 +336,7 @@ let updateFetchState = (
| Some(processingFilters) => fetchedEvents->applyProcessingFilters(~processingFilters)
}

self.fetchState
self.partitionedFetchState
->PartitionedFetchState.update(
~id,
~latestFetchedBlock={
Expand All @@ -344,12 +347,12 @@ let updateFetchState = (
~currentBlockHeight,
~chain=self.chainConfig.chain,
)
->Result.map(fetchState => {
->Result.map(partitionedFetchState => {
{
...self,
fetchState,
partitionedFetchState,
processingFilters: switch self.processingFilters {
| Some(processingFilters) => processingFilters->cleanUpProcessingFilters(~fetchState)
| Some(processingFilters) => processingFilters->cleanUpProcessingFilters(~partitionedFetchState)
| None => None
},
}
Expand All @@ -368,7 +371,7 @@ let hasProcessedToEndblock = (self: t) => {
}

let hasNoMoreEventsToProcess = (self: t, ~hasArbQueueEvents) => {
!hasArbQueueEvents && self.fetchState->PartitionedFetchState.queueSize === 0
!hasArbQueueEvents && self.partitionedFetchState->PartitionedFetchState.queueSize === 0
}

/**
Expand Down Expand Up @@ -424,12 +427,12 @@ let getLastScannedBlockData = lastBlockData => {
}

let isFetchingAtHead = (chainFetcher: t) =>
chainFetcher.fetchState->PartitionedFetchState.isFetchingAtHead
chainFetcher.partitionedFetchState->PartitionedFetchState.isFetchingAtHead

let getFirstEventBlockNumber = (chainFetcher: t) =>
Utils.Math.minOptInt(
chainFetcher.dbFirstEventBlockNumber,
chainFetcher.fetchState->PartitionedFetchState.getFirstEventBlockNumber,
chainFetcher.partitionedFetchState->PartitionedFetchState.getFirstEventBlockNumber,
)

let isPreRegisteringDynamicContracts = (chainFetcher: t) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ let getFetchStateWithData = (self: t, ~shouldDeepCopy=false): ChainMap.t<fetchSt
self.chainFetchers->ChainMap.map(cf => {
{
partitionedFetchState: shouldDeepCopy
? cf.fetchState->PartitionedFetchState.copy
: cf.fetchState,
? cf.partitionedFetchState->PartitionedFetchState.copy
: cf.partitionedFetchState,
heighestBlockBelowThreshold: cf->ChainFetcher.getHeighestBlockBelowThreshold,
}
})
Expand Down Expand Up @@ -417,7 +417,7 @@ let createBatch = (self: t, ~maxBatchSize: int, ~onlyBelowReorgThreshold: bool)
->ChainMap.values
->Array.map(fetcher => (
fetcher.chainConfig.chain->ChainMap.Chain.toString,
fetcher.fetchState->PartitionedFetchState.queueSize,
fetcher.partitionedFetchState->PartitionedFetchState.queueSize,
))
->Array.concat([("arbitrary", self.arbitraryEventQueue->Array.length)])
->Js.Dict.fromArray
Expand Down
Loading
Loading