ponder 0.8.19 → 0.8.21

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.
@@ -3887,6 +3887,8 @@ function prettyPrint(args) {
3887
3887
  const trimmedValue = typeof value === "string" && value.length > 80 ? value.slice(0, 80).concat("...") : value;
3888
3888
  return [key, trimmedValue];
3889
3889
  }).filter(Boolean);
3890
+ if (entries.length === 0)
3891
+ return " (empty object)";
3890
3892
  const maxLength = entries.reduce(
3891
3893
  (acc, [key]) => Math.max(acc, key.length),
3892
3894
  0
@@ -6227,47 +6229,24 @@ var executeSetup = async (indexingService, { event }) => {
6227
6229
  } catch (_error) {
6228
6230
  if (indexingService.isKilled)
6229
6231
  return { status: "killed" };
6230
- const error = _error;
6231
- const decodedCheckpoint = decodeCheckpoint(event.checkpoint);
6232
+ const error = _error instanceof Error ? _error : new Error(String(_error));
6232
6233
  addStackTrace(error, common.options);
6233
- common.metrics.ponder_indexing_has_error.set(1);
6234
+ if (error instanceof BaseError) {
6235
+ error.meta.push(toErrorMeta(event));
6236
+ } else {
6237
+ error.meta = [toErrorMeta(event)];
6238
+ }
6239
+ const decodedCheckpoint = decodeCheckpoint(event.checkpoint);
6234
6240
  common.logger.error({
6235
6241
  service: "indexing",
6236
6242
  msg: `Error while processing '${event.name}' event in '${networkByChainId[event.chainId].name}' block ${decodedCheckpoint.blockNumber}`,
6237
6243
  error
6238
6244
  });
6245
+ common.metrics.ponder_indexing_has_error.set(1);
6239
6246
  return { status: "error", error };
6240
6247
  }
6241
6248
  return { status: "success" };
6242
6249
  };
6243
- var toErrorMeta = (event) => {
6244
- switch (event.type) {
6245
- case "log":
6246
- case "trace": {
6247
- return `Event arguments:
6248
- ${prettyPrint(event.event.args)}`;
6249
- }
6250
- case "transfer": {
6251
- return `Event arguments:
6252
- ${prettyPrint(event.event.transfer)}`;
6253
- }
6254
- case "block": {
6255
- return `Block:
6256
- ${prettyPrint({
6257
- hash: event.event.block.hash,
6258
- number: event.event.block.number,
6259
- timestamp: event.event.block.timestamp
6260
- })}`;
6261
- }
6262
- case "transaction": {
6263
- return `Transaction:
6264
- ${prettyPrint({
6265
- hash: event.event.transaction.hash,
6266
- block: event.event.block.number
6267
- })}`;
6268
- }
6269
- }
6270
- };
6271
6250
  var executeEvent = async (indexingService, { event }) => {
6272
6251
  const {
6273
6252
  common,
@@ -6297,13 +6276,14 @@ var executeEvent = async (indexingService, { event }) => {
6297
6276
  } catch (_error) {
6298
6277
  if (indexingService.isKilled)
6299
6278
  return { status: "killed" };
6300
- const error = _error;
6301
- const decodedCheckpoint = decodeCheckpoint(event.checkpoint);
6279
+ const error = _error instanceof Error ? _error : new Error(String(_error));
6302
6280
  addStackTrace(error, common.options);
6303
- error.meta = Array.isArray(error.meta) ? error.meta : [];
6304
- if (error.meta.length === 0) {
6281
+ if (error instanceof BaseError) {
6305
6282
  error.meta.push(toErrorMeta(event));
6283
+ } else {
6284
+ error.meta = [toErrorMeta(event)];
6306
6285
  }
6286
+ const decodedCheckpoint = decodeCheckpoint(event.checkpoint);
6307
6287
  common.logger.error({
6308
6288
  service: "indexing",
6309
6289
  msg: `Error while processing '${event.name}' event in '${networkByChainId[event.chainId].name}' block ${decodedCheckpoint.blockNumber}`,
@@ -6314,6 +6294,75 @@ var executeEvent = async (indexingService, { event }) => {
6314
6294
  }
6315
6295
  return { status: "success" };
6316
6296
  };
6297
+ var blockText = (block) => `Block:
6298
+ ${prettyPrint({
6299
+ hash: block.hash,
6300
+ number: block.number,
6301
+ timestamp: block.timestamp
6302
+ })}`;
6303
+ var transactionText = (transaction) => `Transaction:
6304
+ ${prettyPrint({
6305
+ hash: transaction.hash,
6306
+ from: transaction.from,
6307
+ to: transaction.to
6308
+ })}`;
6309
+ var logText = (log) => `Log:
6310
+ ${prettyPrint({
6311
+ index: log.logIndex,
6312
+ address: log.address
6313
+ })}`;
6314
+ var traceText = (trace) => `Trace:
6315
+ ${prettyPrint({
6316
+ traceIndex: trace.traceIndex,
6317
+ from: trace.from,
6318
+ to: trace.to
6319
+ })}`;
6320
+ var toErrorMeta = (event) => {
6321
+ switch (event.type) {
6322
+ case "setup": {
6323
+ return `Block:
6324
+ ${prettyPrint({
6325
+ number: event.block
6326
+ })}`;
6327
+ }
6328
+ case "log": {
6329
+ return [
6330
+ `Event arguments:
6331
+ ${prettyPrint(event.event.args)}`,
6332
+ logText(event.event.log),
6333
+ transactionText(event.event.transaction),
6334
+ blockText(event.event.block)
6335
+ ].join("\n");
6336
+ }
6337
+ case "trace": {
6338
+ return [
6339
+ `Call trace arguments:
6340
+ ${prettyPrint(event.event.args)}`,
6341
+ traceText(event.event.trace),
6342
+ transactionText(event.event.transaction),
6343
+ blockText(event.event.block)
6344
+ ].join("\n");
6345
+ }
6346
+ case "transfer": {
6347
+ return [
6348
+ `Transfer arguments:
6349
+ ${prettyPrint(event.event.transfer)}`,
6350
+ traceText(event.event.trace),
6351
+ transactionText(event.event.transaction),
6352
+ blockText(event.event.block)
6353
+ ].join("\n");
6354
+ }
6355
+ case "block": {
6356
+ return blockText(event.event.block);
6357
+ }
6358
+ case "transaction": {
6359
+ return [
6360
+ transactionText(event.event.transaction),
6361
+ blockText(event.event.block)
6362
+ ].join("\n");
6363
+ }
6364
+ }
6365
+ };
6317
6366
 
6318
6367
  // src/indexing/index.ts
6319
6368
  var methods = {
@@ -7237,7 +7286,7 @@ var createSyncStore = ({
7237
7286
  "transactionReceipts.status as txr_status",
7238
7287
  "transactionReceipts.to as txr_to",
7239
7288
  "transactionReceipts.type as txr_type"
7240
- ]).where("event.checkpoint", ">", from).where("event.checkpoint", "<=", to).orderBy("event.checkpoint", "asc").orderBy("event.filterIndex", "asc").limit(limit).execute();
7289
+ ]).where("event.checkpoint", ">", from).where("event.checkpoint", "<=", to).orderBy("event.checkpoint", "asc").orderBy("event.filterIndex", "asc").$if(limit !== void 0, (qb) => qb.limit(limit)).execute();
7241
7290
  }
7242
7291
  );
7243
7292
  const events = rows.map((_row) => {
@@ -8489,6 +8538,9 @@ var createHistoricalSync = async (args) => {
8489
8538
  }
8490
8539
  };
8491
8540
  const syncTransactionReceipts = async (block, transactionHashes) => {
8541
+ if (transactionHashes.size === 0) {
8542
+ return [];
8543
+ }
8492
8544
  if (isBlockReceipts === false) {
8493
8545
  const transactionReceipts2 = await Promise.all(
8494
8546
  Array.from(transactionHashes).map(
@@ -9261,6 +9313,9 @@ var createRealtimeSync = (args) => {
9261
9313
  }
9262
9314
  };
9263
9315
  const syncTransactionReceipts = async (blockHash, transactionHashes) => {
9316
+ if (transactionHashes.size === 0) {
9317
+ return [];
9318
+ }
9264
9319
  if (isBlockReceipts === false) {
9265
9320
  const transactionReceipts2 = await Promise.all(
9266
9321
  Array.from(transactionHashes).map(
@@ -9973,6 +10028,8 @@ var getChainCheckpoint = ({
9973
10028
  };
9974
10029
  var createSync = async (args) => {
9975
10030
  const perNetworkSync = /* @__PURE__ */ new Map();
10031
+ let executedEvents = [];
10032
+ let pendingEvents = [];
9976
10033
  const status = {};
9977
10034
  let isKilled = false;
9978
10035
  await Promise.all(
@@ -10246,42 +10303,34 @@ var createSync = async (args) => {
10246
10303
  { network: network.name },
10247
10304
  hexToNumber7(syncProgress.current.number)
10248
10305
  );
10249
- const blockWithEventData = event;
10250
- const events = buildEvents({
10306
+ const newEvents = buildEvents({
10251
10307
  sources: args.sources,
10252
10308
  chainId: network.chainId,
10253
- blockWithEventData,
10309
+ blockWithEventData: event,
10254
10310
  finalizedChildAddresses: realtimeSync.finalizedChildAddresses,
10255
10311
  unfinalizedChildAddresses: realtimeSync.unfinalizedChildAddresses
10256
10312
  });
10257
- unfinalizedBlocks.push({ ...blockWithEventData, events });
10313
+ unfinalizedBlocks.push(event);
10314
+ pendingEvents.push(...newEvents);
10258
10315
  if (to > from) {
10259
10316
  for (const network2 of args.networks) {
10260
10317
  updateRealtimeStatus({ checkpoint: to, network: network2 });
10261
10318
  }
10262
- const pendingEvents = [];
10263
- for (const { unfinalizedBlocks: unfinalizedBlocks2 } of perNetworkSync.values()) {
10264
- for (const { events: events3 } of unfinalizedBlocks2) {
10265
- for (const event2 of events3) {
10266
- if (event2.checkpoint > from && event2.checkpoint <= to) {
10267
- pendingEvents.push(event2);
10268
- }
10269
- }
10270
- }
10271
- }
10272
- const events2 = pendingEvents.sort(
10273
- (a, b) => a.checkpoint < b.checkpoint ? -1 : 1
10319
+ const events = pendingEvents.filter((event2) => event2.checkpoint < to).sort((a, b) => a.checkpoint < b.checkpoint ? -1 : 1);
10320
+ pendingEvents = pendingEvents.filter(
10321
+ ({ checkpoint }) => checkpoint > to
10274
10322
  );
10323
+ executedEvents.push(...events);
10275
10324
  args.onRealtimeEvent({
10276
10325
  type: "block",
10277
10326
  checkpoint: to,
10278
10327
  status: structuredClone(status),
10279
- events: events2
10328
+ events
10280
10329
  }).then(() => {
10281
- if (events2.length > 0 && isKilled === false) {
10330
+ if (events.length > 0 && isKilled === false) {
10282
10331
  args.common.logger.info({
10283
10332
  service: "app",
10284
- msg: `Indexed ${events2.length} events`
10333
+ msg: `Indexed ${events.length} events`
10285
10334
  });
10286
10335
  }
10287
10336
  });
@@ -10304,7 +10353,6 @@ var createSync = async (args) => {
10304
10353
  service: "sync",
10305
10354
  msg: `Finalized block for '${network.name}' has surpassed overall indexing checkpoint`
10306
10355
  });
10307
- return;
10308
10356
  }
10309
10357
  const finalizedBlocks = unfinalizedBlocks.filter(
10310
10358
  ({ block }) => hexToNumber7(block.number) <= hexToNumber7(event.block.number)
@@ -10312,6 +10360,9 @@ var createSync = async (args) => {
10312
10360
  perNetworkSync.get(network).unfinalizedBlocks = unfinalizedBlocks.filter(
10313
10361
  ({ block }) => hexToNumber7(block.number) > hexToNumber7(event.block.number)
10314
10362
  );
10363
+ executedEvents = executedEvents.filter(
10364
+ (e) => e.checkpoint > checkpoint
10365
+ );
10315
10366
  await Promise.all([
10316
10367
  args.syncStore.insertBlocks({
10317
10368
  blocks: finalizedBlocks.filter(({ hasMatchedFilter }) => hasMatchedFilter).map(({ block }) => block),
@@ -10392,9 +10443,21 @@ var createSync = async (args) => {
10392
10443
  perNetworkSync.get(network).unfinalizedBlocks = unfinalizedBlocks.filter(
10393
10444
  ({ block }) => hexToNumber7(block.number) <= hexToNumber7(event.block.number)
10394
10445
  );
10446
+ const isReorgedEvent = ({ chainId, block }) => chainId === network.chainId && Number(block.number) > hexToNumber7(event.block.number);
10447
+ pendingEvents = pendingEvents.filter(
10448
+ (e) => isReorgedEvent(e) === false
10449
+ );
10450
+ executedEvents = executedEvents.filter(
10451
+ (e) => isReorgedEvent(e) === false
10452
+ );
10453
+ const events = executedEvents.filter((e) => e.checkpoint > checkpoint);
10454
+ executedEvents = executedEvents.filter(
10455
+ (e) => e.checkpoint < checkpoint
10456
+ );
10457
+ pendingEvents.push(...events);
10395
10458
  await args.syncStore.pruneRpcRequestResult({
10396
- blocks: event.reorgedBlocks,
10397
- chainId: network.chainId
10459
+ chainId: network.chainId,
10460
+ blocks: event.reorgedBlocks
10398
10461
  });
10399
10462
  args.onRealtimeEvent({ type: "reorg", checkpoint });
10400
10463
  break;
@@ -10408,11 +10471,28 @@ var createSync = async (args) => {
10408
10471
  async startRealtime() {
10409
10472
  for (const network of args.networks) {
10410
10473
  const { syncProgress, realtimeSync } = perNetworkSync.get(network);
10474
+ const filters = args.sources.filter(({ filter }) => filter.chainId === network.chainId).map(({ filter }) => filter);
10411
10475
  status[network.name].block = {
10412
10476
  number: hexToNumber7(syncProgress.current.number),
10413
10477
  timestamp: hexToNumber7(syncProgress.current.timestamp)
10414
10478
  };
10415
10479
  status[network.name].ready = true;
10480
+ const from = getOmnichainCheckpoint("finalized");
10481
+ const finalized = getChainCheckpoint({
10482
+ syncProgress,
10483
+ network,
10484
+ tag: "finalized"
10485
+ });
10486
+ const end = getChainCheckpoint({
10487
+ syncProgress,
10488
+ network,
10489
+ tag: "end"
10490
+ });
10491
+ const to = min(finalized, end);
10492
+ if (to > from) {
10493
+ const events = await args.syncStore.getEvents({ filters, from, to });
10494
+ pendingEvents.push(...events.events);
10495
+ }
10416
10496
  if (isSyncEnd(syncProgress)) {
10417
10497
  args.common.metrics.ponder_sync_is_complete.set(
10418
10498
  { network: network.name },
@@ -10424,8 +10504,8 @@ var createSync = async (args) => {
10424
10504
  1
10425
10505
  );
10426
10506
  const initialChildAddresses = /* @__PURE__ */ new Map();
10427
- for (const { filter } of args.sources) {
10428
- if (filter.chainId === network.chainId && "address" in filter && isAddressFactory(filter.address)) {
10507
+ for (const filter of filters) {
10508
+ if ("address" in filter && isAddressFactory(filter.address)) {
10429
10509
  const addresses = await args.syncStore.getChildAddresses({
10430
10510
  filter: filter.address
10431
10511
  });