ponder 0.17.4 → 0.17.6
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/CHANGELOG.md +14 -0
- package/dist/esm/build/config.js +31 -16
- package/dist/esm/build/config.js.map +1 -1
- package/dist/esm/rpc/actions.js +13 -3
- package/dist/esm/rpc/actions.js.map +1 -1
- package/dist/esm/rpc/index.js +6 -0
- package/dist/esm/rpc/index.js.map +1 -1
- package/dist/esm/sync-historical/index.js +21 -56
- package/dist/esm/sync-historical/index.js.map +1 -1
- package/dist/types/build/config.d.ts.map +1 -1
- package/dist/types/rpc/actions.d.ts.map +1 -1
- package/dist/types/rpc/index.d.ts +2 -1
- package/dist/types/rpc/index.d.ts.map +1 -1
- package/dist/types/sync-historical/index.d.ts +1 -1
- package/dist/types/sync-historical/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/build/config.ts +48 -30
- package/src/rpc/actions.ts +25 -6
- package/src/rpc/index.ts +12 -0
- package/src/sync-historical/index.ts +70 -106
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
validateTracesAndBlock,
|
|
38
38
|
validateTransactionsAndBlock,
|
|
39
39
|
} from "@/rpc/actions.js";
|
|
40
|
-
import type
|
|
40
|
+
import { type Rpc, sanitizeLogTopics } from "@/rpc/index.js";
|
|
41
41
|
import {
|
|
42
42
|
getChildAddress,
|
|
43
43
|
isAddressFactory,
|
|
@@ -145,120 +145,72 @@ export const createHistoricalSync = (
|
|
|
145
145
|
logsRequestMetadata.estimatedRange,
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
-
const topics = [
|
|
148
|
+
const topics = sanitizeLogTopics([
|
|
149
149
|
topic0 ?? null,
|
|
150
150
|
topic1 ?? null,
|
|
151
151
|
topic2 ?? null,
|
|
152
152
|
topic3 ?? null,
|
|
153
|
-
]
|
|
154
|
-
|
|
155
|
-
// Note: the `topics` field is very fragile for many rpc providers, and
|
|
156
|
-
// cannot handle extra "null" topics
|
|
157
|
-
|
|
158
|
-
if (topics[3] === null) {
|
|
159
|
-
topics.pop();
|
|
160
|
-
if (topics[2] === null) {
|
|
161
|
-
topics.pop();
|
|
162
|
-
if (topics[1] === null) {
|
|
163
|
-
topics.pop();
|
|
164
|
-
if (topics[0] === null) {
|
|
165
|
-
topics.pop();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Batch large arrays of addresses, handling arrays that are empty
|
|
172
|
-
|
|
173
|
-
let addressBatches: (Address | Address[] | undefined)[];
|
|
174
|
-
|
|
175
|
-
if (address === undefined) {
|
|
176
|
-
// no address (match all)
|
|
177
|
-
addressBatches = [undefined];
|
|
178
|
-
} else if (typeof address === "string") {
|
|
179
|
-
// single address
|
|
180
|
-
addressBatches = [address];
|
|
181
|
-
} else if (address.length === 0) {
|
|
182
|
-
// no address (factory with no children)
|
|
183
|
-
return [];
|
|
184
|
-
} else {
|
|
185
|
-
// many addresses
|
|
186
|
-
// Note: it is assumed that `address` is deduplicated
|
|
187
|
-
addressBatches = [];
|
|
188
|
-
for (let i = 0; i < address.length; i += 50) {
|
|
189
|
-
addressBatches.push(address.slice(i, i + 50));
|
|
190
|
-
}
|
|
191
|
-
}
|
|
153
|
+
])!;
|
|
192
154
|
|
|
193
155
|
const logs = await Promise.all(
|
|
194
|
-
intervals.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
156
|
+
intervals.map((interval) =>
|
|
157
|
+
eth_getLogs(
|
|
158
|
+
args.rpc,
|
|
159
|
+
[
|
|
160
|
+
{
|
|
161
|
+
address,
|
|
162
|
+
topics,
|
|
163
|
+
fromBlock: numberToHex(interval[0]),
|
|
164
|
+
toBlock: numberToHex(interval[1]),
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
context,
|
|
168
|
+
).catch((error) => {
|
|
169
|
+
// Note: skip eth_getLogs range retry logic if the chain
|
|
170
|
+
// has a custom block range.
|
|
171
|
+
if (args.chain.ethGetLogsBlockRange !== undefined) {
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const getLogsErrorResponse = getLogsRetryHelper({
|
|
176
|
+
params: [
|
|
199
177
|
{
|
|
200
178
|
address,
|
|
201
179
|
topics,
|
|
202
|
-
fromBlock:
|
|
203
|
-
toBlock:
|
|
180
|
+
fromBlock: toHex(interval[0]),
|
|
181
|
+
toBlock: toHex(interval[1]),
|
|
204
182
|
},
|
|
205
183
|
],
|
|
206
|
-
|
|
207
|
-
)
|
|
208
|
-
// Note: skip eth_getLogs range retry logic if the chain
|
|
209
|
-
// has a custom block range.
|
|
210
|
-
if (args.chain.ethGetLogsBlockRange !== undefined) {
|
|
211
|
-
throw error;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const getLogsErrorResponse = getLogsRetryHelper({
|
|
215
|
-
params: [
|
|
216
|
-
{
|
|
217
|
-
address,
|
|
218
|
-
topics,
|
|
219
|
-
fromBlock: toHex(interval[0]),
|
|
220
|
-
toBlock: toHex(interval[1]),
|
|
221
|
-
},
|
|
222
|
-
],
|
|
223
|
-
error: error as RpcError,
|
|
224
|
-
});
|
|
184
|
+
error: error as RpcError,
|
|
185
|
+
});
|
|
225
186
|
|
|
226
|
-
|
|
187
|
+
if (getLogsErrorResponse.shouldRetry === false) throw error;
|
|
227
188
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
189
|
+
const range =
|
|
190
|
+
hexToNumber(getLogsErrorResponse.ranges[0]!.toBlock) -
|
|
191
|
+
hexToNumber(getLogsErrorResponse.ranges[0]!.fromBlock);
|
|
231
192
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
193
|
+
args.common.logger.debug({
|
|
194
|
+
msg: "Updated eth_getLogs range",
|
|
195
|
+
chain: args.chain.name,
|
|
196
|
+
chain_id: args.chain.id,
|
|
197
|
+
range,
|
|
198
|
+
});
|
|
238
199
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
200
|
+
logsRequestMetadata = {
|
|
201
|
+
estimatedRange: range,
|
|
202
|
+
confirmedRange: getLogsErrorResponse.isSuggestedRange
|
|
203
|
+
? range
|
|
204
|
+
: undefined,
|
|
205
|
+
};
|
|
245
206
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
),
|
|
207
|
+
return syncLogsDynamic(
|
|
208
|
+
{ address, topic0, topic1, topic2, topic3, interval },
|
|
209
|
+
context,
|
|
210
|
+
);
|
|
211
|
+
}),
|
|
252
212
|
),
|
|
253
|
-
).then((logs) =>
|
|
254
|
-
const result: SyncLog[] = [];
|
|
255
|
-
for (const _logs of logs) {
|
|
256
|
-
for (const log of _logs) {
|
|
257
|
-
result.push(log);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return result;
|
|
261
|
-
});
|
|
213
|
+
).then((logs) => logs.flat());
|
|
262
214
|
|
|
263
215
|
/**
|
|
264
216
|
* Dynamically increase the range used in "eth_getLogs" if an
|
|
@@ -483,13 +435,18 @@ export const createHistoricalSync = (
|
|
|
483
435
|
if (filter.type !== "log") continue;
|
|
484
436
|
|
|
485
437
|
const hasAddress = filter.address !== undefined;
|
|
486
|
-
const hasTopic1 = filter.topic1 !== undefined;
|
|
487
|
-
const hasTopic2 = filter.topic2 !== undefined;
|
|
488
|
-
const hasTopic3 = filter.topic3 !== undefined;
|
|
438
|
+
const hasTopic1 = filter.topic1 !== undefined && filter.topic1 !== null;
|
|
439
|
+
const hasTopic2 = filter.topic2 !== undefined && filter.topic2 !== null;
|
|
440
|
+
const hasTopic3 = filter.topic3 !== undefined && filter.topic3 !== null;
|
|
489
441
|
|
|
490
442
|
if (hasAddress === false || hasTopic1 || hasTopic2 || hasTopic3) {
|
|
491
443
|
if (isAddressFactory(filter.address)) {
|
|
492
444
|
const childAddresses = args.childAddresses.get(filter.address.id)!;
|
|
445
|
+
|
|
446
|
+
if (childAddresses.size === 0) {
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
|
|
493
450
|
singleEthGetLogsParams.push({
|
|
494
451
|
address:
|
|
495
452
|
childAddresses.size >=
|
|
@@ -528,6 +485,11 @@ export const createHistoricalSync = (
|
|
|
528
485
|
if (mergedEthGetLogsParams.has(addressKey) === false) {
|
|
529
486
|
if (isAddressFactory(filter.address)) {
|
|
530
487
|
const childAddresses = args.childAddresses.get(filter.address.id)!;
|
|
488
|
+
|
|
489
|
+
if (childAddresses.size === 0) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
|
|
531
493
|
mergedEthGetLogsParams.set(addressKey, {
|
|
532
494
|
address:
|
|
533
495
|
childAddresses.size >=
|
|
@@ -734,12 +696,14 @@ export const createHistoricalSync = (
|
|
|
734
696
|
) {
|
|
735
697
|
isMatched = true;
|
|
736
698
|
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
699
|
+
if (log.transactionHash !== zeroHash) {
|
|
700
|
+
requiredTransactions.add(log.transactionHash);
|
|
701
|
+
if (filter.hasTransactionReceipt) {
|
|
702
|
+
requiredTransactionReceipts.add(log.transactionHash);
|
|
740
703
|
|
|
741
|
-
|
|
742
|
-
|
|
704
|
+
// skip to next log
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
743
707
|
}
|
|
744
708
|
}
|
|
745
709
|
}
|