Skip to content
Closed
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
46 changes: 6 additions & 40 deletions codegenerator/cli/npm/envio/src/Batch.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type chainAfterBatch = {
progressBlockNumber: int,
totalEventsProcessed: int,
fetchState: FetchState.t,
dcsToStore: option<array<FetchState.indexingContract>>,
isProgressAtHeadWhenBatchCreated: bool,
}

Expand Down Expand Up @@ -99,7 +98,6 @@ let getProgressedChainsById = {
~progressBlockNumberAfterBatch,
~fetchStateAfterBatch,
~batchSize,
~dcsToStore,
) => {
// The check is sufficient, since we guarantee to include a full block in a batch
// Also, this might be true even if batchSize is 0,
Expand All @@ -111,7 +109,6 @@ let getProgressedChainsById = {
batchSize,
progressBlockNumber: progressBlockNumberAfterBatch,
totalEventsProcessed: chainBeforeBatch.totalEventsProcessed + batchSize,
dcsToStore,
fetchState: fetchStateAfterBatch,
isProgressAtHeadWhenBatchCreated: progressBlockNumberAfterBatch >=
chainBeforeBatch.sourceBlockNumber,
Expand Down Expand Up @@ -151,48 +148,17 @@ let getProgressedChainsById = {
) {
| Some(batchSize) =>
let leftItems = fetchState.buffer->Js.Array2.sliceFrom(batchSize)
switch fetchState.dcsToStore {
| [] =>
getChainAfterBatchIfProgressed(
~chainBeforeBatch,
~batchSize,
~dcsToStore=None,
~fetchStateAfterBatch=fetchState->FetchState.updateInternal(~mutItems=leftItems),
~progressBlockNumberAfterBatch,
)

| dcs => {
let leftDcsToStore = []
let batchDcs = []
let fetchStateAfterBatch =
fetchState->FetchState.updateInternal(~mutItems=leftItems, ~dcsToStore=leftDcsToStore)

dcs->Array.forEach(dc => {
// Important: This should be a registering block number.
// This works for now since dc.startBlock is a registering block number.
if dc.startBlock <= progressBlockNumberAfterBatch {
batchDcs->Array.push(dc)
} else {
// Mutate the array we passed to the updateInternal beforehand
leftDcsToStore->Array.push(dc)
}
})

getChainAfterBatchIfProgressed(
~chainBeforeBatch,
~batchSize,
~dcsToStore=Some(batchDcs),
~fetchStateAfterBatch,
~progressBlockNumberAfterBatch,
)
}
}
getChainAfterBatchIfProgressed(
~chainBeforeBatch,
~batchSize,
~fetchStateAfterBatch=fetchState->FetchState.updateInternal(~mutItems=leftItems),
~progressBlockNumberAfterBatch,
)
// Skip not affected chains
| None =>
getChainAfterBatchIfProgressed(
~chainBeforeBatch,
~batchSize=0,
~dcsToStore=None,
~fetchStateAfterBatch=chainBeforeBatch.fetchState,
~progressBlockNumberAfterBatch,
)
Expand Down
12 changes: 9 additions & 3 deletions codegenerator/cli/npm/envio/src/EventRegister.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
type registrations = {onBlockByChainId: dict<array<Internal.onBlockConfig>>}
type registrations = {
onBlockByChainId: dict<array<Internal.onBlockConfig>>,
mutable hasEvents: bool,
}

type activeRegistration = {
ecosystem: InternalConfig.ecosystem,
Expand Down Expand Up @@ -40,6 +43,7 @@ let startRegistration = (~ecosystem, ~multichain, ~preloadHandlers) => {
preloadHandlers,
registrations: {
onBlockByChainId: Js.Dict.empty(),
hasEvents: false,
},
finished: false,
}
Expand Down Expand Up @@ -205,7 +209,8 @@ let setEventOptions = (t: t, ~eventOptions, ~logger=Logging.getLogger()) => {
}

let setHandler = (t: t, handler, ~eventOptions, ~logger=Logging.getLogger()) => {
withRegistration(_ => {
withRegistration(registration => {
registration.registrations.hasEvents = true
switch t.handler {
| None =>
t.handler =
Expand All @@ -225,7 +230,8 @@ let setHandler = (t: t, handler, ~eventOptions, ~logger=Logging.getLogger()) =>
}

let setContractRegister = (t: t, contractRegister, ~eventOptions, ~logger=Logging.getLogger()) => {
withRegistration(_ => {
withRegistration(registration => {
registration.registrations.hasEvents = true
switch t.contractRegister {
| None =>
t.contractRegister = Some(
Expand Down
5 changes: 4 additions & 1 deletion codegenerator/cli/npm/envio/src/EventRegister.resi
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
type registrations = {onBlockByChainId: dict<array<Internal.onBlockConfig>>}
type registrations = {
onBlockByChainId: dict<array<Internal.onBlockConfig>>,
mutable hasEvents: bool,
}

let startRegistration: (
~ecosystem: InternalConfig.ecosystem,
Expand Down
Loading
Loading