@@ -29,6 +29,8 @@ the are getting merged until the maxAddrInPartition is reached.
2929*/
3030type partition = {
3131 id : string ,
32+ // The block number of the latest fetched query
33+ // which added all its events to the queue
3234 latestFetchedBlock : blockNumberAndTimestamp ,
3335 selection : selection ,
3436 addressesByContractName : dict <array <Address .t >>,
@@ -414,6 +416,7 @@ module OptimizedPartitions = {
414416 )
415417 }
416418
419+ @inline
417420 let getLatestFullyFetchedBlock = (optimizedPartitions : t ) => {
418421 switch optimizedPartitions .idsInAscOrder -> Array .get (0 ) {
419422 | Some (id ) => Some ((optimizedPartitions .entities -> Js .Dict .unsafeGet (id )).latestFetchedBlock )
@@ -433,9 +436,6 @@ type t = {
433436 contractConfigs : dict <contractConfig >,
434437 // Not used for logic - only metadata
435438 chainId : int ,
436- // The block number of the latest block fetched
437- // which added all its events to the queue
438- latestFullyFetchedBlock : blockNumberAndTimestamp ,
439439 // The block number of the latest block which was added to the queue
440440 // by the onBlock configs
441441 // Need a separate pointer for this
@@ -454,23 +454,34 @@ type t = {
454454}
455455
456456@inline
457- let bufferBlockNumber = ({latestFullyFetchedBlock , latestOnBlockBlockNumber }: t ) => {
458- latestOnBlockBlockNumber < latestFullyFetchedBlock .blockNumber
459- ? latestOnBlockBlockNumber
460- : latestFullyFetchedBlock .blockNumber
457+ let bufferBlockNumber = ({latestOnBlockBlockNumber , optimizedPartitions }: t ) => {
458+ switch optimizedPartitions -> OptimizedPartitions .getLatestFullyFetchedBlock {
459+ | None => latestOnBlockBlockNumber
460+ | Some (latestFullyFetchedBlock ) =>
461+ latestOnBlockBlockNumber < latestFullyFetchedBlock .blockNumber
462+ ? latestOnBlockBlockNumber
463+ : latestFullyFetchedBlock .blockNumber
464+ }
461465}
462466
463467/**
464468* Returns the latest block which is ready to be consumed
465469*/
466470@inline
467- let bufferBlock = ({latestFullyFetchedBlock , latestOnBlockBlockNumber }: t ) => {
468- latestOnBlockBlockNumber < latestFullyFetchedBlock .blockNumber
469- ? {
470- blockNumber : latestOnBlockBlockNumber ,
471- blockTimestamp : 0 ,
472- }
473- : latestFullyFetchedBlock
471+ let bufferBlock = ({optimizedPartitions , latestOnBlockBlockNumber }: t ) => {
472+ switch optimizedPartitions -> OptimizedPartitions .getLatestFullyFetchedBlock {
473+ | None => {
474+ blockNumber : latestOnBlockBlockNumber ,
475+ blockTimestamp : 0 ,
476+ }
477+ | Some (latestFullyFetchedBlock ) =>
478+ latestOnBlockBlockNumber < latestFullyFetchedBlock .blockNumber
479+ ? {
480+ blockNumber : latestOnBlockBlockNumber ,
481+ blockTimestamp : 0 ,
482+ }
483+ : latestFullyFetchedBlock
484+ }
474485}
475486
476487/*
@@ -502,21 +513,10 @@ let updateInternal = (
502513 ~blockLag = fetchState .blockLag ,
503514 ~knownHeight = fetchState .knownHeight ,
504515): t => {
505- let latestFullyFetchedBlock = switch optimizedPartitions -> OptimizedPartitions .getLatestFullyFetchedBlock {
506- | Some (latestFullyFetchedBlock ) => latestFullyFetchedBlock
507- | None => {
508- blockNumber : knownHeight ,
509- // The case is only possible when using only block handlers
510- // so it's fine to have a zero timestamp
511- // since we don't support ordered multichain mode anyways
512- blockTimestamp : 0 ,
513- }
514- }
515-
516516 let mutItemsRef = ref (mutItems )
517517
518518 let latestOnBlockBlockNumber = switch fetchState .onBlockConfigs {
519- | [] => latestFullyFetchedBlock . blockNumber
519+ | [] => knownHeight
520520 | onBlockConfigs => {
521521 // Calculate the max block number we are going to create items for
522522 // Use targetBufferSize to get the last target item in the buffer
@@ -530,7 +530,11 @@ let updateInternal = (
530530 | None => fetchState .buffer
531531 }-> Belt .Array .get (fetchState .targetBufferSize - 1 ) {
532532 | Some (item ) => item -> Internal .getItemBlockNumber
533- | None => latestFullyFetchedBlock .blockNumber
533+ | None =>
534+ switch optimizedPartitions -> OptimizedPartitions .getLatestFullyFetchedBlock {
535+ | None => knownHeight
536+ | Some (latestFullyFetchedBlock ) => latestFullyFetchedBlock .blockNumber
537+ }
534538 }
535539
536540 let mutItems = switch mutItemsRef .contents {
@@ -595,7 +599,6 @@ let updateInternal = (
595599 targetBufferSize : fetchState .targetBufferSize ,
596600 optimizedPartitions ,
597601 latestOnBlockBlockNumber ,
598- latestFullyFetchedBlock ,
599602 indexingContracts ,
600603 blockLag ,
601604 knownHeight ,
@@ -1388,7 +1391,6 @@ let make = (
13881391 chainId ,
13891392 startBlock ,
13901393 endBlock ,
1391- latestFullyFetchedBlock : latestFetchedBlock ,
13921394 latestOnBlockBlockNumber : progressBlockNumber ,
13931395 normalSelection ,
13941396 indexingContracts ,
0 commit comments