ponder 0.8.3 → 0.8.4

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.
@@ -8956,7 +8956,7 @@ var createRealtimeSync = (args) => {
8956
8956
  block.transactions = void 0;
8957
8957
  await args.onEvent({
8958
8958
  type: "block",
8959
- filters: matchedFilters,
8959
+ hasMatchedFilter: matchedFilters.size > 0,
8960
8960
  block,
8961
8961
  factoryLogs,
8962
8962
  logs,
@@ -9712,10 +9712,9 @@ var getChainCheckpoint = ({
9712
9712
  );
9713
9713
  };
9714
9714
  var createSync = async (args) => {
9715
- const localSyncContext = /* @__PURE__ */ new Map();
9715
+ const perNetworkSync = /* @__PURE__ */ new Map();
9716
9716
  const status = {};
9717
9717
  let isKilled = false;
9718
- let pendingEvents = [];
9719
9718
  await Promise.all(
9720
9719
  args.networks.map(async (network) => {
9721
9720
  const requestQueue = createRequestQueue({
@@ -9790,18 +9789,18 @@ var createSync = async (args) => {
9790
9789
  { network: network.name },
9791
9790
  0
9792
9791
  );
9793
- localSyncContext.set(network, {
9792
+ perNetworkSync.set(network, {
9794
9793
  requestQueue,
9795
9794
  syncProgress,
9796
9795
  historicalSync,
9797
9796
  realtimeSync,
9798
- unfinalizedEventData: []
9797
+ unfinalizedBlocks: []
9799
9798
  });
9800
9799
  status[network.name] = { block: null, ready: false };
9801
9800
  })
9802
9801
  );
9803
9802
  const getOmnichainCheckpoint = (tag) => {
9804
- const checkpoints = Array.from(localSyncContext.entries()).map(
9803
+ const checkpoints = Array.from(perNetworkSync.entries()).map(
9805
9804
  ([network, { syncProgress }]) => getChainCheckpoint({ syncProgress, network, tag })
9806
9805
  );
9807
9806
  if (tag === "end" && checkpoints.some((c) => c === void 0)) {
@@ -9840,7 +9839,7 @@ var createSync = async (args) => {
9840
9839
  checkpoint,
9841
9840
  network
9842
9841
  }) => {
9843
- const localBlock = localSyncContext.get(network).realtimeSync.unfinalizedBlocks.findLast(
9842
+ const localBlock = perNetworkSync.get(network).realtimeSync.unfinalizedBlocks.findLast(
9844
9843
  (block) => encodeCheckpoint(blockToCheckpoint(block, network.chainId, "up")) <= checkpoint
9845
9844
  );
9846
9845
  if (localBlock !== void 0) {
@@ -9858,7 +9857,7 @@ var createSync = async (args) => {
9858
9857
  let showLogs = true;
9859
9858
  while (true) {
9860
9859
  const syncGenerator = mergeAsyncGenerators(
9861
- Array.from(localSyncContext.entries()).map(
9860
+ Array.from(perNetworkSync.entries()).map(
9862
9861
  ([network, { syncProgress, historicalSync }]) => localHistoricalSyncGenerator({
9863
9862
  common: args.common,
9864
9863
  network,
@@ -9870,7 +9869,7 @@ var createSync = async (args) => {
9870
9869
  );
9871
9870
  showLogs = false;
9872
9871
  for await (const _ of syncGenerator) {
9873
- if (Array.from(localSyncContext.values()).some(
9872
+ if (Array.from(perNetworkSync.values()).some(
9874
9873
  ({ syncProgress }) => syncProgress.current === void 0
9875
9874
  )) {
9876
9875
  continue;
@@ -9939,7 +9938,7 @@ var createSync = async (args) => {
9939
9938
  }
9940
9939
  }
9941
9940
  const allHistoricalSyncExhaustive = Array.from(
9942
- localSyncContext.values()
9941
+ perNetworkSync.values()
9943
9942
  ).every(({ syncProgress }) => {
9944
9943
  if (isSyncEnd(syncProgress))
9945
9944
  return true;
@@ -9953,7 +9952,7 @@ var createSync = async (args) => {
9953
9952
  break;
9954
9953
  latestFinalizedFetch = Date.now();
9955
9954
  await Promise.all(
9956
- Array.from(localSyncContext.entries()).map(
9955
+ Array.from(perNetworkSync.entries()).map(
9957
9956
  async ([network, { requestQueue, syncProgress }]) => {
9958
9957
  args.common.logger.debug({
9959
9958
  service: "sync",
@@ -9983,7 +9982,7 @@ var createSync = async (args) => {
9983
9982
  network,
9984
9983
  event
9985
9984
  }) => {
9986
- const { syncProgress, realtimeSync, unfinalizedEventData } = localSyncContext.get(network);
9985
+ const { syncProgress, realtimeSync, unfinalizedBlocks } = perNetworkSync.get(network);
9987
9986
  switch (event.type) {
9988
9987
  case "block": {
9989
9988
  const from = getOmnichainCheckpoint("current");
@@ -9993,16 +9992,7 @@ var createSync = async (args) => {
9993
9992
  { network: network.name },
9994
9993
  hexToNumber7(syncProgress.current.number)
9995
9994
  );
9996
- const blockWithEventData = {
9997
- block: event.block,
9998
- filters: event.filters,
9999
- logs: event.logs,
10000
- factoryLogs: event.factoryLogs,
10001
- traces: event.traces,
10002
- transactions: event.transactions,
10003
- transactionReceipts: event.transactionReceipts
10004
- };
10005
- unfinalizedEventData.push(blockWithEventData);
9995
+ const blockWithEventData = event;
10006
9996
  const events = buildEvents({
10007
9997
  sources: args.sources,
10008
9998
  chainId: network.chainId,
@@ -10010,14 +10000,23 @@ var createSync = async (args) => {
10010
10000
  finalizedChildAddresses: realtimeSync.finalizedChildAddresses,
10011
10001
  unfinalizedChildAddresses: realtimeSync.unfinalizedChildAddresses
10012
10002
  });
10013
- pendingEvents.push(...events);
10003
+ unfinalizedBlocks.push({ ...blockWithEventData, events });
10014
10004
  if (to > from) {
10015
10005
  for (const network2 of args.networks) {
10016
10006
  updateRealtimeStatus({ checkpoint: to, network: network2 });
10017
10007
  }
10018
- const events2 = pendingEvents.filter(({ checkpoint }) => checkpoint <= to).sort((a, b) => a.checkpoint < b.checkpoint ? -1 : 1);
10019
- pendingEvents = pendingEvents.filter(
10020
- ({ checkpoint }) => checkpoint > to
10008
+ const pendingEvents = [];
10009
+ for (const { unfinalizedBlocks: unfinalizedBlocks2 } of perNetworkSync.values()) {
10010
+ for (const { events: events3 } of unfinalizedBlocks2) {
10011
+ for (const event2 of events3) {
10012
+ if (event2.checkpoint > from && event2.checkpoint <= to) {
10013
+ pendingEvents.push(event2);
10014
+ }
10015
+ }
10016
+ }
10017
+ }
10018
+ const events2 = pendingEvents.sort(
10019
+ (a, b) => a.checkpoint < b.checkpoint ? -1 : 1
10021
10020
  );
10022
10021
  args.onRealtimeEvent({
10023
10022
  type: "block",
@@ -10046,39 +10045,40 @@ var createSync = async (args) => {
10046
10045
  if (checkpoint > prev) {
10047
10046
  args.onRealtimeEvent({ type: "finalize", checkpoint });
10048
10047
  }
10049
- const finalizedEventData = unfinalizedEventData.filter(
10050
- (ued) => hexToNumber7(ued.block.number) <= hexToNumber7(event.block.number)
10051
- );
10052
- localSyncContext.get(network).unfinalizedEventData = unfinalizedEventData.filter(
10053
- (ued) => hexToNumber7(ued.block.number) > hexToNumber7(event.block.number)
10054
- );
10055
10048
  if (getChainCheckpoint({ syncProgress, network, tag: "finalized" }) > getOmnichainCheckpoint("current")) {
10056
10049
  args.common.logger.warn({
10057
10050
  service: "sync",
10058
10051
  msg: `Finalized block for '${network.name}' has surpassed overall indexing checkpoint`
10059
10052
  });
10053
+ return;
10060
10054
  }
10055
+ const finalizedBlocks = unfinalizedBlocks.filter(
10056
+ ({ block }) => hexToNumber7(block.number) <= hexToNumber7(event.block.number)
10057
+ );
10058
+ perNetworkSync.get(network).unfinalizedBlocks = unfinalizedBlocks.filter(
10059
+ ({ block }) => hexToNumber7(block.number) > hexToNumber7(event.block.number)
10060
+ );
10061
10061
  await Promise.all([
10062
10062
  args.syncStore.insertBlocks({
10063
- blocks: finalizedEventData.filter(({ filters }) => filters.size > 0).map(({ block }) => block),
10063
+ blocks: finalizedBlocks.filter(({ hasMatchedFilter }) => hasMatchedFilter).map(({ block }) => block),
10064
10064
  chainId: network.chainId
10065
10065
  }),
10066
10066
  args.syncStore.insertLogs({
10067
- logs: finalizedEventData.flatMap(
10067
+ logs: finalizedBlocks.flatMap(
10068
10068
  ({ logs, block }) => logs.map((log) => ({ log, block }))
10069
10069
  ),
10070
10070
  shouldUpdateCheckpoint: true,
10071
10071
  chainId: network.chainId
10072
10072
  }),
10073
10073
  args.syncStore.insertLogs({
10074
- logs: finalizedEventData.flatMap(
10074
+ logs: finalizedBlocks.flatMap(
10075
10075
  ({ factoryLogs }) => factoryLogs.map((log) => ({ log }))
10076
10076
  ),
10077
10077
  shouldUpdateCheckpoint: false,
10078
10078
  chainId: network.chainId
10079
10079
  }),
10080
10080
  args.syncStore.insertTransactions({
10081
- transactions: finalizedEventData.flatMap(
10081
+ transactions: finalizedBlocks.flatMap(
10082
10082
  ({ transactions, block }) => transactions.map((transaction) => ({
10083
10083
  transaction,
10084
10084
  block
@@ -10087,13 +10087,13 @@ var createSync = async (args) => {
10087
10087
  chainId: network.chainId
10088
10088
  }),
10089
10089
  args.syncStore.insertTransactionReceipts({
10090
- transactionReceipts: finalizedEventData.flatMap(
10090
+ transactionReceipts: finalizedBlocks.flatMap(
10091
10091
  ({ transactionReceipts }) => transactionReceipts
10092
10092
  ),
10093
10093
  chainId: network.chainId
10094
10094
  }),
10095
10095
  args.syncStore.insertTraces({
10096
- traces: finalizedEventData.flatMap(
10096
+ traces: finalizedBlocks.flatMap(
10097
10097
  ({ traces, block, transactions }) => traces.map((trace) => ({
10098
10098
  trace,
10099
10099
  block,
@@ -10134,15 +10134,8 @@ var createSync = async (args) => {
10134
10134
  { network: network.name },
10135
10135
  hexToNumber7(syncProgress.current.number)
10136
10136
  );
10137
- localSyncContext.get(network).unfinalizedEventData = unfinalizedEventData.filter(
10138
- (led) => hexToNumber7(led.block.number) <= hexToNumber7(event.block.number)
10139
- );
10140
- const reorgedHashes = /* @__PURE__ */ new Set();
10141
- for (const b of event.reorgedBlocks) {
10142
- reorgedHashes.add(b.hash);
10143
- }
10144
- pendingEvents = pendingEvents.filter(
10145
- (e) => reorgedHashes.has(e.block.hash) === false
10137
+ perNetworkSync.get(network).unfinalizedBlocks = unfinalizedBlocks.filter(
10138
+ ({ block }) => hexToNumber7(block.number) <= hexToNumber7(event.block.number)
10146
10139
  );
10147
10140
  await args.syncStore.pruneRpcRequestResult({
10148
10141
  blocks: event.reorgedBlocks,
@@ -10159,7 +10152,7 @@ var createSync = async (args) => {
10159
10152
  getEvents,
10160
10153
  async startRealtime() {
10161
10154
  for (const network of args.networks) {
10162
- const { syncProgress, realtimeSync } = localSyncContext.get(network);
10155
+ const { syncProgress, realtimeSync } = perNetworkSync.get(network);
10163
10156
  status[network.name].block = {
10164
10157
  number: hexToNumber7(syncProgress.current.number),
10165
10158
  timestamp: hexToNumber7(syncProgress.current.timestamp)
@@ -10198,14 +10191,14 @@ var createSync = async (args) => {
10198
10191
  return status;
10199
10192
  },
10200
10193
  getCachedTransport(network) {
10201
- const { requestQueue } = localSyncContext.get(network);
10194
+ const { requestQueue } = perNetworkSync.get(network);
10202
10195
  return cachedTransport({ requestQueue, syncStore: args.syncStore });
10203
10196
  },
10204
10197
  async kill() {
10205
10198
  isKilled = true;
10206
10199
  const promises = [];
10207
10200
  for (const network of args.networks) {
10208
- const { historicalSync, realtimeSync } = localSyncContext.get(network);
10201
+ const { historicalSync, realtimeSync } = perNetworkSync.get(network);
10209
10202
  historicalSync.kill();
10210
10203
  promises.push(realtimeSync.kill());
10211
10204
  }