envio 3.13.0-alpha.0 → 3.13.0
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/package.json +6 -8
- package/src/BatchProcessing.res +4 -5
- package/src/BatchProcessing.res.mjs +4 -11
- package/src/ChainFetching.res +18 -38
- package/src/ChainFetching.res.mjs +14 -20
- package/src/ChainState.res +113 -77
- package/src/ChainState.res.mjs +90 -73
- package/src/ChainState.resi +14 -5
- package/src/Config.res +14 -17
- package/src/Config.res.mjs +5 -20
- package/src/CrossChainState.res +68 -20
- package/src/CrossChainState.res.mjs +48 -5
- package/src/CrossChainState.resi +1 -0
- package/src/Env.res +2 -2
- package/src/ErrorHandling.res +15 -4
- package/src/ErrorHandling.res.mjs +16 -5
- package/src/FinalizeBackfill.res +21 -9
- package/src/FinalizeBackfill.res.mjs +17 -4
- package/src/HandlerRegister.res +0 -37
- package/src/HandlerRegister.res.mjs +0 -18
- package/src/IndexerState.res +2 -0
- package/src/IndexerState.res.mjs +5 -0
- package/src/IndexerState.resi +1 -0
- package/src/Logging.res +6 -38
- package/src/Logging.res.mjs +5 -32
- package/src/Main.res +6 -9
- package/src/Main.res.mjs +3 -5
- package/src/Metrics.res +9 -4
- package/src/Metrics.res.mjs +3 -3
- package/src/Persistence.res +6 -3
- package/src/Persistence.res.mjs +5 -3
- package/src/PgStorage.res +2 -2
- package/src/PgStorage.res.mjs +2 -2
- package/src/Rollback.res +3 -3
- package/src/Server.res +0 -3
- package/src/SimulateItems.res +1 -1
- package/src/SimulateItems.res.mjs +1 -1
- package/src/Supervisor.res +236 -109
- package/src/Supervisor.res.mjs +185 -55
- package/src/TestIndexer.res +6 -3
- package/src/TestIndexer.res.mjs +3 -3
- package/src/Worker.res +6 -0
- package/src/Worker.res.mjs +2 -1
- package/src/bindings/NodeJs.res +25 -16
- package/src/bindings/NodeJs.res.mjs +8 -1
- package/src/sources/AddressSet.res +5 -3
- package/src/sources/AddressStore.res +19 -11
- package/src/sources/AddressStore.res.mjs +2 -7
- package/src/sources/BlockStore.res +10 -9
- package/src/sources/BlockStore.res.mjs +4 -4
- package/src/sources/ChainSources.res +4 -0
- package/src/sources/ChainSources.res.mjs +2 -2
- package/src/sources/EvmChain.res +4 -0
- package/src/sources/EvmChain.res.mjs +3 -1
- package/src/sources/EvmEventItem.res +56 -0
- package/src/sources/EvmEventItem.res.mjs +32 -0
- package/src/sources/EvmHyperSyncSource.res +7 -37
- package/src/sources/EvmHyperSyncSource.res.mjs +8 -29
- package/src/sources/EvmRpcClient.res +41 -59
- package/src/sources/EvmRpcClient.res.mjs +4 -54
- package/src/sources/EvmRpcWs.res +4 -1
- package/src/sources/EvmRpcWs.res.mjs +6 -2
- package/src/sources/FuelHyperSyncSource.res +6 -4
- package/src/sources/FuelHyperSyncSource.res.mjs +7 -9
- package/src/sources/HeightFeed.res +7 -1
- package/src/sources/HeightFeed.res.mjs +9 -7
- package/src/sources/HyperSyncClient.res +1 -14
- package/src/sources/RequestStat.res +7 -0
- package/src/sources/RequestStat.res.mjs +14 -1
- package/src/sources/RpcSource.res +100 -1043
- package/src/sources/RpcSource.res.mjs +81 -1056
- package/src/sources/SimulateSource.res +2 -5
- package/src/sources/SimulateSource.res.mjs +2 -3
- package/src/sources/Source.res +34 -12
- package/src/sources/Source.res.mjs +11 -0
- package/src/sources/SourceManager.res +111 -31
- package/src/sources/SourceManager.res.mjs +65 -31
- package/src/sources/SourceManager.resi +4 -0
- package/src/sources/StartBlockResolver.res +8 -5
- package/src/sources/StartBlockResolver.res.mjs +4 -2
- package/src/sources/SvmHyperSyncSource.res +4 -2
- package/src/sources/SvmHyperSyncSource.res.mjs +4 -6
- package/src/sources/TransactionStore.res +9 -6
- package/src/sources/TransactionStore.res.mjs +2 -2
- package/src/tui/Tui.res +4 -18
- package/src/tui/Tui.res.mjs +3 -6
- package/src/LazyLoader.res +0 -135
- package/src/LazyLoader.res.mjs +0 -118
- package/src/bindings/SDSL.res +0 -12
- package/src/bindings/SDSL.res.mjs +0 -9
- package/src/bindings/Yargs.res +0 -8
- package/src/bindings/Yargs.res.mjs +0 -2
- package/src/sources/Rpc.res +0 -185
- package/src/sources/Rpc.res.mjs +0 -183
|
@@ -1,780 +1,22 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Rpc from "./Rpc.res.mjs";
|
|
4
|
-
import * as Rest from "../vendored/Rest.res.mjs";
|
|
5
|
-
import * as Time from "../Time.res.mjs";
|
|
6
3
|
import * as Utils from "../Utils.res.mjs";
|
|
7
4
|
import * as Source from "./Source.res.mjs";
|
|
8
|
-
import * as Address from "../Address.res.mjs";
|
|
9
5
|
import * as ChainId from "../ChainId.res.mjs";
|
|
10
|
-
import * as Logging from "../Logging.res.mjs";
|
|
11
6
|
import * as EvmRpcWs from "./EvmRpcWs.res.mjs";
|
|
12
|
-
import * as Internal from "../Internal.res.mjs";
|
|
13
|
-
import * as BlockStore from "./BlockStore.res.mjs";
|
|
14
|
-
import * as LazyLoader from "../LazyLoader.res.mjs";
|
|
15
7
|
import * as Performance from "../bindings/Performance.res.mjs";
|
|
16
|
-
import * as
|
|
8
|
+
import * as EvmEventItem from "./EvmEventItem.res.mjs";
|
|
17
9
|
import * as EvmRpcClient from "./EvmRpcClient.res.mjs";
|
|
18
|
-
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
19
|
-
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
20
10
|
import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
|
|
21
11
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
22
12
|
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
23
|
-
import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.js";
|
|
24
13
|
import * as HyperSyncClient from "./HyperSyncClient.res.mjs";
|
|
25
14
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
26
|
-
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
27
15
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
28
16
|
|
|
29
|
-
let TransactionDataNotFound = /* @__PURE__ */Primitive_exceptions.create("RpcSource.TransactionDataNotFound");
|
|
30
|
-
|
|
31
|
-
async function getKnownRawBlock(client, blockNumber) {
|
|
32
|
-
let json = await Rpc.getRawBlock(client, blockNumber);
|
|
33
|
-
if (json !== undefined) {
|
|
34
|
-
return json;
|
|
35
|
-
} else {
|
|
36
|
-
return Stdlib_JsError.throwWithMessage(`RPC returned null for blockNumber ` + blockNumber.toString());
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function parseBlockInfo(json) {
|
|
41
|
-
return {
|
|
42
|
-
number: S$RescriptSchema.parseOrThrow(json["number"], Rpc.hexIntSchema),
|
|
43
|
-
timestamp: S$RescriptSchema.parseOrThrow(json["timestamp"], Rpc.hexIntSchema),
|
|
44
|
-
hash: S$RescriptSchema.parseOrThrow(json["hash"], S$RescriptSchema.string),
|
|
45
|
-
parentHash: S$RescriptSchema.parseOrThrow(json["parentHash"], S$RescriptSchema.string)
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async function getKnownRawBlockWithBackoff(client, sourceName, chainId, blockNumber, backoffMsOnFailure, recordRequest) {
|
|
50
|
-
let currentBackoff = backoffMsOnFailure;
|
|
51
|
-
let result;
|
|
52
|
-
while (Stdlib_Option.isNone(result)) {
|
|
53
|
-
let timerRef = Performance.now();
|
|
54
|
-
let exit = 0;
|
|
55
|
-
let json;
|
|
56
|
-
try {
|
|
57
|
-
json = await getKnownRawBlock(client, blockNumber);
|
|
58
|
-
exit = 1;
|
|
59
|
-
} catch (raw_err) {
|
|
60
|
-
let err = Primitive_exceptions.internalToException(raw_err);
|
|
61
|
-
recordRequest("eth_getBlockByNumber", Performance.secondsSince(timerRef));
|
|
62
|
-
Logging.warn({
|
|
63
|
-
err: Utils.prettifyExn(err),
|
|
64
|
-
msg: `Issue while running fetching batch of events from the RPC. Will wait ` + currentBackoff.toString() + `ms and try again.`,
|
|
65
|
-
source: sourceName,
|
|
66
|
-
chainId: chainId,
|
|
67
|
-
type: "EXPONENTIAL_BACKOFF"
|
|
68
|
-
});
|
|
69
|
-
await Time.resolvePromiseAfterDelay(currentBackoff);
|
|
70
|
-
currentBackoff = (currentBackoff << 1);
|
|
71
|
-
}
|
|
72
|
-
if (exit === 1) {
|
|
73
|
-
recordRequest("eth_getBlockByNumber", Performance.secondsSince(timerRef));
|
|
74
|
-
result = json;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
return Stdlib_Option.getOrThrow(result, undefined);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function getErrorMessage(exn) {
|
|
81
|
-
if (exn.RE_EXN_ID === Rpc.JsonRpcError) {
|
|
82
|
-
return exn._1.message;
|
|
83
|
-
}
|
|
84
|
-
if (exn.RE_EXN_ID !== "JsExn") {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
let msg = Stdlib_JsExn.message(exn._1);
|
|
88
|
-
if (msg === undefined) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
let obj;
|
|
92
|
-
try {
|
|
93
|
-
obj = Stdlib_JSON.Decode.object(JSON.parse(msg));
|
|
94
|
-
} catch (exn$1) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (obj === undefined) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
let match = obj["errorMessage"];
|
|
101
|
-
if (typeof match === "string") {
|
|
102
|
-
return match;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function parseGetNextPageRetryError(exn) {
|
|
107
|
-
if (exn.RE_EXN_ID !== "JsExn") {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
let msg = Stdlib_JsExn.message(exn._1);
|
|
111
|
-
if (msg === undefined) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
let obj;
|
|
115
|
-
try {
|
|
116
|
-
obj = Stdlib_JSON.Decode.object(JSON.parse(msg));
|
|
117
|
-
} catch (exn$1) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
if (obj === undefined) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
let match = obj["kind"];
|
|
124
|
-
let match$1 = obj["attemptedToBlock"];
|
|
125
|
-
let match$2 = obj["retry"];
|
|
126
|
-
if (match === undefined) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
if (typeof match !== "string") {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if (match !== "Retry") {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
if (match$1 === undefined) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (typeof match$1 !== "number") {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (match$2 === undefined) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
if (typeof match$2 !== "object" || match$2 === null || Array.isArray(match$2)) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
let match$3 = obj["requestStats"];
|
|
148
|
-
let requestStats = match$3 !== undefined ? (
|
|
149
|
-
Array.isArray(match$3) ? Stdlib_Array.filterMap(match$3, s => {
|
|
150
|
-
let o = Stdlib_JSON.Decode.object(s);
|
|
151
|
-
if (o === undefined) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
let match = o["method"];
|
|
155
|
-
let match$1 = o["seconds"];
|
|
156
|
-
if (typeof match === "string" && typeof match$1 === "number") {
|
|
157
|
-
return {
|
|
158
|
-
method: match,
|
|
159
|
-
seconds: match$1
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
}) : []
|
|
163
|
-
) : [];
|
|
164
|
-
let match$4 = match$2["tag"];
|
|
165
|
-
let retry;
|
|
166
|
-
if (typeof match$4 === "string") {
|
|
167
|
-
switch (match$4) {
|
|
168
|
-
case "WithBackoff" :
|
|
169
|
-
let match$5 = match$2["message"];
|
|
170
|
-
let match$6 = match$2["backoffMillis"];
|
|
171
|
-
retry = typeof match$5 === "string" && typeof match$6 === "number" ? ({
|
|
172
|
-
TAG: "WithBackoff",
|
|
173
|
-
message: match$5,
|
|
174
|
-
backoffMillis: match$6 | 0
|
|
175
|
-
}) : undefined;
|
|
176
|
-
break;
|
|
177
|
-
case "WithSuggestedToBlock" :
|
|
178
|
-
let match$7 = match$2["toBlock"];
|
|
179
|
-
retry = typeof match$7 === "number" ? ({
|
|
180
|
-
TAG: "WithSuggestedToBlock",
|
|
181
|
-
toBlock: match$7 | 0
|
|
182
|
-
}) : undefined;
|
|
183
|
-
break;
|
|
184
|
-
default:
|
|
185
|
-
retry = undefined;
|
|
186
|
-
}
|
|
187
|
-
} else {
|
|
188
|
-
retry = undefined;
|
|
189
|
-
}
|
|
190
|
-
return Stdlib_Option.map(retry, retry => [
|
|
191
|
-
match$1 | 0,
|
|
192
|
-
retry,
|
|
193
|
-
requestStats
|
|
194
|
-
]);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
let lowercaseAddressSchema = S$RescriptSchema.transform(S$RescriptSchema.string, param => ({
|
|
198
|
-
p: str => str.toLowerCase()
|
|
199
|
-
}));
|
|
200
|
-
|
|
201
|
-
let checksumAddressSchema = S$RescriptSchema.transform(S$RescriptSchema.string, param => ({
|
|
202
|
-
p: str => Address.Evm.fromStringOrThrow(str)
|
|
203
|
-
}));
|
|
204
|
-
|
|
205
|
-
function makeBlockFieldRegistry(addressSchema) {
|
|
206
|
-
return Utils.Record.fromArray([
|
|
207
|
-
{
|
|
208
|
-
location: "number",
|
|
209
|
-
jsonKey: "number",
|
|
210
|
-
schema: Rpc.hexIntSchema
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
location: "timestamp",
|
|
214
|
-
jsonKey: "timestamp",
|
|
215
|
-
schema: Rpc.hexIntSchema
|
|
216
|
-
},
|
|
217
|
-
{
|
|
218
|
-
location: "hash",
|
|
219
|
-
jsonKey: "hash",
|
|
220
|
-
schema: S$RescriptSchema.string
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
location: "parentHash",
|
|
224
|
-
jsonKey: "parentHash",
|
|
225
|
-
schema: S$RescriptSchema.string
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
location: "nonce",
|
|
229
|
-
jsonKey: "nonce",
|
|
230
|
-
schema: Rpc.hexBigintSchema
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
location: "sha3Uncles",
|
|
234
|
-
jsonKey: "sha3Uncles",
|
|
235
|
-
schema: S$RescriptSchema.string
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
location: "logsBloom",
|
|
239
|
-
jsonKey: "logsBloom",
|
|
240
|
-
schema: S$RescriptSchema.string
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
location: "transactionsRoot",
|
|
244
|
-
jsonKey: "transactionsRoot",
|
|
245
|
-
schema: S$RescriptSchema.string
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
location: "stateRoot",
|
|
249
|
-
jsonKey: "stateRoot",
|
|
250
|
-
schema: S$RescriptSchema.string
|
|
251
|
-
},
|
|
252
|
-
{
|
|
253
|
-
location: "receiptsRoot",
|
|
254
|
-
jsonKey: "receiptsRoot",
|
|
255
|
-
schema: S$RescriptSchema.string
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
location: "miner",
|
|
259
|
-
jsonKey: "miner",
|
|
260
|
-
schema: addressSchema
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
location: "difficulty",
|
|
264
|
-
jsonKey: "difficulty",
|
|
265
|
-
schema: Rpc.hexBigintSchema
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
location: "totalDifficulty",
|
|
269
|
-
jsonKey: "totalDifficulty",
|
|
270
|
-
schema: Rpc.hexBigintSchema
|
|
271
|
-
},
|
|
272
|
-
{
|
|
273
|
-
location: "extraData",
|
|
274
|
-
jsonKey: "extraData",
|
|
275
|
-
schema: S$RescriptSchema.string
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
location: "size",
|
|
279
|
-
jsonKey: "size",
|
|
280
|
-
schema: Rpc.hexBigintSchema
|
|
281
|
-
},
|
|
282
|
-
{
|
|
283
|
-
location: "gasLimit",
|
|
284
|
-
jsonKey: "gasLimit",
|
|
285
|
-
schema: Rpc.hexBigintSchema
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
location: "gasUsed",
|
|
289
|
-
jsonKey: "gasUsed",
|
|
290
|
-
schema: Rpc.hexBigintSchema
|
|
291
|
-
},
|
|
292
|
-
{
|
|
293
|
-
location: "uncles",
|
|
294
|
-
jsonKey: "uncles",
|
|
295
|
-
schema: S$RescriptSchema.array(S$RescriptSchema.string)
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
location: "baseFeePerGas",
|
|
299
|
-
jsonKey: "baseFeePerGas",
|
|
300
|
-
schema: Rpc.hexBigintSchema
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
location: "blobGasUsed",
|
|
304
|
-
jsonKey: "blobGasUsed",
|
|
305
|
-
schema: Rpc.hexBigintSchema
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
location: "excessBlobGas",
|
|
309
|
-
jsonKey: "excessBlobGas",
|
|
310
|
-
schema: Rpc.hexBigintSchema
|
|
311
|
-
},
|
|
312
|
-
{
|
|
313
|
-
location: "parentBeaconBlockRoot",
|
|
314
|
-
jsonKey: "parentBeaconBlockRoot",
|
|
315
|
-
schema: S$RescriptSchema.string
|
|
316
|
-
},
|
|
317
|
-
{
|
|
318
|
-
location: "withdrawalsRoot",
|
|
319
|
-
jsonKey: "withdrawalsRoot",
|
|
320
|
-
schema: S$RescriptSchema.string
|
|
321
|
-
},
|
|
322
|
-
{
|
|
323
|
-
location: "l1BlockNumber",
|
|
324
|
-
jsonKey: "l1BlockNumber",
|
|
325
|
-
schema: Rpc.hexIntSchema
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
location: "sendCount",
|
|
329
|
-
jsonKey: "sendCount",
|
|
330
|
-
schema: S$RescriptSchema.string
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
location: "sendRoot",
|
|
334
|
-
jsonKey: "sendRoot",
|
|
335
|
-
schema: S$RescriptSchema.string
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
location: "mixHash",
|
|
339
|
-
jsonKey: "mixHash",
|
|
340
|
-
schema: S$RescriptSchema.string
|
|
341
|
-
}
|
|
342
|
-
].map(def => [
|
|
343
|
-
def.location,
|
|
344
|
-
Internal.evmNullableBlockFields.has(def.location) ? ({
|
|
345
|
-
location: def.location,
|
|
346
|
-
jsonKey: def.jsonKey,
|
|
347
|
-
schema: S$RescriptSchema.nullable(def.schema)
|
|
348
|
-
}) : def
|
|
349
|
-
]));
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
let blockFieldRegistryLowercase = makeBlockFieldRegistry(lowercaseAddressSchema);
|
|
353
|
-
|
|
354
|
-
let blockFieldRegistryChecksum = makeBlockFieldRegistry(checksumAddressSchema);
|
|
355
|
-
|
|
356
|
-
function parseBlockFieldsFromJson(mutBlockAcc, fields, json) {
|
|
357
|
-
fields.forEach(def => {
|
|
358
|
-
let raw = json[def.jsonKey];
|
|
359
|
-
try {
|
|
360
|
-
let parsed = S$RescriptSchema.parseOrThrow(raw, def.schema);
|
|
361
|
-
mutBlockAcc[def.location] = parsed;
|
|
362
|
-
return;
|
|
363
|
-
} catch (raw_error) {
|
|
364
|
-
let error = Primitive_exceptions.internalToException(raw_error);
|
|
365
|
-
if (error.RE_EXN_ID === S$RescriptSchema.Raised) {
|
|
366
|
-
return Stdlib_JsError.throwWithMessage(`Invalid block field "` + def.location + `" found in the RPC response. Error: ` + S$RescriptSchema.$$Error.reason(error._1));
|
|
367
|
-
}
|
|
368
|
-
throw error;
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
function makeThrowingGetEventBlock(getBlockJson, lowercaseAddresses) {
|
|
374
|
-
let blockFieldRegistry = lowercaseAddresses ? blockFieldRegistryLowercase : blockFieldRegistryChecksum;
|
|
375
|
-
let fnsCache = new WeakMap();
|
|
376
|
-
return (log, selectedBlockFields) => {
|
|
377
|
-
let fn = fnsCache.get(selectedBlockFields);
|
|
378
|
-
let tmp;
|
|
379
|
-
if (fn !== undefined) {
|
|
380
|
-
tmp = fn;
|
|
381
|
-
} else {
|
|
382
|
-
let fields = [];
|
|
383
|
-
selectedBlockFields.forEach(fieldName => {
|
|
384
|
-
fields.push(blockFieldRegistry[fieldName]);
|
|
385
|
-
});
|
|
386
|
-
let fn$1 = selectedBlockFields.size === 0 ? param => Promise.resolve({}) : log => getBlockJson(log.blockNumber).then(json => {
|
|
387
|
-
let mutBlockAcc = {};
|
|
388
|
-
parseBlockFieldsFromJson(mutBlockAcc, fields, json);
|
|
389
|
-
return mutBlockAcc;
|
|
390
|
-
});
|
|
391
|
-
fnsCache.set(selectedBlockFields, fn$1);
|
|
392
|
-
tmp = fn$1;
|
|
393
|
-
}
|
|
394
|
-
return tmp(log);
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
function makeFieldRegistry(addressSchema) {
|
|
399
|
-
return Utils.Record.fromArray([
|
|
400
|
-
{
|
|
401
|
-
location: "gas",
|
|
402
|
-
jsonKey: "gas",
|
|
403
|
-
schema: Rpc.hexBigintSchema,
|
|
404
|
-
source: "TransactionOnly"
|
|
405
|
-
},
|
|
406
|
-
{
|
|
407
|
-
location: "gasPrice",
|
|
408
|
-
jsonKey: "gasPrice",
|
|
409
|
-
schema: Rpc.hexBigintSchema,
|
|
410
|
-
source: "TransactionOnly"
|
|
411
|
-
},
|
|
412
|
-
{
|
|
413
|
-
location: "input",
|
|
414
|
-
jsonKey: "input",
|
|
415
|
-
schema: S$RescriptSchema.string,
|
|
416
|
-
source: "TransactionOnly"
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
location: "nonce",
|
|
420
|
-
jsonKey: "nonce",
|
|
421
|
-
schema: Rpc.hexBigintSchema,
|
|
422
|
-
source: "TransactionOnly"
|
|
423
|
-
},
|
|
424
|
-
{
|
|
425
|
-
location: "value",
|
|
426
|
-
jsonKey: "value",
|
|
427
|
-
schema: Rpc.hexBigintSchema,
|
|
428
|
-
source: "TransactionOnly"
|
|
429
|
-
},
|
|
430
|
-
{
|
|
431
|
-
location: "v",
|
|
432
|
-
jsonKey: "v",
|
|
433
|
-
schema: S$RescriptSchema.string,
|
|
434
|
-
source: "TransactionOnly"
|
|
435
|
-
},
|
|
436
|
-
{
|
|
437
|
-
location: "r",
|
|
438
|
-
jsonKey: "r",
|
|
439
|
-
schema: S$RescriptSchema.string,
|
|
440
|
-
source: "TransactionOnly"
|
|
441
|
-
},
|
|
442
|
-
{
|
|
443
|
-
location: "s",
|
|
444
|
-
jsonKey: "s",
|
|
445
|
-
schema: S$RescriptSchema.string,
|
|
446
|
-
source: "TransactionOnly"
|
|
447
|
-
},
|
|
448
|
-
{
|
|
449
|
-
location: "yParity",
|
|
450
|
-
jsonKey: "yParity",
|
|
451
|
-
schema: S$RescriptSchema.string,
|
|
452
|
-
source: "TransactionOnly"
|
|
453
|
-
},
|
|
454
|
-
{
|
|
455
|
-
location: "maxPriorityFeePerGas",
|
|
456
|
-
jsonKey: "maxPriorityFeePerGas",
|
|
457
|
-
schema: Rpc.hexBigintSchema,
|
|
458
|
-
source: "TransactionOnly"
|
|
459
|
-
},
|
|
460
|
-
{
|
|
461
|
-
location: "maxFeePerGas",
|
|
462
|
-
jsonKey: "maxFeePerGas",
|
|
463
|
-
schema: Rpc.hexBigintSchema,
|
|
464
|
-
source: "TransactionOnly"
|
|
465
|
-
},
|
|
466
|
-
{
|
|
467
|
-
location: "maxFeePerBlobGas",
|
|
468
|
-
jsonKey: "maxFeePerBlobGas",
|
|
469
|
-
schema: Rpc.hexBigintSchema,
|
|
470
|
-
source: "TransactionOnly"
|
|
471
|
-
},
|
|
472
|
-
{
|
|
473
|
-
location: "blobVersionedHashes",
|
|
474
|
-
jsonKey: "blobVersionedHashes",
|
|
475
|
-
schema: S$RescriptSchema.array(S$RescriptSchema.string),
|
|
476
|
-
source: "TransactionOnly"
|
|
477
|
-
},
|
|
478
|
-
{
|
|
479
|
-
location: "gasUsed",
|
|
480
|
-
jsonKey: "gasUsed",
|
|
481
|
-
schema: Rpc.hexBigintSchema,
|
|
482
|
-
source: "ReceiptOnly"
|
|
483
|
-
},
|
|
484
|
-
{
|
|
485
|
-
location: "cumulativeGasUsed",
|
|
486
|
-
jsonKey: "cumulativeGasUsed",
|
|
487
|
-
schema: Rpc.hexBigintSchema,
|
|
488
|
-
source: "ReceiptOnly"
|
|
489
|
-
},
|
|
490
|
-
{
|
|
491
|
-
location: "effectiveGasPrice",
|
|
492
|
-
jsonKey: "effectiveGasPrice",
|
|
493
|
-
schema: Rpc.hexBigintSchema,
|
|
494
|
-
source: "ReceiptOnly"
|
|
495
|
-
},
|
|
496
|
-
{
|
|
497
|
-
location: "contractAddress",
|
|
498
|
-
jsonKey: "contractAddress",
|
|
499
|
-
schema: addressSchema,
|
|
500
|
-
source: "ReceiptOnly"
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
location: "logsBloom",
|
|
504
|
-
jsonKey: "logsBloom",
|
|
505
|
-
schema: S$RescriptSchema.string,
|
|
506
|
-
source: "ReceiptOnly"
|
|
507
|
-
},
|
|
508
|
-
{
|
|
509
|
-
location: "root",
|
|
510
|
-
jsonKey: "root",
|
|
511
|
-
schema: S$RescriptSchema.string,
|
|
512
|
-
source: "ReceiptOnly"
|
|
513
|
-
},
|
|
514
|
-
{
|
|
515
|
-
location: "status",
|
|
516
|
-
jsonKey: "status",
|
|
517
|
-
schema: Rpc.hexIntSchema,
|
|
518
|
-
source: "ReceiptOnly"
|
|
519
|
-
},
|
|
520
|
-
{
|
|
521
|
-
location: "l1Fee",
|
|
522
|
-
jsonKey: "l1Fee",
|
|
523
|
-
schema: Rpc.hexBigintSchema,
|
|
524
|
-
source: "ReceiptOnly"
|
|
525
|
-
},
|
|
526
|
-
{
|
|
527
|
-
location: "l1GasPrice",
|
|
528
|
-
jsonKey: "l1GasPrice",
|
|
529
|
-
schema: Rpc.hexBigintSchema,
|
|
530
|
-
source: "ReceiptOnly"
|
|
531
|
-
},
|
|
532
|
-
{
|
|
533
|
-
location: "l1GasUsed",
|
|
534
|
-
jsonKey: "l1GasUsed",
|
|
535
|
-
schema: Rpc.hexBigintSchema,
|
|
536
|
-
source: "ReceiptOnly"
|
|
537
|
-
},
|
|
538
|
-
{
|
|
539
|
-
location: "l1FeeScalar",
|
|
540
|
-
jsonKey: "l1FeeScalar",
|
|
541
|
-
schema: Rpc.decimalFloatSchema,
|
|
542
|
-
source: "ReceiptOnly"
|
|
543
|
-
},
|
|
544
|
-
{
|
|
545
|
-
location: "gasUsedForL1",
|
|
546
|
-
jsonKey: "gasUsedForL1",
|
|
547
|
-
schema: Rpc.hexBigintSchema,
|
|
548
|
-
source: "ReceiptOnly"
|
|
549
|
-
},
|
|
550
|
-
{
|
|
551
|
-
location: "from",
|
|
552
|
-
jsonKey: "from",
|
|
553
|
-
schema: addressSchema,
|
|
554
|
-
source: "Both"
|
|
555
|
-
},
|
|
556
|
-
{
|
|
557
|
-
location: "to",
|
|
558
|
-
jsonKey: "to",
|
|
559
|
-
schema: addressSchema,
|
|
560
|
-
source: "Both"
|
|
561
|
-
},
|
|
562
|
-
{
|
|
563
|
-
location: "type",
|
|
564
|
-
jsonKey: "type",
|
|
565
|
-
schema: Rpc.hexIntSchema,
|
|
566
|
-
source: "Both"
|
|
567
|
-
}
|
|
568
|
-
].map(def => [
|
|
569
|
-
def.location,
|
|
570
|
-
Internal.evmNullableTransactionFields.has(def.location) ? ({
|
|
571
|
-
location: def.location,
|
|
572
|
-
jsonKey: def.jsonKey,
|
|
573
|
-
schema: S$RescriptSchema.nullable(def.schema),
|
|
574
|
-
source: def.source
|
|
575
|
-
}) : def
|
|
576
|
-
]));
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
let fieldRegistryLowercase = makeFieldRegistry(lowercaseAddressSchema);
|
|
580
|
-
|
|
581
|
-
let fieldRegistryChecksum = makeFieldRegistry(checksumAddressSchema);
|
|
582
|
-
|
|
583
|
-
function isRpcTransactionField(name) {
|
|
584
|
-
switch (name) {
|
|
585
|
-
case "hash" :
|
|
586
|
-
case "transactionIndex" :
|
|
587
|
-
return true;
|
|
588
|
-
default:
|
|
589
|
-
return Stdlib_Option.isSome(fieldRegistryChecksum[name]);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
function parseFieldsFromJson(mutTransactionAcc, fields, json) {
|
|
594
|
-
fields.forEach(def => {
|
|
595
|
-
let raw = json[def.jsonKey];
|
|
596
|
-
try {
|
|
597
|
-
let parsed = S$RescriptSchema.parseOrThrow(raw, def.schema);
|
|
598
|
-
mutTransactionAcc[def.location] = parsed;
|
|
599
|
-
return;
|
|
600
|
-
} catch (raw_error) {
|
|
601
|
-
let error = Primitive_exceptions.internalToException(raw_error);
|
|
602
|
-
if (error.RE_EXN_ID === S$RescriptSchema.Raised) {
|
|
603
|
-
return Stdlib_JsError.throwWithMessage(`Invalid transaction field "` + def.location + `" found in the RPC response. Error: ` + S$RescriptSchema.$$Error.reason(error._1));
|
|
604
|
-
}
|
|
605
|
-
throw error;
|
|
606
|
-
}
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
let effectiveGasPriceFallbackDef = {
|
|
611
|
-
location: "effectiveGasPrice",
|
|
612
|
-
jsonKey: "gasPrice",
|
|
613
|
-
schema: Rpc.hexBigintSchema,
|
|
614
|
-
source: "TransactionOnly"
|
|
615
|
-
};
|
|
616
|
-
|
|
617
|
-
function fillEffectiveGasPriceOrThrow(mutTransactionAcc, txJson) {
|
|
618
|
-
let gasPrice = txJson["gasPrice"];
|
|
619
|
-
if (gasPrice !== undefined) {
|
|
620
|
-
return parseFieldsFromJson(mutTransactionAcc, [effectiveGasPriceFallbackDef], txJson);
|
|
621
|
-
} else {
|
|
622
|
-
return Stdlib_JsError.throwWithMessage(`Neither "effectiveGasPrice" nor "gasPrice" is present in the RPC response for the transaction. Remove "effectiveGasPrice" from the field selection, or index this chain via HyperSync.`);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
function makeThrowingGetEventTransaction(getTransactionJson, getReceiptJson, lowercaseAddresses) {
|
|
627
|
-
let fieldRegistry = lowercaseAddresses ? fieldRegistryLowercase : fieldRegistryChecksum;
|
|
628
|
-
let fnsCache = new WeakMap();
|
|
629
|
-
return (log, selectedTransactionFields) => {
|
|
630
|
-
let fn = fnsCache.get(selectedTransactionFields);
|
|
631
|
-
let tmp;
|
|
632
|
-
if (fn !== undefined) {
|
|
633
|
-
tmp = fn;
|
|
634
|
-
} else {
|
|
635
|
-
let hasTransactionIndex = {
|
|
636
|
-
contents: false
|
|
637
|
-
};
|
|
638
|
-
let hasHash = {
|
|
639
|
-
contents: false
|
|
640
|
-
};
|
|
641
|
-
let hasEffectiveGasPrice = {
|
|
642
|
-
contents: false
|
|
643
|
-
};
|
|
644
|
-
let txFields = [];
|
|
645
|
-
let receiptFields = [];
|
|
646
|
-
let bothFields = [];
|
|
647
|
-
selectedTransactionFields.forEach(fieldName => {
|
|
648
|
-
switch (fieldName) {
|
|
649
|
-
case "transactionIndex" :
|
|
650
|
-
hasTransactionIndex.contents = true;
|
|
651
|
-
return;
|
|
652
|
-
case "hash" :
|
|
653
|
-
hasHash.contents = true;
|
|
654
|
-
return;
|
|
655
|
-
default:
|
|
656
|
-
let def = fieldRegistry[fieldName];
|
|
657
|
-
if (def === undefined) {
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
let def$1 = fieldName === "effectiveGasPrice" ? (hasEffectiveGasPrice.contents = true, {
|
|
661
|
-
location: def.location,
|
|
662
|
-
jsonKey: def.jsonKey,
|
|
663
|
-
schema: S$RescriptSchema.nullable(def.schema),
|
|
664
|
-
source: def.source
|
|
665
|
-
}) : def;
|
|
666
|
-
let match = def$1.source;
|
|
667
|
-
switch (match) {
|
|
668
|
-
case "TransactionOnly" :
|
|
669
|
-
txFields.push(def$1);
|
|
670
|
-
return;
|
|
671
|
-
case "ReceiptOnly" :
|
|
672
|
-
receiptFields.push(def$1);
|
|
673
|
-
return;
|
|
674
|
-
case "Both" :
|
|
675
|
-
bothFields.push(def$1);
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
});
|
|
680
|
-
let match = txFields.length !== 0;
|
|
681
|
-
let match$1 = receiptFields.length !== 0;
|
|
682
|
-
let strategy = match ? (
|
|
683
|
-
match$1 ? "TransactionAndReceipt" : "TransactionOnly"
|
|
684
|
-
) : (
|
|
685
|
-
match$1 ? "ReceiptOnly" : (
|
|
686
|
-
bothFields.length !== 0 ? "TransactionOnly" : "NoRpc"
|
|
687
|
-
)
|
|
688
|
-
);
|
|
689
|
-
let targetForBoth = strategy === "ReceiptOnly" ? receiptFields : txFields;
|
|
690
|
-
bothFields.forEach(f => {
|
|
691
|
-
targetForBoth.push(f);
|
|
692
|
-
});
|
|
693
|
-
let setLogFields = (mutTransactionAcc, log) => {
|
|
694
|
-
if (hasTransactionIndex.contents) {
|
|
695
|
-
mutTransactionAcc["transactionIndex"] = log.transactionIndex;
|
|
696
|
-
}
|
|
697
|
-
if (hasHash.contents) {
|
|
698
|
-
mutTransactionAcc["hash"] = log.transactionHash;
|
|
699
|
-
return;
|
|
700
|
-
}
|
|
701
|
-
};
|
|
702
|
-
let fn$1 = selectedTransactionFields.size === 0 ? param => Promise.resolve({}) : (
|
|
703
|
-
strategy === "NoRpc" ? log => {
|
|
704
|
-
let mutTransactionAcc = {};
|
|
705
|
-
setLogFields(mutTransactionAcc, log);
|
|
706
|
-
return Promise.resolve(mutTransactionAcc);
|
|
707
|
-
} : log => {
|
|
708
|
-
let txJsonPromise;
|
|
709
|
-
let exit = 0;
|
|
710
|
-
switch (strategy) {
|
|
711
|
-
case "NoRpc" :
|
|
712
|
-
case "ReceiptOnly" :
|
|
713
|
-
txJsonPromise = Promise.resolve(undefined);
|
|
714
|
-
break;
|
|
715
|
-
case "TransactionOnly" :
|
|
716
|
-
case "TransactionAndReceipt" :
|
|
717
|
-
exit = 1;
|
|
718
|
-
break;
|
|
719
|
-
}
|
|
720
|
-
if (exit === 1) {
|
|
721
|
-
txJsonPromise = getTransactionJson(log.transactionHash).then(v => v);
|
|
722
|
-
}
|
|
723
|
-
let receiptJsonPromise;
|
|
724
|
-
let exit$1 = 0;
|
|
725
|
-
switch (strategy) {
|
|
726
|
-
case "NoRpc" :
|
|
727
|
-
case "TransactionOnly" :
|
|
728
|
-
receiptJsonPromise = Promise.resolve(undefined);
|
|
729
|
-
break;
|
|
730
|
-
case "ReceiptOnly" :
|
|
731
|
-
case "TransactionAndReceipt" :
|
|
732
|
-
exit$1 = 1;
|
|
733
|
-
break;
|
|
734
|
-
}
|
|
735
|
-
if (exit$1 === 1) {
|
|
736
|
-
receiptJsonPromise = getReceiptJson(log.transactionHash).then(v => v);
|
|
737
|
-
}
|
|
738
|
-
return Promise.all([
|
|
739
|
-
txJsonPromise,
|
|
740
|
-
receiptJsonPromise
|
|
741
|
-
]).then(param => {
|
|
742
|
-
let receiptJson = param[1];
|
|
743
|
-
let txJson = param[0];
|
|
744
|
-
let mutTransactionAcc = {};
|
|
745
|
-
setLogFields(mutTransactionAcc, log);
|
|
746
|
-
if (txJson !== undefined) {
|
|
747
|
-
parseFieldsFromJson(mutTransactionAcc, txFields, txJson);
|
|
748
|
-
}
|
|
749
|
-
if (receiptJson !== undefined) {
|
|
750
|
-
parseFieldsFromJson(mutTransactionAcc, receiptFields, receiptJson);
|
|
751
|
-
}
|
|
752
|
-
if (hasEffectiveGasPrice.contents && Stdlib_Option.isNone(mutTransactionAcc["effectiveGasPrice"])) {
|
|
753
|
-
if (txJson !== undefined) {
|
|
754
|
-
fillEffectiveGasPriceOrThrow(mutTransactionAcc, txJson);
|
|
755
|
-
return Promise.resolve(mutTransactionAcc);
|
|
756
|
-
} else {
|
|
757
|
-
return getTransactionJson(log.transactionHash).then(json => {
|
|
758
|
-
fillEffectiveGasPriceOrThrow(mutTransactionAcc, json);
|
|
759
|
-
return mutTransactionAcc;
|
|
760
|
-
});
|
|
761
|
-
}
|
|
762
|
-
} else {
|
|
763
|
-
return Promise.resolve(mutTransactionAcc);
|
|
764
|
-
}
|
|
765
|
-
}).then(mutTransactionAcc => mutTransactionAcc);
|
|
766
|
-
}
|
|
767
|
-
);
|
|
768
|
-
fnsCache.set(selectedTransactionFields, fn$1);
|
|
769
|
-
tmp = fn$1;
|
|
770
|
-
}
|
|
771
|
-
return tmp(log);
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
|
|
775
17
|
function make(param) {
|
|
776
|
-
let
|
|
777
|
-
let
|
|
18
|
+
let transactionStore = param.transactionStore;
|
|
19
|
+
let blockStore = param.blockStore;
|
|
778
20
|
let onEventRegistrations = param.onEventRegistrations;
|
|
779
21
|
let chainId = param.chainId;
|
|
780
22
|
let url = param.url;
|
|
@@ -782,102 +24,10 @@ function make(param) {
|
|
|
782
24
|
let host = Utils.Url.getHostFromUrl(url);
|
|
783
25
|
let urlHost = host !== undefined ? host : Stdlib_JsError.throwWithMessage(`The RPC url for chain ` + ChainId.toString(chainId) + ` is in incorrect format. The RPC url needs to start with either http:// or https://`);
|
|
784
26
|
let name = `RPC (` + urlHost + `)`;
|
|
785
|
-
let
|
|
786
|
-
let rpcClient = EvmRpcClient.make(url, !lowercaseAddresses, syncConfig, undefined, headers, HyperSyncClient.Registration.fromOnEventRegistrations(onEventRegistrations), param.addressStore);
|
|
787
|
-
let pendingRequestStats = [];
|
|
788
|
-
let recordRequest = (method, seconds) => {
|
|
789
|
-
pendingRequestStats.push({
|
|
790
|
-
method: method,
|
|
791
|
-
seconds: seconds
|
|
792
|
-
});
|
|
793
|
-
};
|
|
794
|
-
let drainRequestStats = () => {
|
|
795
|
-
let stats = pendingRequestStats.slice();
|
|
796
|
-
Utils.$$Array.clearInPlace(pendingRequestStats);
|
|
797
|
-
return stats;
|
|
798
|
-
};
|
|
799
|
-
let makeTransactionLoader = () => LazyLoader.make(transactionHash => {
|
|
800
|
-
let timerRef = Performance.now();
|
|
801
|
-
return Rest.fetch(Rpc.GetTransactionByHash.rawRoute, transactionHash, client).then(res => {
|
|
802
|
-
recordRequest("eth_getTransactionByHash", Performance.secondsSince(timerRef));
|
|
803
|
-
return res;
|
|
804
|
-
});
|
|
805
|
-
}, (am, exn) => Logging.error({
|
|
806
|
-
err: Utils.prettifyExn(exn),
|
|
807
|
-
msg: `Top level promise timeout reached. Please review other errors or warnings in the code. This function will retry in ` + (am._retryDelayMillis / 1000 | 0).toString() + ` seconds. It is highly likely that your indexer isn't syncing on one or more chains currently. Also take a look at the "suggestedFix" in the metadata of this command`,
|
|
808
|
-
source: name,
|
|
809
|
-
chainId: chainId,
|
|
810
|
-
metadata: {
|
|
811
|
-
asyncTaskName: "transactionLoader: fetching transaction data - `getTransaction` rpc call",
|
|
812
|
-
suggestedFix: "This likely means the RPC url you are using is not responding correctly. Please try another RPC endipoint."
|
|
813
|
-
}
|
|
814
|
-
}), undefined, undefined, undefined, undefined);
|
|
815
|
-
let makeBlockLoader = () => LazyLoader.make(blockNumber => getKnownRawBlockWithBackoff(client, name, chainId, blockNumber, 1000, recordRequest), (am, exn) => Logging.error({
|
|
816
|
-
err: Utils.prettifyExn(exn),
|
|
817
|
-
msg: `Top level promise timeout reached. Please review other errors or warnings in the code. This function will retry in ` + (am._retryDelayMillis / 1000 | 0).toString() + ` seconds. It is highly likely that your indexer isn't syncing on one or more chains currently. Also take a look at the "suggestedFix" in the metadata of this command`,
|
|
818
|
-
source: name,
|
|
819
|
-
chainId: chainId,
|
|
820
|
-
metadata: {
|
|
821
|
-
asyncTaskName: "blockLoader: fetching block data - `getBlock` rpc call",
|
|
822
|
-
suggestedFix: "This likely means the RPC url you are using is not responding correctly. Please try another RPC endipoint."
|
|
823
|
-
}
|
|
824
|
-
}), undefined, undefined, undefined, undefined);
|
|
825
|
-
let makeReceiptLoader = () => LazyLoader.make(transactionHash => {
|
|
826
|
-
let timerRef = Performance.now();
|
|
827
|
-
return Rest.fetch(Rpc.GetTransactionReceipt.rawRoute, transactionHash, client).then(res => {
|
|
828
|
-
recordRequest("eth_getTransactionReceipt", Performance.secondsSince(timerRef));
|
|
829
|
-
return res;
|
|
830
|
-
});
|
|
831
|
-
}, (am, exn) => Logging.error({
|
|
832
|
-
err: Utils.prettifyExn(exn),
|
|
833
|
-
msg: `Top level promise timeout reached. Please review other errors or warnings in the code. This function will retry in ` + (am._retryDelayMillis / 1000 | 0).toString() + ` seconds. It is highly likely that your indexer isn't syncing on one or more chains currently. Also take a look at the "suggestedFix" in the metadata of this command`,
|
|
834
|
-
source: name,
|
|
835
|
-
chainId: chainId,
|
|
836
|
-
metadata: {
|
|
837
|
-
asyncTaskName: "receiptLoader: fetching transaction receipt - `getTransactionReceipt` rpc call",
|
|
838
|
-
suggestedFix: "This likely means the RPC url you are using is not responding correctly. Please try another RPC endipoint."
|
|
839
|
-
}
|
|
840
|
-
}), undefined, undefined, undefined, undefined);
|
|
841
|
-
let blockLoader = {
|
|
842
|
-
contents: makeBlockLoader()
|
|
843
|
-
};
|
|
844
|
-
let transactionLoader = {
|
|
845
|
-
contents: makeTransactionLoader()
|
|
846
|
-
};
|
|
847
|
-
let receiptLoader = {
|
|
848
|
-
contents: makeReceiptLoader()
|
|
849
|
-
};
|
|
850
|
-
let resetCachedLoaders = () => {
|
|
851
|
-
blockLoader.contents = makeBlockLoader();
|
|
852
|
-
transactionLoader.contents = makeTransactionLoader();
|
|
853
|
-
receiptLoader.contents = makeReceiptLoader();
|
|
854
|
-
};
|
|
855
|
-
let getEventBlockOrThrow = makeThrowingGetEventBlock(blockNumber => LazyLoader.get(blockLoader.contents, blockNumber), lowercaseAddresses);
|
|
856
|
-
let getEventTransactionOrThrow = makeThrowingGetEventTransaction(async transactionHash => {
|
|
857
|
-
let json = await LazyLoader.get(transactionLoader.contents, transactionHash);
|
|
858
|
-
if (json !== undefined) {
|
|
859
|
-
return json;
|
|
860
|
-
}
|
|
861
|
-
throw {
|
|
862
|
-
RE_EXN_ID: TransactionDataNotFound,
|
|
863
|
-
message: `Transaction not found for hash: ` + transactionHash,
|
|
864
|
-
Error: new Error()
|
|
865
|
-
};
|
|
866
|
-
}, async transactionHash => {
|
|
867
|
-
let json = await LazyLoader.get(receiptLoader.contents, transactionHash);
|
|
868
|
-
if (json !== undefined) {
|
|
869
|
-
return json;
|
|
870
|
-
}
|
|
871
|
-
throw {
|
|
872
|
-
RE_EXN_ID: TransactionDataNotFound,
|
|
873
|
-
message: `Transaction receipt not found for hash: ` + transactionHash,
|
|
874
|
-
Error: new Error()
|
|
875
|
-
};
|
|
876
|
-
}, lowercaseAddresses);
|
|
27
|
+
let rpcClient = EvmRpcClient.make(url, !param.lowercaseAddresses, syncConfig, undefined, param.headers, HyperSyncClient.Registration.fromOnEventRegistrations(onEventRegistrations), param.addressStore);
|
|
877
28
|
let getItemsOrThrow = async (fromBlock, toBlock, addressSet, param, knownHeight, partitionId, selection, param$1, retry, param$2) => {
|
|
878
|
-
let
|
|
29
|
+
let totalTimeRef = Performance.now();
|
|
879
30
|
let toBlock$1 = toBlock !== undefined ? Primitive_int.min(toBlock, knownHeight) : knownHeight;
|
|
880
|
-
let firstBlockPromise = fromBlock > 0 && fromBlock <= toBlock$1 ? LazyLoader.get(blockLoader.contents, fromBlock).then(json => parseBlockInfo(json)) : Promise.resolve(undefined);
|
|
881
31
|
if (Utils.$$Array.isEmpty(selection.onEventRegistrations)) {
|
|
882
32
|
throw {
|
|
883
33
|
RE_EXN_ID: Source.GetItemsError,
|
|
@@ -888,187 +38,94 @@ function make(param) {
|
|
|
888
38
|
Error: new Error()
|
|
889
39
|
};
|
|
890
40
|
}
|
|
891
|
-
let
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
41
|
+
let pageFetchTimeRef = Performance.now();
|
|
42
|
+
let match = await rpcClient.getNextPage({
|
|
43
|
+
fromBlock: fromBlock,
|
|
44
|
+
toBlockCeiling: toBlock$1,
|
|
45
|
+
partitionId: partitionId,
|
|
46
|
+
registrationIndexes: selection.onEventRegistrations.map(reg => reg.index),
|
|
47
|
+
clientFilteredContracts: selection.clientFilteredContracts,
|
|
48
|
+
retry: retry
|
|
49
|
+
}, addressSet, blockStore, transactionStore);
|
|
50
|
+
let result = match[0];
|
|
51
|
+
let pageFetchTime = Performance.secondsSince(pageFetchTimeRef);
|
|
52
|
+
let exn = Stdlib_Option.map(result.providerMessage, message => Primitive_exceptions.internalToException(new Error(message)));
|
|
53
|
+
let failedGettingItems = decision => ({
|
|
54
|
+
RE_EXN_ID: Source.GetItemsError,
|
|
55
|
+
_1: {
|
|
56
|
+
TAG: "FailedGettingItems",
|
|
57
|
+
exn: exn,
|
|
58
|
+
attemptedToBlock: result.toBlock,
|
|
59
|
+
retry: decision,
|
|
60
|
+
requestStats: result.requestStats
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
let missing = field => Stdlib_JsError.throwWithMessage(`The RPC client returned a "` + result.kind + `" outcome without a ` + field + `. Please, report to the Envio team.`);
|
|
64
|
+
let match$1 = result.kind;
|
|
65
|
+
switch (match$1) {
|
|
66
|
+
case "Ok" :
|
|
67
|
+
break;
|
|
68
|
+
case "SuggestedToBlock" :
|
|
69
|
+
let toBlock$2 = result.retryToBlock;
|
|
70
|
+
throw failedGettingItems({
|
|
71
|
+
TAG: "WithSuggestedToBlock",
|
|
72
|
+
toBlock: toBlock$2 !== undefined ? toBlock$2 : missing("retryToBlock")
|
|
73
|
+
});
|
|
74
|
+
case "Backoff" :
|
|
75
|
+
let message = result.message;
|
|
76
|
+
let backoffMillis = result.backoffMillis;
|
|
77
|
+
throw failedGettingItems({
|
|
78
|
+
TAG: "WithBackoff",
|
|
79
|
+
message: message !== undefined ? message : missing("message"),
|
|
80
|
+
backoffMillis: backoffMillis !== undefined ? backoffMillis : missing("backoffMillis")
|
|
81
|
+
});
|
|
82
|
+
case "FieldSelection" :
|
|
83
|
+
let blockNumber = result.blockNumber;
|
|
84
|
+
let message$1 = result.message;
|
|
905
85
|
throw {
|
|
906
86
|
RE_EXN_ID: Source.GetItemsError,
|
|
907
87
|
_1: {
|
|
908
|
-
TAG: "
|
|
88
|
+
TAG: "FailedGettingFieldSelection",
|
|
909
89
|
exn: exn,
|
|
910
|
-
|
|
911
|
-
|
|
90
|
+
blockNumber: blockNumber !== undefined ? blockNumber : missing("blockNumber"),
|
|
91
|
+
message: message$1 !== undefined ? message$1 : missing("message"),
|
|
92
|
+
requestStats: result.requestStats
|
|
912
93
|
},
|
|
913
94
|
Error: new Error()
|
|
914
95
|
};
|
|
915
|
-
}
|
|
916
|
-
throw {
|
|
917
|
-
RE_EXN_ID: Source.GetItemsError,
|
|
918
|
-
_1: {
|
|
919
|
-
TAG: "FailedGettingItems",
|
|
920
|
-
exn: exn,
|
|
921
|
-
attemptedToBlock: toBlock$1,
|
|
922
|
-
retry: {
|
|
923
|
-
TAG: "WithBackoff",
|
|
924
|
-
message: "Unexpected issue while fetching events from the RPC client. Attempt a retry.",
|
|
925
|
-
backoffMillis: retry !== 0 ? 1000 * retry | 0 : 500
|
|
926
|
-
}
|
|
927
|
-
},
|
|
928
|
-
Error: new Error()
|
|
929
|
-
};
|
|
930
|
-
}
|
|
931
|
-
let items = match.items;
|
|
932
|
-
match.requestStats.forEach(stat => recordRequest(stat.method, stat.seconds));
|
|
933
|
-
let latestFetchedBlockInfo = await LazyLoader.get(blockLoader.contents, match.toBlock).then(parseBlockInfo);
|
|
934
|
-
let parsedQueueItems = await Promise.all(items.map(param => {
|
|
935
|
-
let decoded = param.params;
|
|
936
|
-
let log = param.log;
|
|
937
|
-
let onEventRegistration = onEventRegistrations[param.onEventRegistrationIndex];
|
|
938
|
-
let eventConfig = onEventRegistration.eventConfig;
|
|
939
|
-
return (async () => {
|
|
940
|
-
let match;
|
|
941
|
-
try {
|
|
942
|
-
match = await Promise.all([
|
|
943
|
-
getEventBlockOrThrow(log, onEventRegistration.fieldSelection.blockFields),
|
|
944
|
-
getEventTransactionOrThrow(log, onEventRegistration.fieldSelection.transactionFields)
|
|
945
|
-
]);
|
|
946
|
-
} catch (raw_exn) {
|
|
947
|
-
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
948
|
-
if (exn.RE_EXN_ID === TransactionDataNotFound) {
|
|
949
|
-
let backoffMillis = retry !== 0 ? 500 * retry | 0 : 100;
|
|
950
|
-
throw {
|
|
951
|
-
RE_EXN_ID: Source.GetItemsError,
|
|
952
|
-
_1: {
|
|
953
|
-
TAG: "FailedGettingItems",
|
|
954
|
-
exn: null,
|
|
955
|
-
attemptedToBlock: toBlock$1,
|
|
956
|
-
retry: {
|
|
957
|
-
TAG: "WithBackoff",
|
|
958
|
-
message: exn.message + `. The RPC provider might be load-balanced between nodes that drift independently slightly from the head. Indexing should continue correctly after retrying the query in ` + backoffMillis.toString() + `ms.`,
|
|
959
|
-
backoffMillis: backoffMillis
|
|
960
|
-
}
|
|
961
|
-
},
|
|
962
|
-
Error: new Error()
|
|
963
|
-
};
|
|
964
|
-
}
|
|
965
|
-
throw {
|
|
966
|
-
RE_EXN_ID: Source.GetItemsError,
|
|
967
|
-
_1: {
|
|
968
|
-
TAG: "FailedGettingFieldSelection",
|
|
969
|
-
exn: exn,
|
|
970
|
-
blockNumber: log.blockNumber,
|
|
971
|
-
logIndex: log.logIndex,
|
|
972
|
-
message: "Failed getting selected fields. Please double-check your RPC provider returns correct data."
|
|
973
|
-
},
|
|
974
|
-
Error: new Error()
|
|
975
|
-
};
|
|
976
|
-
}
|
|
977
|
-
let block = match[0];
|
|
978
|
-
return {
|
|
979
|
-
kind: 0,
|
|
980
|
-
onEventRegistration: onEventRegistration,
|
|
981
|
-
chainId: chainId,
|
|
982
|
-
blockNumber: block.number,
|
|
983
|
-
logIndex: log.logIndex,
|
|
984
|
-
transactionIndex: log.transactionIndex,
|
|
985
|
-
payload: {
|
|
986
|
-
contractName: eventConfig.contractName,
|
|
987
|
-
eventName: eventConfig.name,
|
|
988
|
-
params: decoded,
|
|
989
|
-
chainId: chainId,
|
|
990
|
-
srcAddress: log.address,
|
|
991
|
-
logIndex: log.logIndex,
|
|
992
|
-
transaction: Primitive_option.some(match[1]),
|
|
993
|
-
block: Primitive_option.some(block)
|
|
994
|
-
}
|
|
995
|
-
};
|
|
996
|
-
})();
|
|
997
|
-
}));
|
|
998
|
-
let optFirstBlock = await firstBlockPromise;
|
|
999
|
-
let totalTimeElapsed = Performance.secondsSince(startFetchingBatchTimeRef);
|
|
1000
|
-
let observedBlocks = [];
|
|
1001
|
-
let pushBlockInfo = b => {
|
|
1002
|
-
observedBlocks.push({
|
|
1003
|
-
blockNumber: b.number,
|
|
1004
|
-
blockHash: b.hash,
|
|
1005
|
-
blockTimestamp: b.timestamp
|
|
1006
|
-
});
|
|
1007
|
-
if (b.number > 0) {
|
|
1008
|
-
observedBlocks.push({
|
|
1009
|
-
blockNumber: b.number - 1 | 0,
|
|
1010
|
-
blockHash: b.parentHash
|
|
1011
|
-
});
|
|
1012
|
-
return;
|
|
1013
|
-
}
|
|
1014
|
-
};
|
|
1015
|
-
pushBlockInfo(latestFetchedBlockInfo);
|
|
1016
|
-
if (optFirstBlock !== undefined) {
|
|
1017
|
-
pushBlockInfo(optFirstBlock);
|
|
1018
96
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
blockNumber: log.blockNumber,
|
|
1023
|
-
blockHash: log.blockHash
|
|
1024
|
-
});
|
|
1025
|
-
});
|
|
97
|
+
let parsingTimeRef = Performance.now();
|
|
98
|
+
let parsedQueueItems = EvmEventItem.toInternalItems(result.items, onEventRegistrations, chainId);
|
|
99
|
+
let parsingTimeElapsed = Performance.secondsSince(parsingTimeRef);
|
|
1026
100
|
return {
|
|
1027
101
|
knownHeight: knownHeight,
|
|
1028
102
|
parsedQueueItems: parsedQueueItems,
|
|
1029
|
-
transactionStore:
|
|
1030
|
-
blockStore:
|
|
1031
|
-
|
|
1032
|
-
latestFetchedBlockNumber: latestFetchedBlockInfo.number,
|
|
103
|
+
transactionStore: Primitive_option.some(match[2]),
|
|
104
|
+
blockStore: match[1],
|
|
105
|
+
latestFetchedBlockNumber: result.toBlock,
|
|
1033
106
|
stats: {
|
|
1034
|
-
"total time elapsed (s)":
|
|
107
|
+
"total time elapsed (s)": Performance.secondsSince(totalTimeRef),
|
|
108
|
+
"parsing time (s)": parsingTimeElapsed,
|
|
109
|
+
"page fetch time (s)": pageFetchTime
|
|
1035
110
|
},
|
|
1036
|
-
requestStats:
|
|
111
|
+
requestStats: result.requestStats
|
|
1037
112
|
};
|
|
1038
113
|
};
|
|
1039
|
-
let
|
|
1040
|
-
|
|
1041
|
-
let
|
|
1042
|
-
|
|
1043
|
-
let b = parseBlockInfo(json);
|
|
1044
|
-
observedBlocks.push({
|
|
1045
|
-
blockNumber: b.number,
|
|
1046
|
-
blockHash: b.hash,
|
|
1047
|
-
blockTimestamp: b.timestamp
|
|
1048
|
-
});
|
|
1049
|
-
if (b.number > 0) {
|
|
1050
|
-
observedBlocks.push({
|
|
1051
|
-
blockNumber: b.number - 1 | 0,
|
|
1052
|
-
blockHash: b.parentHash
|
|
1053
|
-
});
|
|
1054
|
-
return;
|
|
1055
|
-
}
|
|
1056
|
-
});
|
|
1057
|
-
let blockStore = BlockStore.fromJs(observedBlocks, "evm", !lowercaseAddresses);
|
|
114
|
+
let getBlockHashes = async (blockNumbers, param) => {
|
|
115
|
+
let match = await rpcClient.getBlockHashes(blockNumbers);
|
|
116
|
+
let result = match[0];
|
|
117
|
+
let message = result.message;
|
|
1058
118
|
return {
|
|
1059
|
-
result: {
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
119
|
+
result: message !== undefined ? ({
|
|
120
|
+
TAG: "Error",
|
|
121
|
+
_0: Primitive_exceptions.internalToException(new Error(message))
|
|
122
|
+
}) : ({
|
|
123
|
+
TAG: "Ok",
|
|
124
|
+
_0: match[1]
|
|
125
|
+
}),
|
|
126
|
+
requestStats: result.requestStats
|
|
1064
127
|
};
|
|
1065
|
-
}
|
|
1066
|
-
result: {
|
|
1067
|
-
TAG: "Error",
|
|
1068
|
-
_0: exn
|
|
1069
|
-
},
|
|
1070
|
-
requestStats: drainRequestStats()
|
|
1071
|
-
}));
|
|
128
|
+
};
|
|
1072
129
|
let createHeightSubscription = Stdlib_Option.map(param.ws, wsUrl => ((onHeight, onStatus) => EvmRpcWs.subscribe(wsUrl, onHeight, onStatus)));
|
|
1073
130
|
return {
|
|
1074
131
|
name: name,
|
|
@@ -1078,51 +135,19 @@ function make(param) {
|
|
|
1078
135
|
pollingInterval: syncConfig.pollingInterval,
|
|
1079
136
|
getBlockHashes: getBlockHashes,
|
|
1080
137
|
getHeightOrThrow: async () => {
|
|
1081
|
-
let
|
|
1082
|
-
let height;
|
|
1083
|
-
try {
|
|
1084
|
-
height = await rpcClient.getHeight();
|
|
1085
|
-
} catch (exn) {
|
|
1086
|
-
recordRequest("eth_blockNumber", Performance.secondsSince(timerRef));
|
|
1087
|
-
throw exn;
|
|
1088
|
-
}
|
|
1089
|
-
recordRequest("eth_blockNumber", Performance.secondsSince(timerRef));
|
|
138
|
+
let match = await rpcClient.getHeight();
|
|
1090
139
|
return {
|
|
1091
|
-
height:
|
|
1092
|
-
requestStats:
|
|
140
|
+
height: match[0],
|
|
141
|
+
requestStats: match[1]
|
|
1093
142
|
};
|
|
1094
143
|
},
|
|
1095
144
|
getItemsOrThrow: getItemsOrThrow,
|
|
1096
145
|
createHeightSubscription: createHeightSubscription,
|
|
1097
|
-
onReorg: onReorg
|
|
146
|
+
onReorg: () => rpcClient.onReorg()
|
|
1098
147
|
};
|
|
1099
148
|
}
|
|
1100
149
|
|
|
1101
|
-
let effectiveGasPriceKey = "effectiveGasPrice";
|
|
1102
|
-
|
|
1103
150
|
export {
|
|
1104
|
-
TransactionDataNotFound,
|
|
1105
|
-
getKnownRawBlock,
|
|
1106
|
-
parseBlockInfo,
|
|
1107
|
-
getKnownRawBlockWithBackoff,
|
|
1108
|
-
getErrorMessage,
|
|
1109
|
-
parseGetNextPageRetryError,
|
|
1110
|
-
lowercaseAddressSchema,
|
|
1111
|
-
checksumAddressSchema,
|
|
1112
|
-
makeBlockFieldRegistry,
|
|
1113
|
-
blockFieldRegistryLowercase,
|
|
1114
|
-
blockFieldRegistryChecksum,
|
|
1115
|
-
parseBlockFieldsFromJson,
|
|
1116
|
-
makeThrowingGetEventBlock,
|
|
1117
|
-
makeFieldRegistry,
|
|
1118
|
-
fieldRegistryLowercase,
|
|
1119
|
-
fieldRegistryChecksum,
|
|
1120
|
-
isRpcTransactionField,
|
|
1121
|
-
parseFieldsFromJson,
|
|
1122
|
-
effectiveGasPriceKey,
|
|
1123
|
-
effectiveGasPriceFallbackDef,
|
|
1124
|
-
fillEffectiveGasPriceOrThrow,
|
|
1125
|
-
makeThrowingGetEventTransaction,
|
|
1126
151
|
make,
|
|
1127
152
|
}
|
|
1128
|
-
/*
|
|
153
|
+
/* Utils Not a pure module */
|