ponder 0.8.3 → 0.8.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/bin/ponder.js +55 -50
- package/dist/bin/ponder.js.map +1 -1
- package/package.json +1 -1
- package/src/sync/index.ts +68 -78
- package/src/sync-historical/index.ts +16 -0
- package/src/sync-realtime/index.ts +6 -5
package/dist/bin/ponder.js
CHANGED
|
@@ -8293,6 +8293,18 @@ var createHistoricalSync = async (args) => {
|
|
|
8293
8293
|
filter.topic2 ?? null,
|
|
8294
8294
|
filter.topic3 ?? null
|
|
8295
8295
|
];
|
|
8296
|
+
if (topics[3] === null) {
|
|
8297
|
+
topics.pop();
|
|
8298
|
+
if (topics[2] === null) {
|
|
8299
|
+
topics.pop();
|
|
8300
|
+
if (topics[1] === null) {
|
|
8301
|
+
topics.pop();
|
|
8302
|
+
if (topics[0] === null) {
|
|
8303
|
+
topics.pop();
|
|
8304
|
+
}
|
|
8305
|
+
}
|
|
8306
|
+
}
|
|
8307
|
+
}
|
|
8296
8308
|
let addressBatches;
|
|
8297
8309
|
if (address === void 0) {
|
|
8298
8310
|
addressBatches = [void 0];
|
|
@@ -8956,7 +8968,7 @@ var createRealtimeSync = (args) => {
|
|
|
8956
8968
|
block.transactions = void 0;
|
|
8957
8969
|
await args.onEvent({
|
|
8958
8970
|
type: "block",
|
|
8959
|
-
|
|
8971
|
+
hasMatchedFilter: matchedFilters.size > 0,
|
|
8960
8972
|
block,
|
|
8961
8973
|
factoryLogs,
|
|
8962
8974
|
logs,
|
|
@@ -9712,10 +9724,9 @@ var getChainCheckpoint = ({
|
|
|
9712
9724
|
);
|
|
9713
9725
|
};
|
|
9714
9726
|
var createSync = async (args) => {
|
|
9715
|
-
const
|
|
9727
|
+
const perNetworkSync = /* @__PURE__ */ new Map();
|
|
9716
9728
|
const status = {};
|
|
9717
9729
|
let isKilled = false;
|
|
9718
|
-
let pendingEvents = [];
|
|
9719
9730
|
await Promise.all(
|
|
9720
9731
|
args.networks.map(async (network) => {
|
|
9721
9732
|
const requestQueue = createRequestQueue({
|
|
@@ -9790,18 +9801,18 @@ var createSync = async (args) => {
|
|
|
9790
9801
|
{ network: network.name },
|
|
9791
9802
|
0
|
|
9792
9803
|
);
|
|
9793
|
-
|
|
9804
|
+
perNetworkSync.set(network, {
|
|
9794
9805
|
requestQueue,
|
|
9795
9806
|
syncProgress,
|
|
9796
9807
|
historicalSync,
|
|
9797
9808
|
realtimeSync,
|
|
9798
|
-
|
|
9809
|
+
unfinalizedBlocks: []
|
|
9799
9810
|
});
|
|
9800
9811
|
status[network.name] = { block: null, ready: false };
|
|
9801
9812
|
})
|
|
9802
9813
|
);
|
|
9803
9814
|
const getOmnichainCheckpoint = (tag) => {
|
|
9804
|
-
const checkpoints = Array.from(
|
|
9815
|
+
const checkpoints = Array.from(perNetworkSync.entries()).map(
|
|
9805
9816
|
([network, { syncProgress }]) => getChainCheckpoint({ syncProgress, network, tag })
|
|
9806
9817
|
);
|
|
9807
9818
|
if (tag === "end" && checkpoints.some((c) => c === void 0)) {
|
|
@@ -9840,7 +9851,7 @@ var createSync = async (args) => {
|
|
|
9840
9851
|
checkpoint,
|
|
9841
9852
|
network
|
|
9842
9853
|
}) => {
|
|
9843
|
-
const localBlock =
|
|
9854
|
+
const localBlock = perNetworkSync.get(network).realtimeSync.unfinalizedBlocks.findLast(
|
|
9844
9855
|
(block) => encodeCheckpoint(blockToCheckpoint(block, network.chainId, "up")) <= checkpoint
|
|
9845
9856
|
);
|
|
9846
9857
|
if (localBlock !== void 0) {
|
|
@@ -9858,7 +9869,7 @@ var createSync = async (args) => {
|
|
|
9858
9869
|
let showLogs = true;
|
|
9859
9870
|
while (true) {
|
|
9860
9871
|
const syncGenerator = mergeAsyncGenerators(
|
|
9861
|
-
Array.from(
|
|
9872
|
+
Array.from(perNetworkSync.entries()).map(
|
|
9862
9873
|
([network, { syncProgress, historicalSync }]) => localHistoricalSyncGenerator({
|
|
9863
9874
|
common: args.common,
|
|
9864
9875
|
network,
|
|
@@ -9870,7 +9881,7 @@ var createSync = async (args) => {
|
|
|
9870
9881
|
);
|
|
9871
9882
|
showLogs = false;
|
|
9872
9883
|
for await (const _ of syncGenerator) {
|
|
9873
|
-
if (Array.from(
|
|
9884
|
+
if (Array.from(perNetworkSync.values()).some(
|
|
9874
9885
|
({ syncProgress }) => syncProgress.current === void 0
|
|
9875
9886
|
)) {
|
|
9876
9887
|
continue;
|
|
@@ -9939,7 +9950,7 @@ var createSync = async (args) => {
|
|
|
9939
9950
|
}
|
|
9940
9951
|
}
|
|
9941
9952
|
const allHistoricalSyncExhaustive = Array.from(
|
|
9942
|
-
|
|
9953
|
+
perNetworkSync.values()
|
|
9943
9954
|
).every(({ syncProgress }) => {
|
|
9944
9955
|
if (isSyncEnd(syncProgress))
|
|
9945
9956
|
return true;
|
|
@@ -9953,7 +9964,7 @@ var createSync = async (args) => {
|
|
|
9953
9964
|
break;
|
|
9954
9965
|
latestFinalizedFetch = Date.now();
|
|
9955
9966
|
await Promise.all(
|
|
9956
|
-
Array.from(
|
|
9967
|
+
Array.from(perNetworkSync.entries()).map(
|
|
9957
9968
|
async ([network, { requestQueue, syncProgress }]) => {
|
|
9958
9969
|
args.common.logger.debug({
|
|
9959
9970
|
service: "sync",
|
|
@@ -9983,7 +9994,7 @@ var createSync = async (args) => {
|
|
|
9983
9994
|
network,
|
|
9984
9995
|
event
|
|
9985
9996
|
}) => {
|
|
9986
|
-
const { syncProgress, realtimeSync,
|
|
9997
|
+
const { syncProgress, realtimeSync, unfinalizedBlocks } = perNetworkSync.get(network);
|
|
9987
9998
|
switch (event.type) {
|
|
9988
9999
|
case "block": {
|
|
9989
10000
|
const from = getOmnichainCheckpoint("current");
|
|
@@ -9993,16 +10004,7 @@ var createSync = async (args) => {
|
|
|
9993
10004
|
{ network: network.name },
|
|
9994
10005
|
hexToNumber7(syncProgress.current.number)
|
|
9995
10006
|
);
|
|
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);
|
|
10007
|
+
const blockWithEventData = event;
|
|
10006
10008
|
const events = buildEvents({
|
|
10007
10009
|
sources: args.sources,
|
|
10008
10010
|
chainId: network.chainId,
|
|
@@ -10010,14 +10012,23 @@ var createSync = async (args) => {
|
|
|
10010
10012
|
finalizedChildAddresses: realtimeSync.finalizedChildAddresses,
|
|
10011
10013
|
unfinalizedChildAddresses: realtimeSync.unfinalizedChildAddresses
|
|
10012
10014
|
});
|
|
10013
|
-
|
|
10015
|
+
unfinalizedBlocks.push({ ...blockWithEventData, events });
|
|
10014
10016
|
if (to > from) {
|
|
10015
10017
|
for (const network2 of args.networks) {
|
|
10016
10018
|
updateRealtimeStatus({ checkpoint: to, network: network2 });
|
|
10017
10019
|
}
|
|
10018
|
-
const
|
|
10019
|
-
|
|
10020
|
-
({
|
|
10020
|
+
const pendingEvents = [];
|
|
10021
|
+
for (const { unfinalizedBlocks: unfinalizedBlocks2 } of perNetworkSync.values()) {
|
|
10022
|
+
for (const { events: events3 } of unfinalizedBlocks2) {
|
|
10023
|
+
for (const event2 of events3) {
|
|
10024
|
+
if (event2.checkpoint > from && event2.checkpoint <= to) {
|
|
10025
|
+
pendingEvents.push(event2);
|
|
10026
|
+
}
|
|
10027
|
+
}
|
|
10028
|
+
}
|
|
10029
|
+
}
|
|
10030
|
+
const events2 = pendingEvents.sort(
|
|
10031
|
+
(a, b) => a.checkpoint < b.checkpoint ? -1 : 1
|
|
10021
10032
|
);
|
|
10022
10033
|
args.onRealtimeEvent({
|
|
10023
10034
|
type: "block",
|
|
@@ -10046,39 +10057,40 @@ var createSync = async (args) => {
|
|
|
10046
10057
|
if (checkpoint > prev) {
|
|
10047
10058
|
args.onRealtimeEvent({ type: "finalize", checkpoint });
|
|
10048
10059
|
}
|
|
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
10060
|
if (getChainCheckpoint({ syncProgress, network, tag: "finalized" }) > getOmnichainCheckpoint("current")) {
|
|
10056
10061
|
args.common.logger.warn({
|
|
10057
10062
|
service: "sync",
|
|
10058
10063
|
msg: `Finalized block for '${network.name}' has surpassed overall indexing checkpoint`
|
|
10059
10064
|
});
|
|
10065
|
+
return;
|
|
10060
10066
|
}
|
|
10067
|
+
const finalizedBlocks = unfinalizedBlocks.filter(
|
|
10068
|
+
({ block }) => hexToNumber7(block.number) <= hexToNumber7(event.block.number)
|
|
10069
|
+
);
|
|
10070
|
+
perNetworkSync.get(network).unfinalizedBlocks = unfinalizedBlocks.filter(
|
|
10071
|
+
({ block }) => hexToNumber7(block.number) > hexToNumber7(event.block.number)
|
|
10072
|
+
);
|
|
10061
10073
|
await Promise.all([
|
|
10062
10074
|
args.syncStore.insertBlocks({
|
|
10063
|
-
blocks:
|
|
10075
|
+
blocks: finalizedBlocks.filter(({ hasMatchedFilter }) => hasMatchedFilter).map(({ block }) => block),
|
|
10064
10076
|
chainId: network.chainId
|
|
10065
10077
|
}),
|
|
10066
10078
|
args.syncStore.insertLogs({
|
|
10067
|
-
logs:
|
|
10079
|
+
logs: finalizedBlocks.flatMap(
|
|
10068
10080
|
({ logs, block }) => logs.map((log) => ({ log, block }))
|
|
10069
10081
|
),
|
|
10070
10082
|
shouldUpdateCheckpoint: true,
|
|
10071
10083
|
chainId: network.chainId
|
|
10072
10084
|
}),
|
|
10073
10085
|
args.syncStore.insertLogs({
|
|
10074
|
-
logs:
|
|
10086
|
+
logs: finalizedBlocks.flatMap(
|
|
10075
10087
|
({ factoryLogs }) => factoryLogs.map((log) => ({ log }))
|
|
10076
10088
|
),
|
|
10077
10089
|
shouldUpdateCheckpoint: false,
|
|
10078
10090
|
chainId: network.chainId
|
|
10079
10091
|
}),
|
|
10080
10092
|
args.syncStore.insertTransactions({
|
|
10081
|
-
transactions:
|
|
10093
|
+
transactions: finalizedBlocks.flatMap(
|
|
10082
10094
|
({ transactions, block }) => transactions.map((transaction) => ({
|
|
10083
10095
|
transaction,
|
|
10084
10096
|
block
|
|
@@ -10087,13 +10099,13 @@ var createSync = async (args) => {
|
|
|
10087
10099
|
chainId: network.chainId
|
|
10088
10100
|
}),
|
|
10089
10101
|
args.syncStore.insertTransactionReceipts({
|
|
10090
|
-
transactionReceipts:
|
|
10102
|
+
transactionReceipts: finalizedBlocks.flatMap(
|
|
10091
10103
|
({ transactionReceipts }) => transactionReceipts
|
|
10092
10104
|
),
|
|
10093
10105
|
chainId: network.chainId
|
|
10094
10106
|
}),
|
|
10095
10107
|
args.syncStore.insertTraces({
|
|
10096
|
-
traces:
|
|
10108
|
+
traces: finalizedBlocks.flatMap(
|
|
10097
10109
|
({ traces, block, transactions }) => traces.map((trace) => ({
|
|
10098
10110
|
trace,
|
|
10099
10111
|
block,
|
|
@@ -10134,15 +10146,8 @@ var createSync = async (args) => {
|
|
|
10134
10146
|
{ network: network.name },
|
|
10135
10147
|
hexToNumber7(syncProgress.current.number)
|
|
10136
10148
|
);
|
|
10137
|
-
|
|
10138
|
-
(
|
|
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
|
|
10149
|
+
perNetworkSync.get(network).unfinalizedBlocks = unfinalizedBlocks.filter(
|
|
10150
|
+
({ block }) => hexToNumber7(block.number) <= hexToNumber7(event.block.number)
|
|
10146
10151
|
);
|
|
10147
10152
|
await args.syncStore.pruneRpcRequestResult({
|
|
10148
10153
|
blocks: event.reorgedBlocks,
|
|
@@ -10159,7 +10164,7 @@ var createSync = async (args) => {
|
|
|
10159
10164
|
getEvents,
|
|
10160
10165
|
async startRealtime() {
|
|
10161
10166
|
for (const network of args.networks) {
|
|
10162
|
-
const { syncProgress, realtimeSync } =
|
|
10167
|
+
const { syncProgress, realtimeSync } = perNetworkSync.get(network);
|
|
10163
10168
|
status[network.name].block = {
|
|
10164
10169
|
number: hexToNumber7(syncProgress.current.number),
|
|
10165
10170
|
timestamp: hexToNumber7(syncProgress.current.timestamp)
|
|
@@ -10198,14 +10203,14 @@ var createSync = async (args) => {
|
|
|
10198
10203
|
return status;
|
|
10199
10204
|
},
|
|
10200
10205
|
getCachedTransport(network) {
|
|
10201
|
-
const { requestQueue } =
|
|
10206
|
+
const { requestQueue } = perNetworkSync.get(network);
|
|
10202
10207
|
return cachedTransport({ requestQueue, syncStore: args.syncStore });
|
|
10203
10208
|
},
|
|
10204
10209
|
async kill() {
|
|
10205
10210
|
isKilled = true;
|
|
10206
10211
|
const promises = [];
|
|
10207
10212
|
for (const network of args.networks) {
|
|
10208
|
-
const { historicalSync, realtimeSync } =
|
|
10213
|
+
const { historicalSync, realtimeSync } = perNetworkSync.get(network);
|
|
10209
10214
|
historicalSync.kill();
|
|
10210
10215
|
promises.push(realtimeSync.kill());
|
|
10211
10216
|
}
|