diff --git a/codegenerator/cli/npm/envio/src/ReorgDetection.res b/codegenerator/cli/npm/envio/src/ReorgDetection.res index 30a067f08..2a87a58bf 100644 --- a/codegenerator/cli/npm/envio/src/ReorgDetection.res +++ b/codegenerator/cli/npm/envio/src/ReorgDetection.res @@ -11,6 +11,11 @@ type blockData = { blockTimestamp: int, } +type reorgGuard = { + lastBlockScannedData: blockData, + firstBlockParentNumberAndHash: option, +} + module LastBlockScannedHashes: { type t /**Instantiat t with existing data*/ @@ -69,7 +74,7 @@ module LastBlockScannedHashes: { let getAllBlockNumbers: t => Belt.Array.t - let hasReorgOccurred: (t, ~firstBlockParentNumberAndHash: option) => bool + let hasReorgOccurred: (t, ~reorgGuard: reorgGuard) => bool /** Return a BlockNumbersAndHashes.t rolled back to where blockData is less @@ -402,31 +407,34 @@ module LastBlockScannedHashes: { /** Checks whether reorg has occured by comparing the parent hash with the last saved block hash. */ - let rec hasReorgOccurredInternal = ( - lastBlockScannedDataList, - ~firstBlockParentNumberAndHash: option, - ) => { - switch (firstBlockParentNumberAndHash, lastBlockScannedDataList) { - | (Some({blockHash: parentHash, blockNumber: parentBlockNumber}), list{head, ...tail}) => - if parentBlockNumber == head.blockNumber { - parentHash != head.blockHash - } else { - //if block numbers do not match, this is a dynamic contract case and should recurse - //through the list to look for a matching block or nothing to validate - tail->hasReorgOccurredInternal(~firstBlockParentNumberAndHash) - } - | _ => //If parentHash is None, either it's the genesis block (no reorg) + let rec hasReorgOccurredInternal = (lastBlockScannedDataList, ~reorgGuard: reorgGuard) => { + switch lastBlockScannedDataList { + | list{head, ...tail} => + switch reorgGuard { + | {lastBlockScannedData} if lastBlockScannedData.blockNumber == head.blockNumber => + lastBlockScannedData.blockHash != head.blockHash + //If parentHash is None, either it's the genesis block (no reorg) //Or its already confirmed so no Reorg - //If recentLastBlockData is None, we have not yet saved blockData to compare against - false + | {firstBlockParentNumberAndHash: None} => false + | { + firstBlockParentNumberAndHash: Some({ + blockHash: parentHash, + blockNumber: parentBlockNumber, + }), + } => + if parentBlockNumber == head.blockNumber { + parentHash != head.blockHash + } else { + //if block numbers do not match, this is a dynamic contract case and should recurse + //through the list to look for a matching block or nothing to validate + tail->hasReorgOccurredInternal(~reorgGuard) + } + } + //If recentLastBlockData is None, we have not yet saved blockData to compare against + | _ => false } } - let hasReorgOccurred = ( - lastBlockScannedHashes: t, - ~firstBlockParentNumberAndHash: option, - ) => - lastBlockScannedHashes.lastBlockScannedDataList->hasReorgOccurredInternal( - ~firstBlockParentNumberAndHash, - ) + let hasReorgOccurred = (lastBlockScannedHashes: t, ~reorgGuard: reorgGuard) => + lastBlockScannedHashes.lastBlockScannedDataList->hasReorgOccurredInternal(~reorgGuard) } diff --git a/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/ChainWorker.res b/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/ChainWorker.res index eb2c2a4b2..b59e9f637 100644 --- a/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/ChainWorker.res +++ b/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/ChainWorker.res @@ -12,17 +12,12 @@ type blockRangeFetchStats = { @as("page fetch time (ms)") pageFetchTime?: int, } -type reorgGuard = { - lastBlockScannedData: ReorgDetection.blockData, - firstBlockParentNumberAndHash: option, -} - /** Thes response returned from a block range fetch */ type blockRangeFetchResponse = { currentBlockHeight: int, - reorgGuard: reorgGuard, + reorgGuard: ReorgDetection.reorgGuard, parsedQueueItems: array, fromBlockQueried: int, latestFetchedBlockNumber: int, diff --git a/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/HyperFuelWorker.res b/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/HyperFuelWorker.res index fef5c46c3..c4a6e6c0b 100644 --- a/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/HyperFuelWorker.res +++ b/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/HyperFuelWorker.res @@ -516,7 +516,7 @@ module Make = ( let lastBlockScannedData = await lastBlockQueriedPromise - let reorgGuard = { + let reorgGuard: ReorgDetection.reorgGuard = { lastBlockScannedData, firstBlockParentNumberAndHash: Some({ ReorgDetection.blockHash: lastBlockScannedData.blockHash, diff --git a/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/HyperSyncWorker.res b/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/HyperSyncWorker.res index 30a6d4564..ce11013ae 100644 --- a/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/HyperSyncWorker.res +++ b/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/HyperSyncWorker.res @@ -501,7 +501,7 @@ module Make = ( let lastBlockScannedData = await lastBlockQueriedPromise - let reorgGuard = { + let reorgGuard: ReorgDetection.reorgGuard = { lastBlockScannedData, firstBlockParentNumberAndHash: pageUnsafe.rollbackGuard->Option.map(v => { ReorgDetection.blockHash: v.firstParentHash, diff --git a/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/RpcWorker.res b/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/RpcWorker.res index 2bc8fd238..ca669e09d 100644 --- a/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/RpcWorker.res +++ b/codegenerator/cli/templates/static/codegen/src/eventFetching/chainWorkers/RpcWorker.res @@ -325,7 +325,7 @@ module Make = ( let totalTimeElapsed = startFetchingBatchTimeRef->Hrtime.timeSince->Hrtime.toMillis->Hrtime.intFromMillis - let reorgGuard: reorgGuard = { + let reorgGuard: ReorgDetection.reorgGuard = { firstBlockParentNumberAndHash: optFirstBlockParent->Option.map(b => { ReorgDetection.blockNumber: b.number, blockHash: b.hash, diff --git a/codegenerator/cli/templates/static/codegen/src/globalState/GlobalState.res b/codegenerator/cli/templates/static/codegen/src/globalState/GlobalState.res index 790ec38d9..56366088c 100644 --- a/codegenerator/cli/templates/static/codegen/src/globalState/GlobalState.res +++ b/codegenerator/cli/templates/static/codegen/src/globalState/GlobalState.res @@ -337,11 +337,11 @@ let handleBlockRangeResponse = (state, ~chain, ~response: ChainWorker.blockRange "stats": stats, }) - let {firstBlockParentNumberAndHash, lastBlockScannedData} = reorgGuard + let {lastBlockScannedData} = reorgGuard let hasReorgOccurred = chainFetcher.lastBlockScannedHashes->ReorgDetection.LastBlockScannedHashes.hasReorgOccurred( - ~firstBlockParentNumberAndHash, + ~reorgGuard, ) if !hasReorgOccurred || !(state.config->Config.shouldRollbackOnReorg) { diff --git a/scenarios/erc20_multichain_factory/pnpm-lock.yaml b/scenarios/erc20_multichain_factory/pnpm-lock.yaml index 8692d6153..09ab9f850 100644 --- a/scenarios/erc20_multichain_factory/pnpm-lock.yaml +++ b/scenarios/erc20_multichain_factory/pnpm-lock.yaml @@ -49,8 +49,8 @@ importers: specifier: 1.4.0 version: 1.4.0 '@envio-dev/hypersync-client': - specifier: 0.6.2 - version: 0.6.2 + specifier: 0.6.3 + version: 0.6.3 '@glennsl/rescript-fetch': specifier: 0.2.0 version: 0.2.0 @@ -134,44 +134,44 @@ packages: resolution: {integrity: sha512-eCSBUTgl8KbPyxky8cecDRLCYu2C1oFV4AZ72bEsI+TxXEvaljaL2kgttfzfu7gW+M89eCz55s49uF2t+YMTWA==} engines: {node: '>=10'} - '@envio-dev/hypersync-client-darwin-arm64@0.6.2': - resolution: {integrity: sha512-dDIuQqEgARR1JYodbGkmck1i9qbYEidc4Kw4DOrRKQ0uZFwflI4o8wm3P+G/ofc1iXwp4pm7jqNUGzZDpK9pqA==} + '@envio-dev/hypersync-client-darwin-arm64@0.6.3': + resolution: {integrity: sha512-w4OLJaq3lD03iXPJxLnPpoxOduvzCfEe2nYtamvIRLPB2SlbxnB5EF5dSyFs6WKh1x4PMsksQOUKeCcOtQPZow==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] - '@envio-dev/hypersync-client-darwin-x64@0.6.2': - resolution: {integrity: sha512-NGlgkmosAzlZ1EuQ5/djkg6sQI/dgVX+XGOLI6Zden0ca2zr/ByBRA7yCKxpwZHYynFN2FoMsMGSRY8jj6XQWw==} + '@envio-dev/hypersync-client-darwin-x64@0.6.3': + resolution: {integrity: sha512-zh98zCbm2cse/iIzyMs1YCcA1iI1U/j4Yex1xBVaEa1ogzQSK9peS6M+NygzdmlwPqr7K9rUQ/U56ICRl67fWw==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] - '@envio-dev/hypersync-client-linux-arm64-gnu@0.6.2': - resolution: {integrity: sha512-p2LQSaOSgjVvvFHOGHnPHTnsDHCWNEG78J29guZyqWojmaxTaR4eGyFEknla7eO0w58EIUGEBTF0+EJ7duMimg==} + '@envio-dev/hypersync-client-linux-arm64-gnu@0.6.3': + resolution: {integrity: sha512-5pI0N6W7W0L7LpgN76BAWRsC+NPOvrlvBEq8IjlBUS47vqZALvcJj3gYNkm466tUBQ4q4tF1x48k7MFKtoO8aw==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - '@envio-dev/hypersync-client-linux-x64-gnu@0.6.2': - resolution: {integrity: sha512-/kIL9Q0e5hM0g6cvdCHL93LMu+OCnwQAGKQHCj2TKKUjVpWFNb0Ki5PMgJhQ8mimEBFsJAnErVK+HrugLTlaVQ==} + '@envio-dev/hypersync-client-linux-x64-gnu@0.6.3': + resolution: {integrity: sha512-jL3sxWVyTJuKdO5y/0tu1EtWSox+nJdpmr7rdVW1w0gLk4ewzWORp9cl5pXkpqM4MUsjJz+NkcQKsUquGYBkKg==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - '@envio-dev/hypersync-client-linux-x64-musl@0.6.2': - resolution: {integrity: sha512-4r5hA/zyxUjWBDYYeXLCl5pBfSI9njEIPuLMFXajjVcAvSXRtBhmgVwa3JrjjCxZ8aLfqk9vvPkb/KgYfrbXXw==} + '@envio-dev/hypersync-client-linux-x64-musl@0.6.3': + resolution: {integrity: sha512-4rAh9x3PEWIweih731lWVEUGm+qrIHouElqZgXfTcZS6KkPeDnSYKVw10K5EyDuDtZla/NccEr0pJmcvpui5Ew==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - '@envio-dev/hypersync-client-win32-x64-msvc@0.6.2': - resolution: {integrity: sha512-VgsSwmDAgvpgo9QsIiwIp9IN+h3g0U/7zrCrvNAMj+lsMHJPZ7L0cfN58dQUr84wL8domJGJrnMKUtu/Yf49ow==} + '@envio-dev/hypersync-client-win32-x64-msvc@0.6.3': + resolution: {integrity: sha512-AINzLdjqU+y6ZiHnxorjFlrGNIw/AAJ80YXABYzokvGhDTF9qupjR1gdZo4sQEumgrRyg7fiG8QnsZVEm6V/zA==} engines: {node: '>= 10'} cpu: [x64] os: [win32] - '@envio-dev/hypersync-client@0.6.2': - resolution: {integrity: sha512-wgp0UmblW8yn/q5NMkVYPFDvOmgHWPTibl/QJYyYK2KXqAMHssUjP07ayduiZCexQOZ94Agpv4SvmYxQNjGBIA==} + '@envio-dev/hypersync-client@0.6.3': + resolution: {integrity: sha512-Lr5WyMZBK1cI++kAQLM/zd62NfUM60A3KWTKgeNew4NOghfoY5YZr99C7vo+CMYePXskYBR+ul+5iNPoHqkFrw==} engines: {node: '>= 10'} '@glennsl/rescript-fetch@0.2.0': @@ -842,80 +842,6 @@ packages: resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} engines: {node: '>=0.10.0'} - npm@10.8.3: - resolution: {integrity: sha512-0IQlyAYvVtQ7uOhDFYZCGK8kkut2nh8cpAdA9E6FvRSJaTgtZRZgNjlC5ZCct//L73ygrpY93CxXpRJDtNqPVg==} - engines: {node: ^18.17.0 || >=20.5.0} - hasBin: true - bundledDependencies: - - '@isaacs/string-locale-compare' - - '@npmcli/arborist' - - '@npmcli/config' - - '@npmcli/fs' - - '@npmcli/map-workspaces' - - '@npmcli/package-json' - - '@npmcli/promise-spawn' - - '@npmcli/redact' - - '@npmcli/run-script' - - '@sigstore/tuf' - - abbrev - - archy - - cacache - - chalk - - ci-info - - cli-columns - - fastest-levenshtein - - fs-minipass - - glob - - graceful-fs - - hosted-git-info - - ini - - init-package-json - - is-cidr - - json-parse-even-better-errors - - libnpmaccess - - libnpmdiff - - libnpmexec - - libnpmfund - - libnpmhook - - libnpmorg - - libnpmpack - - libnpmpublish - - libnpmsearch - - libnpmteam - - libnpmversion - - make-fetch-happen - - minimatch - - minipass - - minipass-pipeline - - ms - - node-gyp - - nopt - - normalize-package-data - - npm-audit-report - - npm-install-checks - - npm-package-arg - - npm-pick-manifest - - npm-profile - - npm-registry-fetch - - npm-user-validate - - p-map - - pacote - - parse-conflict-json - - proc-log - - qrcode-terminal - - read - - semver - - spdx-expression-parse - - ssri - - supports-color - - tar - - text-table - - tiny-relative-date - - treeverse - - validate-npm-package-name - - which - - write-file-atomic - object-assign@4.1.1: resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} engines: {node: '>=0.10.0'} @@ -1341,11 +1267,6 @@ packages: resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==} engines: {node: '>=12'} - yarn@1.22.22: - resolution: {integrity: sha512-prL3kGtyG7o9Z9Sv8IPfBNrWTDmXB4Qbes8A9rEzt6wkJV8mUvoirjU0Mp3GGAU06Y0XQyA3/2/RQFVuK7MTfg==} - engines: {node: '>=4.0.0'} - hasBin: true - yocto-queue@0.1.0: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} @@ -1366,35 +1287,32 @@ snapshots: dependencies: '@elastic/ecs-helpers': 1.1.0 - '@envio-dev/hypersync-client-darwin-arm64@0.6.2': + '@envio-dev/hypersync-client-darwin-arm64@0.6.3': optional: true - '@envio-dev/hypersync-client-darwin-x64@0.6.2': + '@envio-dev/hypersync-client-darwin-x64@0.6.3': optional: true - '@envio-dev/hypersync-client-linux-arm64-gnu@0.6.2': + '@envio-dev/hypersync-client-linux-arm64-gnu@0.6.3': optional: true - '@envio-dev/hypersync-client-linux-x64-gnu@0.6.2': + '@envio-dev/hypersync-client-linux-x64-gnu@0.6.3': optional: true - '@envio-dev/hypersync-client-linux-x64-musl@0.6.2': + '@envio-dev/hypersync-client-linux-x64-musl@0.6.3': optional: true - '@envio-dev/hypersync-client-win32-x64-msvc@0.6.2': + '@envio-dev/hypersync-client-win32-x64-msvc@0.6.3': optional: true - '@envio-dev/hypersync-client@0.6.2': - dependencies: - npm: 10.8.3 - yarn: 1.22.22 + '@envio-dev/hypersync-client@0.6.3': optionalDependencies: - '@envio-dev/hypersync-client-darwin-arm64': 0.6.2 - '@envio-dev/hypersync-client-darwin-x64': 0.6.2 - '@envio-dev/hypersync-client-linux-arm64-gnu': 0.6.2 - '@envio-dev/hypersync-client-linux-x64-gnu': 0.6.2 - '@envio-dev/hypersync-client-linux-x64-musl': 0.6.2 - '@envio-dev/hypersync-client-win32-x64-msvc': 0.6.2 + '@envio-dev/hypersync-client-darwin-arm64': 0.6.3 + '@envio-dev/hypersync-client-darwin-x64': 0.6.3 + '@envio-dev/hypersync-client-linux-arm64-gnu': 0.6.3 + '@envio-dev/hypersync-client-linux-x64-gnu': 0.6.3 + '@envio-dev/hypersync-client-linux-x64-musl': 0.6.3 + '@envio-dev/hypersync-client-win32-x64-msvc': 0.6.3 '@glennsl/rescript-fetch@0.2.0': {} @@ -1663,7 +1581,7 @@ snapshots: envio@file:../../codegenerator/cli/npm/envio: dependencies: - '@envio-dev/hypersync-client': 0.6.2 + '@envio-dev/hypersync-client': 0.6.3 rescript: 11.1.3 rescript-schema: 8.1.0(rescript@11.1.3) viem: 2.21.0 @@ -2063,8 +1981,6 @@ snapshots: normalize-path@3.0.0: {} - npm@10.8.3: {} - object-assign@4.1.1: {} object-inspect@1.13.2: {} @@ -2506,8 +2422,6 @@ snapshots: y18n: 5.0.8 yargs-parser: 21.1.1 - yarn@1.22.22: {} - yocto-queue@0.1.0: {} yoga-layout-prebuilt@1.10.0: diff --git a/scenarios/helpers/src/Indexer.res b/scenarios/helpers/src/Indexer.res index aa285274b..20e8d07e0 100644 --- a/scenarios/helpers/src/Indexer.res +++ b/scenarios/helpers/src/Indexer.res @@ -78,15 +78,11 @@ module type S = { } module ChainWorker: { - type reorgGuard = { - lastBlockScannedData: ReorgDetection.blockData, - firstBlockParentNumberAndHash: option, - } type blockRangeFetchArgs type blockRangeFetchStats type blockRangeFetchResponse = { currentBlockHeight: int, - reorgGuard: reorgGuard, + reorgGuard: ReorgDetection.reorgGuard, parsedQueueItems: array, fromBlockQueried: int, latestFetchedBlockNumber: int,