envio 3.0.0-alpha.2 → 3.0.0-alpha.3

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.
Files changed (60) hide show
  1. package/evm.schema.json +44 -33
  2. package/fuel.schema.json +32 -21
  3. package/index.d.ts +1 -0
  4. package/package.json +7 -6
  5. package/src/Batch.res.mjs +1 -1
  6. package/src/Benchmark.res +394 -0
  7. package/src/Benchmark.res.mjs +398 -0
  8. package/src/ChainFetcher.res +459 -0
  9. package/src/ChainFetcher.res.mjs +281 -0
  10. package/src/ChainManager.res +179 -0
  11. package/src/ChainManager.res.mjs +139 -0
  12. package/src/Config.res +15 -1
  13. package/src/Config.res.mjs +27 -4
  14. package/src/Ecosystem.res +9 -124
  15. package/src/Ecosystem.res.mjs +19 -160
  16. package/src/Env.res +0 -1
  17. package/src/Env.res.mjs +0 -3
  18. package/src/Envio.gen.ts +9 -1
  19. package/src/Envio.res +12 -9
  20. package/src/EventProcessing.res +476 -0
  21. package/src/EventProcessing.res.mjs +341 -0
  22. package/src/FetchState.res +54 -29
  23. package/src/FetchState.res.mjs +62 -35
  24. package/src/GlobalState.res +1169 -0
  25. package/src/GlobalState.res.mjs +1196 -0
  26. package/src/Internal.res +2 -1
  27. package/src/LoadLayer.res +444 -0
  28. package/src/LoadLayer.res.mjs +296 -0
  29. package/src/LoadLayer.resi +32 -0
  30. package/src/Prometheus.res +8 -8
  31. package/src/Prometheus.res.mjs +10 -10
  32. package/src/ReorgDetection.res +6 -10
  33. package/src/ReorgDetection.res.mjs +6 -6
  34. package/src/UserContext.res +356 -0
  35. package/src/UserContext.res.mjs +238 -0
  36. package/src/bindings/DateFns.res +71 -0
  37. package/src/bindings/DateFns.res.mjs +22 -0
  38. package/src/sources/Evm.res +87 -0
  39. package/src/sources/Evm.res.mjs +105 -0
  40. package/src/sources/EvmChain.res +95 -0
  41. package/src/sources/EvmChain.res.mjs +61 -0
  42. package/src/sources/Fuel.res +19 -34
  43. package/src/sources/Fuel.res.mjs +34 -16
  44. package/src/sources/FuelSDK.res +37 -0
  45. package/src/sources/FuelSDK.res.mjs +29 -0
  46. package/src/sources/HyperFuel.res +2 -2
  47. package/src/sources/HyperFuel.resi +1 -1
  48. package/src/sources/HyperFuelClient.res +2 -2
  49. package/src/sources/HyperFuelSource.res +8 -8
  50. package/src/sources/HyperFuelSource.res.mjs +5 -5
  51. package/src/sources/HyperSyncSource.res +5 -5
  52. package/src/sources/HyperSyncSource.res.mjs +5 -5
  53. package/src/sources/RpcSource.res +4 -4
  54. package/src/sources/RpcSource.res.mjs +3 -3
  55. package/src/sources/Solana.res +59 -0
  56. package/src/sources/Solana.res.mjs +79 -0
  57. package/src/sources/Source.res +2 -2
  58. package/src/sources/SourceManager.res +24 -32
  59. package/src/sources/SourceManager.res.mjs +20 -20
  60. package/src/sources/SourceManager.resi +4 -5
@@ -0,0 +1,398 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Fs from "fs";
4
+ import * as Env from "./Env.res.mjs";
5
+ import * as Path from "path";
6
+ import * as NodeJs from "./bindings/NodeJs.res.mjs";
7
+ import * as DateFns from "./bindings/DateFns.res.mjs";
8
+ import * as Js_dict from "rescript/lib/es6/js_dict.js";
9
+ import * as Logging from "./Logging.res.mjs";
10
+ import * as DateFns$1 from "date-fns";
11
+ import * as Throttler from "./Throttler.res.mjs";
12
+ import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
13
+ import * as BigDecimal from "./bindings/BigDecimal.res.mjs";
14
+ import * as Prometheus from "./Prometheus.res.mjs";
15
+ import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
16
+ import BignumberJs from "bignumber.js";
17
+ import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
18
+ import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
19
+
20
+ var schema = S$RescriptSchema.schema(function (s) {
21
+ return {
22
+ counters: s.m(S$RescriptSchema.dict(S$RescriptSchema.$$float)),
23
+ startTime: s.m(S$RescriptSchema.datetime(S$RescriptSchema.string, undefined)),
24
+ endTime: s.m(S$RescriptSchema.datetime(S$RescriptSchema.string, undefined))
25
+ };
26
+ });
27
+
28
+ function make() {
29
+ return {
30
+ counters: {},
31
+ startTime: new Date(),
32
+ endTime: new Date()
33
+ };
34
+ }
35
+
36
+ function increment(self, label, amount) {
37
+ self.endTime = new Date();
38
+ var current = self.counters[label];
39
+ if (current !== undefined) {
40
+ var newAmount = current + amount;
41
+ self.counters[label] = newAmount;
42
+ return newAmount;
43
+ }
44
+ self.counters[label] = amount;
45
+ return amount;
46
+ }
47
+
48
+ var MillisAccum = {
49
+ schema: schema,
50
+ make: make,
51
+ increment: increment
52
+ };
53
+
54
+ var schema$1 = S$RescriptSchema.schema(function (s) {
55
+ return {
56
+ count: s.m(S$RescriptSchema.$$float),
57
+ min: s.m(S$RescriptSchema.$$float),
58
+ max: s.m(S$RescriptSchema.$$float),
59
+ sum: s.m(BigDecimal.schema),
60
+ sumOfSquares: s.m(S$RescriptSchema.option(BigDecimal.schema)),
61
+ decimalPlaces: s.m(S$RescriptSchema.$$int)
62
+ };
63
+ });
64
+
65
+ function make$1(val, decimalPlacesOpt) {
66
+ var decimalPlaces = decimalPlacesOpt !== undefined ? decimalPlacesOpt : 2;
67
+ var bigDecimal = new BignumberJs(val);
68
+ return {
69
+ count: 1,
70
+ min: val,
71
+ max: val,
72
+ sum: bigDecimal,
73
+ sumOfSquares: Env.Benchmark.shouldSaveStdDev ? bigDecimal.multipliedBy(bigDecimal) : undefined,
74
+ decimalPlaces: decimalPlaces
75
+ };
76
+ }
77
+
78
+ function add(self, val) {
79
+ var bigDecimal = new BignumberJs(val);
80
+ return {
81
+ count: self.count + 1,
82
+ min: self.min < val ? self.min : val,
83
+ max: self.max > val ? self.max : val,
84
+ sum: self.sum.plus(bigDecimal),
85
+ sumOfSquares: Belt_Option.map(self.sumOfSquares, (function (s) {
86
+ return s.plus(bigDecimal.multipliedBy(bigDecimal));
87
+ })),
88
+ decimalPlaces: self.decimalPlaces
89
+ };
90
+ }
91
+
92
+ var DataSet = {
93
+ schema: schema$1,
94
+ make: make$1,
95
+ add: add
96
+ };
97
+
98
+ var schema$2 = S$RescriptSchema.dict(schema$1);
99
+
100
+ function make$2() {
101
+ return {};
102
+ }
103
+
104
+ function add$1(self, label, value, decimalPlacesOpt) {
105
+ var decimalPlaces = decimalPlacesOpt !== undefined ? decimalPlacesOpt : 2;
106
+ var dataSet = self[label];
107
+ if (dataSet !== undefined) {
108
+ var updated = add(dataSet, value);
109
+ self[label] = updated;
110
+ return updated;
111
+ }
112
+ var $$new = make$1(value, decimalPlaces);
113
+ self[label] = $$new;
114
+ return $$new;
115
+ }
116
+
117
+ var Group = {
118
+ schema: schema$2,
119
+ make: make$2,
120
+ add: add$1
121
+ };
122
+
123
+ var schema$3 = S$RescriptSchema.dict(schema$2);
124
+
125
+ function make$3() {
126
+ return {};
127
+ }
128
+
129
+ function add$2(self, group, label, value, decimalPlacesOpt) {
130
+ var decimalPlaces = decimalPlacesOpt !== undefined ? decimalPlacesOpt : 2;
131
+ var group$1 = self[group];
132
+ var group$2;
133
+ if (group$1 !== undefined) {
134
+ group$2 = group$1;
135
+ } else {
136
+ var newGroup = {};
137
+ self[group] = newGroup;
138
+ group$2 = newGroup;
139
+ }
140
+ return add$1(group$2, label, value, decimalPlaces);
141
+ }
142
+
143
+ var SummaryData = {
144
+ DataSet: DataSet,
145
+ Group: Group,
146
+ schema: schema$3,
147
+ make: make$3,
148
+ add: add$2
149
+ };
150
+
151
+ function round($$float, precisionOpt) {
152
+ var precision = precisionOpt !== undefined ? precisionOpt : 2;
153
+ var factor = Math.pow(10.0, precision);
154
+ return Math.round($$float * factor) / factor;
155
+ }
156
+
157
+ function makeFromDataSet(dataSet) {
158
+ var n = dataSet.count;
159
+ var countBigDecimal = new BignumberJs(n);
160
+ var mean = dataSet.sum.dividedBy(countBigDecimal);
161
+ var roundBigDecimal = function (bd) {
162
+ return bd.decimalPlaces(dataSet.decimalPlaces).toNumber();
163
+ };
164
+ var roundFloat = function ($$float) {
165
+ return round($$float, dataSet.decimalPlaces);
166
+ };
167
+ var stdDev = Belt_Option.map(dataSet.sumOfSquares, (function (sumOfSquares) {
168
+ var variance = sumOfSquares.dividedBy(countBigDecimal).minus(mean.multipliedBy(mean));
169
+ return roundBigDecimal(variance.sqrt());
170
+ }));
171
+ return {
172
+ n: n,
173
+ mean: roundBigDecimal(mean),
174
+ "std-dev": stdDev,
175
+ min: roundFloat(dataSet.min),
176
+ max: roundFloat(dataSet.max),
177
+ sum: roundBigDecimal(dataSet.sum)
178
+ };
179
+ }
180
+
181
+ var Stats = {
182
+ round: round,
183
+ makeFromDataSet: makeFromDataSet
184
+ };
185
+
186
+ var schema$4 = S$RescriptSchema.schema(function (s) {
187
+ return {
188
+ millisAccum: s.m(schema),
189
+ summaryData: s.m(schema$3)
190
+ };
191
+ });
192
+
193
+ function make$4() {
194
+ return {
195
+ millisAccum: make(),
196
+ summaryData: {}
197
+ };
198
+ }
199
+
200
+ var addDataSet = Env.Benchmark.SaveDataStrategy.shouldSavePrometheus(Env.Benchmark.saveDataStrategy) ? (function (dataSet, group, label) {
201
+ var match = makeFromDataSet(dataSet);
202
+ Prometheus.BenchmarkSummaryData.set(group, label, match.n, match.mean, match["std-dev"], match.min, match.max, match.sum);
203
+ }) : (function (_dataSet, param, param$1) {
204
+
205
+ });
206
+
207
+ var setCounterMillis = Env.Benchmark.SaveDataStrategy.shouldSavePrometheus(Env.Benchmark.saveDataStrategy) ? (function (millisAccum, label, millis) {
208
+ var totalRuntimeMillis = millisAccum.endTime.getTime() - millisAccum.startTime.getTime();
209
+ Prometheus.BenchmarkCounters.set(label, millis, totalRuntimeMillis);
210
+ }) : (function (param, param$1, param$2) {
211
+
212
+ });
213
+
214
+ var LiveMetrics = {
215
+ addDataSet: addDataSet,
216
+ setCounterMillis: setCounterMillis
217
+ };
218
+
219
+ function incrementMillis(self, label, amount) {
220
+ var nextMillis = increment(self.millisAccum, label, amount);
221
+ setCounterMillis(self.millisAccum, label, nextMillis);
222
+ }
223
+
224
+ function addSummaryData(self, group, label, value, decimalPlacesOpt) {
225
+ var decimalPlaces = decimalPlacesOpt !== undefined ? decimalPlacesOpt : 2;
226
+ var updatedDataSet = add$2(self.summaryData, group, label, value, decimalPlaces);
227
+ addDataSet(updatedDataSet, group, label);
228
+ }
229
+
230
+ var Data = {
231
+ schema: schema$4,
232
+ make: make$4,
233
+ LiveMetrics: LiveMetrics,
234
+ incrementMillis: incrementMillis,
235
+ addSummaryData: addSummaryData
236
+ };
237
+
238
+ var data = make$4();
239
+
240
+ var throttler = Throttler.make(Env.ThrottleWrites.jsonFileBenchmarkIntervalMillis, Logging.createChild({
241
+ context: "Benchmarking framework"
242
+ }));
243
+
244
+ var cacheFileName = "BenchmarkCache.json";
245
+
246
+ var cacheFilePath = Path.join(NodeJs.Path.$$__dirname, cacheFileName);
247
+
248
+ var saveToCacheFile = Env.Benchmark.SaveDataStrategy.shouldSaveJsonFile(Env.Benchmark.saveDataStrategy) ? (function (data) {
249
+ var write = function () {
250
+ var json = S$RescriptSchema.reverseConvertToJsonStringOrThrow(data, schema$4, undefined);
251
+ return Fs.promises.writeFile(cacheFilePath, json);
252
+ };
253
+ Throttler.schedule(throttler, write);
254
+ }) : (function (param) {
255
+
256
+ });
257
+
258
+ async function readFromCacheFile() {
259
+ var content;
260
+ try {
261
+ content = await Fs.promises.readFile(cacheFilePath, "utf8");
262
+ }
263
+ catch (exn){
264
+ return ;
265
+ }
266
+ try {
267
+ return S$RescriptSchema.parseJsonStringOrThrow(content, schema$4);
268
+ }
269
+ catch (raw_e){
270
+ var e = Caml_js_exceptions.internalToOCamlException(raw_e);
271
+ if (e.RE_EXN_ID === S$RescriptSchema.Raised) {
272
+ Logging.error("Failed to parse benchmark cache file, please delete it and rerun the benchmark");
273
+ return S$RescriptSchema.$$Error.raise(e._1);
274
+ }
275
+ throw e;
276
+ }
277
+ }
278
+
279
+ function addSummaryData$1(group, label, value, decimalPlacesOpt) {
280
+ var decimalPlaces = decimalPlacesOpt !== undefined ? decimalPlacesOpt : 2;
281
+ addSummaryData(data, group, label, value, decimalPlaces);
282
+ saveToCacheFile(data);
283
+ }
284
+
285
+ function incrementMillis$1(label, amount) {
286
+ incrementMillis(data, label, amount);
287
+ saveToCacheFile(data);
288
+ }
289
+
290
+ function addBlockRangeFetched(totalTimeElapsed, parsingTimeElapsed, pageFetchTime, chainId, fromBlock, toBlock, numEvents, numAddresses, queryName) {
291
+ var group = "BlockRangeFetched Summary for Chain " + String(chainId) + " " + queryName;
292
+ var add = function (label, value) {
293
+ addSummaryData(data, group, label, value, undefined);
294
+ };
295
+ add("Total Time Elapsed (ms)", totalTimeElapsed);
296
+ add("Parsing Time Elapsed (ms)", parsingTimeElapsed);
297
+ add("Page Fetch Time (ms)", pageFetchTime);
298
+ add("Num Events", numEvents);
299
+ add("Num Addresses", numAddresses);
300
+ add("Block Range Size", toBlock - fromBlock | 0);
301
+ incrementMillis(data, "Total Time Fetching Chain " + String(chainId) + " " + queryName, totalTimeElapsed);
302
+ saveToCacheFile(data);
303
+ }
304
+
305
+ var eventProcessingGroup = "EventProcessing Summary";
306
+
307
+ var batchSizeLabel = "Batch Size";
308
+
309
+ function addEventProcessing(batchSize, loadDuration, handlerDuration, dbWriteDuration, totalTimeElapsed) {
310
+ var add = function (label, value) {
311
+ addSummaryData(data, eventProcessingGroup, label, value, undefined);
312
+ };
313
+ add(batchSizeLabel, batchSize);
314
+ add("Load Duration (ms)", loadDuration);
315
+ add("Handler Duration (ms)", handlerDuration);
316
+ add("DB Write Duration (ms)", dbWriteDuration);
317
+ add("Total Time Elapsed (ms)", totalTimeElapsed);
318
+ incrementMillis(data, "Total Time Processing", totalTimeElapsed);
319
+ saveToCacheFile(data);
320
+ }
321
+
322
+ async function printSummary() {
323
+ var data = await readFromCacheFile();
324
+ if (data === undefined) {
325
+ return Logging.error("No benchmark cache file found, please use 'ENVIO_SAVE_BENCHMARK_DATA=true' and rerun the benchmark");
326
+ }
327
+ var summaryData = data.summaryData;
328
+ var millisAccum = data.millisAccum;
329
+ console.log("Time breakdown");
330
+ var timeBreakdown = [[
331
+ "Total Runtime",
332
+ DateFns$1.intervalToDuration({
333
+ start: millisAccum.startTime,
334
+ end: millisAccum.endTime
335
+ })
336
+ ]];
337
+ Belt_Array.forEach(Js_dict.entries(millisAccum.counters), (function (param) {
338
+ timeBreakdown.push([
339
+ param[0],
340
+ DateFns.durationFromMillis(param[1] | 0)
341
+ ]);
342
+ }));
343
+ console.table(Js_dict.fromArray(timeBreakdown));
344
+ console.log("General");
345
+ var batchSizesSum = Belt_Option.getWithDefault(Belt_Option.map(Belt_Option.flatMap(Js_dict.get(summaryData, eventProcessingGroup), (function (g) {
346
+ return Js_dict.get(g, batchSizeLabel);
347
+ })), (function (data) {
348
+ return data.sum;
349
+ })), BigDecimal.zero);
350
+ var totalRuntimeMillis = millisAccum.endTime.getTime() - millisAccum.startTime.getTime();
351
+ var totalRuntimeSeconds = totalRuntimeMillis / 1000;
352
+ var eventsPerSecond = batchSizesSum.dividedBy(new BignumberJs(totalRuntimeSeconds)).decimalPlaces(2).toNumber();
353
+ console.table({
354
+ "batch sizes sum": batchSizesSum.toNumber(),
355
+ "total runtime (sec)": totalRuntimeSeconds,
356
+ "events per second": eventsPerSecond
357
+ });
358
+ return Belt_Array.forEach(Js_dict.entries(summaryData).sort(function (param, param$1) {
359
+ if (param[0] < param$1[0]) {
360
+ return -1;
361
+ } else {
362
+ return 1;
363
+ }
364
+ }), (function (param) {
365
+ console.log(param[0]);
366
+ console.table(Js_dict.fromArray(Belt_Array.map(Js_dict.entries(param[1]), (function (param) {
367
+ return [
368
+ param[0],
369
+ makeFromDataSet(param[1])
370
+ ];
371
+ }))));
372
+ }));
373
+ }
374
+
375
+ var Summary = {
376
+ printSummary: printSummary
377
+ };
378
+
379
+ export {
380
+ MillisAccum ,
381
+ SummaryData ,
382
+ Stats ,
383
+ Data ,
384
+ data ,
385
+ throttler ,
386
+ cacheFileName ,
387
+ cacheFilePath ,
388
+ saveToCacheFile ,
389
+ readFromCacheFile ,
390
+ addSummaryData$1 as addSummaryData,
391
+ incrementMillis$1 as incrementMillis,
392
+ addBlockRangeFetched ,
393
+ eventProcessingGroup ,
394
+ batchSizeLabel ,
395
+ addEventProcessing ,
396
+ Summary ,
397
+ }
398
+ /* schema Not a pure module */