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