envio 3.3.0-alpha.0 → 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 +48 -16
- package/src/ChainFetching.res.mjs +36 -17
- package/src/ChainMetadata.res +1 -11
- package/src/ChainMetadata.res.mjs +1 -10
- package/src/ChainState.res +628 -149
- package/src/ChainState.res.mjs +440 -102
- package/src/ChainState.resi +74 -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 +142 -93
- package/src/CrossChainState.res.mjs +88 -60
- package/src/CrossChainState.resi +2 -10
- package/src/Ecosystem.res +5 -6
- package/src/Ecosystem.res.mjs +3 -3
- package/src/Env.res +0 -7
- package/src/Env.res.mjs +0 -6
- 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 +558 -300
- package/src/FetchState.res.mjs +437 -423
- 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/IndexerLoop.res +2 -3
- package/src/IndexerLoop.res.mjs +1 -1
- package/src/IndexerState.res +10 -11
- package/src/IndexerState.res.mjs +14 -11
- package/src/IndexerState.resi +2 -5
- 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 -74
- package/src/Prometheus.res.mjs +124 -186
- 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 +86 -27
- package/src/sources/SourceManager.res.mjs +84 -47
- package/src/sources/SourceManager.resi +12 -3
- 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";
|
|
@@ -17,7 +19,10 @@ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
|
17
19
|
import * as ReorgDetection from "./ReorgDetection.res.mjs";
|
|
18
20
|
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
19
21
|
import * as HyperFuelSource from "./sources/HyperFuelSource.res.mjs";
|
|
22
|
+
import * as Primitive_float from "@rescript/runtime/lib/es6/Primitive_float.js";
|
|
20
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";
|
|
21
26
|
import * as SvmHyperSyncSource from "./sources/SvmHyperSyncSource.res.mjs";
|
|
22
27
|
import * as SafeCheckpointTracking from "./SafeCheckpointTracking.res.mjs";
|
|
23
28
|
|
|
@@ -35,85 +40,51 @@ function configAddresses(chainConfig) {
|
|
|
35
40
|
return addresses;
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
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) {
|
|
39
44
|
let safeCheckpointTracking = safeCheckpointTrackingOpt !== undefined ? Primitive_option.valFromOption(safeCheckpointTrackingOpt) : undefined;
|
|
40
45
|
let numEventsProcessed = numEventsProcessedOpt !== undefined ? numEventsProcessedOpt : 0;
|
|
41
46
|
let timestampCaughtUpToHeadOrEndblock = timestampCaughtUpToHeadOrEndblockOpt !== undefined ? Primitive_option.valFromOption(timestampCaughtUpToHeadOrEndblockOpt) : undefined;
|
|
42
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);
|
|
43
51
|
return {
|
|
44
52
|
logger: logger,
|
|
45
53
|
fetchState: fetchState,
|
|
54
|
+
indexingAddresses: indexingAddresses,
|
|
46
55
|
sourceManager: sourceManager,
|
|
47
56
|
chainConfig: chainConfig,
|
|
48
57
|
isProgressAtHead: isProgressAtHead,
|
|
49
58
|
timestampCaughtUpToHeadOrEndblock: timestampCaughtUpToHeadOrEndblock,
|
|
50
59
|
committedProgressBlockNumber: committedProgressBlockNumber,
|
|
60
|
+
processingBlockNumber: committedProgressBlockNumber,
|
|
51
61
|
numEventsProcessed: numEventsProcessed,
|
|
62
|
+
pendingBudget: 0,
|
|
63
|
+
chainDensity: chainDensity,
|
|
52
64
|
reorgDetection: reorgDetection,
|
|
53
|
-
safeCheckpointTracking: safeCheckpointTracking
|
|
65
|
+
safeCheckpointTracking: safeCheckpointTracking,
|
|
66
|
+
transactionStore: transactionStore,
|
|
67
|
+
blockStore: blockStore
|
|
54
68
|
};
|
|
55
69
|
}
|
|
56
70
|
|
|
57
|
-
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) {
|
|
58
72
|
let firstEventBlock = firstEventBlockOpt !== undefined ? Primitive_option.valFromOption(firstEventBlockOpt) : undefined;
|
|
59
73
|
let knownHeight = knownHeightOpt !== undefined ? knownHeightOpt : 0;
|
|
60
|
-
let
|
|
61
|
-
|
|
62
|
-
|
|
74
|
+
let match = Stdlib_Option.getOr(registrationsByChainId[chainConfig.id.toString()], {
|
|
75
|
+
onEventRegistrations: [],
|
|
76
|
+
onBlockRegistrations: []
|
|
77
|
+
});
|
|
78
|
+
let onEventRegistrations = match.onEventRegistrations;
|
|
63
79
|
chainConfig.contracts.forEach(contract => {
|
|
64
|
-
let contractName = contract.name;
|
|
65
|
-
contract.events.forEach(eventConfig => {
|
|
66
|
-
let hasContractRegister = Stdlib_Option.isSome(eventConfig.contractRegister);
|
|
67
|
-
EventRouter.addOrThrow(eventRouter, eventConfig.id, undefined, contractName, eventConfig.isWildcard, eventConfig.name, ChainMap.Chain.makeUnsafe(chainConfig.id));
|
|
68
|
-
let shouldBeIncluded;
|
|
69
|
-
if (config.enableRawEvents) {
|
|
70
|
-
shouldBeIncluded = true;
|
|
71
|
-
} else {
|
|
72
|
-
let isRegistered = hasContractRegister || Stdlib_Option.isSome(eventConfig.handler);
|
|
73
|
-
if (!isRegistered) {
|
|
74
|
-
notRegisteredEvents.push(eventConfig);
|
|
75
|
-
}
|
|
76
|
-
shouldBeIncluded = isRegistered;
|
|
77
|
-
}
|
|
78
|
-
let shouldSkip;
|
|
79
|
-
try {
|
|
80
|
-
let getEventFiltersOrThrow = eventConfig.getEventFiltersOrThrow;
|
|
81
|
-
if (getEventFiltersOrThrow) {
|
|
82
|
-
let match = getEventFiltersOrThrow(ChainMap.Chain.makeUnsafe(chainConfig.id));
|
|
83
|
-
shouldSkip = match.TAG === "Static" ? match._0.length === 0 : false;
|
|
84
|
-
} else {
|
|
85
|
-
shouldSkip = false;
|
|
86
|
-
}
|
|
87
|
-
} catch (exn) {
|
|
88
|
-
shouldSkip = false;
|
|
89
|
-
}
|
|
90
|
-
if (shouldBeIncluded && !shouldSkip) {
|
|
91
|
-
eventConfigs.push(eventConfig);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
80
|
let startBlock = contract.startBlock;
|
|
96
81
|
if (startBlock !== undefined && startBlock < chainConfig.startBlock) {
|
|
97
|
-
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.`);
|
|
98
83
|
}
|
|
99
84
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
) + ` ` + notRegisteredEvents.map(eventConfig => eventConfig.contractName + `.` + eventConfig.name).join(", ") + ` don't have an event handler and skipped for indexing.`);
|
|
104
|
-
}
|
|
105
|
-
let onBlockConfigs = registrations.onBlockByChainId[chainConfig.id.toString()];
|
|
106
|
-
if (onBlockConfigs !== undefined) {
|
|
107
|
-
onBlockConfigs.forEach(onBlockConfig => {
|
|
108
|
-
if (Stdlib_Option.getOr(onBlockConfig.startBlock, startBlock) < startBlock) {
|
|
109
|
-
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.`);
|
|
110
|
-
}
|
|
111
|
-
if (endBlock !== undefined && Stdlib_Option.getOr(onBlockConfig.endBlock, endBlock) > endBlock) {
|
|
112
|
-
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.`);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
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));
|
|
117
88
|
let chainReorgCheckpoints = Stdlib_Array.filterMap(reorgCheckpoints, reorgCheckpoint => {
|
|
118
89
|
if (reorgCheckpoint.chain_id === chainConfig.id) {
|
|
119
90
|
return reorgCheckpoint;
|
|
@@ -125,22 +96,19 @@ function makeInternal(chainConfig, indexingAddresses, startBlock, endBlock, firs
|
|
|
125
96
|
let sources$1;
|
|
126
97
|
switch (sources.TAG) {
|
|
127
98
|
case "EvmSourceConfig" :
|
|
128
|
-
let evmContracts = chainConfig.contracts.map(contract => ({
|
|
129
|
-
name: contract.name,
|
|
130
|
-
abi: contract.abi,
|
|
131
|
-
events: contract.events
|
|
132
|
-
}));
|
|
133
99
|
let evmRpcs = sources.rpcs.map(rpc => {
|
|
134
100
|
let syncConfig = rpc.syncConfig;
|
|
135
101
|
let ws = rpc.ws;
|
|
102
|
+
let headers = rpc.headers;
|
|
136
103
|
return {
|
|
137
104
|
url: rpc.url,
|
|
138
105
|
sourceFor: rpc.sourceFor,
|
|
139
106
|
syncConfig: syncConfig,
|
|
140
|
-
ws: ws
|
|
107
|
+
ws: ws,
|
|
108
|
+
headers: headers
|
|
141
109
|
};
|
|
142
110
|
});
|
|
143
|
-
sources$1 = EvmChain.makeSources(chain,
|
|
111
|
+
sources$1 = EvmChain.makeSources(chain, onEventRegistrations, sources.hypersync, evmRpcs, lowercaseAddresses);
|
|
144
112
|
break;
|
|
145
113
|
case "FuelSourceConfig" :
|
|
146
114
|
sources$1 = [HyperFuelSource.make({
|
|
@@ -152,51 +120,46 @@ function makeInternal(chainConfig, indexingAddresses, startBlock, endBlock, firs
|
|
|
152
120
|
case "SvmSourceConfig" :
|
|
153
121
|
let rpc = sources.rpc;
|
|
154
122
|
let hypersync = sources.hypersync;
|
|
155
|
-
|
|
156
|
-
let svmEventConfigs = chainConfig.contracts.flatMap(contract => contract.events);
|
|
157
|
-
sources$1 = [SvmHyperSyncSource.make({
|
|
123
|
+
sources$1 = hypersync !== undefined ? [SvmHyperSyncSource.make({
|
|
158
124
|
chain: chain,
|
|
159
125
|
endpointUrl: hypersync,
|
|
160
126
|
apiToken: Env.envioApiToken,
|
|
161
|
-
|
|
127
|
+
onEventRegistrations: onEventRegistrations,
|
|
162
128
|
clientTimeoutMillis: Env.hyperSyncClientTimeoutMillis
|
|
163
|
-
})]
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
129
|
+
})] : (
|
|
130
|
+
rpc !== undefined ? [Svm.makeRPCSource(chain, rpc, undefined)] : Stdlib_JsError.throwWithMessage(`Chain ` + chain.toString() + ` has no SVM data source`)
|
|
131
|
+
);
|
|
167
132
|
break;
|
|
168
133
|
case "CustomSources" :
|
|
169
134
|
sources$1 = sources._0;
|
|
170
135
|
break;
|
|
171
136
|
}
|
|
172
|
-
|
|
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);
|
|
173
140
|
}
|
|
174
141
|
|
|
175
|
-
function makeFromConfig(chainConfig, config,
|
|
142
|
+
function makeFromConfig(chainConfig, config, registrationsByChainId, knownHeight) {
|
|
176
143
|
let logger = Logging.createChild({
|
|
177
144
|
chainId: chainConfig.id
|
|
178
145
|
});
|
|
179
|
-
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);
|
|
180
147
|
}
|
|
181
148
|
|
|
182
|
-
function makeFromDbState(chainConfig, resumedChainState, reorgCheckpoints, isInReorgThreshold, isRealtime, config,
|
|
149
|
+
function makeFromDbState(chainConfig, resumedChainState, reorgCheckpoints, isInReorgThreshold, isRealtime, config, registrationsByChainId, reducedPollingInterval) {
|
|
183
150
|
let chainId = chainConfig.id;
|
|
184
151
|
let logger = Logging.createChild({
|
|
185
152
|
chainId: chainId
|
|
186
153
|
});
|
|
187
154
|
Prometheus.ProgressEventsCount.set(resumedChainState.numEventsProcessed, chainId);
|
|
188
155
|
let progressBlockNumber = resumedChainState.progressBlockNumber >= 0 ? resumedChainState.progressBlockNumber : resumedChainState.startBlock - 1 | 0;
|
|
189
|
-
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);
|
|
190
157
|
}
|
|
191
158
|
|
|
192
159
|
function logger(cs) {
|
|
193
160
|
return cs.logger;
|
|
194
161
|
}
|
|
195
162
|
|
|
196
|
-
function fetchState(cs) {
|
|
197
|
-
return cs.fetchState;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
163
|
function sourceManager(cs) {
|
|
201
164
|
return cs.sourceManager;
|
|
202
165
|
}
|
|
@@ -225,10 +188,152 @@ function numEventsProcessed(cs) {
|
|
|
225
188
|
return cs.numEventsProcessed;
|
|
226
189
|
}
|
|
227
190
|
|
|
191
|
+
function pendingBudget(cs) {
|
|
192
|
+
return cs.pendingBudget;
|
|
193
|
+
}
|
|
194
|
+
|
|
228
195
|
function timestampCaughtUpToHeadOrEndblock(cs) {
|
|
229
196
|
return cs.timestampCaughtUpToHeadOrEndblock;
|
|
230
197
|
}
|
|
231
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
|
+
|
|
235
|
+
function startFetchingQueries(cs, queries) {
|
|
236
|
+
FetchState.startFetchingQueries(cs.fetchState, queries);
|
|
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);
|
|
335
|
+
}
|
|
336
|
+
|
|
232
337
|
function hasProcessedToEndblock(cs) {
|
|
233
338
|
let fetchState = cs.fetchState;
|
|
234
339
|
let committedProgressBlockNumber = cs.committedProgressBlockNumber;
|
|
@@ -253,17 +358,156 @@ function isActivelyIndexing(cs) {
|
|
|
253
358
|
return FetchState.isActivelyIndexing(cs.fetchState);
|
|
254
359
|
}
|
|
255
360
|
|
|
256
|
-
function isReady(cs) {
|
|
257
|
-
return cs.timestampCaughtUpToHeadOrEndblock !== undefined;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
361
|
function isFetchingAtHead(cs) {
|
|
261
362
|
return FetchState.isFetchingAtHead(cs.fetchState);
|
|
262
363
|
}
|
|
263
364
|
|
|
264
|
-
function
|
|
265
|
-
|
|
266
|
-
|
|
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);
|
|
267
511
|
}
|
|
268
512
|
|
|
269
513
|
function registerReorgGuard(cs, blockHashes, knownHeight) {
|
|
@@ -277,6 +521,7 @@ function prepareReorg(cs, eventsProcessedDiff) {
|
|
|
277
521
|
cs.numEventsProcessed = cs.numEventsProcessed + eventsProcessedDiff;
|
|
278
522
|
}
|
|
279
523
|
cs.fetchState = FetchState.resetPendingQueries(cs.fetchState);
|
|
524
|
+
cs.pendingBudget = 0;
|
|
280
525
|
}
|
|
281
526
|
|
|
282
527
|
function updateKnownHeight(cs, knownHeight) {
|
|
@@ -295,14 +540,13 @@ function setEndBlockToFirstEvent(cs, blockNumber) {
|
|
|
295
540
|
startBlock: init.startBlock,
|
|
296
541
|
endBlock: blockNumber,
|
|
297
542
|
normalSelection: init.normalSelection,
|
|
298
|
-
indexingAddresses: init.indexingAddresses,
|
|
299
543
|
contractConfigs: init.contractConfigs,
|
|
300
544
|
chainId: init.chainId,
|
|
301
545
|
latestOnBlockBlockNumber: init.latestOnBlockBlockNumber,
|
|
302
546
|
blockLag: init.blockLag,
|
|
303
547
|
buffer: init.buffer,
|
|
304
548
|
maxOnBlockBufferSize: init.maxOnBlockBufferSize,
|
|
305
|
-
|
|
549
|
+
onBlockRegistrations: init.onBlockRegistrations,
|
|
306
550
|
knownHeight: init.knownHeight,
|
|
307
551
|
firstEventBlock: init.firstEventBlock
|
|
308
552
|
};
|
|
@@ -314,32 +558,74 @@ function setEndBlockToFirstEvent(cs, blockNumber) {
|
|
|
314
558
|
startBlock: init$1.startBlock,
|
|
315
559
|
endBlock: blockNumber,
|
|
316
560
|
normalSelection: init$1.normalSelection,
|
|
317
|
-
indexingAddresses: init$1.indexingAddresses,
|
|
318
561
|
contractConfigs: init$1.contractConfigs,
|
|
319
562
|
chainId: init$1.chainId,
|
|
320
563
|
latestOnBlockBlockNumber: init$1.latestOnBlockBlockNumber,
|
|
321
564
|
blockLag: init$1.blockLag,
|
|
322
565
|
buffer: init$1.buffer,
|
|
323
566
|
maxOnBlockBufferSize: init$1.maxOnBlockBufferSize,
|
|
324
|
-
|
|
567
|
+
onBlockRegistrations: init$1.onBlockRegistrations,
|
|
325
568
|
knownHeight: init$1.knownHeight,
|
|
326
569
|
firstEventBlock: init$1.firstEventBlock
|
|
327
570
|
};
|
|
328
571
|
}
|
|
329
572
|
|
|
330
573
|
function enterReorgThreshold(cs) {
|
|
331
|
-
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);
|
|
332
617
|
}
|
|
333
618
|
|
|
334
619
|
function advanceAfterBatch(cs, batch, enteringReorgThreshold) {
|
|
335
620
|
let chainAfterBatch = batch.progressedChainsById[cs.fetchState.chainId];
|
|
336
621
|
if (chainAfterBatch !== undefined) {
|
|
337
|
-
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;
|
|
338
624
|
return;
|
|
339
625
|
}
|
|
340
626
|
}
|
|
341
627
|
|
|
342
|
-
function applyBatchProgress(cs, batch) {
|
|
628
|
+
function applyBatchProgress(cs, batch, blockTimestampName) {
|
|
343
629
|
let chainId = cs.chainConfig.id;
|
|
344
630
|
let chainAfterBatch = batch.progressedChainsById[chainId];
|
|
345
631
|
if (chainAfterBatch === undefined) {
|
|
@@ -351,9 +637,9 @@ function applyBatchProgress(cs, batch) {
|
|
|
351
637
|
if (cs.numEventsProcessed !== chainAfterBatch.totalEventsProcessed) {
|
|
352
638
|
Prometheus.ProgressEventsCount.set(chainAfterBatch.totalEventsProcessed, chainId);
|
|
353
639
|
}
|
|
354
|
-
let
|
|
355
|
-
if (
|
|
356
|
-
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;
|
|
357
643
|
Prometheus.ProgressLatency.set((Date.now() | 0) - blockTimestampMs | 0, chainId);
|
|
358
644
|
}
|
|
359
645
|
let match = cs.fetchState.firstEventBlock;
|
|
@@ -366,21 +652,45 @@ function applyBatchProgress(cs, batch) {
|
|
|
366
652
|
startBlock: init.startBlock,
|
|
367
653
|
endBlock: init.endBlock,
|
|
368
654
|
normalSelection: init.normalSelection,
|
|
369
|
-
indexingAddresses: init.indexingAddresses,
|
|
370
655
|
contractConfigs: init.contractConfigs,
|
|
371
656
|
chainId: init.chainId,
|
|
372
657
|
latestOnBlockBlockNumber: init.latestOnBlockBlockNumber,
|
|
373
658
|
blockLag: init.blockLag,
|
|
374
659
|
buffer: init.buffer,
|
|
375
660
|
maxOnBlockBufferSize: init.maxOnBlockBufferSize,
|
|
376
|
-
|
|
661
|
+
onBlockRegistrations: init.onBlockRegistrations,
|
|
377
662
|
knownHeight: init.knownHeight,
|
|
378
663
|
firstEventBlock: firstEventBlock
|
|
379
664
|
};
|
|
380
665
|
}
|
|
381
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
|
+
}
|
|
382
689
|
cs.committedProgressBlockNumber = chainAfterBatch.progressBlockNumber;
|
|
690
|
+
cs.processingBlockNumber = Primitive_int.max(cs.processingBlockNumber, chainAfterBatch.progressBlockNumber);
|
|
383
691
|
cs.numEventsProcessed = chainAfterBatch.totalEventsProcessed;
|
|
692
|
+
cs.transactionStore.prune(chainAfterBatch.progressBlockNumber);
|
|
693
|
+
cs.blockStore.prune(chainAfterBatch.progressBlockNumber);
|
|
384
694
|
cs.isProgressAtHead = cs.isProgressAtHead || chainAfterBatch.isProgressAtHeadWhenBatchCreated;
|
|
385
695
|
let safeCheckpointTracking = cs.safeCheckpointTracking;
|
|
386
696
|
if (safeCheckpointTracking !== undefined) {
|
|
@@ -401,8 +711,11 @@ function rollback(cs, newProgressBlockNumber, eventsProcessedDiff, rollbackTarge
|
|
|
401
711
|
if (newProgressBlockNumber === undefined) {
|
|
402
712
|
if (isReorgChain) {
|
|
403
713
|
cs.reorgDetection = ReorgDetection.rollbackToValidBlockNumber(cs.reorgDetection, rollbackTargetBlockNumber);
|
|
404
|
-
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);
|
|
405
717
|
cs.committedProgressBlockNumber = Primitive_int.min(cs.committedProgressBlockNumber, rollbackTargetBlockNumber);
|
|
718
|
+
cs.processingBlockNumber = Primitive_int.min(cs.processingBlockNumber, rollbackTargetBlockNumber);
|
|
406
719
|
return;
|
|
407
720
|
} else {
|
|
408
721
|
return;
|
|
@@ -422,8 +735,11 @@ function rollback(cs, newProgressBlockNumber, eventsProcessedDiff, rollbackTarge
|
|
|
422
735
|
if (safeCheckpointTracking !== undefined) {
|
|
423
736
|
cs.safeCheckpointTracking = SafeCheckpointTracking.rollback(safeCheckpointTracking, newProgressBlockNumber);
|
|
424
737
|
}
|
|
425
|
-
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);
|
|
426
741
|
cs.committedProgressBlockNumber = newProgressBlockNumber;
|
|
742
|
+
cs.processingBlockNumber = newProgressBlockNumber;
|
|
427
743
|
cs.numEventsProcessed = newTotalEventsProcessed;
|
|
428
744
|
}
|
|
429
745
|
|
|
@@ -433,7 +749,6 @@ export {
|
|
|
433
749
|
makeFromConfig,
|
|
434
750
|
makeFromDbState,
|
|
435
751
|
logger,
|
|
436
|
-
fetchState,
|
|
437
752
|
sourceManager,
|
|
438
753
|
chainConfig,
|
|
439
754
|
reorgDetection,
|
|
@@ -441,13 +756,36 @@ export {
|
|
|
441
756
|
isProgressAtHead,
|
|
442
757
|
committedProgressBlockNumber,
|
|
443
758
|
numEventsProcessed,
|
|
759
|
+
pendingBudget,
|
|
760
|
+
startFetchingQueries,
|
|
444
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,
|
|
445
780
|
hasProcessedToEndblock,
|
|
446
781
|
getHighestBlockBelowThreshold,
|
|
447
782
|
isActivelyIndexing,
|
|
448
783
|
isReady,
|
|
449
784
|
isFetchingAtHead,
|
|
785
|
+
isAtHeadWithoutEndBlock,
|
|
450
786
|
handleQueryResult,
|
|
787
|
+
materializeBatchItems,
|
|
788
|
+
materializePageItems,
|
|
451
789
|
registerReorgGuard,
|
|
452
790
|
prepareReorg,
|
|
453
791
|
updateKnownHeight,
|