envio 3.0.2 → 3.1.0-rc.1
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/README.md +0 -1
- package/evm.schema.json +15 -8
- package/fuel.schema.json +19 -12
- package/index.d.ts +0 -2
- package/package.json +6 -7
- package/rescript.json +1 -1
- package/src/Batch.res +4 -214
- package/src/Batch.res.mjs +6 -165
- package/src/ChainFetcher.res +12 -28
- package/src/ChainFetcher.res.mjs +8 -17
- package/src/ChainManager.res +10 -9
- package/src/ChainManager.res.mjs +6 -10
- package/src/Config.res +9 -25
- package/src/Config.res.mjs +17 -27
- package/src/Core.res +7 -0
- package/src/Ctx.res +1 -0
- package/src/Env.res +0 -8
- package/src/Env.res.mjs +0 -6
- package/src/EventConfigBuilder.res +13 -123
- package/src/EventConfigBuilder.res.mjs +6 -73
- package/src/EventProcessing.res +5 -29
- package/src/EventProcessing.res.mjs +11 -20
- package/src/EventUtils.res +0 -27
- package/src/EventUtils.res.mjs +0 -24
- package/src/FetchState.res +2 -15
- package/src/FetchState.res.mjs +3 -18
- package/src/GlobalState.res +26 -39
- package/src/GlobalState.res.mjs +12 -40
- package/src/HandlerLoader.res +6 -5
- package/src/HandlerLoader.res.mjs +27 -9
- package/src/HandlerRegister.res +1 -12
- package/src/HandlerRegister.res.mjs +1 -6
- package/src/HandlerRegister.resi +1 -1
- package/src/Hasura.res +96 -32
- package/src/Hasura.res.mjs +93 -38
- package/src/InMemoryStore.res +205 -45
- package/src/InMemoryStore.res.mjs +157 -40
- package/src/InMemoryTable.res +165 -249
- package/src/InMemoryTable.res.mjs +156 -227
- package/src/Internal.res +10 -34
- package/src/Internal.res.mjs +9 -3
- package/src/LoadLayer.res +5 -5
- package/src/LoadLayer.res.mjs +5 -5
- package/src/LogSelection.res +15 -19
- package/src/LogSelection.res.mjs +5 -6
- package/src/Main.res +4 -6
- package/src/Main.res.mjs +26 -15
- package/src/Persistence.res +7 -132
- package/src/Persistence.res.mjs +1 -102
- package/src/PgStorage.res +57 -40
- package/src/PgStorage.res.mjs +60 -34
- package/src/ReorgDetection.res +35 -58
- package/src/ReorgDetection.res.mjs +21 -29
- package/src/SimulateItems.res.mjs +21 -3
- package/src/Sink.res +2 -2
- package/src/Sink.res.mjs +1 -1
- package/src/TableIndices.res +9 -2
- package/src/TableIndices.res.mjs +7 -1
- package/src/TestIndexer.res +53 -60
- package/src/TestIndexer.res.mjs +77 -63
- package/src/TestIndexerProxyStorage.res +4 -14
- package/src/TestIndexerProxyStorage.res.mjs +1 -5
- package/src/UserContext.res +2 -4
- package/src/UserContext.res.mjs +4 -5
- package/src/Utils.res +0 -2
- package/src/Utils.res.mjs +0 -3
- package/src/bindings/ClickHouse.res +45 -38
- package/src/bindings/ClickHouse.res.mjs +16 -17
- package/src/bindings/Vitest.res +3 -0
- package/src/db/InternalTable.res +59 -18
- package/src/db/InternalTable.res.mjs +82 -51
- package/src/db/Table.res +9 -2
- package/src/db/Table.res.mjs +10 -7
- package/src/sources/EnvioApiClient.res +15 -0
- package/src/sources/EnvioApiClient.res.mjs +24 -0
- package/src/sources/EvmChain.res +32 -10
- package/src/sources/EvmChain.res.mjs +31 -5
- package/src/sources/HyperFuelSource.res +15 -58
- package/src/sources/HyperFuelSource.res.mjs +20 -39
- package/src/sources/HyperSync.res +54 -100
- package/src/sources/HyperSync.res.mjs +67 -96
- package/src/sources/HyperSync.resi +4 -22
- package/src/sources/HyperSyncClient.res +70 -247
- package/src/sources/HyperSyncClient.res.mjs +47 -46
- package/src/sources/HyperSyncSource.res +94 -166
- package/src/sources/HyperSyncSource.res.mjs +100 -127
- package/src/sources/RpcSource.res +43 -22
- package/src/sources/RpcSource.res.mjs +50 -35
- package/src/sources/SimulateSource.res +1 -7
- package/src/sources/SimulateSource.res.mjs +1 -7
- package/src/sources/Source.res +10 -1
- package/src/sources/Source.res.mjs +3 -0
- package/src/sources/SourceManager.res +177 -8
- package/src/sources/SourceManager.res.mjs +141 -3
- package/src/sources/SourceManager.resi +19 -0
- package/src/tui/Tui.res +44 -6
- package/src/tui/Tui.res.mjs +56 -8
- package/src/tui/components/TuiData.res +3 -0
- package/svm.schema.json +11 -4
- package/src/sources/HyperSyncJsonApi.res +0 -390
- package/src/sources/HyperSyncJsonApi.res.mjs +0 -237
|
@@ -2,22 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import * as Utils from "./Utils.res.mjs";
|
|
4
4
|
import * as Config from "./Config.res.mjs";
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
7
|
-
import * as
|
|
5
|
+
import * as Internal from "./Internal.res.mjs";
|
|
6
|
+
import * as Prometheus from "./Prometheus.res.mjs";
|
|
7
|
+
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
8
8
|
import * as ErrorHandling from "./ErrorHandling.res.mjs";
|
|
9
9
|
import * as InMemoryTable from "./InMemoryTable.res.mjs";
|
|
10
|
+
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
11
|
+
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
10
12
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
11
13
|
|
|
12
|
-
function hashRawEventsKey(key) {
|
|
13
|
-
return EventUtils.getEventIdKeyString(key.chainId, key.eventId);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
14
|
let UndefinedEntity = /* @__PURE__ */Primitive_exceptions.create("InMemoryStore.EntityTables.UndefinedEntity");
|
|
17
15
|
|
|
18
16
|
function make(entities) {
|
|
19
17
|
let init = {};
|
|
20
|
-
|
|
18
|
+
entities.forEach(entityConfig => {
|
|
21
19
|
init[entityConfig.name] = InMemoryTable.Entity.make();
|
|
22
20
|
});
|
|
23
21
|
return init;
|
|
@@ -35,40 +33,21 @@ function get(self, entityName) {
|
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
function clone(self) {
|
|
39
|
-
return Object.fromEntries(Belt_Array.map(Object.entries(self), param => [
|
|
40
|
-
param[0],
|
|
41
|
-
InMemoryTable.Entity.clone(param[1])
|
|
42
|
-
]));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
36
|
let EntityTables = {
|
|
46
37
|
UndefinedEntity: UndefinedEntity,
|
|
47
38
|
make: make,
|
|
48
|
-
get: get
|
|
49
|
-
clone: clone
|
|
39
|
+
get: get
|
|
50
40
|
};
|
|
51
41
|
|
|
52
|
-
function make$1(entities,
|
|
42
|
+
function make$1(entities, committedCheckpointIdOpt) {
|
|
43
|
+
let committedCheckpointId = committedCheckpointIdOpt !== undefined ? committedCheckpointIdOpt : Internal.initialCheckpointId;
|
|
53
44
|
return {
|
|
54
|
-
|
|
45
|
+
allEntities: entities,
|
|
46
|
+
rawEvents: [],
|
|
55
47
|
entities: make(entities),
|
|
56
48
|
effects: {},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function clone$1(self) {
|
|
62
|
-
return {
|
|
63
|
-
rawEvents: InMemoryTable.clone(self.rawEvents),
|
|
64
|
-
entities: clone(self.entities),
|
|
65
|
-
effects: Stdlib_Dict.mapValues(self.effects, table => ({
|
|
66
|
-
idsToStore: table.idsToStore.slice(),
|
|
67
|
-
invalidationsCount: table.invalidationsCount,
|
|
68
|
-
dict: Utils.Dict.shallowCopy(table.dict),
|
|
69
|
-
effect: table.effect
|
|
70
|
-
})),
|
|
71
|
-
rollbackTargetCheckpointId: self.rollbackTargetCheckpointId
|
|
49
|
+
rollback: undefined,
|
|
50
|
+
committedCheckpointId: committedCheckpointId
|
|
72
51
|
};
|
|
73
52
|
}
|
|
74
53
|
|
|
@@ -93,10 +72,145 @@ function getInMemTable(inMemoryStore, entityConfig) {
|
|
|
93
72
|
}
|
|
94
73
|
|
|
95
74
|
function isRollingBack(inMemoryStore) {
|
|
96
|
-
return inMemoryStore.
|
|
75
|
+
return inMemoryStore.rollback !== undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function writeBatch(inMemoryStore, persistence, batch, config, isInReorgThreshold) {
|
|
79
|
+
let match = persistence.storageStatus;
|
|
80
|
+
if (typeof match !== "object") {
|
|
81
|
+
return Stdlib_JsError.throwWithMessage(`Failed to access the indexer storage. The Persistence layer is not initialized.`);
|
|
82
|
+
}
|
|
83
|
+
if (match.TAG === "Initializing") {
|
|
84
|
+
return Stdlib_JsError.throwWithMessage(`Failed to access the indexer storage. The Persistence layer is not initialized.`);
|
|
85
|
+
}
|
|
86
|
+
let cache = match._0.cache;
|
|
87
|
+
let committedCheckpointId = inMemoryStore.committedCheckpointId;
|
|
88
|
+
let totalChanges = {
|
|
89
|
+
contents: 0
|
|
90
|
+
};
|
|
91
|
+
persistence.allEntities.forEach(entityConfig => {
|
|
92
|
+
totalChanges.contents = totalChanges.contents + getInMemTable(inMemoryStore, entityConfig).changesCount;
|
|
93
|
+
});
|
|
94
|
+
let keepLatestChanges = totalChanges.contents < 50000;
|
|
95
|
+
let updatedEntities = Stdlib_Array.filterMap(persistence.allEntities, entityConfig => {
|
|
96
|
+
let table = getInMemTable(inMemoryStore, entityConfig);
|
|
97
|
+
table.changesCount = table.changesCount - table.prevEntityChanges.length;
|
|
98
|
+
let changes = table.prevEntityChanges;
|
|
99
|
+
Utils.Dict.forEach(table.latestEntityChangeById, change => {
|
|
100
|
+
if (change.checkpointId > committedCheckpointId) {
|
|
101
|
+
changes.push(change);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
if (Utils.$$Array.isEmpty(changes)) {
|
|
106
|
+
return;
|
|
107
|
+
} else {
|
|
108
|
+
return {
|
|
109
|
+
entityConfig: entityConfig,
|
|
110
|
+
changes: changes
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
let acc = [];
|
|
115
|
+
await persistence.storage.writeBatch(batch, inMemoryStore.rawEvents, inMemoryStore.rollback, isInReorgThreshold, config, persistence.allEntities, (Utils.Dict.forEach(inMemoryStore.effects, inMemTable => {
|
|
116
|
+
let idsToStore = inMemTable.idsToStore;
|
|
117
|
+
let invalidationsCount = inMemTable.invalidationsCount;
|
|
118
|
+
let effect = inMemTable.effect;
|
|
119
|
+
let dict = inMemTable.dict;
|
|
120
|
+
if (idsToStore.length === 0) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
let items = idsToStore.map(id => ({
|
|
124
|
+
id: id,
|
|
125
|
+
output: dict[id]
|
|
126
|
+
}));
|
|
127
|
+
let effectName = effect.name;
|
|
128
|
+
let c = cache[effectName];
|
|
129
|
+
let effectCacheRecord;
|
|
130
|
+
if (c !== undefined) {
|
|
131
|
+
effectCacheRecord = c;
|
|
132
|
+
} else {
|
|
133
|
+
let c$1 = {
|
|
134
|
+
effectName: effectName,
|
|
135
|
+
count: 0
|
|
136
|
+
};
|
|
137
|
+
cache[effectName] = c$1;
|
|
138
|
+
effectCacheRecord = c$1;
|
|
139
|
+
}
|
|
140
|
+
let shouldInitialize = effectCacheRecord.count === 0;
|
|
141
|
+
effectCacheRecord.count = (effectCacheRecord.count + items.length | 0) - invalidationsCount | 0;
|
|
142
|
+
Prometheus.EffectCacheCount.set(effectCacheRecord.count, effectName);
|
|
143
|
+
acc.push({
|
|
144
|
+
effect: effect,
|
|
145
|
+
items: items,
|
|
146
|
+
shouldInitialize: shouldInitialize
|
|
147
|
+
});
|
|
148
|
+
}), acc), updatedEntities);
|
|
149
|
+
inMemoryStore.rawEvents = [];
|
|
150
|
+
inMemoryStore.effects = {};
|
|
151
|
+
inMemoryStore.rollback = undefined;
|
|
152
|
+
let checkpointId = Utils.$$Array.last(batch.checkpointIds);
|
|
153
|
+
inMemoryStore.committedCheckpointId = checkpointId !== undefined ? checkpointId : committedCheckpointId;
|
|
154
|
+
if (keepLatestChanges) {
|
|
155
|
+
persistence.allEntities.forEach(entityConfig => {
|
|
156
|
+
let table = getInMemTable(inMemoryStore, entityConfig);
|
|
157
|
+
inMemoryStore.entities[entityConfig.name] = InMemoryTable.Entity.resetButKeepLatestChanges(table);
|
|
158
|
+
});
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
let loadedFromDbCount = {
|
|
162
|
+
contents: 0
|
|
163
|
+
};
|
|
164
|
+
let resetTables = persistence.allEntities.map(entityConfig => {
|
|
165
|
+
let resetTable = InMemoryTable.Entity.resetButKeepLoadedFromDbChanges(getInMemTable(inMemoryStore, entityConfig));
|
|
166
|
+
loadedFromDbCount.contents = loadedFromDbCount.contents + resetTable.changesCount;
|
|
167
|
+
return resetTable;
|
|
168
|
+
});
|
|
169
|
+
let dropEverything = loadedFromDbCount.contents >= 50000;
|
|
170
|
+
persistence.allEntities.forEach((entityConfig, idx) => {
|
|
171
|
+
inMemoryStore.entities[entityConfig.name] = dropEverything ? InMemoryTable.Entity.make() : resetTables[idx];
|
|
172
|
+
});
|
|
97
173
|
}
|
|
98
174
|
|
|
99
|
-
function
|
|
175
|
+
async function prepareRollbackDiff(inMemoryStore, persistence, rollbackTargetCheckpointId, rollbackDiffCheckpointId) {
|
|
176
|
+
inMemoryStore.rawEvents = [];
|
|
177
|
+
inMemoryStore.entities = make(inMemoryStore.allEntities);
|
|
178
|
+
inMemoryStore.effects = {};
|
|
179
|
+
inMemoryStore.rollback = {
|
|
180
|
+
targetCheckpointId: rollbackTargetCheckpointId,
|
|
181
|
+
diffCheckpointId: rollbackDiffCheckpointId
|
|
182
|
+
};
|
|
183
|
+
let deletedEntities = {};
|
|
184
|
+
let setEntities = {};
|
|
185
|
+
await Promise.all(persistence.allEntities.map(async entityConfig => {
|
|
186
|
+
let entityTable = getInMemTable(inMemoryStore, entityConfig);
|
|
187
|
+
let match = await persistence.storage.getRollbackData(entityConfig, rollbackTargetCheckpointId);
|
|
188
|
+
match[0].forEach(data => {
|
|
189
|
+
Utils.Dict.push(deletedEntities, entityConfig.name, data.id);
|
|
190
|
+
InMemoryTable.Entity.set(entityTable, inMemoryStore.committedCheckpointId, {
|
|
191
|
+
type: "DELETE",
|
|
192
|
+
entityId: data.id,
|
|
193
|
+
checkpointId: rollbackDiffCheckpointId
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
let restoredEntities = S$RescriptSchema.parseOrThrow(match[1], entityConfig.rowsSchema);
|
|
197
|
+
restoredEntities.forEach(entity => {
|
|
198
|
+
Utils.Dict.push(setEntities, entityConfig.name, entity.id);
|
|
199
|
+
InMemoryTable.Entity.set(entityTable, inMemoryStore.committedCheckpointId, {
|
|
200
|
+
type: "SET",
|
|
201
|
+
entityId: entity.id,
|
|
202
|
+
entity: entity,
|
|
203
|
+
checkpointId: rollbackDiffCheckpointId
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}));
|
|
207
|
+
return {
|
|
208
|
+
deletedEntities: deletedEntities,
|
|
209
|
+
setEntities: setEntities
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function setBatchDcs(inMemoryStore, batch) {
|
|
100
214
|
let inMemTable = getInMemTable(inMemoryStore, Config.EnvioAddresses.entityConfig);
|
|
101
215
|
let itemIdx = 0;
|
|
102
216
|
for (let checkpoint = 0, checkpoint_finish = batch.checkpointIds.length; checkpoint < checkpoint_finish; ++checkpoint) {
|
|
@@ -120,12 +234,12 @@ function setBatchDcs(inMemoryStore, batch, shouldSaveHistory) {
|
|
|
120
234
|
registration_log_index: entity_registration_log_index,
|
|
121
235
|
contract_name: entity_contract_name
|
|
122
236
|
};
|
|
123
|
-
InMemoryTable.Entity.set(inMemTable, {
|
|
237
|
+
InMemoryTable.Entity.set(inMemTable, inMemoryStore.committedCheckpointId, {
|
|
124
238
|
type: "SET",
|
|
125
239
|
entityId: entity_id,
|
|
126
240
|
entity: entity,
|
|
127
241
|
checkpointId: checkpointId
|
|
128
|
-
}
|
|
242
|
+
});
|
|
129
243
|
}
|
|
130
244
|
}
|
|
131
245
|
}
|
|
@@ -133,14 +247,17 @@ function setBatchDcs(inMemoryStore, batch, shouldSaveHistory) {
|
|
|
133
247
|
}
|
|
134
248
|
}
|
|
135
249
|
|
|
250
|
+
let keepLatestChangesLimit = 50000;
|
|
251
|
+
|
|
136
252
|
export {
|
|
137
|
-
hashRawEventsKey,
|
|
138
253
|
EntityTables,
|
|
139
254
|
make$1 as make,
|
|
140
|
-
|
|
255
|
+
keepLatestChangesLimit,
|
|
141
256
|
getEffectInMemTable,
|
|
142
257
|
getInMemTable,
|
|
143
258
|
isRollingBack,
|
|
259
|
+
writeBatch,
|
|
260
|
+
prepareRollbackDiff,
|
|
144
261
|
setBatchDcs,
|
|
145
262
|
}
|
|
146
263
|
/* Utils Not a pure module */
|