ponder 0.8.18 → 0.8.20
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/bin/ponder.js +57 -26
- package/dist/bin/ponder.js.map +1 -1
- package/package.json +1 -1
- package/src/database/index.ts +1 -1
- package/src/sync/index.ts +75 -28
- package/src/sync-historical/index.ts +4 -0
- package/src/sync-realtime/index.ts +4 -0
- package/src/sync-store/index.ts +2 -2
package/dist/bin/ponder.js
CHANGED
|
@@ -4637,7 +4637,7 @@ END;
|
|
|
4637
4637
|
$$ LANGUAGE plpgsql
|
|
4638
4638
|
`).execute(qb.internal);
|
|
4639
4639
|
await sql2.raw(`
|
|
4640
|
-
CREATE TRIGGER "${tableName.trigger}"
|
|
4640
|
+
CREATE OR REPLACE TRIGGER "${tableName.trigger}"
|
|
4641
4641
|
AFTER INSERT OR UPDATE OR DELETE ON "${preBuild.namespace}"."${tableName.sql}"
|
|
4642
4642
|
FOR EACH ROW EXECUTE FUNCTION ${tableName.triggerFn};
|
|
4643
4643
|
`).execute(qb.internal);
|
|
@@ -7237,7 +7237,7 @@ var createSyncStore = ({
|
|
|
7237
7237
|
"transactionReceipts.status as txr_status",
|
|
7238
7238
|
"transactionReceipts.to as txr_to",
|
|
7239
7239
|
"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();
|
|
7240
|
+
]).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
7241
|
}
|
|
7242
7242
|
);
|
|
7243
7243
|
const events = rows.map((_row) => {
|
|
@@ -8489,6 +8489,9 @@ var createHistoricalSync = async (args) => {
|
|
|
8489
8489
|
}
|
|
8490
8490
|
};
|
|
8491
8491
|
const syncTransactionReceipts = async (block, transactionHashes) => {
|
|
8492
|
+
if (transactionHashes.size === 0) {
|
|
8493
|
+
return [];
|
|
8494
|
+
}
|
|
8492
8495
|
if (isBlockReceipts === false) {
|
|
8493
8496
|
const transactionReceipts2 = await Promise.all(
|
|
8494
8497
|
Array.from(transactionHashes).map(
|
|
@@ -9261,6 +9264,9 @@ var createRealtimeSync = (args) => {
|
|
|
9261
9264
|
}
|
|
9262
9265
|
};
|
|
9263
9266
|
const syncTransactionReceipts = async (blockHash, transactionHashes) => {
|
|
9267
|
+
if (transactionHashes.size === 0) {
|
|
9268
|
+
return [];
|
|
9269
|
+
}
|
|
9264
9270
|
if (isBlockReceipts === false) {
|
|
9265
9271
|
const transactionReceipts2 = await Promise.all(
|
|
9266
9272
|
Array.from(transactionHashes).map(
|
|
@@ -9973,6 +9979,8 @@ var getChainCheckpoint = ({
|
|
|
9973
9979
|
};
|
|
9974
9980
|
var createSync = async (args) => {
|
|
9975
9981
|
const perNetworkSync = /* @__PURE__ */ new Map();
|
|
9982
|
+
let executedEvents = [];
|
|
9983
|
+
let pendingEvents = [];
|
|
9976
9984
|
const status = {};
|
|
9977
9985
|
let isKilled = false;
|
|
9978
9986
|
await Promise.all(
|
|
@@ -10246,42 +10254,34 @@ var createSync = async (args) => {
|
|
|
10246
10254
|
{ network: network.name },
|
|
10247
10255
|
hexToNumber7(syncProgress.current.number)
|
|
10248
10256
|
);
|
|
10249
|
-
const
|
|
10250
|
-
const events = buildEvents({
|
|
10257
|
+
const newEvents = buildEvents({
|
|
10251
10258
|
sources: args.sources,
|
|
10252
10259
|
chainId: network.chainId,
|
|
10253
|
-
blockWithEventData,
|
|
10260
|
+
blockWithEventData: event,
|
|
10254
10261
|
finalizedChildAddresses: realtimeSync.finalizedChildAddresses,
|
|
10255
10262
|
unfinalizedChildAddresses: realtimeSync.unfinalizedChildAddresses
|
|
10256
10263
|
});
|
|
10257
|
-
unfinalizedBlocks.push(
|
|
10264
|
+
unfinalizedBlocks.push(event);
|
|
10265
|
+
pendingEvents.push(...newEvents);
|
|
10258
10266
|
if (to > from) {
|
|
10259
10267
|
for (const network2 of args.networks) {
|
|
10260
10268
|
updateRealtimeStatus({ checkpoint: to, network: network2 });
|
|
10261
10269
|
}
|
|
10262
|
-
const
|
|
10263
|
-
|
|
10264
|
-
|
|
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
|
|
10270
|
+
const events = pendingEvents.filter((event2) => event2.checkpoint < to).sort((a, b) => a.checkpoint < b.checkpoint ? -1 : 1);
|
|
10271
|
+
pendingEvents = pendingEvents.filter(
|
|
10272
|
+
({ checkpoint }) => checkpoint > to
|
|
10274
10273
|
);
|
|
10274
|
+
executedEvents.push(...events);
|
|
10275
10275
|
args.onRealtimeEvent({
|
|
10276
10276
|
type: "block",
|
|
10277
10277
|
checkpoint: to,
|
|
10278
10278
|
status: structuredClone(status),
|
|
10279
|
-
events
|
|
10279
|
+
events
|
|
10280
10280
|
}).then(() => {
|
|
10281
|
-
if (
|
|
10281
|
+
if (events.length > 0 && isKilled === false) {
|
|
10282
10282
|
args.common.logger.info({
|
|
10283
10283
|
service: "app",
|
|
10284
|
-
msg: `Indexed ${
|
|
10284
|
+
msg: `Indexed ${events.length} events`
|
|
10285
10285
|
});
|
|
10286
10286
|
}
|
|
10287
10287
|
});
|
|
@@ -10304,7 +10304,6 @@ var createSync = async (args) => {
|
|
|
10304
10304
|
service: "sync",
|
|
10305
10305
|
msg: `Finalized block for '${network.name}' has surpassed overall indexing checkpoint`
|
|
10306
10306
|
});
|
|
10307
|
-
return;
|
|
10308
10307
|
}
|
|
10309
10308
|
const finalizedBlocks = unfinalizedBlocks.filter(
|
|
10310
10309
|
({ block }) => hexToNumber7(block.number) <= hexToNumber7(event.block.number)
|
|
@@ -10312,6 +10311,9 @@ var createSync = async (args) => {
|
|
|
10312
10311
|
perNetworkSync.get(network).unfinalizedBlocks = unfinalizedBlocks.filter(
|
|
10313
10312
|
({ block }) => hexToNumber7(block.number) > hexToNumber7(event.block.number)
|
|
10314
10313
|
);
|
|
10314
|
+
executedEvents = executedEvents.filter(
|
|
10315
|
+
(e) => e.checkpoint > checkpoint
|
|
10316
|
+
);
|
|
10315
10317
|
await Promise.all([
|
|
10316
10318
|
args.syncStore.insertBlocks({
|
|
10317
10319
|
blocks: finalizedBlocks.filter(({ hasMatchedFilter }) => hasMatchedFilter).map(({ block }) => block),
|
|
@@ -10392,9 +10394,21 @@ var createSync = async (args) => {
|
|
|
10392
10394
|
perNetworkSync.get(network).unfinalizedBlocks = unfinalizedBlocks.filter(
|
|
10393
10395
|
({ block }) => hexToNumber7(block.number) <= hexToNumber7(event.block.number)
|
|
10394
10396
|
);
|
|
10397
|
+
const isReorgedEvent = ({ chainId, block }) => chainId === network.chainId && Number(block.number) > hexToNumber7(event.block.number);
|
|
10398
|
+
pendingEvents = pendingEvents.filter(
|
|
10399
|
+
(e) => isReorgedEvent(e) === false
|
|
10400
|
+
);
|
|
10401
|
+
executedEvents = executedEvents.filter(
|
|
10402
|
+
(e) => isReorgedEvent(e) === false
|
|
10403
|
+
);
|
|
10404
|
+
const events = executedEvents.filter((e) => e.checkpoint > checkpoint);
|
|
10405
|
+
executedEvents = executedEvents.filter(
|
|
10406
|
+
(e) => e.checkpoint < checkpoint
|
|
10407
|
+
);
|
|
10408
|
+
pendingEvents.push(...events);
|
|
10395
10409
|
await args.syncStore.pruneRpcRequestResult({
|
|
10396
|
-
|
|
10397
|
-
|
|
10410
|
+
chainId: network.chainId,
|
|
10411
|
+
blocks: event.reorgedBlocks
|
|
10398
10412
|
});
|
|
10399
10413
|
args.onRealtimeEvent({ type: "reorg", checkpoint });
|
|
10400
10414
|
break;
|
|
@@ -10408,11 +10422,28 @@ var createSync = async (args) => {
|
|
|
10408
10422
|
async startRealtime() {
|
|
10409
10423
|
for (const network of args.networks) {
|
|
10410
10424
|
const { syncProgress, realtimeSync } = perNetworkSync.get(network);
|
|
10425
|
+
const filters = args.sources.filter(({ filter }) => filter.chainId === network.chainId).map(({ filter }) => filter);
|
|
10411
10426
|
status[network.name].block = {
|
|
10412
10427
|
number: hexToNumber7(syncProgress.current.number),
|
|
10413
10428
|
timestamp: hexToNumber7(syncProgress.current.timestamp)
|
|
10414
10429
|
};
|
|
10415
10430
|
status[network.name].ready = true;
|
|
10431
|
+
const from = getOmnichainCheckpoint("finalized");
|
|
10432
|
+
const finalized = getChainCheckpoint({
|
|
10433
|
+
syncProgress,
|
|
10434
|
+
network,
|
|
10435
|
+
tag: "finalized"
|
|
10436
|
+
});
|
|
10437
|
+
const end = getChainCheckpoint({
|
|
10438
|
+
syncProgress,
|
|
10439
|
+
network,
|
|
10440
|
+
tag: "end"
|
|
10441
|
+
});
|
|
10442
|
+
const to = min(finalized, end);
|
|
10443
|
+
if (to > from) {
|
|
10444
|
+
const events = await args.syncStore.getEvents({ filters, from, to });
|
|
10445
|
+
pendingEvents.push(...events.events);
|
|
10446
|
+
}
|
|
10416
10447
|
if (isSyncEnd(syncProgress)) {
|
|
10417
10448
|
args.common.metrics.ponder_sync_is_complete.set(
|
|
10418
10449
|
{ network: network.name },
|
|
@@ -10424,8 +10455,8 @@ var createSync = async (args) => {
|
|
|
10424
10455
|
1
|
|
10425
10456
|
);
|
|
10426
10457
|
const initialChildAddresses = /* @__PURE__ */ new Map();
|
|
10427
|
-
for (const
|
|
10428
|
-
if (
|
|
10458
|
+
for (const filter of filters) {
|
|
10459
|
+
if ("address" in filter && isAddressFactory(filter.address)) {
|
|
10429
10460
|
const addresses = await args.syncStore.getChildAddresses({
|
|
10430
10461
|
filter: filter.address
|
|
10431
10462
|
});
|