envio 3.3.0-alpha.1 → 3.3.0-alpha.11
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/evm.schema.json +10 -0
- package/index.d.ts +45 -25
- package/licenses/CLA.md +35 -0
- package/licenses/EULA.md +67 -0
- package/licenses/LICENSE.md +45 -0
- package/licenses/README.md +35 -0
- package/package.json +10 -9
- package/src/Address.res +5 -2
- package/src/Address.res.mjs +3 -1
- package/src/Api.res +1 -1
- package/src/Api.res.mjs +1 -1
- package/src/Batch.res +0 -6
- package/src/Batch.res.mjs +1 -12
- package/src/BatchProcessing.res +7 -12
- package/src/BatchProcessing.res.mjs +8 -7
- package/src/Bin.res +3 -0
- package/src/Bin.res.mjs +4 -0
- package/src/ChainFetching.res +53 -16
- package/src/ChainFetching.res.mjs +37 -19
- package/src/ChainMetadata.res +1 -11
- package/src/ChainMetadata.res.mjs +1 -10
- package/src/ChainState.res +630 -161
- package/src/ChainState.res.mjs +438 -101
- package/src/ChainState.resi +77 -4
- package/src/Config.res +70 -38
- package/src/Config.res.mjs +52 -12
- package/src/ContractRegisterContext.res +2 -12
- package/src/ContractRegisterContext.res.mjs +3 -5
- package/src/Core.res +34 -3
- package/src/Core.res.mjs +12 -0
- package/src/CrossChainState.res +130 -89
- package/src/CrossChainState.res.mjs +66 -61
- package/src/CrossChainState.resi +1 -1
- package/src/Ecosystem.res +5 -6
- package/src/Ecosystem.res.mjs +3 -3
- package/src/Envio.res +17 -11
- package/src/EnvioGlobal.res +53 -0
- package/src/EnvioGlobal.res.mjs +31 -0
- package/src/EventConfigBuilder.res +191 -127
- package/src/EventConfigBuilder.res.mjs +116 -66
- package/src/EventProcessing.res +77 -28
- package/src/EventProcessing.res.mjs +56 -29
- package/src/ExitOnCaughtUp.res +10 -2
- package/src/ExitOnCaughtUp.res.mjs +10 -1
- package/src/FetchState.res +684 -415
- package/src/FetchState.res.mjs +505 -486
- package/src/HandlerLoader.res +8 -104
- package/src/HandlerLoader.res.mjs +2 -81
- package/src/HandlerRegister.res +520 -144
- package/src/HandlerRegister.res.mjs +286 -133
- package/src/HandlerRegister.resi +24 -8
- package/src/IndexerState.res +10 -3
- package/src/IndexerState.res.mjs +11 -4
- package/src/IndexerState.resi +2 -1
- package/src/IndexingAddresses.res +108 -0
- package/src/IndexingAddresses.res.mjs +101 -0
- package/src/IndexingAddresses.resi +34 -0
- package/src/Internal.res +166 -48
- package/src/Internal.res.mjs +30 -2
- package/src/LoadLayer.res +5 -5
- package/src/LoadLayer.res.mjs +6 -6
- package/src/LogSelection.res +92 -217
- package/src/LogSelection.res.mjs +95 -184
- package/src/Main.res +71 -236
- package/src/Main.res.mjs +60 -145
- package/src/Metrics.res +74 -0
- package/src/Metrics.res.mjs +75 -0
- package/src/PgStorage.res +4 -4
- package/src/PgStorage.res.mjs +5 -5
- package/src/Prometheus.res +10 -63
- package/src/Prometheus.res.mjs +124 -171
- package/src/PruneStaleHistory.res +2 -2
- package/src/PruneStaleHistory.res.mjs +3 -3
- package/src/RawEvent.res +7 -2
- package/src/RawEvent.res.mjs +4 -4
- package/src/Rollback.res +3 -3
- package/src/Rollback.res.mjs +4 -4
- package/src/RollbackCommit.res +4 -1
- package/src/RollbackCommit.res.mjs +3 -2
- package/src/SimulateDeadInputTracker.res +85 -0
- package/src/SimulateDeadInputTracker.res.mjs +73 -0
- package/src/SimulateDeadInputTracker.resi +12 -0
- package/src/SimulateItems.res +128 -28
- package/src/SimulateItems.res.mjs +82 -40
- package/src/TestIndexer.res +55 -41
- package/src/TestIndexer.res.mjs +39 -32
- package/src/TopicFilter.res +1 -25
- package/src/TopicFilter.res.mjs +0 -74
- package/src/bindings/Performance.res +7 -0
- package/src/bindings/Performance.res.mjs +21 -0
- package/src/bindings/Performance.resi +7 -0
- package/src/bindings/Viem.res +0 -46
- package/src/bindings/Viem.res.mjs +1 -43
- package/src/sources/BlockStore.res +46 -0
- package/src/sources/BlockStore.res.mjs +24 -0
- package/src/sources/EventRouter.res +31 -49
- package/src/sources/EventRouter.res.mjs +12 -25
- package/src/sources/Evm.res +83 -72
- package/src/sources/Evm.res.mjs +53 -69
- package/src/sources/EvmChain.res +7 -34
- package/src/sources/EvmChain.res.mjs +6 -27
- package/src/sources/EvmRpcClient.res +71 -5
- package/src/sources/EvmRpcClient.res.mjs +13 -4
- package/src/sources/FieldMask.res +39 -0
- package/src/sources/FieldMask.res.mjs +42 -0
- package/src/sources/Fuel.res +9 -6
- package/src/sources/Fuel.res.mjs +5 -10
- package/src/sources/HyperFuelSource.res +46 -50
- package/src/sources/HyperFuelSource.res.mjs +64 -54
- package/src/sources/HyperSync.res +45 -42
- package/src/sources/HyperSync.res.mjs +68 -60
- package/src/sources/HyperSync.resi +14 -4
- package/src/sources/HyperSyncClient.res +107 -119
- package/src/sources/HyperSyncClient.res.mjs +36 -31
- package/src/sources/HyperSyncHeightStream.res +1 -8
- package/src/sources/HyperSyncHeightStream.res.mjs +0 -2
- package/src/sources/HyperSyncSource.res +60 -254
- package/src/sources/HyperSyncSource.res.mjs +57 -180
- package/src/sources/Rpc.res +15 -79
- package/src/sources/Rpc.res.mjs +25 -101
- package/src/sources/RpcSource.res +221 -514
- package/src/sources/RpcSource.res.mjs +216 -411
- package/src/sources/RpcWebSocketHeightStream.res +0 -5
- package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -2
- package/src/sources/SimulateSource.res +44 -20
- package/src/sources/SimulateSource.res.mjs +41 -14
- package/src/sources/Source.res +34 -6
- package/src/sources/SourceManager.res +77 -19
- package/src/sources/SourceManager.res.mjs +63 -21
- package/src/sources/SourceManager.resi +10 -0
- package/src/sources/Svm.res +31 -16
- package/src/sources/Svm.res.mjs +36 -13
- package/src/sources/SvmHyperSyncClient.res +5 -32
- package/src/sources/SvmHyperSyncSource.res +159 -134
- package/src/sources/SvmHyperSyncSource.res.mjs +164 -129
- package/src/sources/TransactionStore.res +49 -0
- package/src/sources/TransactionStore.res.mjs +30 -0
- package/src/tui/Tui.res +13 -16
- package/src/tui/Tui.res.mjs +12 -14
- package/svm.schema.json +49 -37
- package/src/bindings/Hrtime.res +0 -58
- package/src/bindings/Hrtime.res.mjs +0 -90
- package/src/bindings/Hrtime.resi +0 -30
package/src/ChainState.res.mjs
CHANGED
|
@@ -7,9 +7,11 @@ import * as Utils from "./Utils.res.mjs";
|
|
|
7
7
|
import * as Logging from "./Logging.res.mjs";
|
|
8
8
|
import * as ChainMap from "./ChainMap.res.mjs";
|
|
9
9
|
import * as EvmChain from "./sources/EvmChain.res.mjs";
|
|
10
|
+
import * as FieldMask from "./sources/FieldMask.res.mjs";
|
|
11
|
+
import * as BlockStore from "./sources/BlockStore.res.mjs";
|
|
10
12
|
import * as FetchState from "./FetchState.res.mjs";
|
|
11
13
|
import * as Prometheus from "./Prometheus.res.mjs";
|
|
12
|
-
import * as
|
|
14
|
+
import * as Stdlib_Null from "@rescript/runtime/lib/es6/Stdlib_Null.js";
|
|
13
15
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
14
16
|
import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
|
|
15
17
|
import * as SourceManager from "./sources/SourceManager.res.mjs";
|
|
@@ -19,6 +21,8 @@ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
|
19
21
|
import * as HyperFuelSource from "./sources/HyperFuelSource.res.mjs";
|
|
20
22
|
import * as Primitive_float from "@rescript/runtime/lib/es6/Primitive_float.js";
|
|
21
23
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
24
|
+
import * as TransactionStore from "./sources/TransactionStore.res.mjs";
|
|
25
|
+
import * as IndexingAddresses from "./IndexingAddresses.res.mjs";
|
|
22
26
|
import * as SvmHyperSyncSource from "./sources/SvmHyperSyncSource.res.mjs";
|
|
23
27
|
import * as SafeCheckpointTracking from "./SafeCheckpointTracking.res.mjs";
|
|
24
28
|
|
|
@@ -36,86 +40,62 @@ function configAddresses(chainConfig) {
|
|
|
36
40
|
return addresses;
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
function
|
|
43
|
+
function validateOnEventRegistrations(chainId, registrations) {
|
|
44
|
+
registrations.forEach((registration, expectedIndex) => {
|
|
45
|
+
if (registration.index !== expectedIndex) {
|
|
46
|
+
return Stdlib_JsError.throwWithMessage(`Invalid onEvent registration index for chain ` + chainId.toString() + `: ` + registration.eventConfig.contractName + `.` + registration.eventConfig.name + ` has index ` + registration.index.toString() + `, but its ChainState position is ` + expectedIndex.toString() + `.`);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function make(chainConfig, fetchState, onEventRegistrationsOpt, indexingAddresses, sourceManager, reorgDetection, committedProgressBlockNumber, safeCheckpointTrackingOpt, numEventsProcessedOpt, timestampCaughtUpToHeadOrEndblockOpt, isProgressAtHeadOpt, transactionStoreOpt, chainDensityOpt, blockStoreOpt, logger) {
|
|
52
|
+
let onEventRegistrations = onEventRegistrationsOpt !== undefined ? onEventRegistrationsOpt : [];
|
|
40
53
|
let safeCheckpointTracking = safeCheckpointTrackingOpt !== undefined ? Primitive_option.valFromOption(safeCheckpointTrackingOpt) : undefined;
|
|
41
54
|
let numEventsProcessed = numEventsProcessedOpt !== undefined ? numEventsProcessedOpt : 0;
|
|
42
55
|
let timestampCaughtUpToHeadOrEndblock = timestampCaughtUpToHeadOrEndblockOpt !== undefined ? Primitive_option.valFromOption(timestampCaughtUpToHeadOrEndblockOpt) : undefined;
|
|
43
56
|
let isProgressAtHead = isProgressAtHeadOpt !== undefined ? isProgressAtHeadOpt : false;
|
|
57
|
+
let transactionStore = transactionStoreOpt !== undefined ? Primitive_option.valFromOption(transactionStoreOpt) : TransactionStore.make("evm", false);
|
|
58
|
+
let chainDensity = chainDensityOpt !== undefined ? Primitive_option.valFromOption(chainDensityOpt) : undefined;
|
|
59
|
+
let blockStore = blockStoreOpt !== undefined ? Primitive_option.valFromOption(blockStoreOpt) : BlockStore.make("evm", false);
|
|
60
|
+
validateOnEventRegistrations(chainConfig.id, onEventRegistrations);
|
|
44
61
|
return {
|
|
45
62
|
logger: logger,
|
|
63
|
+
onEventRegistrations: onEventRegistrations,
|
|
46
64
|
fetchState: fetchState,
|
|
65
|
+
indexingAddresses: indexingAddresses,
|
|
47
66
|
sourceManager: sourceManager,
|
|
48
67
|
chainConfig: chainConfig,
|
|
49
68
|
isProgressAtHead: isProgressAtHead,
|
|
50
69
|
timestampCaughtUpToHeadOrEndblock: timestampCaughtUpToHeadOrEndblock,
|
|
51
70
|
committedProgressBlockNumber: committedProgressBlockNumber,
|
|
71
|
+
processingBlockNumber: committedProgressBlockNumber,
|
|
52
72
|
numEventsProcessed: numEventsProcessed,
|
|
53
73
|
pendingBudget: 0,
|
|
74
|
+
chainDensity: chainDensity,
|
|
54
75
|
reorgDetection: reorgDetection,
|
|
55
|
-
safeCheckpointTracking: safeCheckpointTracking
|
|
76
|
+
safeCheckpointTracking: safeCheckpointTracking,
|
|
77
|
+
transactionStore: transactionStore,
|
|
78
|
+
blockStore: blockStore
|
|
56
79
|
};
|
|
57
80
|
}
|
|
58
81
|
|
|
59
|
-
function makeInternal(chainConfig, indexingAddresses, startBlock, endBlock, firstEventBlockOpt, progressBlockNumber, config,
|
|
82
|
+
function makeInternal(chainConfig, indexingAddresses, startBlock, endBlock, firstEventBlockOpt, progressBlockNumber, config, registrationsByChainId, logger, timestampCaughtUpToHeadOrEndblock, numEventsProcessed, isInReorgThreshold, isRealtime, reorgCheckpoints, maxReorgDepth, knownHeightOpt, reducedPollingInterval) {
|
|
60
83
|
let firstEventBlock = firstEventBlockOpt !== undefined ? Primitive_option.valFromOption(firstEventBlockOpt) : undefined;
|
|
61
84
|
let knownHeight = knownHeightOpt !== undefined ? knownHeightOpt : 0;
|
|
62
|
-
let
|
|
63
|
-
|
|
64
|
-
|
|
85
|
+
let match = Stdlib_Option.getOr(registrationsByChainId[chainConfig.id.toString()], {
|
|
86
|
+
onEventRegistrations: [],
|
|
87
|
+
onBlockRegistrations: []
|
|
88
|
+
});
|
|
89
|
+
let onEventRegistrations = match.onEventRegistrations;
|
|
65
90
|
chainConfig.contracts.forEach(contract => {
|
|
66
|
-
let contractName = contract.name;
|
|
67
|
-
contract.events.forEach(eventConfig => {
|
|
68
|
-
let hasContractRegister = Stdlib_Option.isSome(eventConfig.contractRegister);
|
|
69
|
-
EventRouter.addOrThrow(eventRouter, eventConfig.id, undefined, contractName, eventConfig.isWildcard, eventConfig.name, ChainMap.Chain.makeUnsafe(chainConfig.id));
|
|
70
|
-
let shouldBeIncluded;
|
|
71
|
-
if (config.enableRawEvents) {
|
|
72
|
-
shouldBeIncluded = true;
|
|
73
|
-
} else {
|
|
74
|
-
let isRegistered = hasContractRegister || Stdlib_Option.isSome(eventConfig.handler);
|
|
75
|
-
if (!isRegistered) {
|
|
76
|
-
notRegisteredEvents.push(eventConfig);
|
|
77
|
-
}
|
|
78
|
-
shouldBeIncluded = isRegistered;
|
|
79
|
-
}
|
|
80
|
-
let shouldSkip;
|
|
81
|
-
try {
|
|
82
|
-
let getEventFiltersOrThrow = eventConfig.getEventFiltersOrThrow;
|
|
83
|
-
if (getEventFiltersOrThrow) {
|
|
84
|
-
let match = getEventFiltersOrThrow(ChainMap.Chain.makeUnsafe(chainConfig.id));
|
|
85
|
-
shouldSkip = match.TAG === "Static" ? match._0.length === 0 : false;
|
|
86
|
-
} else {
|
|
87
|
-
shouldSkip = false;
|
|
88
|
-
}
|
|
89
|
-
} catch (exn) {
|
|
90
|
-
shouldSkip = false;
|
|
91
|
-
}
|
|
92
|
-
if (shouldBeIncluded && !shouldSkip) {
|
|
93
|
-
eventConfigs.push(eventConfig);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
91
|
let startBlock = contract.startBlock;
|
|
98
92
|
if (startBlock !== undefined && startBlock < chainConfig.startBlock) {
|
|
99
|
-
return Stdlib_JsError.throwWithMessage(`The start block for contract "` +
|
|
93
|
+
return Stdlib_JsError.throwWithMessage(`The start block for contract "` + contract.name + `" is less than the chain start block. This is not supported yet.`);
|
|
100
94
|
}
|
|
101
95
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
) + ` ` + notRegisteredEvents.map(eventConfig => eventConfig.contractName + `.` + eventConfig.name).join(", ") + ` don't have an event handler and skipped for indexing.`);
|
|
106
|
-
}
|
|
107
|
-
let onBlockConfigs = registrations.onBlockByChainId[chainConfig.id.toString()];
|
|
108
|
-
if (onBlockConfigs !== undefined) {
|
|
109
|
-
onBlockConfigs.forEach(onBlockConfig => {
|
|
110
|
-
if (Stdlib_Option.getOr(onBlockConfig.startBlock, startBlock) < startBlock) {
|
|
111
|
-
Stdlib_JsError.throwWithMessage(`The start block for onBlock handler "` + onBlockConfig.name + `" is less than the chain start block (` + startBlock.toString() + `). This is not supported yet.`);
|
|
112
|
-
}
|
|
113
|
-
if (endBlock !== undefined && Stdlib_Option.getOr(onBlockConfig.endBlock, endBlock) > endBlock) {
|
|
114
|
-
return Stdlib_JsError.throwWithMessage(`The end block for onBlock handler "` + onBlockConfig.name + `" is greater than the chain end block (` + endBlock.toString() + `). This is not supported yet.`);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
let fetchState = FetchState.make(startBlock, endBlock, eventConfigs, indexingAddresses, config.maxAddrInPartition, chainConfig.id, (config.batchSize << 1), knownHeight, progressBlockNumber, onBlockConfigs, Primitive_int.max(!config.shouldRollbackOnReorg || isInReorgThreshold ? 0 : chainConfig.maxReorgDepth, chainConfig.blockLag), Primitive_option.some(firstEventBlock));
|
|
96
|
+
let contractConfigs = IndexingAddresses.makeContractConfigs(onEventRegistrations);
|
|
97
|
+
let indexingAddressIndex = IndexingAddresses.make(contractConfigs, indexingAddresses);
|
|
98
|
+
let fetchState = FetchState.make(startBlock, endBlock, onEventRegistrations, contractConfigs, indexingAddresses, config.maxAddrInPartition, chainConfig.id, (config.batchSize << 1), knownHeight, progressBlockNumber, match.onBlockRegistrations, Primitive_int.max(!config.shouldRollbackOnReorg || isInReorgThreshold ? 0 : chainConfig.maxReorgDepth, chainConfig.blockLag), Primitive_option.some(firstEventBlock));
|
|
119
99
|
let chainReorgCheckpoints = Stdlib_Array.filterMap(reorgCheckpoints, reorgCheckpoint => {
|
|
120
100
|
if (reorgCheckpoint.chain_id === chainConfig.id) {
|
|
121
101
|
return reorgCheckpoint;
|
|
@@ -127,22 +107,19 @@ function makeInternal(chainConfig, indexingAddresses, startBlock, endBlock, firs
|
|
|
127
107
|
let sources$1;
|
|
128
108
|
switch (sources.TAG) {
|
|
129
109
|
case "EvmSourceConfig" :
|
|
130
|
-
let evmContracts = chainConfig.contracts.map(contract => ({
|
|
131
|
-
name: contract.name,
|
|
132
|
-
abi: contract.abi,
|
|
133
|
-
events: contract.events
|
|
134
|
-
}));
|
|
135
110
|
let evmRpcs = sources.rpcs.map(rpc => {
|
|
136
111
|
let syncConfig = rpc.syncConfig;
|
|
137
112
|
let ws = rpc.ws;
|
|
113
|
+
let headers = rpc.headers;
|
|
138
114
|
return {
|
|
139
115
|
url: rpc.url,
|
|
140
116
|
sourceFor: rpc.sourceFor,
|
|
141
117
|
syncConfig: syncConfig,
|
|
142
|
-
ws: ws
|
|
118
|
+
ws: ws,
|
|
119
|
+
headers: headers
|
|
143
120
|
};
|
|
144
121
|
});
|
|
145
|
-
sources$1 = EvmChain.makeSources(chain,
|
|
122
|
+
sources$1 = EvmChain.makeSources(chain, onEventRegistrations, sources.hypersync, evmRpcs, lowercaseAddresses);
|
|
146
123
|
break;
|
|
147
124
|
case "FuelSourceConfig" :
|
|
148
125
|
sources$1 = [HyperFuelSource.make({
|
|
@@ -154,51 +131,46 @@ function makeInternal(chainConfig, indexingAddresses, startBlock, endBlock, firs
|
|
|
154
131
|
case "SvmSourceConfig" :
|
|
155
132
|
let rpc = sources.rpc;
|
|
156
133
|
let hypersync = sources.hypersync;
|
|
157
|
-
|
|
158
|
-
let svmEventConfigs = chainConfig.contracts.flatMap(contract => contract.events);
|
|
159
|
-
sources$1 = [SvmHyperSyncSource.make({
|
|
134
|
+
sources$1 = hypersync !== undefined ? [SvmHyperSyncSource.make({
|
|
160
135
|
chain: chain,
|
|
161
136
|
endpointUrl: hypersync,
|
|
162
137
|
apiToken: Env.envioApiToken,
|
|
163
|
-
|
|
138
|
+
onEventRegistrations: onEventRegistrations,
|
|
164
139
|
clientTimeoutMillis: Env.hyperSyncClientTimeoutMillis
|
|
165
|
-
})]
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
140
|
+
})] : (
|
|
141
|
+
rpc !== undefined ? [Svm.makeRPCSource(chain, rpc, undefined)] : Stdlib_JsError.throwWithMessage(`Chain ` + chain.toString() + ` has no SVM data source`)
|
|
142
|
+
);
|
|
169
143
|
break;
|
|
170
144
|
case "CustomSources" :
|
|
171
145
|
sources$1 = sources._0;
|
|
172
146
|
break;
|
|
173
147
|
}
|
|
174
|
-
|
|
148
|
+
let firstEventBlock$1 = fetchState.firstEventBlock;
|
|
149
|
+
let chainDensity = firstEventBlock$1 !== undefined && progressBlockNumber > firstEventBlock$1 && numEventsProcessed > 0 ? numEventsProcessed / (progressBlockNumber - firstEventBlock$1 | 0) : undefined;
|
|
150
|
+
return make(chainConfig, fetchState, onEventRegistrations, indexingAddressIndex, SourceManager.make(sources$1, isRealtime, undefined, undefined, undefined, reducedPollingInterval, undefined, undefined), ReorgDetection.make(chainReorgCheckpoints, maxReorgDepth, config.shouldRollbackOnReorg), progressBlockNumber, Primitive_option.some(SafeCheckpointTracking.make(maxReorgDepth, config.shouldRollbackOnReorg, chainReorgCheckpoints)), numEventsProcessed, Primitive_option.some(timestampCaughtUpToHeadOrEndblock), undefined, Primitive_option.some(TransactionStore.make(config.ecosystem.name, !lowercaseAddresses)), Primitive_option.some(chainDensity), Primitive_option.some(BlockStore.make(config.ecosystem.name, !lowercaseAddresses)), logger);
|
|
175
151
|
}
|
|
176
152
|
|
|
177
|
-
function makeFromConfig(chainConfig, config,
|
|
153
|
+
function makeFromConfig(chainConfig, config, registrationsByChainId, knownHeight) {
|
|
178
154
|
let logger = Logging.createChild({
|
|
179
155
|
chainId: chainConfig.id
|
|
180
156
|
});
|
|
181
|
-
return makeInternal(chainConfig, configAddresses(chainConfig), chainConfig.startBlock, chainConfig.endBlock, undefined, -1, config,
|
|
157
|
+
return makeInternal(chainConfig, configAddresses(chainConfig), chainConfig.startBlock, chainConfig.endBlock, undefined, -1, config, registrationsByChainId, logger, undefined, 0, false, false, [], chainConfig.maxReorgDepth, knownHeight, undefined);
|
|
182
158
|
}
|
|
183
159
|
|
|
184
|
-
function makeFromDbState(chainConfig, resumedChainState, reorgCheckpoints, isInReorgThreshold, isRealtime, config,
|
|
160
|
+
function makeFromDbState(chainConfig, resumedChainState, reorgCheckpoints, isInReorgThreshold, isRealtime, config, registrationsByChainId, reducedPollingInterval) {
|
|
185
161
|
let chainId = chainConfig.id;
|
|
186
162
|
let logger = Logging.createChild({
|
|
187
163
|
chainId: chainId
|
|
188
164
|
});
|
|
189
165
|
Prometheus.ProgressEventsCount.set(resumedChainState.numEventsProcessed, chainId);
|
|
190
166
|
let progressBlockNumber = resumedChainState.progressBlockNumber >= 0 ? resumedChainState.progressBlockNumber : resumedChainState.startBlock - 1 | 0;
|
|
191
|
-
return makeInternal(chainConfig, resumedChainState.indexingAddresses, resumedChainState.startBlock, resumedChainState.endBlock, Primitive_option.some(resumedChainState.firstEventBlockNumber), progressBlockNumber, config,
|
|
167
|
+
return makeInternal(chainConfig, resumedChainState.indexingAddresses, resumedChainState.startBlock, resumedChainState.endBlock, Primitive_option.some(resumedChainState.firstEventBlockNumber), progressBlockNumber, config, registrationsByChainId, logger, Env.updateSyncTimeOnRestart ? undefined : resumedChainState.timestampCaughtUpToHeadOrEndblock, resumedChainState.numEventsProcessed, isInReorgThreshold, isRealtime, reorgCheckpoints, resumedChainState.maxReorgDepth, resumedChainState.sourceBlockNumber, reducedPollingInterval);
|
|
192
168
|
}
|
|
193
169
|
|
|
194
170
|
function logger(cs) {
|
|
195
171
|
return cs.logger;
|
|
196
172
|
}
|
|
197
173
|
|
|
198
|
-
function fetchState(cs) {
|
|
199
|
-
return cs.fetchState;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
174
|
function sourceManager(cs) {
|
|
203
175
|
return cs.sourceManager;
|
|
204
176
|
}
|
|
@@ -235,9 +207,140 @@ function timestampCaughtUpToHeadOrEndblock(cs) {
|
|
|
235
207
|
return cs.timestampCaughtUpToHeadOrEndblock;
|
|
236
208
|
}
|
|
237
209
|
|
|
210
|
+
function knownHeight(cs) {
|
|
211
|
+
return cs.fetchState.knownHeight;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function contractAddresses(cs, contractName) {
|
|
215
|
+
return IndexingAddresses.getContractAddresses(cs.indexingAddresses, contractName);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function bufferSize(cs) {
|
|
219
|
+
return FetchState.bufferSize(cs.fetchState);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function bufferReadyCount(cs) {
|
|
223
|
+
return FetchState.bufferReadyCount(cs.fetchState);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function getProgressPercentage(cs) {
|
|
227
|
+
return FetchState.getProgressPercentage(cs.fetchState);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function chainDensity(cs) {
|
|
231
|
+
return cs.chainDensity;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function hasReadyItem(cs) {
|
|
235
|
+
if (FetchState.isActivelyIndexing(cs.fetchState)) {
|
|
236
|
+
return FetchState.hasReadyItem(cs.fetchState);
|
|
237
|
+
} else {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function isReadyToEnterReorgThreshold(cs) {
|
|
243
|
+
return FetchState.isReadyToEnterReorgThreshold(cs.fetchState);
|
|
244
|
+
}
|
|
245
|
+
|
|
238
246
|
function startFetchingQueries(cs, queries) {
|
|
239
247
|
FetchState.startFetchingQueries(cs.fetchState, queries);
|
|
240
|
-
cs.pendingBudget = cs.pendingBudget + Stdlib_Array.reduce(queries, 0, (acc, query) => acc + query.
|
|
248
|
+
cs.pendingBudget = cs.pendingBudget + Stdlib_Array.reduce(queries, 0, (acc, query) => acc + query.itemsEst);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function isReady(cs) {
|
|
252
|
+
return cs.timestampCaughtUpToHeadOrEndblock !== undefined;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function fetchCeiling(cs) {
|
|
256
|
+
let fetchState = cs.fetchState;
|
|
257
|
+
let endBlock = fetchState.endBlock;
|
|
258
|
+
if (endBlock !== undefined) {
|
|
259
|
+
return Primitive_int.min(endBlock, fetchState.knownHeight);
|
|
260
|
+
} else {
|
|
261
|
+
return fetchState.knownHeight;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function readyBufferDensity(cs) {
|
|
266
|
+
let readyCount = FetchState.bufferReadyCount(cs.fetchState);
|
|
267
|
+
let span = FetchState.bufferBlockNumber(cs.fetchState) - cs.processingBlockNumber | 0;
|
|
268
|
+
if (readyCount > 0 && span > 0) {
|
|
269
|
+
return readyCount / span;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function effectiveDensity(cs) {
|
|
274
|
+
let match = cs.chainDensity;
|
|
275
|
+
let match$1 = readyBufferDensity(cs);
|
|
276
|
+
if (match !== undefined) {
|
|
277
|
+
if (match$1 !== undefined) {
|
|
278
|
+
return Primitive_float.max(match, match$1);
|
|
279
|
+
} else {
|
|
280
|
+
return match;
|
|
281
|
+
}
|
|
282
|
+
} else if (match$1 !== undefined) {
|
|
283
|
+
return match$1;
|
|
284
|
+
} else {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function targetBlock(cs, chainTargetItems) {
|
|
290
|
+
let fetchState = cs.fetchState;
|
|
291
|
+
let fetchCeiling$1 = fetchCeiling(cs);
|
|
292
|
+
let bufferBlockNumber = FetchState.bufferBlockNumber(fetchState);
|
|
293
|
+
let density = effectiveDensity(cs);
|
|
294
|
+
if (density !== undefined && density > 0) {
|
|
295
|
+
return Primitive_int.min(fetchCeiling$1, bufferBlockNumber + (Math.ceil(chainTargetItems / density) | 0) | 0);
|
|
296
|
+
} else {
|
|
297
|
+
return Primitive_int.min(bufferBlockNumber + 20000 | 0, fetchCeiling$1);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function progressRange(cs) {
|
|
302
|
+
let fetchState = cs.fetchState;
|
|
303
|
+
let lower = Stdlib_Option.getOr(fetchState.firstEventBlock, fetchState.startBlock);
|
|
304
|
+
return [
|
|
305
|
+
lower,
|
|
306
|
+
fetchCeiling(cs)
|
|
307
|
+
];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function progressAtBlock(cs, blockNumber) {
|
|
311
|
+
let match = progressRange(cs);
|
|
312
|
+
let upper = match[1];
|
|
313
|
+
let lower = match[0];
|
|
314
|
+
if (upper <= lower) {
|
|
315
|
+
return 1;
|
|
316
|
+
} else {
|
|
317
|
+
return Primitive_float.max(0, Primitive_float.min(1, (blockNumber - lower | 0) / (upper - lower | 0)));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function blockAtProgress(cs, progress) {
|
|
322
|
+
let match = progressRange(cs);
|
|
323
|
+
let lower = match[0];
|
|
324
|
+
return lower + (Math.ceil(progress * (match[1] - lower | 0)) | 0) | 0;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function getNextQuery(cs, chainTargetItems, chunkItemsMultiplierOpt, maxTargetBlock) {
|
|
328
|
+
let chunkItemsMultiplier = chunkItemsMultiplierOpt !== undefined ? chunkItemsMultiplierOpt : 1;
|
|
329
|
+
let chainTargetBlock = targetBlock(cs, chainTargetItems);
|
|
330
|
+
let chainTargetBlock$1 = maxTargetBlock !== undefined ? Primitive_int.min(chainTargetBlock, maxTargetBlock) : chainTargetBlock;
|
|
331
|
+
let density = effectiveDensity(cs);
|
|
332
|
+
let chainTargetItems$1;
|
|
333
|
+
if (density !== undefined && density > 0) {
|
|
334
|
+
let rangeCost = density * (chainTargetBlock$1 - FetchState.bufferBlockNumber(cs.fetchState) | 0);
|
|
335
|
+
chainTargetItems$1 = Primitive_float.min(chainTargetItems, Math.ceil(rangeCost) + cs.pendingBudget);
|
|
336
|
+
} else {
|
|
337
|
+
chainTargetItems$1 = chainTargetItems;
|
|
338
|
+
}
|
|
339
|
+
return FetchState.getNextQuery(cs.fetchState, chainTargetBlock$1, chainTargetItems$1, chunkItemsMultiplier);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function dispatch(cs, executeQuery, waitForNewBlock, onNewBlock, action, stateId) {
|
|
343
|
+
return SourceManager.dispatch(cs.sourceManager, cs.fetchState, executeQuery, waitForNewBlock, onNewBlock, action, stateId);
|
|
241
344
|
}
|
|
242
345
|
|
|
243
346
|
function hasProcessedToEndblock(cs) {
|
|
@@ -264,18 +367,160 @@ function isActivelyIndexing(cs) {
|
|
|
264
367
|
return FetchState.isActivelyIndexing(cs.fetchState);
|
|
265
368
|
}
|
|
266
369
|
|
|
267
|
-
function isReady(cs) {
|
|
268
|
-
return cs.timestampCaughtUpToHeadOrEndblock !== undefined;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
370
|
function isFetchingAtHead(cs) {
|
|
272
371
|
return FetchState.isFetchingAtHead(cs.fetchState);
|
|
273
372
|
}
|
|
274
373
|
|
|
275
|
-
function
|
|
276
|
-
|
|
374
|
+
function isAtHeadWithoutEndBlock(cs) {
|
|
375
|
+
if (cs.isProgressAtHead) {
|
|
376
|
+
return Stdlib_Option.isNone(cs.fetchState.endBlock);
|
|
377
|
+
} else {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function groupBatchItems(items, includeBlocks) {
|
|
383
|
+
let txBlockNumbers = [];
|
|
384
|
+
let transactionIndices = [];
|
|
385
|
+
let transactionMasks = [];
|
|
386
|
+
let payloadGroups = [];
|
|
387
|
+
let anyTransactionFieldSelected = {
|
|
388
|
+
contents: false
|
|
389
|
+
};
|
|
390
|
+
let blockBlockNumbers = [];
|
|
391
|
+
let blockMasks = [];
|
|
392
|
+
let blockItemGroups = [];
|
|
393
|
+
items.forEach(item => {
|
|
394
|
+
if (item.kind !== 0) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
let blockNumber = item.blockNumber;
|
|
398
|
+
let match = item.payload.transaction;
|
|
399
|
+
if (match == null) {
|
|
400
|
+
let transactionIndex = item.transactionIndex;
|
|
401
|
+
let mask = item.onEventRegistration.eventConfig.transactionFieldMask;
|
|
402
|
+
if (mask !== 0) {
|
|
403
|
+
anyTransactionFieldSelected.contents = true;
|
|
404
|
+
}
|
|
405
|
+
let last = payloadGroups.length - 1 | 0;
|
|
406
|
+
if (last >= 0 && txBlockNumbers[last] === blockNumber && transactionIndices[last] === transactionIndex) {
|
|
407
|
+
payloadGroups[last].push(item.payload);
|
|
408
|
+
transactionMasks[last] = FieldMask.orMask(transactionMasks[last], mask);
|
|
409
|
+
} else {
|
|
410
|
+
txBlockNumbers.push(blockNumber);
|
|
411
|
+
transactionIndices.push(transactionIndex);
|
|
412
|
+
transactionMasks.push(mask);
|
|
413
|
+
payloadGroups.push([item.payload]);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (!includeBlocks) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
let match$1 = item.payload.block;
|
|
420
|
+
if (!(match$1 == null)) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
let mask$1 = item.onEventRegistration.eventConfig.blockFieldMask;
|
|
424
|
+
let last$1 = blockItemGroups.length - 1 | 0;
|
|
425
|
+
if (last$1 >= 0 && blockBlockNumbers[last$1] === blockNumber) {
|
|
426
|
+
blockItemGroups[last$1].push(item);
|
|
427
|
+
blockMasks[last$1] = FieldMask.orMask(blockMasks[last$1], mask$1);
|
|
428
|
+
} else {
|
|
429
|
+
blockBlockNumbers.push(blockNumber);
|
|
430
|
+
blockMasks.push(mask$1);
|
|
431
|
+
blockItemGroups.push([item]);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
return [
|
|
435
|
+
{
|
|
436
|
+
txBlockNumbers: txBlockNumbers,
|
|
437
|
+
transactionIndices: transactionIndices,
|
|
438
|
+
transactionMasks: transactionMasks,
|
|
439
|
+
payloadGroups: payloadGroups,
|
|
440
|
+
anyTransactionFieldSelected: anyTransactionFieldSelected.contents
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
blockBlockNumbers: blockBlockNumbers,
|
|
444
|
+
blockMasks: blockMasks,
|
|
445
|
+
blockItemGroups: blockItemGroups
|
|
446
|
+
}
|
|
447
|
+
];
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
async function applyTransactionGroups(store, g) {
|
|
451
|
+
if (!Utils.$$Array.notEmpty(g.payloadGroups)) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (g.anyTransactionFieldSelected) {
|
|
455
|
+
let txs = await store.materialize(g.txBlockNumbers, g.transactionIndices, g.transactionMasks);
|
|
456
|
+
g.payloadGroups.forEach((payloads, i) => {
|
|
457
|
+
let tx = txs[i];
|
|
458
|
+
payloads.forEach(payload => {
|
|
459
|
+
payload.transaction = tx;
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
g.payloadGroups.forEach(payloads => {
|
|
465
|
+
payloads.forEach(payload => {
|
|
466
|
+
payload.transaction = {};
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
async function applyBlockGroups(store, g) {
|
|
472
|
+
if (!Utils.$$Array.notEmpty(g.blockItemGroups)) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
let blocks = await store.materialize(g.blockBlockNumbers, g.blockMasks);
|
|
476
|
+
g.blockItemGroups.forEach((group, i) => {
|
|
477
|
+
let block = blocks[i];
|
|
478
|
+
group.forEach(ei => {
|
|
479
|
+
ei.payload.block = block;
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function includeBlocksForEcosystem(ecosystem) {
|
|
485
|
+
switch (ecosystem) {
|
|
486
|
+
case "fuel" :
|
|
487
|
+
return false;
|
|
488
|
+
case "evm" :
|
|
489
|
+
case "svm" :
|
|
490
|
+
return true;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
async function materializeBatchItems(cs, items, ecosystem) {
|
|
495
|
+
let match = groupBatchItems(items, includeBlocksForEcosystem(ecosystem));
|
|
496
|
+
await Promise.all([
|
|
497
|
+
applyTransactionGroups(cs.transactionStore, match[0]),
|
|
498
|
+
applyBlockGroups(cs.blockStore, match[1])
|
|
499
|
+
]);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
async function materializePageItems(items, transactionStore, blockStore, ecosystem) {
|
|
503
|
+
let match = groupBatchItems(items, includeBlocksForEcosystem(ecosystem));
|
|
504
|
+
await Promise.all([
|
|
505
|
+
transactionStore !== undefined ? applyTransactionGroups(Primitive_option.valFromOption(transactionStore), match[0]) : Promise.resolve(),
|
|
506
|
+
blockStore !== undefined ? applyBlockGroups(Primitive_option.valFromOption(blockStore), match[1]) : Promise.resolve()
|
|
507
|
+
]);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function filterByClientAddress(cs, items) {
|
|
511
|
+
return FetchState.filterByClientAddress(items, cs.indexingAddresses);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function handleQueryResult(cs, query, newItems, newItemsWithDcs, latestFetchedBlock, knownHeight, txPage, blockPage) {
|
|
515
|
+
if (txPage !== undefined) {
|
|
516
|
+
cs.transactionStore.merge(Primitive_option.valFromOption(txPage));
|
|
517
|
+
}
|
|
518
|
+
if (blockPage !== undefined) {
|
|
519
|
+
cs.blockStore.merge(Primitive_option.valFromOption(blockPage));
|
|
520
|
+
}
|
|
521
|
+
let fs = newItemsWithDcs.length !== 0 ? FetchState.registerDynamicContracts(cs.fetchState, cs.indexingAddresses, newItemsWithDcs) : cs.fetchState;
|
|
277
522
|
cs.fetchState = FetchState.updateKnownHeight(FetchState.handleQueryResult(fs, query, latestFetchedBlock, newItems), knownHeight);
|
|
278
|
-
cs.pendingBudget = Primitive_float.max(0, cs.pendingBudget - query.
|
|
523
|
+
cs.pendingBudget = Primitive_float.max(0, cs.pendingBudget - query.itemsEst);
|
|
279
524
|
}
|
|
280
525
|
|
|
281
526
|
function registerReorgGuard(cs, blockHashes, knownHeight) {
|
|
@@ -308,14 +553,13 @@ function setEndBlockToFirstEvent(cs, blockNumber) {
|
|
|
308
553
|
startBlock: init.startBlock,
|
|
309
554
|
endBlock: blockNumber,
|
|
310
555
|
normalSelection: init.normalSelection,
|
|
311
|
-
indexingAddresses: init.indexingAddresses,
|
|
312
556
|
contractConfigs: init.contractConfigs,
|
|
313
557
|
chainId: init.chainId,
|
|
314
558
|
latestOnBlockBlockNumber: init.latestOnBlockBlockNumber,
|
|
315
559
|
blockLag: init.blockLag,
|
|
316
560
|
buffer: init.buffer,
|
|
317
561
|
maxOnBlockBufferSize: init.maxOnBlockBufferSize,
|
|
318
|
-
|
|
562
|
+
onBlockRegistrations: init.onBlockRegistrations,
|
|
319
563
|
knownHeight: init.knownHeight,
|
|
320
564
|
firstEventBlock: init.firstEventBlock
|
|
321
565
|
};
|
|
@@ -327,14 +571,13 @@ function setEndBlockToFirstEvent(cs, blockNumber) {
|
|
|
327
571
|
startBlock: init$1.startBlock,
|
|
328
572
|
endBlock: blockNumber,
|
|
329
573
|
normalSelection: init$1.normalSelection,
|
|
330
|
-
indexingAddresses: init$1.indexingAddresses,
|
|
331
574
|
contractConfigs: init$1.contractConfigs,
|
|
332
575
|
chainId: init$1.chainId,
|
|
333
576
|
latestOnBlockBlockNumber: init$1.latestOnBlockBlockNumber,
|
|
334
577
|
blockLag: init$1.blockLag,
|
|
335
578
|
buffer: init$1.buffer,
|
|
336
579
|
maxOnBlockBufferSize: init$1.maxOnBlockBufferSize,
|
|
337
|
-
|
|
580
|
+
onBlockRegistrations: init$1.onBlockRegistrations,
|
|
338
581
|
knownHeight: init$1.knownHeight,
|
|
339
582
|
firstEventBlock: init$1.firstEventBlock
|
|
340
583
|
};
|
|
@@ -344,15 +587,58 @@ function enterReorgThreshold(cs) {
|
|
|
344
587
|
cs.fetchState = FetchState.updateInternal(cs.fetchState, undefined, undefined, undefined, cs.chainConfig.blockLag, undefined);
|
|
345
588
|
}
|
|
346
589
|
|
|
590
|
+
function toChainMetadata(cs) {
|
|
591
|
+
return {
|
|
592
|
+
first_event_block: Stdlib_Null.fromOption(cs.fetchState.firstEventBlock),
|
|
593
|
+
buffer_block: FetchState.bufferBlockNumber(cs.fetchState),
|
|
594
|
+
ready_at: Stdlib_Null.fromOption(cs.timestampCaughtUpToHeadOrEndblock),
|
|
595
|
+
_is_hyper_sync: SourceManager.getActiveSource(cs.sourceManager).poweredByHyperSync
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function toChainData(cs) {
|
|
600
|
+
return {
|
|
601
|
+
chainId: cs.chainConfig.id,
|
|
602
|
+
poweredByHyperSync: SourceManager.getActiveSource(cs.sourceManager).poweredByHyperSync,
|
|
603
|
+
firstEventBlockNumber: cs.fetchState.firstEventBlock,
|
|
604
|
+
latestProcessedBlock: cs.committedProgressBlockNumber === -1 ? undefined : cs.committedProgressBlockNumber,
|
|
605
|
+
timestampCaughtUpToHeadOrEndblock: cs.timestampCaughtUpToHeadOrEndblock,
|
|
606
|
+
numEventsProcessed: cs.numEventsProcessed,
|
|
607
|
+
latestFetchedBlockNumber: Primitive_int.max(FetchState.bufferBlockNumber(cs.fetchState), 0),
|
|
608
|
+
currentBlockHeight: hasProcessedToEndblock(cs) ? Stdlib_Option.getOr(cs.fetchState.endBlock, cs.fetchState.knownHeight) : cs.fetchState.knownHeight,
|
|
609
|
+
numBatchesFetched: 0,
|
|
610
|
+
startBlock: cs.fetchState.startBlock,
|
|
611
|
+
endBlock: cs.fetchState.endBlock,
|
|
612
|
+
numAddresses: IndexingAddresses.size(cs.indexingAddresses)
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function toChainBeforeBatch(cs) {
|
|
617
|
+
return {
|
|
618
|
+
fetchState: cs.fetchState,
|
|
619
|
+
reorgDetection: cs.reorgDetection,
|
|
620
|
+
progressBlockNumber: cs.committedProgressBlockNumber,
|
|
621
|
+
sourceBlockNumber: cs.fetchState.knownHeight,
|
|
622
|
+
totalEventsProcessed: cs.numEventsProcessed,
|
|
623
|
+
chainConfig: cs.chainConfig
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function isReadyToEnterReorgThresholdAfterBatch(cs, batch) {
|
|
628
|
+
let chainAfterBatch = batch.progressedChainsById[cs.fetchState.chainId];
|
|
629
|
+
return FetchState.isReadyToEnterReorgThreshold(chainAfterBatch !== undefined ? chainAfterBatch.fetchState : cs.fetchState);
|
|
630
|
+
}
|
|
631
|
+
|
|
347
632
|
function advanceAfterBatch(cs, batch, enteringReorgThreshold) {
|
|
348
633
|
let chainAfterBatch = batch.progressedChainsById[cs.fetchState.chainId];
|
|
349
634
|
if (chainAfterBatch !== undefined) {
|
|
350
635
|
cs.fetchState = enteringReorgThreshold ? FetchState.updateInternal(chainAfterBatch.fetchState, undefined, undefined, undefined, cs.chainConfig.blockLag, undefined) : chainAfterBatch.fetchState;
|
|
636
|
+
cs.processingBlockNumber = chainAfterBatch.progressBlockNumber;
|
|
351
637
|
return;
|
|
352
638
|
}
|
|
353
639
|
}
|
|
354
640
|
|
|
355
|
-
function applyBatchProgress(cs, batch) {
|
|
641
|
+
function applyBatchProgress(cs, batch, blockTimestampName) {
|
|
356
642
|
let chainId = cs.chainConfig.id;
|
|
357
643
|
let chainAfterBatch = batch.progressedChainsById[chainId];
|
|
358
644
|
if (chainAfterBatch === undefined) {
|
|
@@ -364,9 +650,9 @@ function applyBatchProgress(cs, batch) {
|
|
|
364
650
|
if (cs.numEventsProcessed !== chainAfterBatch.totalEventsProcessed) {
|
|
365
651
|
Prometheus.ProgressEventsCount.set(chainAfterBatch.totalEventsProcessed, chainId);
|
|
366
652
|
}
|
|
367
|
-
let
|
|
368
|
-
if (
|
|
369
|
-
let blockTimestampMs =
|
|
653
|
+
let blockTimestamp = Stdlib_Option.flatMap(Stdlib_Option.flatMap(Batch.findLastEventItem(batch, chainId), eventItem => Primitive_option.fromNullable(eventItem.payload.block)), block => block[blockTimestampName]);
|
|
654
|
+
if (blockTimestamp !== undefined) {
|
|
655
|
+
let blockTimestampMs = Primitive_option.valFromOption(blockTimestamp) * 1000 | 0;
|
|
370
656
|
Prometheus.ProgressLatency.set((Date.now() | 0) - blockTimestampMs | 0, chainId);
|
|
371
657
|
}
|
|
372
658
|
let match = cs.fetchState.firstEventBlock;
|
|
@@ -379,21 +665,45 @@ function applyBatchProgress(cs, batch) {
|
|
|
379
665
|
startBlock: init.startBlock,
|
|
380
666
|
endBlock: init.endBlock,
|
|
381
667
|
normalSelection: init.normalSelection,
|
|
382
|
-
indexingAddresses: init.indexingAddresses,
|
|
383
668
|
contractConfigs: init.contractConfigs,
|
|
384
669
|
chainId: init.chainId,
|
|
385
670
|
latestOnBlockBlockNumber: init.latestOnBlockBlockNumber,
|
|
386
671
|
blockLag: init.blockLag,
|
|
387
672
|
buffer: init.buffer,
|
|
388
673
|
maxOnBlockBufferSize: init.maxOnBlockBufferSize,
|
|
389
|
-
|
|
674
|
+
onBlockRegistrations: init.onBlockRegistrations,
|
|
390
675
|
knownHeight: init.knownHeight,
|
|
391
676
|
firstEventBlock: firstEventBlock
|
|
392
677
|
};
|
|
393
678
|
}
|
|
394
679
|
}
|
|
680
|
+
let deltaBlocks = chainAfterBatch.progressBlockNumber - cs.committedProgressBlockNumber | 0;
|
|
681
|
+
if (deltaBlocks > 0) {
|
|
682
|
+
let deltaEvents = chainAfterBatch.totalEventsProcessed - cs.numEventsProcessed;
|
|
683
|
+
let match$1 = cs.chainDensity;
|
|
684
|
+
let match$2 = deltaEvents > 0;
|
|
685
|
+
let exit = 0;
|
|
686
|
+
if (match$1 !== undefined || match$2) {
|
|
687
|
+
exit = 1;
|
|
688
|
+
}
|
|
689
|
+
if (exit === 1) {
|
|
690
|
+
let batchDensity = deltaEvents / deltaBlocks;
|
|
691
|
+
let oldDensity = cs.chainDensity;
|
|
692
|
+
let tmp;
|
|
693
|
+
if (oldDensity !== undefined) {
|
|
694
|
+
let alpha = Primitive_float.min(1, deltaBlocks / 100);
|
|
695
|
+
tmp = oldDensity * (1 - alpha) + batchDensity * alpha;
|
|
696
|
+
} else {
|
|
697
|
+
tmp = batchDensity;
|
|
698
|
+
}
|
|
699
|
+
cs.chainDensity = tmp;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
395
702
|
cs.committedProgressBlockNumber = chainAfterBatch.progressBlockNumber;
|
|
703
|
+
cs.processingBlockNumber = Primitive_int.max(cs.processingBlockNumber, chainAfterBatch.progressBlockNumber);
|
|
396
704
|
cs.numEventsProcessed = chainAfterBatch.totalEventsProcessed;
|
|
705
|
+
cs.transactionStore.prune(chainAfterBatch.progressBlockNumber);
|
|
706
|
+
cs.blockStore.prune(chainAfterBatch.progressBlockNumber);
|
|
397
707
|
cs.isProgressAtHead = cs.isProgressAtHead || chainAfterBatch.isProgressAtHeadWhenBatchCreated;
|
|
398
708
|
let safeCheckpointTracking = cs.safeCheckpointTracking;
|
|
399
709
|
if (safeCheckpointTracking !== undefined) {
|
|
@@ -414,8 +724,11 @@ function rollback(cs, newProgressBlockNumber, eventsProcessedDiff, rollbackTarge
|
|
|
414
724
|
if (newProgressBlockNumber === undefined) {
|
|
415
725
|
if (isReorgChain) {
|
|
416
726
|
cs.reorgDetection = ReorgDetection.rollbackToValidBlockNumber(cs.reorgDetection, rollbackTargetBlockNumber);
|
|
417
|
-
cs.fetchState = FetchState.rollback(cs.fetchState, rollbackTargetBlockNumber);
|
|
727
|
+
cs.fetchState = FetchState.rollback(cs.fetchState, cs.indexingAddresses, rollbackTargetBlockNumber);
|
|
728
|
+
cs.transactionStore.rollback(rollbackTargetBlockNumber);
|
|
729
|
+
cs.blockStore.rollback(rollbackTargetBlockNumber);
|
|
418
730
|
cs.committedProgressBlockNumber = Primitive_int.min(cs.committedProgressBlockNumber, rollbackTargetBlockNumber);
|
|
731
|
+
cs.processingBlockNumber = Primitive_int.min(cs.processingBlockNumber, rollbackTargetBlockNumber);
|
|
419
732
|
return;
|
|
420
733
|
} else {
|
|
421
734
|
return;
|
|
@@ -435,8 +748,11 @@ function rollback(cs, newProgressBlockNumber, eventsProcessedDiff, rollbackTarge
|
|
|
435
748
|
if (safeCheckpointTracking !== undefined) {
|
|
436
749
|
cs.safeCheckpointTracking = SafeCheckpointTracking.rollback(safeCheckpointTracking, newProgressBlockNumber);
|
|
437
750
|
}
|
|
438
|
-
cs.fetchState = FetchState.rollback(cs.fetchState, newProgressBlockNumber);
|
|
751
|
+
cs.fetchState = FetchState.rollback(cs.fetchState, cs.indexingAddresses, newProgressBlockNumber);
|
|
752
|
+
cs.transactionStore.rollback(newProgressBlockNumber);
|
|
753
|
+
cs.blockStore.rollback(newProgressBlockNumber);
|
|
439
754
|
cs.committedProgressBlockNumber = newProgressBlockNumber;
|
|
755
|
+
cs.processingBlockNumber = newProgressBlockNumber;
|
|
440
756
|
cs.numEventsProcessed = newTotalEventsProcessed;
|
|
441
757
|
}
|
|
442
758
|
|
|
@@ -446,7 +762,6 @@ export {
|
|
|
446
762
|
makeFromConfig,
|
|
447
763
|
makeFromDbState,
|
|
448
764
|
logger,
|
|
449
|
-
fetchState,
|
|
450
765
|
sourceManager,
|
|
451
766
|
chainConfig,
|
|
452
767
|
reorgDetection,
|
|
@@ -457,12 +772,34 @@ export {
|
|
|
457
772
|
pendingBudget,
|
|
458
773
|
startFetchingQueries,
|
|
459
774
|
timestampCaughtUpToHeadOrEndblock,
|
|
775
|
+
knownHeight,
|
|
776
|
+
contractAddresses,
|
|
777
|
+
bufferSize,
|
|
778
|
+
bufferReadyCount,
|
|
779
|
+
getProgressPercentage,
|
|
780
|
+
chainDensity,
|
|
781
|
+
effectiveDensity,
|
|
782
|
+
hasReadyItem,
|
|
783
|
+
isReadyToEnterReorgThreshold,
|
|
784
|
+
targetBlock,
|
|
785
|
+
progressAtBlock,
|
|
786
|
+
blockAtProgress,
|
|
787
|
+
getNextQuery,
|
|
788
|
+
dispatch,
|
|
789
|
+
toChainData,
|
|
790
|
+
toChainMetadata,
|
|
791
|
+
toChainBeforeBatch,
|
|
792
|
+
isReadyToEnterReorgThresholdAfterBatch,
|
|
460
793
|
hasProcessedToEndblock,
|
|
461
794
|
getHighestBlockBelowThreshold,
|
|
462
795
|
isActivelyIndexing,
|
|
463
796
|
isReady,
|
|
464
797
|
isFetchingAtHead,
|
|
798
|
+
isAtHeadWithoutEndBlock,
|
|
799
|
+
filterByClientAddress,
|
|
465
800
|
handleQueryResult,
|
|
801
|
+
materializeBatchItems,
|
|
802
|
+
materializePageItems,
|
|
466
803
|
registerReorgGuard,
|
|
467
804
|
prepareReorg,
|
|
468
805
|
updateKnownHeight,
|