envio 3.2.1 → 3.3.0-alpha.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 -7
- package/src/Batch.res +12 -15
- package/src/Batch.res.mjs +4 -5
- package/src/BatchProcessing.res +199 -0
- package/src/BatchProcessing.res.mjs +125 -0
- package/src/ChainFetching.res +375 -0
- package/src/ChainFetching.res.mjs +206 -0
- package/src/ChainMetadata.res +27 -0
- package/src/ChainMetadata.res.mjs +27 -0
- package/src/ChainState.res +618 -0
- package/src/ChainState.res.mjs +461 -0
- package/src/ChainState.resi +85 -0
- package/src/Config.res +13 -4
- package/src/Config.res.mjs +8 -3
- package/src/ContractRegisterContext.res +106 -0
- package/src/ContractRegisterContext.res.mjs +76 -0
- package/src/Core.res +3 -0
- package/src/CrossChainState.res +269 -0
- package/src/CrossChainState.res.mjs +197 -0
- package/src/CrossChainState.resi +47 -0
- package/src/Ecosystem.res +58 -0
- package/src/Ecosystem.res.mjs +43 -1
- package/src/Env.res +7 -2
- package/src/Env.res.mjs +5 -2
- package/src/EventConfigBuilder.res +2 -2
- package/src/EventProcessing.res +60 -46
- package/src/EventProcessing.res.mjs +33 -32
- package/src/EventUtils.res +0 -4
- package/src/EventUtils.res.mjs +0 -4
- package/src/ExitOnCaughtUp.res +10 -0
- package/src/ExitOnCaughtUp.res.mjs +22 -0
- package/src/FetchState.res +124 -62
- package/src/FetchState.res.mjs +159 -93
- package/src/InMemoryStore.res +36 -451
- package/src/InMemoryStore.res.mjs +20 -369
- package/src/IndexerLoop.res +44 -0
- package/src/IndexerLoop.res.mjs +46 -0
- package/src/IndexerState.res +544 -0
- package/src/IndexerState.res.mjs +547 -0
- package/src/IndexerState.resi +132 -0
- package/src/Internal.res +29 -8
- package/src/LoadLayer.res +20 -18
- package/src/LoadLayer.res.mjs +14 -12
- package/src/LoadLayer.resi +6 -3
- package/src/Logging.res +11 -44
- package/src/Logging.res.mjs +10 -42
- package/src/Main.res +54 -79
- package/src/Main.res.mjs +44 -56
- package/src/PgStorage.res +8 -71
- package/src/PgStorage.res.mjs +3 -47
- package/src/Prometheus.res +7 -8
- package/src/Prometheus.res.mjs +7 -4
- package/src/PruneStaleHistory.res +45 -0
- package/src/PruneStaleHistory.res.mjs +46 -0
- package/src/RawEvent.res +73 -0
- package/src/RawEvent.res.mjs +51 -0
- package/src/Rollback.res +204 -0
- package/src/Rollback.res.mjs +118 -0
- package/src/SimulateItems.res +12 -10
- package/src/SimulateItems.res.mjs +1 -1
- package/src/UserContext.res +26 -114
- package/src/UserContext.res.mjs +15 -78
- package/src/Writing.res +242 -0
- package/src/Writing.res.mjs +215 -0
- package/src/db/InternalTable.res +14 -27
- package/src/sources/Evm.res +40 -1
- package/src/sources/Evm.res.mjs +94 -84
- package/src/sources/Fuel.res +40 -1
- package/src/sources/Fuel.res.mjs +36 -26
- package/src/sources/HyperFuel.res +41 -120
- package/src/sources/HyperFuel.res.mjs +42 -80
- package/src/sources/HyperFuel.resi +1 -24
- package/src/sources/HyperFuelClient.res +16 -297
- package/src/sources/HyperFuelClient.res.mjs +5 -4
- package/src/sources/HyperFuelSource.res +33 -8
- package/src/sources/HyperFuelSource.res.mjs +56 -10
- package/src/sources/HyperSyncSource.res +5 -3
- package/src/sources/HyperSyncSource.res.mjs +1 -1
- package/src/sources/RpcSource.res +2 -2
- package/src/sources/RpcSource.res.mjs +1 -1
- package/src/sources/SourceManager.res +8 -18
- package/src/sources/SourceManager.res.mjs +8 -5
- package/src/sources/SourceManager.resi +4 -1
- package/src/sources/Svm.res +18 -1
- package/src/sources/Svm.res.mjs +30 -22
- package/src/sources/SvmHyperSyncSource.res +1 -1
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
- package/src/tui/Tui.res +38 -36
- package/src/tui/Tui.res.mjs +51 -51
- package/src/ChainFetcher.res +0 -519
- package/src/ChainFetcher.res.mjs +0 -314
- package/src/ChainManager.res +0 -358
- package/src/ChainManager.res.mjs +0 -291
- package/src/Ctx.res +0 -6
- package/src/Ctx.res.mjs +0 -2
- package/src/GlobalState.res +0 -1056
- package/src/GlobalState.res.mjs +0 -1086
- package/src/GlobalStateManager.res +0 -57
- package/src/GlobalStateManager.res.mjs +0 -68
- package/src/GlobalStateManager.resi +0 -7
- package/src/Ports.res +0 -5
- package/src/Ports.res.mjs +0 -9
- package/src/adapters/MarkBatchProcessedAdapter.res +0 -5
- package/src/adapters/MarkBatchProcessedAdapter.res.mjs +0 -14
- package/src/sources/EnvioApiClient.res +0 -15
- package/src/sources/EnvioApiClient.res.mjs +0 -24
|
@@ -1,84 +1,22 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Env from "./Env.res.mjs";
|
|
4
3
|
import * as Table from "./db/Table.res.mjs";
|
|
5
4
|
import * as Utils from "./Utils.res.mjs";
|
|
6
5
|
import * as Config from "./Config.res.mjs";
|
|
7
|
-
import * as Logging from "./Logging.res.mjs";
|
|
8
6
|
import * as Internal from "./Internal.res.mjs";
|
|
9
|
-
import * as
|
|
10
|
-
import * as Prometheus from "./Prometheus.res.mjs";
|
|
11
|
-
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
12
|
-
import * as ErrorHandling from "./ErrorHandling.res.mjs";
|
|
7
|
+
import * as IndexerState from "./IndexerState.res.mjs";
|
|
13
8
|
import * as InMemoryTable from "./InMemoryTable.res.mjs";
|
|
14
9
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
15
|
-
import * as RollbackCommit from "./RollbackCommit.res.mjs";
|
|
16
|
-
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
17
|
-
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
18
|
-
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
19
10
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
20
|
-
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
21
11
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function make(entities) {
|
|
25
|
-
let init = {};
|
|
26
|
-
entities.forEach(entityConfig => {
|
|
27
|
-
init[entityConfig.name] = InMemoryTable.Entity.make();
|
|
28
|
-
});
|
|
29
|
-
return init;
|
|
12
|
+
function getInMemTable(state, entityConfig) {
|
|
13
|
+
return IndexerState.EntityTables.get(IndexerState.entities(state), entityConfig.name);
|
|
30
14
|
}
|
|
31
15
|
|
|
32
|
-
function
|
|
33
|
-
let table = self[entityName];
|
|
34
|
-
if (table !== undefined) {
|
|
35
|
-
return table;
|
|
36
|
-
} else {
|
|
37
|
-
return ErrorHandling.mkLogAndRaise(undefined, "Unexpected, entity InMemoryTable is undefined", {
|
|
38
|
-
RE_EXN_ID: UndefinedEntity,
|
|
39
|
-
entityName: entityName
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
let EntityTables = {
|
|
45
|
-
UndefinedEntity: UndefinedEntity,
|
|
46
|
-
make: make,
|
|
47
|
-
get: get
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
function make$1(entities, committedCheckpointIdOpt, persistence, config, onError) {
|
|
51
|
-
let committedCheckpointId = committedCheckpointIdOpt !== undefined ? committedCheckpointIdOpt : Internal.initialCheckpointId;
|
|
52
|
-
let intervalMillis = Env.ThrottleWrites.chainMetadataIntervalMillis;
|
|
53
|
-
let chainMetaThrottler = Throttler.make(intervalMillis, Logging.createChild({
|
|
54
|
-
context: "Throttler for chain metadata writes",
|
|
55
|
-
intervalMillis: intervalMillis
|
|
56
|
-
}));
|
|
57
|
-
return {
|
|
58
|
-
allEntities: entities,
|
|
59
|
-
entities: make(entities),
|
|
60
|
-
effects: {},
|
|
61
|
-
rollback: undefined,
|
|
62
|
-
committedCheckpointId: committedCheckpointId,
|
|
63
|
-
processedCheckpointId: committedCheckpointId,
|
|
64
|
-
processedBatches: [],
|
|
65
|
-
isProcessing: false,
|
|
66
|
-
processedBatchesCount: 0,
|
|
67
|
-
writeFiber: undefined,
|
|
68
|
-
hasFailedWrite: false,
|
|
69
|
-
onError: onError,
|
|
70
|
-
commitWaiters: [],
|
|
71
|
-
persistence: persistence,
|
|
72
|
-
config: config,
|
|
73
|
-
chainMeta: {},
|
|
74
|
-
chainMetaDirty: false,
|
|
75
|
-
chainMetaThrottler: chainMetaThrottler
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function getEffectInMemTable(inMemoryStore, effect) {
|
|
16
|
+
function getEffectInMemTable(state, effect) {
|
|
80
17
|
let key = effect.name;
|
|
81
|
-
let
|
|
18
|
+
let effects = IndexerState.effects(state);
|
|
19
|
+
let table = effects[key];
|
|
82
20
|
if (table !== undefined) {
|
|
83
21
|
return table;
|
|
84
22
|
}
|
|
@@ -89,7 +27,7 @@ function getEffectInMemTable(inMemoryStore, effect) {
|
|
|
89
27
|
changesCount: 0,
|
|
90
28
|
effect: effect
|
|
91
29
|
};
|
|
92
|
-
|
|
30
|
+
effects[key] = table$1;
|
|
93
31
|
return table$1;
|
|
94
32
|
}
|
|
95
33
|
|
|
@@ -155,285 +93,18 @@ function dropCommittedEffects(inMemTable, committedCheckpointId, keepLoadedFromD
|
|
|
155
93
|
inMemTable.changesCount = inMemTable.changesCount - keysToDelete.length;
|
|
156
94
|
}
|
|
157
95
|
|
|
158
|
-
function
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
function isRollingBack(inMemoryStore) {
|
|
163
|
-
return inMemoryStore.rollback !== undefined;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function getChangesCount(inMemoryStore) {
|
|
167
|
-
let total = {
|
|
168
|
-
contents: 0
|
|
169
|
-
};
|
|
170
|
-
inMemoryStore.allEntities.forEach(entityConfig => {
|
|
171
|
-
total.contents = total.contents + getInMemTable(inMemoryStore, entityConfig).changesCount;
|
|
172
|
-
});
|
|
173
|
-
Utils.Dict.forEach(inMemoryStore.effects, inMemTable => {
|
|
174
|
-
total.contents = total.contents + inMemTable.changesCount;
|
|
175
|
-
});
|
|
176
|
-
inMemoryStore.processedBatches.forEach(batch => {
|
|
177
|
-
total.contents = total.contents + batch.totalBatchSize;
|
|
178
|
-
});
|
|
179
|
-
return total.contents;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function wakeCommitWaiters(inMemoryStore) {
|
|
183
|
-
let waiters = inMemoryStore.commitWaiters;
|
|
184
|
-
inMemoryStore.commitWaiters = [];
|
|
185
|
-
waiters.forEach(resolve => resolve());
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function waitForCommit(inMemoryStore) {
|
|
189
|
-
return new Promise((resolve, param) => {
|
|
190
|
-
inMemoryStore.commitWaiters.push(resolve);
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function drainBatchRun(inMemoryStore) {
|
|
195
|
-
let all = inMemoryStore.processedBatches;
|
|
196
|
-
let isInReorgThreshold = all[0].isInReorgThreshold;
|
|
197
|
-
let rest = [];
|
|
198
|
-
let progressedChainsById = {};
|
|
199
|
-
let totalBatchSize = {
|
|
200
|
-
contents: 0
|
|
201
|
-
};
|
|
202
|
-
let items = [];
|
|
203
|
-
let checkpointIds = [];
|
|
204
|
-
let checkpointChainIds = [];
|
|
205
|
-
let checkpointBlockNumbers = [];
|
|
206
|
-
let checkpointBlockHashes = [];
|
|
207
|
-
let checkpointEventsProcessed = [];
|
|
208
|
-
all.forEach(batch => {
|
|
209
|
-
if (Utils.$$Array.isEmpty(rest) && batch.isInReorgThreshold === isInReorgThreshold) {
|
|
210
|
-
Utils.Dict.forEachWithKey(batch.progressedChainsById, (chainAfterBatch, key) => {
|
|
211
|
-
progressedChainsById[key] = chainAfterBatch;
|
|
212
|
-
});
|
|
213
|
-
totalBatchSize.contents = totalBatchSize.contents + batch.totalBatchSize | 0;
|
|
214
|
-
items.push(...batch.items);
|
|
215
|
-
checkpointIds.push(...batch.checkpointIds);
|
|
216
|
-
checkpointChainIds.push(...batch.checkpointChainIds);
|
|
217
|
-
checkpointBlockNumbers.push(...batch.checkpointBlockNumbers);
|
|
218
|
-
checkpointBlockHashes.push(...batch.checkpointBlockHashes);
|
|
219
|
-
checkpointEventsProcessed.push(...batch.checkpointEventsProcessed);
|
|
220
|
-
} else {
|
|
221
|
-
rest.push(batch);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
inMemoryStore.processedBatches = rest;
|
|
225
|
-
return {
|
|
226
|
-
totalBatchSize: totalBatchSize.contents,
|
|
227
|
-
items: items,
|
|
228
|
-
progressedChainsById: progressedChainsById,
|
|
229
|
-
isInReorgThreshold: isInReorgThreshold,
|
|
230
|
-
checkpointIds: checkpointIds,
|
|
231
|
-
checkpointChainIds: checkpointChainIds,
|
|
232
|
-
checkpointBlockNumbers: checkpointBlockNumbers,
|
|
233
|
-
checkpointBlockHashes: checkpointBlockHashes,
|
|
234
|
-
checkpointEventsProcessed: checkpointEventsProcessed
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function snapshotEffects(inMemoryStore, cache) {
|
|
239
|
-
let acc = [];
|
|
240
|
-
Utils.Dict.forEach(inMemoryStore.effects, inMemTable => {
|
|
241
|
-
let idsToStore = inMemTable.idsToStore;
|
|
242
|
-
let invalidationsCount = inMemTable.invalidationsCount;
|
|
243
|
-
let dict = inMemTable.dict;
|
|
244
|
-
let effect = inMemTable.effect;
|
|
245
|
-
if (idsToStore.length !== 0) {
|
|
246
|
-
let items = Stdlib_Array.filterMap(idsToStore, id => {
|
|
247
|
-
let match = dict[id];
|
|
248
|
-
if (match.type === "SET") {
|
|
249
|
-
return {
|
|
250
|
-
id: id,
|
|
251
|
-
output: match.entity
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
let effectName = effect.name;
|
|
256
|
-
let c = cache[effectName];
|
|
257
|
-
let effectCacheRecord;
|
|
258
|
-
if (c !== undefined) {
|
|
259
|
-
effectCacheRecord = c;
|
|
260
|
-
} else {
|
|
261
|
-
let c$1 = {
|
|
262
|
-
effectName: effectName,
|
|
263
|
-
count: 0
|
|
264
|
-
};
|
|
265
|
-
cache[effectName] = c$1;
|
|
266
|
-
effectCacheRecord = c$1;
|
|
267
|
-
}
|
|
268
|
-
let shouldInitialize = effectCacheRecord.count === 0;
|
|
269
|
-
effectCacheRecord.count = (effectCacheRecord.count + items.length | 0) - invalidationsCount | 0;
|
|
270
|
-
Prometheus.EffectCacheCount.set(effectCacheRecord.count, effectName);
|
|
271
|
-
acc.push({
|
|
272
|
-
effect: effect,
|
|
273
|
-
items: items,
|
|
274
|
-
shouldInitialize: shouldInitialize
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
inMemTable.idsToStore = [];
|
|
278
|
-
inMemTable.invalidationsCount = 0;
|
|
279
|
-
});
|
|
280
|
-
return acc;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
async function runOneWrite(inMemoryStore, persistence, config) {
|
|
284
|
-
let match = persistence.storageStatus;
|
|
285
|
-
let cache;
|
|
286
|
-
cache = typeof match !== "object" || match.TAG === "Initializing" ? Stdlib_JsError.throwWithMessage(`Failed to access the indexer storage. The Persistence layer is not initialized.`) : match._0.cache;
|
|
287
|
-
let chainMetaData = inMemoryStore.chainMetaDirty ? (inMemoryStore.chainMetaDirty = false, Utils.Dict.shallowCopy(inMemoryStore.chainMeta)) : undefined;
|
|
288
|
-
let match$1 = inMemoryStore.processedBatches;
|
|
289
|
-
if (match$1.length === 0) {
|
|
290
|
-
if (chainMetaData !== undefined) {
|
|
291
|
-
return await persistence.storage.setChainMeta(chainMetaData);
|
|
292
|
-
} else {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
let committedCheckpointId = inMemoryStore.committedCheckpointId;
|
|
297
|
-
let batch = drainBatchRun(inMemoryStore);
|
|
298
|
-
let checkpointId = Utils.$$Array.last(batch.checkpointIds);
|
|
299
|
-
let upToCheckpointId = checkpointId !== undefined ? checkpointId : committedCheckpointId;
|
|
300
|
-
let rollback = inMemoryStore.rollback;
|
|
301
|
-
inMemoryStore.rollback = undefined;
|
|
302
|
-
let updatedEntities = Stdlib_Array.filterMap(persistence.allEntities, entityConfig => {
|
|
303
|
-
let table = getInMemTable(inMemoryStore, entityConfig);
|
|
304
|
-
let changes = InMemoryTable.Entity.snapshotChanges(table, committedCheckpointId, upToCheckpointId);
|
|
305
|
-
if (Utils.$$Array.isEmpty(changes)) {
|
|
306
|
-
return;
|
|
307
|
-
} else {
|
|
308
|
-
return {
|
|
309
|
-
entityConfig: entityConfig,
|
|
310
|
-
changes: changes
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
let updatedEffectsCache = snapshotEffects(inMemoryStore, cache);
|
|
315
|
-
await persistence.storage.writeBatch(batch, rollback, batch.isInReorgThreshold, config, persistence.allEntities, updatedEffectsCache, updatedEntities, chainMetaData);
|
|
316
|
-
inMemoryStore.committedCheckpointId = upToCheckpointId;
|
|
317
|
-
if (rollback !== undefined && Utils.$$Array.notEmpty(RollbackCommit.callbacks)) {
|
|
318
|
-
return await RollbackCommit.fire(rollback.progressBlockNumberByChainId);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
function hasPendingWrite(inMemoryStore) {
|
|
323
|
-
if (Utils.$$Array.notEmpty(inMemoryStore.processedBatches)) {
|
|
324
|
-
return true;
|
|
325
|
-
} else {
|
|
326
|
-
return inMemoryStore.chainMetaDirty;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
async function runWriteLoop(inMemoryStore) {
|
|
331
|
-
while (hasPendingWrite(inMemoryStore) && !inMemoryStore.hasFailedWrite) {
|
|
332
|
-
try {
|
|
333
|
-
await runOneWrite(inMemoryStore, inMemoryStore.persistence, inMemoryStore.config);
|
|
334
|
-
wakeCommitWaiters(inMemoryStore);
|
|
335
|
-
} catch (raw_exn) {
|
|
336
|
-
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
337
|
-
inMemoryStore.hasFailedWrite = true;
|
|
338
|
-
inMemoryStore.onError(exn);
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
inMemoryStore.writeFiber = undefined;
|
|
342
|
-
return wakeCommitWaiters(inMemoryStore);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function kick(inMemoryStore) {
|
|
346
|
-
if (Stdlib_Option.isNone(inMemoryStore.writeFiber) && !inMemoryStore.hasFailedWrite && hasPendingWrite(inMemoryStore)) {
|
|
347
|
-
inMemoryStore.writeFiber = runWriteLoop(inMemoryStore);
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function metaFieldsEqual(a, b) {
|
|
353
|
-
if (Primitive_object.equal(a.first_event_block, b.first_event_block) && a.buffer_block === b.buffer_block && a._is_hyper_sync === b._is_hyper_sync) {
|
|
354
|
-
return Primitive_object.equal(Stdlib_Option.map(Primitive_option.fromNull(a.ready_at), prim => prim.getTime()), Stdlib_Option.map(Primitive_option.fromNull(b.ready_at), prim => prim.getTime()));
|
|
355
|
-
} else {
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
function setChainMeta(inMemoryStore, chainsData) {
|
|
361
|
-
Utils.Dict.forEachWithKey(chainsData, (meta, chainId) => {
|
|
362
|
-
let prev = inMemoryStore.chainMeta[chainId];
|
|
363
|
-
let changed = prev !== undefined ? !metaFieldsEqual(meta, prev) : true;
|
|
364
|
-
if (changed) {
|
|
365
|
-
inMemoryStore.chainMeta[chainId] = meta;
|
|
366
|
-
inMemoryStore.chainMetaDirty = true;
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
if (inMemoryStore.chainMetaDirty) {
|
|
371
|
-
return Throttler.schedule(inMemoryStore.chainMetaThrottler, () => {
|
|
372
|
-
kick(inMemoryStore);
|
|
373
|
-
return Promise.resolve();
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function commitBatch(inMemoryStore, batch) {
|
|
379
|
-
inMemoryStore.processedBatches.push(batch);
|
|
380
|
-
let checkpointId = Utils.$$Array.last(batch.checkpointIds);
|
|
381
|
-
if (checkpointId !== undefined) {
|
|
382
|
-
inMemoryStore.processedCheckpointId = checkpointId;
|
|
383
|
-
}
|
|
384
|
-
kick(inMemoryStore);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function dropCommitted(inMemoryStore, keepLoadedFromDb) {
|
|
388
|
-
let committedCheckpointId = inMemoryStore.committedCheckpointId;
|
|
389
|
-
inMemoryStore.allEntities.forEach(entityConfig => InMemoryTable.Entity.dropCommittedChanges(getInMemTable(inMemoryStore, entityConfig), committedCheckpointId, keepLoadedFromDb));
|
|
390
|
-
Utils.Dict.forEach(inMemoryStore.effects, inMemTable => dropCommittedEffects(inMemTable, committedCheckpointId, keepLoadedFromDb));
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
async function awaitCapacity(inMemoryStore) {
|
|
394
|
-
if (!inMemoryStore.hasFailedWrite && getChangesCount(inMemoryStore) >= Env.inMemoryObjectsTarget) {
|
|
395
|
-
dropCommitted(inMemoryStore, true);
|
|
396
|
-
if (getChangesCount(inMemoryStore) >= Env.inMemoryObjectsTarget) {
|
|
397
|
-
dropCommitted(inMemoryStore, false);
|
|
398
|
-
}
|
|
399
|
-
if (getChangesCount(inMemoryStore) >= Env.inMemoryObjectsTarget && Utils.$$Array.notEmpty(inMemoryStore.processedBatches)) {
|
|
400
|
-
kick(inMemoryStore);
|
|
401
|
-
await waitForCommit(inMemoryStore);
|
|
402
|
-
return await awaitCapacity(inMemoryStore);
|
|
403
|
-
} else {
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
async function flush(inMemoryStore) {
|
|
410
|
-
if (inMemoryStore.hasFailedWrite) {
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
kick(inMemoryStore);
|
|
414
|
-
let fiber = inMemoryStore.writeFiber;
|
|
415
|
-
if (fiber !== undefined) {
|
|
416
|
-
await fiber;
|
|
417
|
-
return await flush(inMemoryStore);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
async function prepareRollbackDiff(inMemoryStore, persistence, rollbackTargetCheckpointId, rollbackDiffCheckpointId, progressBlockNumberByChainId) {
|
|
422
|
-
inMemoryStore.entities = make(inMemoryStore.allEntities);
|
|
423
|
-
inMemoryStore.effects = {};
|
|
424
|
-
inMemoryStore.rollback = {
|
|
425
|
-
targetCheckpointId: rollbackTargetCheckpointId,
|
|
426
|
-
diffCheckpointId: rollbackDiffCheckpointId,
|
|
427
|
-
progressBlockNumberByChainId: progressBlockNumberByChainId
|
|
428
|
-
};
|
|
96
|
+
async function prepareRollbackDiff(state, rollbackTargetCheckpointId, rollbackDiffCheckpointId, progressBlockNumberByChainId) {
|
|
97
|
+
IndexerState.beginRollbackDiff(state, rollbackTargetCheckpointId, rollbackDiffCheckpointId, progressBlockNumberByChainId);
|
|
98
|
+
let persistence = IndexerState.persistence(state);
|
|
99
|
+
let committedCheckpointId = IndexerState.committedCheckpointId(state);
|
|
429
100
|
let deletedEntities = {};
|
|
430
101
|
let setEntities = {};
|
|
431
102
|
await Promise.all(persistence.allEntities.map(async entityConfig => {
|
|
432
|
-
let entityTable = getInMemTable(
|
|
103
|
+
let entityTable = getInMemTable(state, entityConfig);
|
|
433
104
|
let match = await persistence.storage.getRollbackData(entityConfig, rollbackTargetCheckpointId);
|
|
434
105
|
match[0].forEach(data => {
|
|
435
106
|
Utils.Dict.push(deletedEntities, entityConfig.name, data.id);
|
|
436
|
-
InMemoryTable.Entity.set(entityTable,
|
|
107
|
+
InMemoryTable.Entity.set(entityTable, committedCheckpointId, {
|
|
437
108
|
type: "DELETE",
|
|
438
109
|
entityId: data.id,
|
|
439
110
|
checkpointId: rollbackDiffCheckpointId
|
|
@@ -442,7 +113,7 @@ async function prepareRollbackDiff(inMemoryStore, persistence, rollbackTargetChe
|
|
|
442
113
|
let restoredEntities = S$RescriptSchema.parseOrThrow(match[1], Table.pgRowsSchema(entityConfig.table));
|
|
443
114
|
restoredEntities.forEach(entity => {
|
|
444
115
|
Utils.Dict.push(setEntities, entityConfig.name, entity.id);
|
|
445
|
-
InMemoryTable.Entity.set(entityTable,
|
|
116
|
+
InMemoryTable.Entity.set(entityTable, committedCheckpointId, {
|
|
446
117
|
type: "SET",
|
|
447
118
|
entityId: entity.id,
|
|
448
119
|
entity: entity,
|
|
@@ -456,8 +127,9 @@ async function prepareRollbackDiff(inMemoryStore, persistence, rollbackTargetChe
|
|
|
456
127
|
};
|
|
457
128
|
}
|
|
458
129
|
|
|
459
|
-
function setBatchDcs(
|
|
460
|
-
let inMemTable = getInMemTable(
|
|
130
|
+
function setBatchDcs(state, batch) {
|
|
131
|
+
let inMemTable = getInMemTable(state, Config.EnvioAddresses.entityConfig);
|
|
132
|
+
let committedCheckpointId = IndexerState.committedCheckpointId(state);
|
|
461
133
|
let itemIdx = 0;
|
|
462
134
|
for (let checkpoint = 0, checkpoint_finish = batch.checkpointIds.length; checkpoint < checkpoint_finish; ++checkpoint) {
|
|
463
135
|
let checkpointId = batch.checkpointIds[checkpoint];
|
|
@@ -480,7 +152,7 @@ function setBatchDcs(inMemoryStore, batch) {
|
|
|
480
152
|
registration_log_index: entity_registration_log_index,
|
|
481
153
|
contract_name: entity_contract_name
|
|
482
154
|
};
|
|
483
|
-
InMemoryTable.Entity.set(inMemTable,
|
|
155
|
+
InMemoryTable.Entity.set(inMemTable, committedCheckpointId, {
|
|
484
156
|
type: "SET",
|
|
485
157
|
entityId: entity_id,
|
|
486
158
|
entity: entity,
|
|
@@ -493,36 +165,15 @@ function setBatchDcs(inMemoryStore, batch) {
|
|
|
493
165
|
}
|
|
494
166
|
}
|
|
495
167
|
|
|
496
|
-
let keepLatestChangesLimit = Env.inMemoryObjectsTarget;
|
|
497
|
-
|
|
498
168
|
export {
|
|
499
|
-
|
|
500
|
-
make$1 as make,
|
|
501
|
-
keepLatestChangesLimit,
|
|
169
|
+
getInMemTable,
|
|
502
170
|
getEffectInMemTable,
|
|
503
171
|
hasEffectOutput,
|
|
504
172
|
getEffectOutputUnsafe,
|
|
505
173
|
setEffectOutput,
|
|
506
174
|
initEffectOutputFromDb,
|
|
507
175
|
dropCommittedEffects,
|
|
508
|
-
getInMemTable,
|
|
509
|
-
isRollingBack,
|
|
510
|
-
getChangesCount,
|
|
511
|
-
wakeCommitWaiters,
|
|
512
|
-
waitForCommit,
|
|
513
|
-
drainBatchRun,
|
|
514
|
-
snapshotEffects,
|
|
515
|
-
runOneWrite,
|
|
516
|
-
hasPendingWrite,
|
|
517
|
-
runWriteLoop,
|
|
518
|
-
kick,
|
|
519
|
-
metaFieldsEqual,
|
|
520
|
-
setChainMeta,
|
|
521
|
-
commitBatch,
|
|
522
|
-
dropCommitted,
|
|
523
|
-
awaitCapacity,
|
|
524
|
-
flush,
|
|
525
176
|
prepareRollbackDiff,
|
|
526
177
|
setBatchDcs,
|
|
527
178
|
}
|
|
528
|
-
/*
|
|
179
|
+
/* Table Not a pure module */
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// The indexer run loop: it owns scheduling and wires the operation modules
|
|
2
|
+
// together. Each operation (ChainFetching, BatchProcessing, Rollback) is handed
|
|
3
|
+
// the schedule* effects it needs to re-enter the loop; this is the only module
|
|
4
|
+
// that knows how they connect. State and its transitions live in IndexerState.
|
|
5
|
+
|
|
6
|
+
// Fire-and-forget an async step. Every launchable owns a try/catch that routes
|
|
7
|
+
// failures to errorExit, so there's no rejection to swallow here.
|
|
8
|
+
@inline
|
|
9
|
+
let launch = (state: IndexerState.t, work: unit => promise<unit>) =>
|
|
10
|
+
if !(state->IndexerState.isStopped) {
|
|
11
|
+
work()->Promise.ignore
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Kick off the indexer loops. The schedule* effects are mutually recursive
|
|
15
|
+
// (fetch kicks process/rollback, which kick fetch again), so they're defined as
|
|
16
|
+
// one `let rec` block and threaded into the operations as the only way back in.
|
|
17
|
+
let start = (state: IndexerState.t) => {
|
|
18
|
+
let rec scheduleFetch = () =>
|
|
19
|
+
launch(state, () =>
|
|
20
|
+
state
|
|
21
|
+
->IndexerState.crossChainState
|
|
22
|
+
->CrossChainState.checkAndFetch(~fetchChain=(~chain, ~concurrencyLimit, ~bufferLimit) =>
|
|
23
|
+
ChainFetching.fetchChain(
|
|
24
|
+
state,
|
|
25
|
+
chain,
|
|
26
|
+
~concurrencyLimit,
|
|
27
|
+
~bufferLimit,
|
|
28
|
+
~stateId=state->IndexerState.epoch,
|
|
29
|
+
~scheduleFetch,
|
|
30
|
+
~scheduleProcessing,
|
|
31
|
+
~scheduleRollback,
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
and scheduleProcessing = () =>
|
|
36
|
+
launch(state, () => BatchProcessing.startProcessing(state, ~scheduleFetch, ~scheduleRollback))
|
|
37
|
+
and scheduleRollback = () =>
|
|
38
|
+
launch(state, () =>
|
|
39
|
+
Rollback.rollback(state, ~scheduleFetch, ~scheduleProcessing, ~scheduleRollback)
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
scheduleFetch()
|
|
43
|
+
scheduleProcessing()
|
|
44
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Rollback from "./Rollback.res.mjs";
|
|
4
|
+
import * as IndexerState from "./IndexerState.res.mjs";
|
|
5
|
+
import * as ChainFetching from "./ChainFetching.res.mjs";
|
|
6
|
+
import * as BatchProcessing from "./BatchProcessing.res.mjs";
|
|
7
|
+
import * as CrossChainState from "./CrossChainState.res.mjs";
|
|
8
|
+
|
|
9
|
+
function launch(state, work) {
|
|
10
|
+
if (!IndexerState.isStopped(state)) {
|
|
11
|
+
work();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function start(state) {
|
|
17
|
+
let scheduleFetch = () => {
|
|
18
|
+
let work = () => CrossChainState.checkAndFetch(IndexerState.crossChainState(state), (chain, concurrencyLimit, bufferLimit) => ChainFetching.fetchChain(state, chain, concurrencyLimit, bufferLimit, IndexerState.epoch(state), scheduleFetch, scheduleProcessing, scheduleRollback));
|
|
19
|
+
if (!IndexerState.isStopped(state)) {
|
|
20
|
+
work();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
let scheduleProcessing = () => {
|
|
25
|
+
let work = () => BatchProcessing.startProcessing(state, scheduleFetch, scheduleRollback);
|
|
26
|
+
if (!IndexerState.isStopped(state)) {
|
|
27
|
+
work();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
let scheduleRollback = () => {
|
|
32
|
+
let work = () => Rollback.rollback(state, scheduleFetch, scheduleProcessing, scheduleRollback);
|
|
33
|
+
if (!IndexerState.isStopped(state)) {
|
|
34
|
+
work();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
scheduleFetch();
|
|
39
|
+
scheduleProcessing();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
launch,
|
|
44
|
+
start,
|
|
45
|
+
}
|
|
46
|
+
/* Rollback Not a pure module */
|