ponder 0.9.5-debug.1 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{types/bin → bin}/ponder.d.ts +6 -5
- package/dist/bin/ponder.js +12933 -0
- package/dist/bin/ponder.js.map +1 -0
- package/dist/chunk-K2TLRLX3.js +163 -0
- package/dist/chunk-K2TLRLX3.js.map +1 -0
- package/dist/chunk-LHCA5XFV.js +257 -0
- package/dist/chunk-LHCA5XFV.js.map +1 -0
- package/dist/{types/drizzle → drizzle}/onchain.d.ts +96 -49
- package/dist/drizzle/onchain.js +19 -0
- package/dist/drizzle/onchain.js.map +1 -0
- package/dist/index.d.ts +819 -0
- package/dist/index.js +2217 -0
- package/dist/index.js.map +1 -0
- package/dist/utils-ceNucOJb.d.ts +14 -0
- package/package.json +17 -17
- package/src/bin/commands/dev.ts +1 -1
- package/src/bin/ponder.ts +1 -1
- package/src/build/configAndIndexingFunctions.ts +1 -1
- package/src/build/factory.ts +1 -1
- package/src/client/index.ts +1 -1
- package/src/indexing-store/historical.ts +1 -1
- package/src/indexing-store/realtime.ts +1 -1
- package/src/internal/telemetry.ts +1 -1
- package/src/sync/fragments.ts +1 -1
- package/src/sync-realtime/index.ts +1 -1
- package/src/utils/generators.ts +1 -1
- package/src/utils/mutex.ts +1 -1
- package/src/utils/requestQueue.ts +1 -1
- package/CHANGELOG.md +0 -2201
- package/dist/esm/bin/commands/codegen.js +0 -37
- package/dist/esm/bin/commands/codegen.js.map +0 -1
- package/dist/esm/bin/commands/dev.js +0 -242
- package/dist/esm/bin/commands/dev.js.map +0 -1
- package/dist/esm/bin/commands/list.js +0 -103
- package/dist/esm/bin/commands/list.js.map +0 -1
- package/dist/esm/bin/commands/serve.js +0 -123
- package/dist/esm/bin/commands/serve.js.map +0 -1
- package/dist/esm/bin/commands/start.js +0 -136
- package/dist/esm/bin/commands/start.js.map +0 -1
- package/dist/esm/bin/ponder.js +0 -118
- package/dist/esm/bin/ponder.js.map +0 -1
- package/dist/esm/bin/utils/codegen.js +0 -26
- package/dist/esm/bin/utils/codegen.js.map +0 -1
- package/dist/esm/bin/utils/exit.js +0 -69
- package/dist/esm/bin/utils/exit.js.map +0 -1
- package/dist/esm/bin/utils/run.js +0 -247
- package/dist/esm/bin/utils/run.js.map +0 -1
- package/dist/esm/bin/utils/runServer.js +0 -8
- package/dist/esm/bin/utils/runServer.js.map +0 -1
- package/dist/esm/build/configAndIndexingFunctions.js +0 -654
- package/dist/esm/build/configAndIndexingFunctions.js.map +0 -1
- package/dist/esm/build/factory.js +0 -43
- package/dist/esm/build/factory.js.map +0 -1
- package/dist/esm/build/index.js +0 -431
- package/dist/esm/build/index.js.map +0 -1
- package/dist/esm/build/plugin.js +0 -43
- package/dist/esm/build/plugin.js.map +0 -1
- package/dist/esm/build/pre.js +0 -112
- package/dist/esm/build/pre.js.map +0 -1
- package/dist/esm/build/schema.js +0 -89
- package/dist/esm/build/schema.js.map +0 -1
- package/dist/esm/build/stacktrace.js +0 -137
- package/dist/esm/build/stacktrace.js.map +0 -1
- package/dist/esm/client/index.js +0 -124
- package/dist/esm/client/index.js.map +0 -1
- package/dist/esm/client/validate.js +0 -1151
- package/dist/esm/client/validate.js.map +0 -1
- package/dist/esm/config/address.js +0 -2
- package/dist/esm/config/address.js.map +0 -1
- package/dist/esm/config/eventFilter.js +0 -2
- package/dist/esm/config/eventFilter.js.map +0 -1
- package/dist/esm/config/index.js +0 -2
- package/dist/esm/config/index.js.map +0 -1
- package/dist/esm/config/networks.js +0 -120
- package/dist/esm/config/networks.js.map +0 -1
- package/dist/esm/config/utilityTypes.js +0 -2
- package/dist/esm/config/utilityTypes.js.map +0 -1
- package/dist/esm/database/index.js +0 -914
- package/dist/esm/database/index.js.map +0 -1
- package/dist/esm/drizzle/bigint.js +0 -36
- package/dist/esm/drizzle/bigint.js.map +0 -1
- package/dist/esm/drizzle/hex.js +0 -38
- package/dist/esm/drizzle/hex.js.map +0 -1
- package/dist/esm/drizzle/index.js +0 -43
- package/dist/esm/drizzle/index.js.map +0 -1
- package/dist/esm/drizzle/kit/index.js +0 -658
- package/dist/esm/drizzle/kit/index.js.map +0 -1
- package/dist/esm/drizzle/onchain.js +0 -102
- package/dist/esm/drizzle/onchain.js.map +0 -1
- package/dist/esm/graphql/index.js +0 -704
- package/dist/esm/graphql/index.js.map +0 -1
- package/dist/esm/graphql/json.js +0 -42
- package/dist/esm/graphql/json.js.map +0 -1
- package/dist/esm/graphql/middleware.js +0 -80
- package/dist/esm/graphql/middleware.js.map +0 -1
- package/dist/esm/index.js +0 -9
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/indexing/addStackTrace.js +0 -54
- package/dist/esm/indexing/addStackTrace.js.map +0 -1
- package/dist/esm/indexing/index.js +0 -10
- package/dist/esm/indexing/index.js.map +0 -1
- package/dist/esm/indexing/ponderActions.js +0 -60
- package/dist/esm/indexing/ponderActions.js.map +0 -1
- package/dist/esm/indexing/service.js +0 -312
- package/dist/esm/indexing/service.js.map +0 -1
- package/dist/esm/indexing-store/historical.js +0 -591
- package/dist/esm/indexing-store/historical.js.map +0 -1
- package/dist/esm/indexing-store/index.js +0 -19
- package/dist/esm/indexing-store/index.js.map +0 -1
- package/dist/esm/indexing-store/metadata.js +0 -46
- package/dist/esm/indexing-store/metadata.js.map +0 -1
- package/dist/esm/indexing-store/realtime.js +0 -295
- package/dist/esm/indexing-store/realtime.js.map +0 -1
- package/dist/esm/internal/common.js +0 -2
- package/dist/esm/internal/common.js.map +0 -1
- package/dist/esm/internal/errors.js +0 -175
- package/dist/esm/internal/errors.js.map +0 -1
- package/dist/esm/internal/logger.js +0 -96
- package/dist/esm/internal/logger.js.map +0 -1
- package/dist/esm/internal/metrics.js +0 -569
- package/dist/esm/internal/metrics.js.map +0 -1
- package/dist/esm/internal/options.js +0 -69
- package/dist/esm/internal/options.js.map +0 -1
- package/dist/esm/internal/shutdown.js +0 -18
- package/dist/esm/internal/shutdown.js.map +0 -1
- package/dist/esm/internal/telemetry.js +0 -199
- package/dist/esm/internal/telemetry.js.map +0 -1
- package/dist/esm/internal/types.js +0 -2
- package/dist/esm/internal/types.js.map +0 -1
- package/dist/esm/server/error.js +0 -55
- package/dist/esm/server/error.js.map +0 -1
- package/dist/esm/server/index.js +0 -107
- package/dist/esm/server/index.js.map +0 -1
- package/dist/esm/sync/abi.js +0 -67
- package/dist/esm/sync/abi.js.map +0 -1
- package/dist/esm/sync/events.js +0 -607
- package/dist/esm/sync/events.js.map +0 -1
- package/dist/esm/sync/filter.js +0 -356
- package/dist/esm/sync/filter.js.map +0 -1
- package/dist/esm/sync/fragments.js +0 -300
- package/dist/esm/sync/fragments.js.map +0 -1
- package/dist/esm/sync/index.js +0 -1001
- package/dist/esm/sync/index.js.map +0 -1
- package/dist/esm/sync/transport.js +0 -94
- package/dist/esm/sync/transport.js.map +0 -1
- package/dist/esm/sync-historical/index.js +0 -590
- package/dist/esm/sync-historical/index.js.map +0 -1
- package/dist/esm/sync-realtime/bloom.js +0 -75
- package/dist/esm/sync-realtime/bloom.js.map +0 -1
- package/dist/esm/sync-realtime/index.js +0 -794
- package/dist/esm/sync-realtime/index.js.map +0 -1
- package/dist/esm/sync-store/encoding.js +0 -157
- package/dist/esm/sync-store/encoding.js.map +0 -1
- package/dist/esm/sync-store/index.js +0 -727
- package/dist/esm/sync-store/index.js.map +0 -1
- package/dist/esm/sync-store/migrations.js +0 -1186
- package/dist/esm/sync-store/migrations.js.map +0 -1
- package/dist/esm/types/db.js +0 -2
- package/dist/esm/types/db.js.map +0 -1
- package/dist/esm/types/eth.js +0 -2
- package/dist/esm/types/eth.js.map +0 -1
- package/dist/esm/types/sync.js +0 -2
- package/dist/esm/types/sync.js.map +0 -1
- package/dist/esm/types/utils.js +0 -2
- package/dist/esm/types/utils.js.map +0 -1
- package/dist/esm/types/virtual.js +0 -2
- package/dist/esm/types/virtual.js.map +0 -1
- package/dist/esm/ui/ProgressBar.js +0 -11
- package/dist/esm/ui/ProgressBar.js.map +0 -1
- package/dist/esm/ui/Table.js +0 -50
- package/dist/esm/ui/Table.js.map +0 -1
- package/dist/esm/ui/app.js +0 -113
- package/dist/esm/ui/app.js.map +0 -1
- package/dist/esm/ui/graphiql.html.js +0 -59
- package/dist/esm/ui/graphiql.html.js.map +0 -1
- package/dist/esm/ui/index.js +0 -21
- package/dist/esm/ui/index.js.map +0 -1
- package/dist/esm/utils/bigint.js +0 -37
- package/dist/esm/utils/bigint.js.map +0 -1
- package/dist/esm/utils/chains.js +0 -3
- package/dist/esm/utils/chains.js.map +0 -1
- package/dist/esm/utils/checkpoint.js +0 -114
- package/dist/esm/utils/checkpoint.js.map +0 -1
- package/dist/esm/utils/chunk.js +0 -8
- package/dist/esm/utils/chunk.js.map +0 -1
- package/dist/esm/utils/date.js +0 -27
- package/dist/esm/utils/date.js.map +0 -1
- package/dist/esm/utils/debug.js +0 -2
- package/dist/esm/utils/debug.js.map +0 -1
- package/dist/esm/utils/dedupe.js +0 -33
- package/dist/esm/utils/dedupe.js.map +0 -1
- package/dist/esm/utils/duplicates.js +0 -19
- package/dist/esm/utils/duplicates.js.map +0 -1
- package/dist/esm/utils/estimate.js +0 -6
- package/dist/esm/utils/estimate.js.map +0 -1
- package/dist/esm/utils/extend.js +0 -28
- package/dist/esm/utils/extend.js.map +0 -1
- package/dist/esm/utils/format.js +0 -20
- package/dist/esm/utils/format.js.map +0 -1
- package/dist/esm/utils/generators.js +0 -77
- package/dist/esm/utils/generators.js.map +0 -1
- package/dist/esm/utils/hash.js +0 -11
- package/dist/esm/utils/hash.js.map +0 -1
- package/dist/esm/utils/interval.js +0 -171
- package/dist/esm/utils/interval.js.map +0 -1
- package/dist/esm/utils/lowercase.js +0 -7
- package/dist/esm/utils/lowercase.js.map +0 -1
- package/dist/esm/utils/mutex.js +0 -25
- package/dist/esm/utils/mutex.js.map +0 -1
- package/dist/esm/utils/never.js +0 -4
- package/dist/esm/utils/never.js.map +0 -1
- package/dist/esm/utils/offset.js +0 -73
- package/dist/esm/utils/offset.js.map +0 -1
- package/dist/esm/utils/order.js +0 -18
- package/dist/esm/utils/order.js.map +0 -1
- package/dist/esm/utils/partition.js +0 -37
- package/dist/esm/utils/partition.js.map +0 -1
- package/dist/esm/utils/pg.js +0 -126
- package/dist/esm/utils/pg.js.map +0 -1
- package/dist/esm/utils/pglite.js +0 -80
- package/dist/esm/utils/pglite.js.map +0 -1
- package/dist/esm/utils/port.js +0 -30
- package/dist/esm/utils/port.js.map +0 -1
- package/dist/esm/utils/print.js +0 -23
- package/dist/esm/utils/print.js.map +0 -1
- package/dist/esm/utils/promiseWithResolvers.js +0 -13
- package/dist/esm/utils/promiseWithResolvers.js.map +0 -1
- package/dist/esm/utils/queue.js +0 -145
- package/dist/esm/utils/queue.js.map +0 -1
- package/dist/esm/utils/range.js +0 -8
- package/dist/esm/utils/range.js.map +0 -1
- package/dist/esm/utils/requestQueue.js +0 -127
- package/dist/esm/utils/requestQueue.js.map +0 -1
- package/dist/esm/utils/result.js +0 -10
- package/dist/esm/utils/result.js.map +0 -1
- package/dist/esm/utils/rpc.js +0 -202
- package/dist/esm/utils/rpc.js.map +0 -1
- package/dist/esm/utils/serialize.js +0 -23
- package/dist/esm/utils/serialize.js.map +0 -1
- package/dist/esm/utils/timer.js +0 -17
- package/dist/esm/utils/timer.js.map +0 -1
- package/dist/esm/utils/wait.js +0 -8
- package/dist/esm/utils/wait.js.map +0 -1
- package/dist/esm/utils/zipper.js +0 -67
- package/dist/esm/utils/zipper.js.map +0 -1
- package/dist/types/bin/commands/codegen.d.ts +0 -5
- package/dist/types/bin/commands/codegen.d.ts.map +0 -1
- package/dist/types/bin/commands/dev.d.ts +0 -5
- package/dist/types/bin/commands/dev.d.ts.map +0 -1
- package/dist/types/bin/commands/list.d.ts +0 -5
- package/dist/types/bin/commands/list.d.ts.map +0 -1
- package/dist/types/bin/commands/serve.d.ts +0 -5
- package/dist/types/bin/commands/serve.d.ts.map +0 -1
- package/dist/types/bin/commands/start.d.ts +0 -5
- package/dist/types/bin/commands/start.d.ts.map +0 -1
- package/dist/types/bin/ponder.d.ts.map +0 -1
- package/dist/types/bin/utils/codegen.d.ts +0 -6
- package/dist/types/bin/utils/codegen.d.ts.map +0 -1
- package/dist/types/bin/utils/exit.d.ts +0 -9
- package/dist/types/bin/utils/exit.d.ts.map +0 -1
- package/dist/types/bin/utils/run.d.ts +0 -14
- package/dist/types/bin/utils/run.d.ts.map +0 -1
- package/dist/types/bin/utils/runServer.d.ts +0 -12
- package/dist/types/bin/utils/runServer.d.ts.map +0 -1
- package/dist/types/build/configAndIndexingFunctions.d.ts +0 -37
- package/dist/types/build/configAndIndexingFunctions.d.ts.map +0 -1
- package/dist/types/build/factory.d.ts +0 -10
- package/dist/types/build/factory.d.ts.map +0 -1
- package/dist/types/build/index.d.ts +0 -70
- package/dist/types/build/index.d.ts.map +0 -1
- package/dist/types/build/plugin.d.ts +0 -4
- package/dist/types/build/plugin.d.ts.map +0 -1
- package/dist/types/build/pre.d.ts +0 -35
- package/dist/types/build/pre.d.ts.map +0 -1
- package/dist/types/build/schema.d.ts +0 -18
- package/dist/types/build/schema.d.ts.map +0 -1
- package/dist/types/build/stacktrace.d.ts +0 -13
- package/dist/types/build/stacktrace.d.ts.map +0 -1
- package/dist/types/client/index.d.ts +0 -27
- package/dist/types/client/index.d.ts.map +0 -1
- package/dist/types/client/validate.d.ts +0 -2
- package/dist/types/client/validate.d.ts.map +0 -1
- package/dist/types/config/address.d.ts +0 -14
- package/dist/types/config/address.d.ts.map +0 -1
- package/dist/types/config/eventFilter.d.ts +0 -18
- package/dist/types/config/eventFilter.d.ts.map +0 -1
- package/dist/types/config/index.d.ts +0 -143
- package/dist/types/config/index.d.ts.map +0 -1
- package/dist/types/config/networks.d.ts +0 -30
- package/dist/types/config/networks.d.ts.map +0 -1
- package/dist/types/config/utilityTypes.d.ts +0 -43
- package/dist/types/config/utilityTypes.d.ts.map +0 -1
- package/dist/types/database/index.d.ts +0 -91
- package/dist/types/database/index.d.ts.map +0 -1
- package/dist/types/drizzle/bigint.d.ts +0 -25
- package/dist/types/drizzle/bigint.d.ts.map +0 -1
- package/dist/types/drizzle/hex.d.ts +0 -25
- package/dist/types/drizzle/hex.d.ts.map +0 -1
- package/dist/types/drizzle/index.d.ts +0 -14
- package/dist/types/drizzle/index.d.ts.map +0 -1
- package/dist/types/drizzle/kit/index.d.ts +0 -49
- package/dist/types/drizzle/kit/index.d.ts.map +0 -1
- package/dist/types/drizzle/onchain.d.ts.map +0 -1
- package/dist/types/graphql/index.d.ts +0 -14
- package/dist/types/graphql/index.d.ts.map +0 -1
- package/dist/types/graphql/json.d.ts +0 -3
- package/dist/types/graphql/json.d.ts.map +0 -1
- package/dist/types/graphql/middleware.d.ts +0 -29
- package/dist/types/graphql/middleware.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -18
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/indexing/addStackTrace.d.ts +0 -3
- package/dist/types/indexing/addStackTrace.d.ts.map +0 -1
- package/dist/types/indexing/index.d.ts +0 -575
- package/dist/types/indexing/index.d.ts.map +0 -1
- package/dist/types/indexing/ponderActions.d.ts +0 -47
- package/dist/types/indexing/ponderActions.d.ts.map +0 -1
- package/dist/types/indexing/service.d.ts +0 -73
- package/dist/types/indexing/service.d.ts.map +0 -1
- package/dist/types/indexing-store/historical.d.ts +0 -19
- package/dist/types/indexing-store/historical.d.ts.map +0 -1
- package/dist/types/indexing-store/index.d.ts +0 -10
- package/dist/types/indexing-store/index.d.ts.map +0 -1
- package/dist/types/indexing-store/metadata.d.ts +0 -10
- package/dist/types/indexing-store/metadata.d.ts.map +0 -1
- package/dist/types/indexing-store/realtime.d.ts +0 -10
- package/dist/types/indexing-store/realtime.d.ts.map +0 -1
- package/dist/types/internal/common.d.ts +0 -13
- package/dist/types/internal/common.d.ts.map +0 -1
- package/dist/types/internal/errors.d.ts +0 -55
- package/dist/types/internal/errors.d.ts.map +0 -1
- package/dist/types/internal/logger.d.ts +0 -26
- package/dist/types/internal/logger.d.ts.map +0 -1
- package/dist/types/internal/metrics.d.ts +0 -77
- package/dist/types/internal/metrics.d.ts.map +0 -1
- package/dist/types/internal/options.d.ts +0 -59
- package/dist/types/internal/options.d.ts.map +0 -1
- package/dist/types/internal/shutdown.d.ts +0 -8
- package/dist/types/internal/shutdown.d.ts.map +0 -1
- package/dist/types/internal/telemetry.d.ts +0 -43
- package/dist/types/internal/telemetry.d.ts.map +0 -1
- package/dist/types/internal/types.d.ts +0 -328
- package/dist/types/internal/types.d.ts.map +0 -1
- package/dist/types/server/error.d.ts +0 -5
- package/dist/types/server/error.d.ts.map +0 -1
- package/dist/types/server/index.d.ts +0 -13
- package/dist/types/server/index.d.ts.map +0 -1
- package/dist/types/sync/abi.d.ts +0 -54
- package/dist/types/sync/abi.d.ts.map +0 -1
- package/dist/types/sync/events.d.ts +0 -24
- package/dist/types/sync/events.d.ts.map +0 -1
- package/dist/types/sync/filter.d.ts +0 -71
- package/dist/types/sync/filter.d.ts.map +0 -1
- package/dist/types/sync/fragments.d.ts +0 -21
- package/dist/types/sync/fragments.d.ts.map +0 -1
- package/dist/types/sync/index.d.ts +0 -112
- package/dist/types/sync/index.d.ts.map +0 -1
- package/dist/types/sync/transport.d.ts +0 -8
- package/dist/types/sync/transport.d.ts.map +0 -1
- package/dist/types/sync-historical/index.d.ts +0 -28
- package/dist/types/sync-historical/index.d.ts.map +0 -1
- package/dist/types/sync-realtime/bloom.d.ts +0 -19
- package/dist/types/sync-realtime/bloom.d.ts.map +0 -1
- package/dist/types/sync-realtime/index.d.ts +0 -48
- package/dist/types/sync-realtime/index.d.ts.map +0 -1
- package/dist/types/sync-store/encoding.d.ts +0 -151
- package/dist/types/sync-store/encoding.d.ts.map +0 -1
- package/dist/types/sync-store/index.d.ts +0 -104
- package/dist/types/sync-store/index.d.ts.map +0 -1
- package/dist/types/sync-store/migrations.d.ts +0 -13
- package/dist/types/sync-store/migrations.d.ts.map +0 -1
- package/dist/types/types/db.d.ts +0 -213
- package/dist/types/types/db.d.ts.map +0 -1
- package/dist/types/types/eth.d.ts +0 -196
- package/dist/types/types/eth.d.ts.map +0 -1
- package/dist/types/types/sync.d.ts +0 -15
- package/dist/types/types/sync.d.ts.map +0 -1
- package/dist/types/types/utils.d.ts +0 -22
- package/dist/types/types/utils.d.ts.map +0 -1
- package/dist/types/types/virtual.d.ts +0 -95
- package/dist/types/types/virtual.d.ts.map +0 -1
- package/dist/types/ui/ProgressBar.d.ts +0 -7
- package/dist/types/ui/ProgressBar.d.ts.map +0 -1
- package/dist/types/ui/Table.d.ts +0 -24
- package/dist/types/ui/Table.d.ts.map +0 -1
- package/dist/types/ui/app.d.ts +0 -14
- package/dist/types/ui/app.d.ts.map +0 -1
- package/dist/types/ui/graphiql.html.d.ts +0 -2
- package/dist/types/ui/graphiql.html.d.ts.map +0 -1
- package/dist/types/ui/index.d.ts +0 -5
- package/dist/types/ui/index.d.ts.map +0 -1
- package/dist/types/utils/bigint.d.ts +0 -15
- package/dist/types/utils/bigint.d.ts.map +0 -1
- package/dist/types/utils/chains.d.ts +0 -3
- package/dist/types/utils/chains.d.ts.map +0 -1
- package/dist/types/utils/checkpoint.d.ts +0 -40
- package/dist/types/utils/checkpoint.d.ts.map +0 -1
- package/dist/types/utils/chunk.d.ts +0 -2
- package/dist/types/utils/chunk.d.ts.map +0 -1
- package/dist/types/utils/date.d.ts +0 -7
- package/dist/types/utils/date.d.ts.map +0 -1
- package/dist/types/utils/debug.d.ts +0 -105
- package/dist/types/utils/debug.d.ts.map +0 -1
- package/dist/types/utils/dedupe.d.ts +0 -20
- package/dist/types/utils/dedupe.d.ts.map +0 -1
- package/dist/types/utils/duplicates.d.ts +0 -7
- package/dist/types/utils/duplicates.d.ts.map +0 -1
- package/dist/types/utils/estimate.d.ts +0 -11
- package/dist/types/utils/estimate.d.ts.map +0 -1
- package/dist/types/utils/extend.d.ts +0 -13
- package/dist/types/utils/extend.d.ts.map +0 -1
- package/dist/types/utils/format.d.ts +0 -3
- package/dist/types/utils/format.d.ts.map +0 -1
- package/dist/types/utils/generators.d.ts +0 -23
- package/dist/types/utils/generators.d.ts.map +0 -1
- package/dist/types/utils/hash.d.ts +0 -11
- package/dist/types/utils/hash.d.ts.map +0 -1
- package/dist/types/utils/interval.d.ts +0 -53
- package/dist/types/utils/interval.d.ts.map +0 -1
- package/dist/types/utils/lowercase.d.ts +0 -5
- package/dist/types/utils/lowercase.d.ts.map +0 -1
- package/dist/types/utils/mutex.d.ts +0 -8
- package/dist/types/utils/mutex.d.ts.map +0 -1
- package/dist/types/utils/never.d.ts +0 -2
- package/dist/types/utils/never.d.ts.map +0 -1
- package/dist/types/utils/offset.d.ts +0 -3
- package/dist/types/utils/offset.d.ts.map +0 -1
- package/dist/types/utils/order.d.ts +0 -2
- package/dist/types/utils/order.d.ts.map +0 -1
- package/dist/types/utils/partition.d.ts +0 -22
- package/dist/types/utils/partition.d.ts.map +0 -1
- package/dist/types/utils/pg.d.ts +0 -5
- package/dist/types/utils/pg.d.ts.map +0 -1
- package/dist/types/utils/pglite.d.ts +0 -25
- package/dist/types/utils/pglite.d.ts.map +0 -1
- package/dist/types/utils/port.d.ts +0 -5
- package/dist/types/utils/port.d.ts.map +0 -1
- package/dist/types/utils/print.d.ts +0 -2
- package/dist/types/utils/print.d.ts.map +0 -1
- package/dist/types/utils/promiseWithResolvers.d.ts +0 -10
- package/dist/types/utils/promiseWithResolvers.d.ts.map +0 -1
- package/dist/types/utils/queue.d.ts +0 -33
- package/dist/types/utils/queue.d.ts.map +0 -1
- package/dist/types/utils/range.d.ts +0 -8
- package/dist/types/utils/range.d.ts.map +0 -1
- package/dist/types/utils/requestQueue.d.ts +0 -21
- package/dist/types/utils/requestQueue.d.ts.map +0 -1
- package/dist/types/utils/result.d.ts +0 -17
- package/dist/types/utils/result.d.ts.map +0 -1
- package/dist/types/utils/rpc.d.ts +0 -57
- package/dist/types/utils/rpc.d.ts.map +0 -1
- package/dist/types/utils/serialize.d.ts +0 -19
- package/dist/types/utils/serialize.d.ts.map +0 -1
- package/dist/types/utils/timer.d.ts +0 -11
- package/dist/types/utils/timer.d.ts.map +0 -1
- package/dist/types/utils/wait.d.ts +0 -6
- package/dist/types/utils/wait.d.ts.map +0 -1
- package/dist/types/utils/zipper.d.ts +0 -36
- package/dist/types/utils/zipper.d.ts.map +0 -1
- package/src/utils/dedupe.ts +0 -40
- package/src/utils/promiseWithResolvers.ts +0 -20
- package/src/utils/queue.ts +0 -250
package/dist/esm/sync/index.js
DELETED
|
@@ -1,1001 +0,0 @@
|
|
|
1
|
-
import { createHistoricalSync, } from '../sync-historical/index.js';
|
|
2
|
-
import { createRealtimeSync, } from '../sync-realtime/index.js';
|
|
3
|
-
import { MAX_CHECKPOINT, ZERO_CHECKPOINT, ZERO_CHECKPOINT_STRING, decodeCheckpoint, encodeCheckpoint, min, } from '../utils/checkpoint.js';
|
|
4
|
-
import { estimate } from '../utils/estimate.js';
|
|
5
|
-
import { formatPercentage } from '../utils/format.js';
|
|
6
|
-
import { bufferAsyncGenerator, mergeAsyncGenerators, } from '../utils/generators.js';
|
|
7
|
-
import { intervalDifference, intervalIntersection, intervalIntersectionMany, intervalSum, sortIntervals, } from '../utils/interval.js';
|
|
8
|
-
import { intervalUnion } from '../utils/interval.js';
|
|
9
|
-
import { createMutex } from '../utils/mutex.js';
|
|
10
|
-
import { never } from '../utils/never.js';
|
|
11
|
-
import { partition } from '../utils/partition.js';
|
|
12
|
-
import { _eth_getBlockByNumber } from '../utils/rpc.js';
|
|
13
|
-
import { startClock } from '../utils/timer.js';
|
|
14
|
-
import { zipperMany } from '../utils/zipper.js';
|
|
15
|
-
import { hexToBigInt, hexToNumber, toHex } from "viem";
|
|
16
|
-
import { buildEvents, decodeEvents } from "./events.js";
|
|
17
|
-
import { isAddressFactory } from "./filter.js";
|
|
18
|
-
export const syncBlockToLightBlock = ({ hash, parentHash, number, timestamp, }) => ({
|
|
19
|
-
hash,
|
|
20
|
-
parentHash,
|
|
21
|
-
number,
|
|
22
|
-
timestamp,
|
|
23
|
-
});
|
|
24
|
-
/** Convert `block` to a `Checkpoint`. */
|
|
25
|
-
export const blockToCheckpoint = (block, chainId, rounding) => {
|
|
26
|
-
return {
|
|
27
|
-
...(rounding === "up" ? MAX_CHECKPOINT : ZERO_CHECKPOINT),
|
|
28
|
-
blockTimestamp: hexToNumber(block.timestamp),
|
|
29
|
-
chainId: BigInt(chainId),
|
|
30
|
-
blockNumber: hexToBigInt(block.number),
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Returns true if all filters have a defined end block and the current
|
|
35
|
-
* sync progress has reached the final end block.
|
|
36
|
-
*/
|
|
37
|
-
const isSyncEnd = (syncProgress) => {
|
|
38
|
-
if (syncProgress.end === undefined || syncProgress.current === undefined) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
return (hexToNumber(syncProgress.current.number) >=
|
|
42
|
-
hexToNumber(syncProgress.end.number));
|
|
43
|
-
};
|
|
44
|
-
/** Returns true if sync progress has reached the finalized block. */
|
|
45
|
-
const isSyncFinalized = (syncProgress) => {
|
|
46
|
-
if (syncProgress.current === undefined) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
return (hexToNumber(syncProgress.current.number) >=
|
|
50
|
-
hexToNumber(syncProgress.finalized.number));
|
|
51
|
-
};
|
|
52
|
-
/** Returns the closest-to-tip block that is part of the historical sync. */
|
|
53
|
-
const getHistoricalLast = (syncProgress) => {
|
|
54
|
-
return syncProgress.end === undefined
|
|
55
|
-
? syncProgress.finalized
|
|
56
|
-
: hexToNumber(syncProgress.end.number) >
|
|
57
|
-
hexToNumber(syncProgress.finalized.number)
|
|
58
|
-
? syncProgress.finalized
|
|
59
|
-
: syncProgress.end;
|
|
60
|
-
};
|
|
61
|
-
export const splitEvents = (events) => {
|
|
62
|
-
let hash;
|
|
63
|
-
const result = [];
|
|
64
|
-
for (const event of events) {
|
|
65
|
-
if (hash === undefined || hash !== event.event.block.hash) {
|
|
66
|
-
result.push({
|
|
67
|
-
checkpoint: encodeCheckpoint({
|
|
68
|
-
...MAX_CHECKPOINT,
|
|
69
|
-
blockTimestamp: Number(event.event.block.timestamp),
|
|
70
|
-
chainId: BigInt(event.chainId),
|
|
71
|
-
blockNumber: event.event.block.number,
|
|
72
|
-
}),
|
|
73
|
-
events: [],
|
|
74
|
-
});
|
|
75
|
-
hash = event.event.block.hash;
|
|
76
|
-
}
|
|
77
|
-
result[result.length - 1].events.push(event);
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
};
|
|
81
|
-
/** Returns the checkpoint for a given block tag. */
|
|
82
|
-
export const getChainCheckpoint = ({ syncProgress, network, tag, }) => {
|
|
83
|
-
if (tag === "end" && syncProgress.end === undefined) {
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
if (tag === "current" && isSyncEnd(syncProgress)) {
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
|
-
const block = syncProgress[tag];
|
|
90
|
-
return encodeCheckpoint(blockToCheckpoint(block, network.chainId,
|
|
91
|
-
// The checkpoint returned by this function is meant to be used in
|
|
92
|
-
// a closed interval (includes endpoints), so "start" should be inclusive.
|
|
93
|
-
tag === "start" ? "down" : "up"));
|
|
94
|
-
};
|
|
95
|
-
export const createSync = async (params) => {
|
|
96
|
-
const perNetworkSync = new Map();
|
|
97
|
-
const getMultichainCheckpoint = ({ tag, network, }) => {
|
|
98
|
-
const syncProgress = perNetworkSync.get(network).syncProgress;
|
|
99
|
-
return getChainCheckpoint({ syncProgress, network, tag });
|
|
100
|
-
};
|
|
101
|
-
const getOmnichainCheckpoint = ({ tag, }) => {
|
|
102
|
-
const checkpoints = Array.from(perNetworkSync.entries()).map(([network, { syncProgress }]) => getChainCheckpoint({ syncProgress, network, tag }));
|
|
103
|
-
if (tag === "end" && checkpoints.some((c) => c === undefined)) {
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
106
|
-
if (tag === "current" && checkpoints.every((c) => c === undefined)) {
|
|
107
|
-
return undefined;
|
|
108
|
-
}
|
|
109
|
-
return min(...checkpoints);
|
|
110
|
-
};
|
|
111
|
-
const updateHistoricalStatus = ({ events, checkpoint, network, }) => {
|
|
112
|
-
if (Number(decodeCheckpoint(checkpoint).chainId) === network.chainId) {
|
|
113
|
-
status[network.name].block = {
|
|
114
|
-
timestamp: decodeCheckpoint(checkpoint).blockTimestamp,
|
|
115
|
-
number: Number(decodeCheckpoint(checkpoint).blockNumber),
|
|
116
|
-
};
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
let i = events.length - 1;
|
|
120
|
-
while (i >= 0) {
|
|
121
|
-
const event = events[i];
|
|
122
|
-
if (network.chainId === event.chainId) {
|
|
123
|
-
status[network.name].block = {
|
|
124
|
-
timestamp: decodeCheckpoint(event.checkpoint).blockTimestamp,
|
|
125
|
-
number: Number(decodeCheckpoint(event.checkpoint).blockNumber),
|
|
126
|
-
};
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
i--;
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
const updateRealtimeStatus = ({ checkpoint, network, }) => {
|
|
133
|
-
const localBlock = perNetworkSync
|
|
134
|
-
.get(network)
|
|
135
|
-
.realtimeSync.unfinalizedBlocks.findLast((block) => encodeCheckpoint(blockToCheckpoint(block, network.chainId, "up")) <=
|
|
136
|
-
checkpoint);
|
|
137
|
-
if (localBlock !== undefined) {
|
|
138
|
-
status[network.name].block = {
|
|
139
|
-
timestamp: hexToNumber(localBlock.timestamp),
|
|
140
|
-
number: hexToNumber(localBlock.number),
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
async function* getEvents() {
|
|
145
|
-
let cursor = params.initialCheckpoint !== ZERO_CHECKPOINT_STRING
|
|
146
|
-
? params.initialCheckpoint
|
|
147
|
-
: getOmnichainCheckpoint({ tag: "start" });
|
|
148
|
-
const to = min(getOmnichainCheckpoint({ tag: "end" }), getOmnichainCheckpoint({ tag: "finalized" }));
|
|
149
|
-
const eventGenerators = Array.from(perNetworkSync.entries()).map(([network, { syncProgress, historicalSync }]) => {
|
|
150
|
-
const sources = params.indexingBuild.sources.filter(({ filter }) => filter.chainId === network.chainId);
|
|
151
|
-
const localSyncGenerator = getLocalSyncGenerator({
|
|
152
|
-
common: params.common,
|
|
153
|
-
network,
|
|
154
|
-
syncProgress,
|
|
155
|
-
historicalSync,
|
|
156
|
-
});
|
|
157
|
-
const localEventGenerator = getLocalEventGenerator({
|
|
158
|
-
common: params.common,
|
|
159
|
-
network,
|
|
160
|
-
syncStore: params.syncStore,
|
|
161
|
-
sources,
|
|
162
|
-
localSyncGenerator,
|
|
163
|
-
from: params.initialCheckpoint !== ZERO_CHECKPOINT_STRING
|
|
164
|
-
? params.initialCheckpoint
|
|
165
|
-
: getChainCheckpoint({ syncProgress, network, tag: "start" }),
|
|
166
|
-
to,
|
|
167
|
-
limit: Math.round(params.common.options.syncEventsQuerySize /
|
|
168
|
-
(params.indexingBuild.networks.length * 2)),
|
|
169
|
-
});
|
|
170
|
-
async function* decodeEventGenerator() {
|
|
171
|
-
for await (const { events, checkpoint } of localEventGenerator) {
|
|
172
|
-
const decodedEvents = decodeEvents(params.common, sources, events);
|
|
173
|
-
params.common.logger.debug({
|
|
174
|
-
service: "app",
|
|
175
|
-
msg: `Decoded ${decodedEvents.length} '${network.name}' events`,
|
|
176
|
-
});
|
|
177
|
-
yield { events: decodedEvents, checkpoint };
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return bufferAsyncGenerator(decodeEventGenerator(), 1);
|
|
181
|
-
});
|
|
182
|
-
const mergeAsync = params.ordering === "multichain"
|
|
183
|
-
? mergeAsyncGenerators
|
|
184
|
-
: mergeAsyncGeneratorsWithEventOrder;
|
|
185
|
-
for await (const { events, checkpoint } of mergeAsync(eventGenerators)) {
|
|
186
|
-
if (params.ordering === "multichain") {
|
|
187
|
-
const network = params.indexingBuild.networks.find((network) => network.chainId === Number(decodeCheckpoint(checkpoint).chainId));
|
|
188
|
-
params.common.logger.debug({
|
|
189
|
-
service: "sync",
|
|
190
|
-
msg: `Sequenced ${events.length} '${network.name}' events for timestamp range [${decodeCheckpoint(cursor).blockTimestamp}, ${decodeCheckpoint(checkpoint).blockTimestamp}]`,
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
params.common.logger.debug({
|
|
195
|
-
service: "sync",
|
|
196
|
-
msg: `Sequenced ${events.length} events for timestamp range [${decodeCheckpoint(cursor).blockTimestamp}, ${decodeCheckpoint(checkpoint).blockTimestamp}]`,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
for (const network of params.indexingBuild.networks) {
|
|
200
|
-
updateHistoricalStatus({ events, checkpoint, network });
|
|
201
|
-
}
|
|
202
|
-
yield events;
|
|
203
|
-
cursor = checkpoint;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
/** Events that have been executed but not finalized. */
|
|
207
|
-
let executedEvents = [];
|
|
208
|
-
/** Events that have not been executed. */
|
|
209
|
-
let pendingEvents = [];
|
|
210
|
-
const realtimeMutex = createMutex();
|
|
211
|
-
const checkpoints = {
|
|
212
|
-
// Note: `checkpoints.current` not used in multichain ordering
|
|
213
|
-
current: ZERO_CHECKPOINT_STRING,
|
|
214
|
-
finalized: ZERO_CHECKPOINT_STRING,
|
|
215
|
-
};
|
|
216
|
-
// Note: `latencyTimers` not used in multichain ordering
|
|
217
|
-
const latencyTimers = new Map();
|
|
218
|
-
const onRealtimeSyncEvent = (event, { network, sources, syncProgress, realtimeSync, }) => {
|
|
219
|
-
switch (event.type) {
|
|
220
|
-
case "block": {
|
|
221
|
-
const events = buildEvents({
|
|
222
|
-
sources: params.indexingBuild.sources,
|
|
223
|
-
chainId: network.chainId,
|
|
224
|
-
blockWithEventData: event,
|
|
225
|
-
finalizedChildAddresses: realtimeSync.finalizedChildAddresses,
|
|
226
|
-
unfinalizedChildAddresses: realtimeSync.unfinalizedChildAddresses,
|
|
227
|
-
});
|
|
228
|
-
params.common.logger.debug({
|
|
229
|
-
service: "sync",
|
|
230
|
-
msg: `Extracted ${events.length} '${network.name}' events for block ${hexToNumber(event.block.number)}`,
|
|
231
|
-
});
|
|
232
|
-
if (params.ordering === "multichain") {
|
|
233
|
-
// Note: `checkpoints.current` not used in multichain ordering
|
|
234
|
-
const checkpoint = getMultichainCheckpoint({
|
|
235
|
-
tag: "current",
|
|
236
|
-
network,
|
|
237
|
-
});
|
|
238
|
-
status[network.name].block = {
|
|
239
|
-
timestamp: hexToNumber(event.block.timestamp),
|
|
240
|
-
number: hexToNumber(event.block.number),
|
|
241
|
-
};
|
|
242
|
-
const readyEvents = events.concat(pendingEvents);
|
|
243
|
-
pendingEvents = [];
|
|
244
|
-
executedEvents = executedEvents.concat(readyEvents);
|
|
245
|
-
const decodedEvents = decodeEvents(params.common, sources, readyEvents);
|
|
246
|
-
params.common.logger.debug({
|
|
247
|
-
service: "sync",
|
|
248
|
-
msg: `Decoded ${decodedEvents.length} '${network.name}' events for block ${hexToNumber(event.block.number)}`,
|
|
249
|
-
});
|
|
250
|
-
params.common.logger.debug({
|
|
251
|
-
service: "sync",
|
|
252
|
-
msg: `Sequenced ${decodedEvents.length} '${network.name}' events for block ${hexToNumber(event.block.number)}`,
|
|
253
|
-
});
|
|
254
|
-
params
|
|
255
|
-
.onRealtimeEvent({
|
|
256
|
-
type: "block",
|
|
257
|
-
checkpoint,
|
|
258
|
-
status: structuredClone(status),
|
|
259
|
-
events: decodedEvents.sort((a, b) => a.checkpoint < b.checkpoint ? -1 : 1),
|
|
260
|
-
network,
|
|
261
|
-
})
|
|
262
|
-
.then(() => {
|
|
263
|
-
// update `ponder_realtime_latency` metric
|
|
264
|
-
if (event.endClock) {
|
|
265
|
-
params.common.metrics.ponder_realtime_latency.observe({ network: network.name }, event.endClock());
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
const from = checkpoints.current;
|
|
271
|
-
checkpoints.current = getOmnichainCheckpoint({ tag: "current" });
|
|
272
|
-
const to = getOmnichainCheckpoint({ tag: "current" });
|
|
273
|
-
if (event.endClock !== undefined) {
|
|
274
|
-
latencyTimers.set(encodeCheckpoint(blockToCheckpoint(event.block, network.chainId, "up")), event.endClock);
|
|
275
|
-
}
|
|
276
|
-
if (to > from) {
|
|
277
|
-
for (const network of params.indexingBuild.networks) {
|
|
278
|
-
updateRealtimeStatus({ checkpoint: to, network });
|
|
279
|
-
}
|
|
280
|
-
// Move ready events from pending to executed
|
|
281
|
-
const readyEvents = pendingEvents
|
|
282
|
-
.concat(events)
|
|
283
|
-
.filter(({ checkpoint }) => checkpoint < to);
|
|
284
|
-
pendingEvents = pendingEvents
|
|
285
|
-
.concat(events)
|
|
286
|
-
.filter(({ checkpoint }) => checkpoint > to);
|
|
287
|
-
executedEvents = executedEvents.concat(readyEvents);
|
|
288
|
-
const decodedEvents = decodeEvents(params.common, sources, readyEvents);
|
|
289
|
-
params.common.logger.debug({
|
|
290
|
-
service: "sync",
|
|
291
|
-
msg: `Decoded ${decodedEvents.length} '${network.name}' events for block ${hexToNumber(event.block.number)}`,
|
|
292
|
-
});
|
|
293
|
-
params.common.logger.debug({
|
|
294
|
-
service: "sync",
|
|
295
|
-
msg: `Sequenced ${decodedEvents.length} '${network.name}' events for timestamp range [${decodeCheckpoint(from).blockTimestamp}, ${decodeCheckpoint(to).blockTimestamp}]`,
|
|
296
|
-
});
|
|
297
|
-
params
|
|
298
|
-
.onRealtimeEvent({
|
|
299
|
-
type: "block",
|
|
300
|
-
checkpoint: to,
|
|
301
|
-
status: structuredClone(status),
|
|
302
|
-
events: decodedEvents.sort((a, b) => a.checkpoint < b.checkpoint ? -1 : 1),
|
|
303
|
-
network,
|
|
304
|
-
})
|
|
305
|
-
.then(() => {
|
|
306
|
-
// update `ponder_realtime_latency` metric
|
|
307
|
-
for (const [checkpoint, timer] of latencyTimers) {
|
|
308
|
-
if (checkpoint > from && checkpoint <= to) {
|
|
309
|
-
const chainId = Number(decodeCheckpoint(checkpoint).chainId);
|
|
310
|
-
const network = params.indexingBuild.networks.find((network) => network.chainId === chainId);
|
|
311
|
-
params.common.metrics.ponder_realtime_latency.observe({ network: network.name }, timer());
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
pendingEvents = pendingEvents.concat(events);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
break;
|
|
321
|
-
}
|
|
322
|
-
case "finalize": {
|
|
323
|
-
const from = checkpoints.finalized;
|
|
324
|
-
checkpoints.finalized = getOmnichainCheckpoint({ tag: "finalized" });
|
|
325
|
-
const to = getOmnichainCheckpoint({ tag: "finalized" });
|
|
326
|
-
if (params.ordering === "omnichain" &&
|
|
327
|
-
getChainCheckpoint({ syncProgress, network, tag: "finalized" }) >
|
|
328
|
-
getOmnichainCheckpoint({ tag: "current" })) {
|
|
329
|
-
params.common.logger.warn({
|
|
330
|
-
service: "sync",
|
|
331
|
-
msg: `Finalized '${network.name}' block has surpassed overall indexing checkpoint`,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
// Remove all finalized data
|
|
335
|
-
executedEvents = executedEvents.filter((e) => e.checkpoint > to);
|
|
336
|
-
// Raise event to parent function (runtime)
|
|
337
|
-
if (to > from) {
|
|
338
|
-
params.onRealtimeEvent({
|
|
339
|
-
type: "finalize",
|
|
340
|
-
checkpoint: to,
|
|
341
|
-
network,
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
case "reorg": {
|
|
347
|
-
// Remove all reorged data
|
|
348
|
-
let reorgedEvents = 0;
|
|
349
|
-
const isReorgedEvent = ({ chainId, block }) => {
|
|
350
|
-
if (chainId === network.chainId &&
|
|
351
|
-
Number(block.number) > hexToNumber(event.block.number)) {
|
|
352
|
-
reorgedEvents++;
|
|
353
|
-
return true;
|
|
354
|
-
}
|
|
355
|
-
return false;
|
|
356
|
-
};
|
|
357
|
-
pendingEvents = pendingEvents.filter((e) => isReorgedEvent(e) === false);
|
|
358
|
-
executedEvents = executedEvents.filter((e) => isReorgedEvent(e) === false);
|
|
359
|
-
params.common.logger.debug({
|
|
360
|
-
service: "sync",
|
|
361
|
-
msg: `Removed ${reorgedEvents} reorged '${network.name}' events`,
|
|
362
|
-
});
|
|
363
|
-
if (params.ordering === "multichain") {
|
|
364
|
-
// Note: `checkpoints.current` not used in multichain ordering
|
|
365
|
-
const checkpoint = getMultichainCheckpoint({
|
|
366
|
-
tag: "current",
|
|
367
|
-
network,
|
|
368
|
-
});
|
|
369
|
-
// Move events from executed to pending
|
|
370
|
-
const events = executedEvents.filter((e) => e.checkpoint > checkpoint);
|
|
371
|
-
executedEvents = executedEvents.filter((e) => e.checkpoint < checkpoint);
|
|
372
|
-
pendingEvents = pendingEvents.concat(events);
|
|
373
|
-
params.common.logger.debug({
|
|
374
|
-
service: "sync",
|
|
375
|
-
msg: `Rescheduled ${events.length} reorged events`,
|
|
376
|
-
});
|
|
377
|
-
params.onRealtimeEvent({ type: "reorg", checkpoint, network });
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
const from = checkpoints.current;
|
|
381
|
-
checkpoints.current = getOmnichainCheckpoint({ tag: "current" });
|
|
382
|
-
const to = getOmnichainCheckpoint({ tag: "current" });
|
|
383
|
-
// Move events from executed to pending
|
|
384
|
-
const events = executedEvents.filter((e) => e.checkpoint > to);
|
|
385
|
-
executedEvents = executedEvents.filter((e) => e.checkpoint < to);
|
|
386
|
-
pendingEvents = pendingEvents.concat(events);
|
|
387
|
-
params.common.logger.debug({
|
|
388
|
-
service: "sync",
|
|
389
|
-
msg: `Rescheduled ${events.length} reorged events`,
|
|
390
|
-
});
|
|
391
|
-
if (to < from) {
|
|
392
|
-
params.onRealtimeEvent({
|
|
393
|
-
type: "reorg",
|
|
394
|
-
checkpoint: to,
|
|
395
|
-
network,
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
break;
|
|
400
|
-
}
|
|
401
|
-
default:
|
|
402
|
-
never(event);
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
await Promise.all(params.indexingBuild.networks.map(async (network, index) => {
|
|
406
|
-
const requestQueue = params.requestQueues[index];
|
|
407
|
-
const sources = params.indexingBuild.sources.filter(({ filter }) => filter.chainId === network.chainId);
|
|
408
|
-
// Invalidate sync cache for devnet sources
|
|
409
|
-
if (network.disableCache) {
|
|
410
|
-
params.common.logger.warn({
|
|
411
|
-
service: "sync",
|
|
412
|
-
msg: `Deleting cache records for '${network.name}'`,
|
|
413
|
-
});
|
|
414
|
-
await params.syncStore.pruneByChain({
|
|
415
|
-
chainId: network.chainId,
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
const historicalSync = await createHistoricalSync({
|
|
419
|
-
common: params.common,
|
|
420
|
-
sources,
|
|
421
|
-
syncStore: params.syncStore,
|
|
422
|
-
requestQueue,
|
|
423
|
-
network,
|
|
424
|
-
onFatalError: params.onFatalError,
|
|
425
|
-
});
|
|
426
|
-
const syncProgress = await getLocalSyncProgress({
|
|
427
|
-
common: params.common,
|
|
428
|
-
network,
|
|
429
|
-
sources,
|
|
430
|
-
requestQueue,
|
|
431
|
-
intervalsCache: historicalSync.intervalsCache,
|
|
432
|
-
});
|
|
433
|
-
const realtimeSync = createRealtimeSync({
|
|
434
|
-
common: params.common,
|
|
435
|
-
sources,
|
|
436
|
-
requestQueue,
|
|
437
|
-
network,
|
|
438
|
-
onEvent: realtimeMutex((event) => perChainOnRealtimeSyncEvent(event)
|
|
439
|
-
.then((event) => {
|
|
440
|
-
onRealtimeSyncEvent(event, {
|
|
441
|
-
network,
|
|
442
|
-
sources,
|
|
443
|
-
syncProgress,
|
|
444
|
-
realtimeSync,
|
|
445
|
-
});
|
|
446
|
-
if (isSyncFinalized(syncProgress) && isSyncEnd(syncProgress)) {
|
|
447
|
-
// The realtime service can be killed if `endBlock` is
|
|
448
|
-
// defined has become finalized.
|
|
449
|
-
params.common.metrics.ponder_sync_is_realtime.set({ network: network.name }, 0);
|
|
450
|
-
params.common.metrics.ponder_sync_is_complete.set({ network: network.name }, 1);
|
|
451
|
-
params.common.logger.info({
|
|
452
|
-
service: "sync",
|
|
453
|
-
msg: `Killing '${network.name}' live indexing because the end block ${hexToNumber(syncProgress.end.number)} has been finalized`,
|
|
454
|
-
});
|
|
455
|
-
realtimeSync.kill();
|
|
456
|
-
}
|
|
457
|
-
})
|
|
458
|
-
.catch((error) => {
|
|
459
|
-
params.common.logger.error({
|
|
460
|
-
service: "sync",
|
|
461
|
-
msg: `Fatal error: Unable to process ${event.type} event`,
|
|
462
|
-
error,
|
|
463
|
-
});
|
|
464
|
-
params.onFatalError(error);
|
|
465
|
-
})),
|
|
466
|
-
onFatalError: params.onFatalError,
|
|
467
|
-
});
|
|
468
|
-
params.common.metrics.ponder_sync_is_realtime.set({ network: network.name }, 0);
|
|
469
|
-
params.common.metrics.ponder_sync_is_complete.set({ network: network.name }, 0);
|
|
470
|
-
perNetworkSync.set(network, {
|
|
471
|
-
syncProgress,
|
|
472
|
-
historicalSync,
|
|
473
|
-
realtimeSync,
|
|
474
|
-
});
|
|
475
|
-
const perChainOnRealtimeSyncEvent = getPerChainOnRealtimeSyncEvent({
|
|
476
|
-
common: params.common,
|
|
477
|
-
network,
|
|
478
|
-
sources,
|
|
479
|
-
syncStore: params.syncStore,
|
|
480
|
-
syncProgress,
|
|
481
|
-
});
|
|
482
|
-
}));
|
|
483
|
-
const status = {};
|
|
484
|
-
const seconds = {};
|
|
485
|
-
for (const network of params.indexingBuild.networks) {
|
|
486
|
-
status[network.name] = { block: null, ready: false };
|
|
487
|
-
}
|
|
488
|
-
if (params.ordering === "multichain") {
|
|
489
|
-
for (const network of params.indexingBuild.networks) {
|
|
490
|
-
seconds[network.name] = {
|
|
491
|
-
start: decodeCheckpoint(getMultichainCheckpoint({ tag: "start", network })).blockTimestamp,
|
|
492
|
-
end: decodeCheckpoint(min(getOmnichainCheckpoint({ tag: "end" }), getOmnichainCheckpoint({ tag: "finalized" }))).blockTimestamp,
|
|
493
|
-
cached: decodeCheckpoint(params.initialCheckpoint).blockTimestamp,
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
for (const network of params.indexingBuild.networks) {
|
|
499
|
-
seconds[network.name] = {
|
|
500
|
-
start: decodeCheckpoint(getOmnichainCheckpoint({ tag: "start" }))
|
|
501
|
-
.blockTimestamp,
|
|
502
|
-
end: decodeCheckpoint(min(getOmnichainCheckpoint({ tag: "end" }), getOmnichainCheckpoint({ tag: "finalized" }))).blockTimestamp,
|
|
503
|
-
cached: decodeCheckpoint(params.initialCheckpoint).blockTimestamp,
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
return {
|
|
508
|
-
getEvents,
|
|
509
|
-
async startRealtime() {
|
|
510
|
-
for (const network of params.indexingBuild.networks) {
|
|
511
|
-
const { syncProgress, realtimeSync } = perNetworkSync.get(network);
|
|
512
|
-
const filters = params.indexingBuild.sources
|
|
513
|
-
.filter(({ filter }) => filter.chainId === network.chainId)
|
|
514
|
-
.map(({ filter }) => filter);
|
|
515
|
-
status[network.name].block = {
|
|
516
|
-
number: hexToNumber(syncProgress.current.number),
|
|
517
|
-
timestamp: hexToNumber(syncProgress.current.timestamp),
|
|
518
|
-
};
|
|
519
|
-
status[network.name].ready = true;
|
|
520
|
-
// Fetch any events between the omnichain finalized checkpoint and the single-chain
|
|
521
|
-
// finalized checkpoint and add them to pendingEvents. These events are synced during
|
|
522
|
-
// the historical phase, but must be indexed in the realtime phase because events
|
|
523
|
-
// synced in realtime on other chains might be ordered before them.
|
|
524
|
-
const from = getOmnichainCheckpoint({ tag: "finalized" });
|
|
525
|
-
const finalized = getChainCheckpoint({
|
|
526
|
-
syncProgress,
|
|
527
|
-
network,
|
|
528
|
-
tag: "finalized",
|
|
529
|
-
});
|
|
530
|
-
const end = getChainCheckpoint({
|
|
531
|
-
syncProgress,
|
|
532
|
-
network,
|
|
533
|
-
tag: "end",
|
|
534
|
-
});
|
|
535
|
-
const to = min(finalized, end);
|
|
536
|
-
if (to > from) {
|
|
537
|
-
const events = await params.syncStore.getEvents({
|
|
538
|
-
filters,
|
|
539
|
-
from,
|
|
540
|
-
to,
|
|
541
|
-
});
|
|
542
|
-
params.common.logger.debug({
|
|
543
|
-
service: "sync",
|
|
544
|
-
msg: `Extracted and scheduled ${events.events.length} '${network.name}' events`,
|
|
545
|
-
});
|
|
546
|
-
pendingEvents = pendingEvents.concat(events.events);
|
|
547
|
-
}
|
|
548
|
-
if (isSyncEnd(syncProgress)) {
|
|
549
|
-
params.common.metrics.ponder_sync_is_complete.set({ network: network.name }, 1);
|
|
550
|
-
}
|
|
551
|
-
else {
|
|
552
|
-
params.common.metrics.ponder_sync_is_realtime.set({ network: network.name }, 1);
|
|
553
|
-
const initialChildAddresses = new Map();
|
|
554
|
-
for (const filter of filters) {
|
|
555
|
-
switch (filter.type) {
|
|
556
|
-
case "log":
|
|
557
|
-
if (isAddressFactory(filter.address)) {
|
|
558
|
-
const addresses = await params.syncStore.getChildAddresses({
|
|
559
|
-
filter: filter.address,
|
|
560
|
-
});
|
|
561
|
-
initialChildAddresses.set(filter.address, new Set(addresses));
|
|
562
|
-
}
|
|
563
|
-
break;
|
|
564
|
-
case "transaction":
|
|
565
|
-
case "transfer":
|
|
566
|
-
case "trace":
|
|
567
|
-
if (isAddressFactory(filter.fromAddress)) {
|
|
568
|
-
const addresses = await params.syncStore.getChildAddresses({
|
|
569
|
-
filter: filter.fromAddress,
|
|
570
|
-
});
|
|
571
|
-
initialChildAddresses.set(filter.fromAddress, new Set(addresses));
|
|
572
|
-
}
|
|
573
|
-
if (isAddressFactory(filter.toAddress)) {
|
|
574
|
-
const addresses = await params.syncStore.getChildAddresses({
|
|
575
|
-
filter: filter.toAddress,
|
|
576
|
-
});
|
|
577
|
-
initialChildAddresses.set(filter.toAddress, new Set(addresses));
|
|
578
|
-
}
|
|
579
|
-
break;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
params.common.logger.debug({
|
|
583
|
-
service: "sync",
|
|
584
|
-
msg: `Initialized '${network.name}' realtime sync with ${initialChildAddresses.size} factory child addresses`,
|
|
585
|
-
});
|
|
586
|
-
realtimeSync.start({ syncProgress, initialChildAddresses });
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
},
|
|
590
|
-
getStatus() {
|
|
591
|
-
return status;
|
|
592
|
-
},
|
|
593
|
-
seconds,
|
|
594
|
-
getFinalizedCheckpoint() {
|
|
595
|
-
return getOmnichainCheckpoint({ tag: "finalized" });
|
|
596
|
-
},
|
|
597
|
-
};
|
|
598
|
-
};
|
|
599
|
-
export const getPerChainOnRealtimeSyncEvent = ({ common, network, sources, syncStore, syncProgress, }) => {
|
|
600
|
-
let unfinalizedBlocks = [];
|
|
601
|
-
return async (event) => {
|
|
602
|
-
switch (event.type) {
|
|
603
|
-
case "block": {
|
|
604
|
-
syncProgress.current = event.block;
|
|
605
|
-
common.logger.debug({
|
|
606
|
-
service: "sync",
|
|
607
|
-
msg: `Updated '${network.name}' current block to ${hexToNumber(event.block.number)}`,
|
|
608
|
-
});
|
|
609
|
-
common.metrics.ponder_sync_block.set({ network: network.name }, hexToNumber(syncProgress.current.number));
|
|
610
|
-
unfinalizedBlocks.push(event);
|
|
611
|
-
return event;
|
|
612
|
-
}
|
|
613
|
-
case "finalize": {
|
|
614
|
-
const finalizedInterval = [
|
|
615
|
-
hexToNumber(syncProgress.finalized.number),
|
|
616
|
-
hexToNumber(event.block.number),
|
|
617
|
-
];
|
|
618
|
-
syncProgress.finalized = event.block;
|
|
619
|
-
common.logger.debug({
|
|
620
|
-
service: "sync",
|
|
621
|
-
msg: `Updated '${network.name}' finalized block to ${hexToNumber(event.block.number)}`,
|
|
622
|
-
});
|
|
623
|
-
// Remove all finalized data
|
|
624
|
-
const finalizedBlocks = unfinalizedBlocks.filter(({ block }) => hexToNumber(block.number) <= hexToNumber(event.block.number));
|
|
625
|
-
unfinalizedBlocks = unfinalizedBlocks.filter(({ block }) => hexToNumber(block.number) > hexToNumber(event.block.number));
|
|
626
|
-
// Add finalized blocks, logs, transactions, receipts, and traces to the sync-store.
|
|
627
|
-
await Promise.all([
|
|
628
|
-
syncStore.insertBlocks({
|
|
629
|
-
blocks: finalizedBlocks
|
|
630
|
-
.filter(({ hasMatchedFilter }) => hasMatchedFilter)
|
|
631
|
-
.map(({ block }) => block),
|
|
632
|
-
chainId: network.chainId,
|
|
633
|
-
}),
|
|
634
|
-
syncStore.insertLogs({
|
|
635
|
-
logs: finalizedBlocks.flatMap(({ logs, block }) => logs.map((log) => ({ log, block }))),
|
|
636
|
-
shouldUpdateCheckpoint: true,
|
|
637
|
-
chainId: network.chainId,
|
|
638
|
-
}),
|
|
639
|
-
syncStore.insertLogs({
|
|
640
|
-
logs: finalizedBlocks.flatMap(({ factoryLogs }) => factoryLogs.map((log) => ({ log }))),
|
|
641
|
-
shouldUpdateCheckpoint: false,
|
|
642
|
-
chainId: network.chainId,
|
|
643
|
-
}),
|
|
644
|
-
syncStore.insertTransactions({
|
|
645
|
-
transactions: finalizedBlocks.flatMap(({ transactions, block }) => transactions.map((transaction) => ({
|
|
646
|
-
transaction,
|
|
647
|
-
block,
|
|
648
|
-
}))),
|
|
649
|
-
chainId: network.chainId,
|
|
650
|
-
}),
|
|
651
|
-
syncStore.insertTransactionReceipts({
|
|
652
|
-
transactionReceipts: finalizedBlocks.flatMap(({ transactionReceipts }) => transactionReceipts),
|
|
653
|
-
chainId: network.chainId,
|
|
654
|
-
}),
|
|
655
|
-
syncStore.insertTraces({
|
|
656
|
-
traces: finalizedBlocks.flatMap(({ traces, block, transactions }) => traces.map((trace) => ({
|
|
657
|
-
trace,
|
|
658
|
-
block,
|
|
659
|
-
transaction: transactions.find((t) => t.hash === trace.transactionHash),
|
|
660
|
-
}))),
|
|
661
|
-
chainId: network.chainId,
|
|
662
|
-
}),
|
|
663
|
-
]);
|
|
664
|
-
// Add corresponding intervals to the sync-store
|
|
665
|
-
// Note: this should happen after insertion so the database doesn't become corrupted
|
|
666
|
-
if (network.disableCache === false) {
|
|
667
|
-
const syncedIntervals = [];
|
|
668
|
-
for (const { filter } of sources) {
|
|
669
|
-
const intervals = intervalIntersection([finalizedInterval], [
|
|
670
|
-
[
|
|
671
|
-
filter.fromBlock ?? 0,
|
|
672
|
-
filter.toBlock ?? Number.POSITIVE_INFINITY,
|
|
673
|
-
],
|
|
674
|
-
]);
|
|
675
|
-
for (const interval of intervals) {
|
|
676
|
-
syncedIntervals.push({ interval, filter });
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
await syncStore.insertIntervals({
|
|
680
|
-
intervals: syncedIntervals,
|
|
681
|
-
chainId: network.chainId,
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
return event;
|
|
685
|
-
}
|
|
686
|
-
case "reorg": {
|
|
687
|
-
syncProgress.current = event.block;
|
|
688
|
-
common.logger.debug({
|
|
689
|
-
service: "sync",
|
|
690
|
-
msg: `Updated '${network.name}' current block to ${hexToNumber(event.block.number)}`,
|
|
691
|
-
});
|
|
692
|
-
common.metrics.ponder_sync_block.set({ network: network.name }, hexToNumber(syncProgress.current.number));
|
|
693
|
-
// Remove all reorged data
|
|
694
|
-
unfinalizedBlocks = unfinalizedBlocks.filter(({ block }) => hexToNumber(block.number) <= hexToNumber(event.block.number));
|
|
695
|
-
await syncStore.pruneRpcRequestResult({
|
|
696
|
-
chainId: network.chainId,
|
|
697
|
-
blocks: event.reorgedBlocks,
|
|
698
|
-
});
|
|
699
|
-
return event;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
};
|
|
703
|
-
};
|
|
704
|
-
export async function* getLocalEventGenerator(params) {
|
|
705
|
-
let cursor = params.from;
|
|
706
|
-
// Estimate optimal range (seconds) to query at a time, eventually
|
|
707
|
-
// used to determine `to` passed to `getEvents`.
|
|
708
|
-
let estimateSeconds = 1000;
|
|
709
|
-
params.common.logger.debug({
|
|
710
|
-
service: "sync",
|
|
711
|
-
msg: `Initialized '${params.network.name}' extract query for timestamp range [${decodeCheckpoint(params.from).blockTimestamp}, ${decodeCheckpoint(params.to).blockTimestamp}]`,
|
|
712
|
-
});
|
|
713
|
-
for await (const syncCheckpoint of bufferAsyncGenerator(params.localSyncGenerator, Number.POSITIVE_INFINITY)) {
|
|
714
|
-
let consecutiveErrors = 0;
|
|
715
|
-
while (cursor < min(syncCheckpoint, params.to)) {
|
|
716
|
-
const estimateCheckpoint = encodeCheckpoint({
|
|
717
|
-
...ZERO_CHECKPOINT,
|
|
718
|
-
chainId: BigInt(params.network.chainId),
|
|
719
|
-
blockTimestamp: Math.min(decodeCheckpoint(cursor).blockTimestamp + estimateSeconds, MAX_CHECKPOINT.blockTimestamp),
|
|
720
|
-
});
|
|
721
|
-
const to = min(syncCheckpoint, estimateCheckpoint, params.to);
|
|
722
|
-
try {
|
|
723
|
-
const { events, cursor: queryCursor } = await params.syncStore.getEvents({
|
|
724
|
-
filters: params.sources.map(({ filter }) => filter),
|
|
725
|
-
from: cursor,
|
|
726
|
-
to,
|
|
727
|
-
limit: params.limit,
|
|
728
|
-
});
|
|
729
|
-
params.common.logger.debug({
|
|
730
|
-
service: "sync",
|
|
731
|
-
msg: `Extracted ${events.length} '${params.network.name}' events for timestamp range [${decodeCheckpoint(cursor).blockTimestamp}, ${decodeCheckpoint(queryCursor).blockTimestamp}]`,
|
|
732
|
-
});
|
|
733
|
-
estimateSeconds = estimate({
|
|
734
|
-
from: decodeCheckpoint(cursor).blockTimestamp,
|
|
735
|
-
to: decodeCheckpoint(queryCursor).blockTimestamp,
|
|
736
|
-
target: params.limit,
|
|
737
|
-
result: events.length,
|
|
738
|
-
min: 10,
|
|
739
|
-
max: 86400,
|
|
740
|
-
prev: estimateSeconds,
|
|
741
|
-
maxIncrease: 1.08,
|
|
742
|
-
});
|
|
743
|
-
params.common.logger.debug({
|
|
744
|
-
service: "sync",
|
|
745
|
-
msg: `Updated '${params.network.name}' extract query estimate to ${estimateSeconds} seconds`,
|
|
746
|
-
});
|
|
747
|
-
consecutiveErrors = 0;
|
|
748
|
-
cursor = queryCursor;
|
|
749
|
-
yield { events, checkpoint: cursor };
|
|
750
|
-
}
|
|
751
|
-
catch (error) {
|
|
752
|
-
if (params.common.shutdown.isKilled) {
|
|
753
|
-
throw error;
|
|
754
|
-
}
|
|
755
|
-
params.common.logger.warn({
|
|
756
|
-
service: "sync",
|
|
757
|
-
msg: `Failed '${params.network.name}' extract query for timestamp range [${decodeCheckpoint(cursor).blockTimestamp}, ${decodeCheckpoint(to).blockTimestamp}]`,
|
|
758
|
-
error: error,
|
|
759
|
-
});
|
|
760
|
-
// Handle errors by reducing the requested range by 10x
|
|
761
|
-
estimateSeconds = Math.max(10, Math.round(estimateSeconds / 10));
|
|
762
|
-
params.common.logger.debug({
|
|
763
|
-
service: "sync",
|
|
764
|
-
msg: `Updated '${params.network.name}' getEvents query estimate to ${estimateSeconds} seconds`,
|
|
765
|
-
});
|
|
766
|
-
if (++consecutiveErrors > 4)
|
|
767
|
-
throw error;
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
export async function* getLocalSyncGenerator({ common, network, syncProgress, historicalSync, }) {
|
|
773
|
-
const label = { network: network.name };
|
|
774
|
-
let cursor = hexToNumber(syncProgress.start.number);
|
|
775
|
-
const last = getHistoricalLast(syncProgress);
|
|
776
|
-
// Estimate optimal range (blocks) to sync at a time, eventually to be used to
|
|
777
|
-
// determine `interval` passed to `historicalSync.sync()`.
|
|
778
|
-
let estimateRange = 25;
|
|
779
|
-
// Handle two special cases:
|
|
780
|
-
// 1. `syncProgress.start` > `syncProgress.finalized`
|
|
781
|
-
// 2. `cached` is defined
|
|
782
|
-
if (hexToNumber(syncProgress.start.number) >
|
|
783
|
-
hexToNumber(syncProgress.finalized.number)) {
|
|
784
|
-
syncProgress.current = syncProgress.finalized;
|
|
785
|
-
common.logger.warn({
|
|
786
|
-
service: "sync",
|
|
787
|
-
msg: `Skipped '${network.name}' historical sync because the start block is unfinalized`,
|
|
788
|
-
});
|
|
789
|
-
common.metrics.ponder_sync_block.set(label, hexToNumber(syncProgress.current.number));
|
|
790
|
-
common.metrics.ponder_historical_total_blocks.set(label, 0);
|
|
791
|
-
common.metrics.ponder_historical_cached_blocks.set(label, 0);
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
const totalInterval = [
|
|
795
|
-
hexToNumber(syncProgress.start.number),
|
|
796
|
-
hexToNumber(last.number),
|
|
797
|
-
];
|
|
798
|
-
common.logger.debug({
|
|
799
|
-
service: "sync",
|
|
800
|
-
msg: `Initialized '${network.name}' historical sync for block range [${totalInterval[0]}, ${totalInterval[1]}]`,
|
|
801
|
-
});
|
|
802
|
-
const requiredIntervals = Array.from(historicalSync.intervalsCache.entries()).flatMap(([filter, fragmentIntervals]) => intervalDifference([
|
|
803
|
-
[
|
|
804
|
-
filter.fromBlock ?? 0,
|
|
805
|
-
Math.min(filter.toBlock ?? Number.POSITIVE_INFINITY, totalInterval[1]),
|
|
806
|
-
],
|
|
807
|
-
], intervalIntersectionMany(fragmentIntervals.map(({ intervals }) => intervals))));
|
|
808
|
-
const required = intervalSum(intervalUnion(requiredIntervals));
|
|
809
|
-
const total = totalInterval[1] - totalInterval[0] + 1;
|
|
810
|
-
common.metrics.ponder_historical_total_blocks.set(label, total);
|
|
811
|
-
common.metrics.ponder_historical_cached_blocks.set(label, total - required);
|
|
812
|
-
// Handle cache hit
|
|
813
|
-
if (syncProgress.current !== undefined) {
|
|
814
|
-
common.metrics.ponder_sync_block.set(label, hexToNumber(syncProgress.current.number));
|
|
815
|
-
// `getEvents` can make progress without calling `sync`, so immediately "yield"
|
|
816
|
-
yield encodeCheckpoint(blockToCheckpoint(syncProgress.current, network.chainId, "up"));
|
|
817
|
-
if (hexToNumber(syncProgress.current.number) === hexToNumber(last.number)) {
|
|
818
|
-
common.logger.info({
|
|
819
|
-
service: "sync",
|
|
820
|
-
msg: `Skipped '${network.name}' historical sync because all blocks are cached`,
|
|
821
|
-
});
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
else {
|
|
825
|
-
common.logger.info({
|
|
826
|
-
service: "sync",
|
|
827
|
-
msg: `Started '${network.name}' historical sync with ${formatPercentage((total - required) / total)} cached`,
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
cursor = hexToNumber(syncProgress.current.number) + 1;
|
|
831
|
-
}
|
|
832
|
-
else {
|
|
833
|
-
common.logger.info({
|
|
834
|
-
service: "historical",
|
|
835
|
-
msg: `Started '${network.name}' historical sync with 0% cached`,
|
|
836
|
-
});
|
|
837
|
-
}
|
|
838
|
-
while (true) {
|
|
839
|
-
// Select a range of blocks to sync bounded by `finalizedBlock`.
|
|
840
|
-
// It is important for devEx that the interval is not too large, because
|
|
841
|
-
// time spent syncing ≈ time before indexing function feedback.
|
|
842
|
-
const interval = [
|
|
843
|
-
Math.min(cursor, hexToNumber(last.number)),
|
|
844
|
-
Math.min(cursor + estimateRange, hexToNumber(last.number)),
|
|
845
|
-
];
|
|
846
|
-
const endClock = startClock();
|
|
847
|
-
const synced = await historicalSync.sync(interval);
|
|
848
|
-
common.logger.debug({
|
|
849
|
-
service: "sync",
|
|
850
|
-
msg: `Synced ${interval[1] - interval[0] + 1} '${network.name}' blocks in range [${interval[0]}, ${interval[1]}]`,
|
|
851
|
-
});
|
|
852
|
-
// Update cursor to record progress
|
|
853
|
-
cursor = interval[1] + 1;
|
|
854
|
-
// `synced` will be undefined if a cache hit occur in `historicalSync.sync()`.
|
|
855
|
-
if (synced === undefined) {
|
|
856
|
-
// If the all known blocks are synced, then update `syncProgress.current`, else
|
|
857
|
-
// progress to the next iteration.
|
|
858
|
-
if (interval[1] === hexToNumber(last.number)) {
|
|
859
|
-
syncProgress.current = last;
|
|
860
|
-
}
|
|
861
|
-
else {
|
|
862
|
-
continue;
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
else {
|
|
866
|
-
if (interval[1] === hexToNumber(last.number)) {
|
|
867
|
-
syncProgress.current = last;
|
|
868
|
-
}
|
|
869
|
-
else {
|
|
870
|
-
syncProgress.current = synced;
|
|
871
|
-
}
|
|
872
|
-
const duration = endClock();
|
|
873
|
-
common.metrics.ponder_sync_block.set(label, hexToNumber(syncProgress.current.number));
|
|
874
|
-
common.metrics.ponder_historical_duration.observe(label, duration);
|
|
875
|
-
common.metrics.ponder_historical_completed_blocks.inc(label, interval[1] - interval[0] + 1);
|
|
876
|
-
// Use the duration and interval of the last call to `sync` to update estimate
|
|
877
|
-
// 25 <= estimate(new) <= estimate(prev) * 2 <= 100_000
|
|
878
|
-
estimateRange = Math.min(Math.max(25, Math.round((1000 * (interval[1] - interval[0])) / duration)), estimateRange * 2, 100000);
|
|
879
|
-
common.logger.debug({
|
|
880
|
-
service: "sync",
|
|
881
|
-
msg: `Updated '${network.name}' historical sync estimate to ${estimateRange} blocks`,
|
|
882
|
-
});
|
|
883
|
-
}
|
|
884
|
-
yield encodeCheckpoint(blockToCheckpoint(syncProgress.current, network.chainId, "up"));
|
|
885
|
-
if (isSyncEnd(syncProgress) || isSyncFinalized(syncProgress)) {
|
|
886
|
-
common.logger.info({
|
|
887
|
-
service: "sync",
|
|
888
|
-
msg: `Completed '${network.name}' historical sync`,
|
|
889
|
-
});
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
export const getLocalSyncProgress = async ({ common, sources, network, requestQueue, intervalsCache, }) => {
|
|
895
|
-
const syncProgress = {};
|
|
896
|
-
const filters = sources.map(({ filter }) => filter);
|
|
897
|
-
// Earliest `fromBlock` among all `filters`
|
|
898
|
-
const start = Math.min(...filters.map((filter) => filter.fromBlock ?? 0));
|
|
899
|
-
const cached = getCachedBlock({ filters, intervalsCache });
|
|
900
|
-
const diagnostics = await Promise.all(cached === undefined
|
|
901
|
-
? [
|
|
902
|
-
requestQueue.request({ method: "eth_chainId" }),
|
|
903
|
-
_eth_getBlockByNumber(requestQueue, { blockTag: "latest" }),
|
|
904
|
-
_eth_getBlockByNumber(requestQueue, { blockNumber: start }),
|
|
905
|
-
]
|
|
906
|
-
: [
|
|
907
|
-
requestQueue.request({ method: "eth_chainId" }),
|
|
908
|
-
_eth_getBlockByNumber(requestQueue, { blockTag: "latest" }),
|
|
909
|
-
_eth_getBlockByNumber(requestQueue, { blockNumber: start }),
|
|
910
|
-
_eth_getBlockByNumber(requestQueue, { blockNumber: cached }),
|
|
911
|
-
]);
|
|
912
|
-
const finalized = Math.max(0, hexToNumber(diagnostics[1].number) - network.finalityBlockCount);
|
|
913
|
-
syncProgress.finalized = await _eth_getBlockByNumber(requestQueue, {
|
|
914
|
-
blockNumber: finalized,
|
|
915
|
-
});
|
|
916
|
-
syncProgress.start = diagnostics[2];
|
|
917
|
-
if (diagnostics.length === 4) {
|
|
918
|
-
syncProgress.current = diagnostics[3];
|
|
919
|
-
}
|
|
920
|
-
// Warn if the config has a different chainId than the remote.
|
|
921
|
-
if (hexToNumber(diagnostics[0]) !== network.chainId) {
|
|
922
|
-
common.logger.warn({
|
|
923
|
-
service: "sync",
|
|
924
|
-
msg: `Remote chain ID (${diagnostics[0]}) does not match configured chain ID (${network.chainId}) for network "${network.name}"`,
|
|
925
|
-
});
|
|
926
|
-
}
|
|
927
|
-
if (filters.some((filter) => filter.toBlock === undefined)) {
|
|
928
|
-
return syncProgress;
|
|
929
|
-
}
|
|
930
|
-
// Latest `toBlock` among all `filters`
|
|
931
|
-
const end = Math.max(...filters.map((filter) => filter.toBlock));
|
|
932
|
-
if (end > hexToNumber(diagnostics[1].number)) {
|
|
933
|
-
syncProgress.end = {
|
|
934
|
-
number: toHex(end),
|
|
935
|
-
hash: "0x",
|
|
936
|
-
parentHash: "0x",
|
|
937
|
-
timestamp: toHex(MAX_CHECKPOINT.blockTimestamp),
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
else {
|
|
941
|
-
syncProgress.end = await _eth_getBlockByNumber(requestQueue, {
|
|
942
|
-
blockNumber: end,
|
|
943
|
-
});
|
|
944
|
-
}
|
|
945
|
-
return syncProgress;
|
|
946
|
-
};
|
|
947
|
-
/** Returns the closest-to-tip block that has been synced for all `sources`. */
|
|
948
|
-
export const getCachedBlock = ({ filters, intervalsCache, }) => {
|
|
949
|
-
const latestCompletedBlocks = filters.map((filter) => {
|
|
950
|
-
const requiredInterval = [
|
|
951
|
-
filter.fromBlock ?? 0,
|
|
952
|
-
filter.toBlock ?? Number.POSITIVE_INFINITY,
|
|
953
|
-
];
|
|
954
|
-
const fragmentIntervals = intervalsCache.get(filter);
|
|
955
|
-
const completedIntervals = sortIntervals(intervalIntersection([requiredInterval], intervalIntersectionMany(fragmentIntervals.map(({ intervals }) => intervals))));
|
|
956
|
-
if (completedIntervals.length === 0)
|
|
957
|
-
return undefined;
|
|
958
|
-
const earliestCompletedInterval = completedIntervals[0];
|
|
959
|
-
if (earliestCompletedInterval[0] !== (filter.fromBlock ?? 0)) {
|
|
960
|
-
return undefined;
|
|
961
|
-
}
|
|
962
|
-
return earliestCompletedInterval[1];
|
|
963
|
-
});
|
|
964
|
-
const minCompletedBlock = Math.min(...latestCompletedBlocks.filter((block) => block !== undefined));
|
|
965
|
-
// Filter i has known progress if a completed interval is found or if
|
|
966
|
-
// `_latestCompletedBlocks[i]` is undefined but `filters[i].fromBlock`
|
|
967
|
-
// is > `_minCompletedBlock`.
|
|
968
|
-
if (latestCompletedBlocks.every((block, i) => block !== undefined || (filters[i].fromBlock ?? 0) > minCompletedBlock)) {
|
|
969
|
-
return minCompletedBlock;
|
|
970
|
-
}
|
|
971
|
-
return undefined;
|
|
972
|
-
};
|
|
973
|
-
/**
|
|
974
|
-
* Merges multiple event generators into a single generator while preserving
|
|
975
|
-
* the order of events.
|
|
976
|
-
*
|
|
977
|
-
* @param generators - Generators to merge.
|
|
978
|
-
* @returns A single generator that yields events from all generators.
|
|
979
|
-
*/
|
|
980
|
-
export async function* mergeAsyncGeneratorsWithEventOrder(generators) {
|
|
981
|
-
const results = await Promise.all(generators.map((gen) => gen.next()));
|
|
982
|
-
while (results.some((res) => res.done !== true)) {
|
|
983
|
-
const supremum = min(...results.map((res) => (res.done ? undefined : res.value.checkpoint)));
|
|
984
|
-
const eventArrays = [];
|
|
985
|
-
for (const result of results) {
|
|
986
|
-
if (result.done === false) {
|
|
987
|
-
const [left, right] = partition(result.value.events, (event) => event.checkpoint <= supremum);
|
|
988
|
-
eventArrays.push(left);
|
|
989
|
-
result.value.events = right;
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
const events = zipperMany(eventArrays).sort((a, b) => a.checkpoint < b.checkpoint ? -1 : 1);
|
|
993
|
-
const index = results.findIndex((res) => res.done === false && res.value.checkpoint === supremum);
|
|
994
|
-
const resultPromise = generators[index].next();
|
|
995
|
-
if (events.length > 0) {
|
|
996
|
-
yield { events, checkpoint: supremum };
|
|
997
|
-
}
|
|
998
|
-
results[index] = await resultPromise;
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
//# sourceMappingURL=index.js.map
|