envio 3.15.0 → 3.16.0-subgraph
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -34
- package/evm.schema.json +11 -2
- package/fuel.schema.json +10 -1
- package/index.d.ts +6 -0
- package/licenses/README.md +1 -1
- package/package.json +10 -9
- package/src/Batch.res.mjs +5 -5
- package/src/BatchProcessing.res +1 -0
- package/src/BatchProcessing.res.mjs +1 -0
- package/src/Bin.res +7 -0
- package/src/Bin.res.mjs +8 -0
- package/src/ChainFetching.res +450 -16
- package/src/ChainFetching.res.mjs +403 -32
- package/src/ChainState.res +124 -7
- package/src/ChainState.res.mjs +128 -67
- package/src/ChainState.resi +26 -0
- package/src/Clock.res +57 -0
- package/src/Clock.res.mjs +72 -0
- package/src/Config.res +31 -3
- package/src/Config.res.mjs +15 -4
- package/src/ContractRegisterContext.res +3 -6
- package/src/ContractRegisterContext.res.mjs +4 -2
- package/src/Core.res +95 -36
- package/src/Core.res.mjs +90 -1
- package/src/CrossChainState.res +12 -2
- package/src/CrossChainState.res.mjs +3 -3
- package/src/Ecosystem.res +7 -4
- package/src/Ecosystem.res.mjs +8 -8
- package/src/EffectCacheLookup.res +98 -0
- package/src/EffectCacheLookup.res.mjs +116 -0
- package/src/EffectState.res +10 -2
- package/src/EffectState.res.mjs +8 -4
- package/src/EffectState.resi +3 -1
- package/src/EntityId.res +2 -7
- package/src/EntityId.res.mjs +1 -8
- package/src/EntityTables.res +4 -1
- package/src/EntityTables.res.mjs +1 -1
- package/src/Env.res +20 -0
- package/src/Env.res.mjs +16 -0
- package/src/EventProcessing.res +38 -1
- package/src/EventProcessing.res.mjs +28 -1
- package/src/FetchState.res +408 -73
- package/src/FetchState.res.mjs +361 -91
- package/src/FinalizeBackfill.res +2 -4
- package/src/FinalizeBackfill.res.mjs +3 -4
- package/src/HandlerLoader.res +39 -15
- package/src/HandlerLoader.res.mjs +27 -8
- package/src/HandlerRegister.res +4 -0
- package/src/HandlerRegister.res.mjs +5 -2
- package/src/HandlerRegister.resi +2 -0
- package/src/InMemoryTable.res +17 -16
- package/src/InMemoryTable.res.mjs +14 -15
- package/src/IndexerState.res +28 -4
- package/src/IndexerState.res.mjs +19 -6
- package/src/IndexerState.resi +4 -0
- package/src/Internal.res +61 -49
- package/src/Internal.res.mjs +36 -80
- package/src/LoadLayer.res +54 -15
- package/src/LoadLayer.res.mjs +75 -45
- package/src/LoadLayer.resi +26 -0
- package/src/Main.res +14 -1
- package/src/Main.res.mjs +4 -3
- package/src/Persistence.res +3 -23
- package/src/Persistence.res.mjs +3 -3
- package/src/PreloadLookahead.res +202 -0
- package/src/PreloadLookahead.res.mjs +218 -0
- package/src/Rollback.res +0 -1
- package/src/Rollback.res.mjs +1 -1
- package/src/RunScope.res +3 -0
- package/src/SafeCheckpointTracking.res +4 -4
- package/src/SafeCheckpointTracking.res.mjs +1 -1
- package/src/SimulateItems.res +42 -26
- package/src/SimulateItems.res.mjs +40 -16
- package/src/StagedRows.res +106 -0
- package/src/StagedRows.res.mjs +102 -0
- package/src/Staging.res +32 -14
- package/src/Staging.res.mjs +17 -20
- package/src/Storage.res +303 -948
- package/src/Storage.res.mjs +229 -708
- package/src/SubgraphLog.res +19 -0
- package/src/SubgraphLog.res.mjs +26 -0
- package/src/Supervisor.res +75 -56
- package/src/Supervisor.res.mjs +55 -26
- package/src/SyncWrites.res +107 -0
- package/src/SyncWrites.res.mjs +98 -0
- package/src/TestIndexer.res +22 -27
- package/src/TestIndexer.res.mjs +20 -17
- package/src/Throttler.res +15 -8
- package/src/Throttler.res.mjs +9 -6
- package/src/Throttler.resi +1 -1
- package/src/UserContext.res +419 -46
- package/src/UserContext.res.mjs +318 -30
- package/src/Utils.res +17 -6
- package/src/Utils.res.mjs +12 -6
- package/src/Writing.res +0 -1
- package/src/Writing.res.mjs +1 -1
- package/src/bindings/ClickHouse.res +0 -322
- package/src/bindings/ClickHouse.res.mjs +0 -338
- package/src/bindings/StorageClient.res +108 -174
- package/src/bindings/StorageClient.res.mjs +19 -8
- package/src/bindings/Vitest.res +0 -26
- package/src/bindings/Vitest.res.mjs +0 -3
- package/src/db/Table.res +24 -150
- package/src/db/Table.res.mjs +38 -272
- package/src/sources/AddressSet.res +2 -0
- package/src/sources/AddressStore.res +3 -0
- package/src/sources/CallSource.res +274 -0
- package/src/sources/CallSource.res.mjs +196 -0
- package/src/sources/ChainSources.res +2 -0
- package/src/sources/ChainSources.res.mjs +2 -2
- package/src/sources/EvmChain.res +10 -1
- package/src/sources/EvmChain.res.mjs +6 -3
- package/src/sources/EvmHyperSyncSource.res +2 -2
- package/src/sources/EvmHyperSyncSource.res.mjs +1 -1
- package/src/sources/EvmRpcClient.res +13 -3
- package/src/sources/EvmRpcClient.res.mjs +4 -3
- package/src/sources/EvmRpcWs.res +4 -3
- package/src/sources/EvmRpcWs.res.mjs +2 -2
- package/src/sources/HeightFeed.res +31 -10
- package/src/sources/HeightFeed.res.mjs +10 -6
- package/src/sources/HeightStream.res +32 -17
- package/src/sources/HeightStream.res.mjs +10 -10
- package/src/sources/HyperSync.res +2 -1
- package/src/sources/HyperSync.res.mjs +2 -1
- package/src/sources/HyperSyncSSE.res +4 -6
- package/src/sources/HyperSyncSSE.res.mjs +2 -2
- package/src/sources/RpcSource.res +10 -1
- package/src/sources/RpcSource.res.mjs +4 -3
- package/src/sources/Source.res +3 -0
- package/src/sources/SourceManager.res +84 -77
- package/src/sources/SourceManager.res.mjs +17 -20
- package/src/sources/SourceManager.resi +3 -4
- package/src/sources/StartBlockResolver.res +1 -0
- package/src/sources/StartBlockResolver.res.mjs +3 -2
- package/src/sources/SvmHyperSyncSource.res +2 -2
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
- package/src/subgraph/abi-types.ts +84 -0
- package/src/subgraph/aggregations.ts +745 -0
- package/src/subgraph/as-package.ts +143 -0
- package/src/subgraph/assemblyscript-regex.ts +67 -0
- package/src/subgraph/assemblyscript.ts +731 -0
- package/src/subgraph/blocks.ts +398 -0
- package/src/subgraph/calls-source.ts +702 -0
- package/src/subgraph/calls.ts +258 -0
- package/src/subgraph/conformance.ts +106 -0
- package/src/subgraph/errors.ts +85 -0
- package/src/subgraph/graft.ts +73 -0
- package/src/subgraph/graph-cli-worker.mjs +35 -0
- package/src/subgraph/graph-cli.ts +900 -0
- package/src/subgraph/graph-node-decimal.ts +199 -0
- package/src/subgraph/graph-ts-enums.ts +28 -0
- package/src/subgraph/graph-ts-types/VERSION +2 -0
- package/src/subgraph/graph-ts-types/chain/arweave.d.ts +70 -0
- package/src/subgraph/graph-ts-types/chain/cosmos.d.ts +327 -0
- package/src/subgraph/graph-ts-types/chain/ethereum.d.ts +233 -0
- package/src/subgraph/graph-ts-types/chain/near.d.ts +253 -0
- package/src/subgraph/graph-ts-types/chain/starknet.d.ts +32 -0
- package/src/subgraph/graph-ts-types/common/collections.d.ts +136 -0
- package/src/subgraph/graph-ts-types/common/conversion.d.ts +11 -0
- package/src/subgraph/graph-ts-types/common/datasource.d.ts +30 -0
- package/src/subgraph/graph-ts-types/common/eager-offset.d.ts +0 -0
- package/src/subgraph/graph-ts-types/common/json.d.ts +17 -0
- package/src/subgraph/graph-ts-types/common/numbers.d.ts +120 -0
- package/src/subgraph/graph-ts-types/common/value.d.ts +120 -0
- package/src/subgraph/graph-ts-types/common/yaml.d.ts +90 -0
- package/src/subgraph/graph-ts-types/global/global.d.ts +194 -0
- package/src/subgraph/graph-ts-types/helper-functions.d.ts +22 -0
- package/src/subgraph/graph-ts-types/index.d.ts +102 -0
- package/src/subgraph/graph-ts.ts +4339 -0
- package/src/subgraph/hosts.ts +554 -0
- package/src/subgraph/log.ts +28 -0
- package/src/subgraph/receipts.ts +184 -0
- package/src/subgraph/register-slots.ts +93 -0
- package/src/subgraph/rollup.ts +109 -0
- package/src/subgraph/rpc.ts +337 -0
- package/src/subgraph/runtime.ts +2059 -0
- package/src/subgraph/scope.ts +176 -0
- package/src/subgraph/stats.ts +42 -0
- package/src/subgraph/template-instances.ts +66 -0
- package/src/subgraph/toolchain.ts +327 -0
- package/src/subgraph/transient.ts +176 -0
- package/svm.schema.json +11 -2
- package/src/PgWriting.res +0 -36
- package/src/PgWriting.res.mjs +0 -34
- package/src/db/IndexDefinition.res +0 -47
- package/src/db/IndexDefinition.res.mjs +0 -67
package/src/FetchState.res.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import * as Env from "./Env.res.mjs";
|
|
|
4
4
|
import * as Utils from "./Utils.res.mjs";
|
|
5
5
|
import * as ChainId from "./ChainId.res.mjs";
|
|
6
6
|
import * as Js_math from "@rescript/runtime/lib/es6/Js_math.js";
|
|
7
|
+
import * as Internal from "./Internal.res.mjs";
|
|
7
8
|
import * as BlockItem from "./sources/BlockItem.res.mjs";
|
|
8
9
|
import * as AddressSet from "./sources/AddressSet.res.mjs";
|
|
9
10
|
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
@@ -793,6 +794,77 @@ function compareTiebreak(a, b) {
|
|
|
793
794
|
}
|
|
794
795
|
}
|
|
795
796
|
|
|
797
|
+
function blockOrderRank(item) {
|
|
798
|
+
let round = item.runsAfterBlock;
|
|
799
|
+
if (round !== undefined) {
|
|
800
|
+
return 3 + round | 0;
|
|
801
|
+
} else if (item.kind !== 0) {
|
|
802
|
+
if (Internal.itemRunsFirst(item)) {
|
|
803
|
+
return -1;
|
|
804
|
+
} else {
|
|
805
|
+
return 3;
|
|
806
|
+
}
|
|
807
|
+
} else if (item.callRank === 2) {
|
|
808
|
+
return 2;
|
|
809
|
+
} else {
|
|
810
|
+
return 0;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
function compareWithCalls(a, b) {
|
|
815
|
+
let ra = blockOrderRank(a);
|
|
816
|
+
let rb = blockOrderRank(b);
|
|
817
|
+
if (ra !== rb) {
|
|
818
|
+
if (ra < rb) {
|
|
819
|
+
return -1;
|
|
820
|
+
} else {
|
|
821
|
+
return 1;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
if (ra === 3 || ra === -1) {
|
|
825
|
+
let la = a.logIndex;
|
|
826
|
+
let lb = b.logIndex;
|
|
827
|
+
if (la !== lb) {
|
|
828
|
+
if (la < lb) {
|
|
829
|
+
return -1;
|
|
830
|
+
} else {
|
|
831
|
+
return 1;
|
|
832
|
+
}
|
|
833
|
+
} else {
|
|
834
|
+
return compareTiebreak(a, b);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
let ta = a.transactionIndex;
|
|
838
|
+
let tb = b.transactionIndex;
|
|
839
|
+
if (ta !== tb) {
|
|
840
|
+
if (ta < tb) {
|
|
841
|
+
return -1;
|
|
842
|
+
} else {
|
|
843
|
+
return 1;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
let ca = Stdlib_Option.isSome(a.callRank) ? 1 : 0;
|
|
847
|
+
let cb = Stdlib_Option.isSome(b.callRank) ? 1 : 0;
|
|
848
|
+
if (ca !== cb) {
|
|
849
|
+
if (ca < cb) {
|
|
850
|
+
return -1;
|
|
851
|
+
} else {
|
|
852
|
+
return 1;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
let la$1 = a.logIndex;
|
|
856
|
+
let lb$1 = b.logIndex;
|
|
857
|
+
if (la$1 !== lb$1) {
|
|
858
|
+
if (la$1 < lb$1) {
|
|
859
|
+
return -1;
|
|
860
|
+
} else {
|
|
861
|
+
return 1;
|
|
862
|
+
}
|
|
863
|
+
} else {
|
|
864
|
+
return compareTiebreak(a, b);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
796
868
|
function compareBufferItem(a, b) {
|
|
797
869
|
let ba = a.blockNumber;
|
|
798
870
|
let bb = b.blockNumber;
|
|
@@ -803,8 +875,29 @@ function compareBufferItem(a, b) {
|
|
|
803
875
|
return 1;
|
|
804
876
|
}
|
|
805
877
|
}
|
|
806
|
-
|
|
807
|
-
|
|
878
|
+
if (Internal.callOrderingActive.contents) {
|
|
879
|
+
return compareWithCalls(a, b);
|
|
880
|
+
}
|
|
881
|
+
let round = a.runsAfterBlock;
|
|
882
|
+
let ka;
|
|
883
|
+
if (round !== undefined) {
|
|
884
|
+
ka = 1 + round | 0;
|
|
885
|
+
} else {
|
|
886
|
+
let kind = a.kind;
|
|
887
|
+
ka = kind !== 0 ? (
|
|
888
|
+
Internal.itemRunsFirst(a) ? -1 : kind
|
|
889
|
+
) : 0;
|
|
890
|
+
}
|
|
891
|
+
let round$1 = b.runsAfterBlock;
|
|
892
|
+
let kb;
|
|
893
|
+
if (round$1 !== undefined) {
|
|
894
|
+
kb = 1 + round$1 | 0;
|
|
895
|
+
} else {
|
|
896
|
+
let kind$1 = b.kind;
|
|
897
|
+
kb = kind$1 !== 0 ? (
|
|
898
|
+
Internal.itemRunsFirst(b) ? -1 : kind$1
|
|
899
|
+
) : 0;
|
|
900
|
+
}
|
|
808
901
|
if (ka !== kb) {
|
|
809
902
|
if (ka < kb) {
|
|
810
903
|
return -1;
|
|
@@ -826,7 +919,7 @@ function compareBufferItem(a, b) {
|
|
|
826
919
|
}
|
|
827
920
|
|
|
828
921
|
function isSameLog(a, b) {
|
|
829
|
-
if (a.kind !== 0 || b.kind !== 0 || a.blockNumber !== b.blockNumber || a.logIndex !== b.logIndex) {
|
|
922
|
+
if (a.kind !== 0 || b.kind !== 0 || a.callRank !== b.callRank || a.blockNumber !== b.blockNumber || a.logIndex !== b.logIndex) {
|
|
830
923
|
return false;
|
|
831
924
|
}
|
|
832
925
|
let match = a.orderPath;
|
|
@@ -929,7 +1022,9 @@ function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, mutItemsSo
|
|
|
929
1022
|
tmp = latestFullyFetchedBlock !== undefined ? latestFullyFetchedBlock : knownHeight;
|
|
930
1023
|
}
|
|
931
1024
|
let maxBlockNumber = Primitive_int.min(tmp, knownHeight);
|
|
932
|
-
|
|
1025
|
+
let through = fetchState.blockRegisterThrough;
|
|
1026
|
+
let maxBlockNumber$1 = through !== undefined ? Primitive_int.min(maxBlockNumber, through) : maxBlockNumber;
|
|
1027
|
+
latestOnBlockBlockNumber = appendOnBlockItems(blockItems, onBlockRegistrations, fetchState.startBlock, fetchState.latestOnBlockBlockNumber, maxBlockNumber$1, fetchState.maxOnBlockBufferSize);
|
|
933
1028
|
} else {
|
|
934
1029
|
latestOnBlockBlockNumber = knownHeight;
|
|
935
1030
|
}
|
|
@@ -941,26 +1036,49 @@ function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, mutItemsSo
|
|
|
941
1036
|
chainId: fetchState.chainId,
|
|
942
1037
|
latestOnBlockBlockNumber: latestOnBlockBlockNumber,
|
|
943
1038
|
blockLag: blockLag,
|
|
1039
|
+
blockThrottle: fetchState.blockThrottle,
|
|
944
1040
|
buffer: blockItems.length !== 0 ? mergeIntoBuffer(base, blockItems) : base,
|
|
945
1041
|
maxOnBlockBufferSize: fetchState.maxOnBlockBufferSize,
|
|
946
1042
|
onBlockRegistrations: fetchState.onBlockRegistrations,
|
|
947
1043
|
knownHeight: knownHeight,
|
|
948
1044
|
firstEventBlock: fetchState.firstEventBlock,
|
|
949
|
-
|
|
1045
|
+
clientFilterPolicy: fetchState.clientFilterPolicy,
|
|
1046
|
+
creationBlocks: fetchState.creationBlocks,
|
|
1047
|
+
blockRegisterThrough: fetchState.blockRegisterThrough
|
|
950
1048
|
};
|
|
951
1049
|
}
|
|
952
1050
|
|
|
953
|
-
function
|
|
1051
|
+
function switchToClientSideFiltering(clientFilteredContracts, contractNames, policy, dynamicContracts, addressStore, onNotice, isAlreadyReportedOpt) {
|
|
954
1052
|
let isAlreadyReported = isAlreadyReportedOpt !== undefined ? isAlreadyReportedOpt : false;
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1053
|
+
let switched = new Set(Array.from(clientFilteredContracts));
|
|
1054
|
+
contractNames.forEach(contractName => {
|
|
1055
|
+
if (switched.has(contractName)) {
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
if (policy.allDynamicContracts && dynamicContracts.has(contractName)) {
|
|
1059
|
+
switched.add(contractName);
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
let threshold = policy.addressThreshold;
|
|
1063
|
+
if (threshold === undefined) {
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
let addressCount = addressStore.contractCount(contractName);
|
|
1067
|
+
if (addressCount > threshold) {
|
|
1068
|
+
switched.add(contractName);
|
|
1069
|
+
if (!isAlreadyReported) {
|
|
1070
|
+
return onNotice({
|
|
1071
|
+
TAG: "SwitchedToClientSideFiltering",
|
|
1072
|
+
contractName: contractName,
|
|
1073
|
+
addressCount: addressCount,
|
|
1074
|
+
threshold: threshold
|
|
1075
|
+
});
|
|
1076
|
+
} else {
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1081
|
+
return switched;
|
|
964
1082
|
}
|
|
965
1083
|
|
|
966
1084
|
function claimedFetchedBlock(p, knownHeight) {
|
|
@@ -1286,6 +1404,43 @@ function createPartitions(registeringSetsByContract, addressStore, dynamicContra
|
|
|
1286
1404
|
return make(allPartitions, maxAddrInPartition, nextPartitionIndexRef.contents, dynamicContracts, clientFilteredContracts);
|
|
1287
1405
|
}
|
|
1288
1406
|
|
|
1407
|
+
function creationBlockKey(contractName, address) {
|
|
1408
|
+
return contractName + `:` + address.toLowerCase();
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
function markCreationBlockEvents(creationBlocks, newItems, fetchedThrough) {
|
|
1412
|
+
Object.entries(creationBlocks).forEach(param => {
|
|
1413
|
+
if (param[1].block < fetchedThrough) {
|
|
1414
|
+
return Utils.Dict.deleteInPlace(creationBlocks, param[0]);
|
|
1415
|
+
}
|
|
1416
|
+
});
|
|
1417
|
+
newItems.forEach(item => {
|
|
1418
|
+
if (item.kind !== 0) {
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
let key = creationBlockKey(item.onEventRegistration.eventConfig.contractName, item.payload.srcAddress);
|
|
1422
|
+
let match = creationBlocks[key];
|
|
1423
|
+
if (match !== undefined && match.block === item.blockNumber) {
|
|
1424
|
+
item.runsAfterBlock = match.round;
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
function creationRoundOfRegistration(fetchState, item) {
|
|
1431
|
+
let creationBlocks = fetchState.creationBlocks;
|
|
1432
|
+
if (creationBlocks === undefined) {
|
|
1433
|
+
return 1;
|
|
1434
|
+
}
|
|
1435
|
+
let key = creationBlockKey(item.onEventRegistration.eventConfig.contractName, item.payload.srcAddress);
|
|
1436
|
+
let match = creationBlocks[key];
|
|
1437
|
+
if (match !== undefined && match.block === item.blockNumber) {
|
|
1438
|
+
return match.round + 1 | 0;
|
|
1439
|
+
} else {
|
|
1440
|
+
return 1;
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1289
1444
|
function registerDynamicContracts(fetchState, addressStore, onNotice, claimCeilingOpt, registrations) {
|
|
1290
1445
|
let claimCeiling = claimCeilingOpt !== undefined ? claimCeilingOpt : fetchState.knownHeight;
|
|
1291
1446
|
if (Utils.$$Array.isEmpty(fetchState.normalSelection.onEventRegistrations)) {
|
|
@@ -1300,8 +1455,17 @@ function registerDynamicContracts(fetchState, addressStore, onNotice, claimCeili
|
|
|
1300
1455
|
let exit = 0;
|
|
1301
1456
|
if (typeof verdict !== "object" || verdict.TAG !== "Added") {
|
|
1302
1457
|
exit = 1;
|
|
1303
|
-
} else if (verdict.fetchable
|
|
1304
|
-
|
|
1458
|
+
} else if (verdict.fetchable) {
|
|
1459
|
+
let creationBlocks = fetchState.creationBlocks;
|
|
1460
|
+
if (creationBlocks !== undefined) {
|
|
1461
|
+
creationBlocks[creationBlockKey(registration.contractName, registration.address)] = {
|
|
1462
|
+
block: registration.registrationBlock,
|
|
1463
|
+
round: Stdlib_Option.getOr(registration.creationRound, 1)
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
if (!registeringContractNames.includes(registration.contractName)) {
|
|
1467
|
+
registeringContractNames.push(registration.contractName);
|
|
1468
|
+
}
|
|
1305
1469
|
}
|
|
1306
1470
|
if (exit === 1) {
|
|
1307
1471
|
reportRejectedRegistration(verdict, onNotice, registration.address, registration.contractName);
|
|
@@ -1362,20 +1526,7 @@ function registerDynamicContracts(fetchState, addressStore, onNotice, claimCeili
|
|
|
1362
1526
|
}
|
|
1363
1527
|
}
|
|
1364
1528
|
}
|
|
1365
|
-
let
|
|
1366
|
-
let clientFilteredContracts;
|
|
1367
|
-
if (threshold !== undefined) {
|
|
1368
|
-
let clientFilteredContracts$1 = new Set(Array.from(fetchState.optimizedPartitions.clientFilteredContracts));
|
|
1369
|
-
Array.from(dynamicContractsRef).forEach(contractName => {
|
|
1370
|
-
let addressCount = addressStore.contractCount(contractName);
|
|
1371
|
-
if (!clientFilteredContracts$1.has(contractName) && addressCount > threshold) {
|
|
1372
|
-
return addClientFilteredContract(clientFilteredContracts$1, contractName, onNotice, addressCount, threshold, undefined);
|
|
1373
|
-
}
|
|
1374
|
-
});
|
|
1375
|
-
clientFilteredContracts = clientFilteredContracts$1;
|
|
1376
|
-
} else {
|
|
1377
|
-
clientFilteredContracts = fetchState.optimizedPartitions.clientFilteredContracts;
|
|
1378
|
-
}
|
|
1529
|
+
let clientFilteredContracts = switchToClientSideFiltering(fetchState.optimizedPartitions.clientFilteredContracts, Array.from(dynamicContractsRef), fetchState.clientFilterPolicy, dynamicContractsRef, addressStore, onNotice, undefined);
|
|
1379
1530
|
let registeringSetsByContract = {};
|
|
1380
1531
|
registeringContractNames.forEach(contractName => {
|
|
1381
1532
|
registeringSetsByContract[contractName] = AddressStore.makeSet(addressStore, contractName, {
|
|
@@ -1386,8 +1537,100 @@ function registerDynamicContracts(fetchState, addressStore, onNotice, claimCeili
|
|
|
1386
1537
|
return updateInternal(fetchState, optimizedPartitions, undefined, undefined, undefined, undefined);
|
|
1387
1538
|
}
|
|
1388
1539
|
|
|
1540
|
+
function switchDynamicContractsToClientSideFiltering(fetchState, addressStore) {
|
|
1541
|
+
if (fetchState.clientFilterPolicy.allDynamicContracts) {
|
|
1542
|
+
return fetchState;
|
|
1543
|
+
}
|
|
1544
|
+
let newrecord = {...fetchState};
|
|
1545
|
+
let init = fetchState.clientFilterPolicy;
|
|
1546
|
+
newrecord.clientFilterPolicy = {
|
|
1547
|
+
addressThreshold: init.addressThreshold,
|
|
1548
|
+
allDynamicContracts: true
|
|
1549
|
+
};
|
|
1550
|
+
let match = newrecord.optimizedPartitions;
|
|
1551
|
+
let clientFilteredContracts = match.clientFilteredContracts;
|
|
1552
|
+
let dynamicContracts = match.dynamicContracts;
|
|
1553
|
+
let switched = new Set(Array.from(clientFilteredContracts).concat(Array.from(dynamicContracts)));
|
|
1554
|
+
if (switched.size === clientFilteredContracts.size) {
|
|
1555
|
+
return newrecord;
|
|
1556
|
+
} else {
|
|
1557
|
+
return updateInternal(newrecord, createPartitions({}, addressStore, dynamicContracts, switched, newrecord.normalSelection, match.maxAddrInPartition, match.nextPartitionIndex, Object.values(newrecord.optimizedPartitions.entities), 0, newrecord.knownHeight), undefined, undefined, undefined, undefined);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1389
1561
|
function handleQueryResult(fetchState, query, latestFetchedBlock, newItems) {
|
|
1390
|
-
|
|
1562
|
+
let tmp;
|
|
1563
|
+
if (newItems.length !== 0) {
|
|
1564
|
+
let creationBlocks = fetchState.creationBlocks;
|
|
1565
|
+
if (creationBlocks !== undefined) {
|
|
1566
|
+
markCreationBlockEvents(creationBlocks, newItems, bufferBlockNumber(fetchState));
|
|
1567
|
+
}
|
|
1568
|
+
tmp = mergeIntoBuffer(fetchState.buffer, newItems);
|
|
1569
|
+
} else {
|
|
1570
|
+
tmp = undefined;
|
|
1571
|
+
}
|
|
1572
|
+
return updateInternal(fetchState, handleQueryResponse(fetchState.optimizedPartitions, query, fetchState.knownHeight, newItems.length, latestFetchedBlock), tmp, true, undefined, undefined);
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
function capAtEndBlock(fetchState, block) {
|
|
1576
|
+
let endBlock = fetchState.endBlock;
|
|
1577
|
+
if (endBlock !== undefined) {
|
|
1578
|
+
return Primitive_int.min(block, endBlock);
|
|
1579
|
+
} else {
|
|
1580
|
+
return block;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
function canAdvanceBlockRegisters(fetchState, through) {
|
|
1585
|
+
let after = fetchState.blockRegisterThrough;
|
|
1586
|
+
if (after !== undefined) {
|
|
1587
|
+
return capAtEndBlock(fetchState, through) > after;
|
|
1588
|
+
} else {
|
|
1589
|
+
return false;
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
function blockRegisterItemsAfter(fetchState, after, through, limit) {
|
|
1594
|
+
let match = fetchState.blockRegisterThrough;
|
|
1595
|
+
if (match === undefined) {
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1598
|
+
if (capAtEndBlock(fetchState, through) <= after) {
|
|
1599
|
+
return;
|
|
1600
|
+
}
|
|
1601
|
+
let through$1 = capAtEndBlock(fetchState, through);
|
|
1602
|
+
let items = [];
|
|
1603
|
+
let covered = appendOnBlockItems(items, fetchState.onBlockRegistrations.filter(r => r.contractRegister !== undefined), fetchState.startBlock, after, through$1, limit);
|
|
1604
|
+
return [
|
|
1605
|
+
items,
|
|
1606
|
+
covered
|
|
1607
|
+
];
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
function nextBlockRegisterItems(fetchState, through, limit) {
|
|
1611
|
+
let after = fetchState.blockRegisterThrough;
|
|
1612
|
+
if (after !== undefined) {
|
|
1613
|
+
return blockRegisterItemsAfter(fetchState, after, through, limit);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
function setBlockRegisterThrough(fetchState, through) {
|
|
1618
|
+
let current = fetchState.blockRegisterThrough;
|
|
1619
|
+
if (current === undefined) {
|
|
1620
|
+
return fetchState;
|
|
1621
|
+
}
|
|
1622
|
+
if (through <= current) {
|
|
1623
|
+
return fetchState;
|
|
1624
|
+
}
|
|
1625
|
+
let newrecord = {...fetchState};
|
|
1626
|
+
return updateInternal((newrecord.blockRegisterThrough = through, newrecord), undefined, undefined, undefined, undefined, undefined);
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
function blockRegisterFrontier(fetchState) {
|
|
1630
|
+
let optimizedPartitions = fetchState.optimizedPartitions;
|
|
1631
|
+
let id = optimizedPartitions.idsInAscOrder[0];
|
|
1632
|
+
let block = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
|
|
1633
|
+
return capAtEndBlock(fetchState, block !== undefined ? Primitive_int.min(block, fetchState.knownHeight) : fetchState.knownHeight);
|
|
1391
1634
|
}
|
|
1392
1635
|
|
|
1393
1636
|
function startFetchingQueries(param, queries) {
|
|
@@ -1624,15 +1867,30 @@ function acceptCandidates(candidates, reservations, chainTargetItems, partitionI
|
|
|
1624
1867
|
};
|
|
1625
1868
|
}
|
|
1626
1869
|
|
|
1627
|
-
function
|
|
1628
|
-
let
|
|
1870
|
+
function blocksBehindHeadAllowedByThrottle(param) {
|
|
1871
|
+
let blockThrottle = param.blockThrottle;
|
|
1629
1872
|
let endBlock = param.endBlock;
|
|
1630
|
-
|
|
1631
|
-
|
|
1873
|
+
if (endBlock !== undefined && (param.knownHeight - param.blockLag | 0) >= endBlock) {
|
|
1874
|
+
return 0;
|
|
1875
|
+
} else {
|
|
1876
|
+
return Primitive_int.max(0, blockThrottle - 1 | 0);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
function headFetchTarget(fetchState) {
|
|
1881
|
+
return (fetchState.knownHeight - fetchState.blockLag | 0) - blocksBehindHeadAllowedByThrottle(fetchState) | 0;
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
function getNextQuery(fetchState, chainTargetBlock, chainTargetItems) {
|
|
1885
|
+
let blockLag = fetchState.blockLag;
|
|
1886
|
+
let endBlock = fetchState.endBlock;
|
|
1887
|
+
let optimizedPartitions = fetchState.optimizedPartitions;
|
|
1888
|
+
let headBlockNumber = fetchState.knownHeight - blockLag | 0;
|
|
1632
1889
|
if (headBlockNumber <= 0) {
|
|
1633
1890
|
return "WaitingForNewBlock";
|
|
1634
1891
|
}
|
|
1635
|
-
let
|
|
1892
|
+
let caughtUpBlockNumber = headBlockNumber - blocksBehindHeadAllowedByThrottle(fetchState) | 0;
|
|
1893
|
+
let isOnBlockBehindTheHead = fetchState.latestOnBlockBlockNumber < caughtUpBlockNumber;
|
|
1636
1894
|
let shouldWaitForNewBlock = (
|
|
1637
1895
|
endBlock !== undefined ? headBlockNumber < endBlock : true
|
|
1638
1896
|
) && !isOnBlockBehindTheHead;
|
|
@@ -1658,7 +1916,7 @@ function getNextQuery(param, chainTargetBlock, chainTargetItems) {
|
|
|
1658
1916
|
}
|
|
1659
1917
|
}
|
|
1660
1918
|
inFlightCounts[idx] = inFlightCount;
|
|
1661
|
-
if (p.mutPendingQueries.length !== 0 || p.latestFetchedBlock <
|
|
1919
|
+
if (p.mutPendingQueries.length !== 0 || p.latestFetchedBlock < caughtUpBlockNumber) {
|
|
1662
1920
|
shouldWaitForNewBlock = false;
|
|
1663
1921
|
}
|
|
1664
1922
|
}
|
|
@@ -1749,13 +2007,15 @@ function getReadyItemsCount(fetchState, targetSize, fromItem) {
|
|
|
1749
2007
|
return acc;
|
|
1750
2008
|
}
|
|
1751
2009
|
|
|
1752
|
-
function make$1(startBlock, endBlock, onEventRegistrations, addressStore, addressRows, maxAddrInPartition, chainId, onNotice, maxOnBlockBufferSize, knownHeight, progressBlockNumberOpt, onBlockRegistrationsOpt, blockLagOpt, firstEventBlockOpt, clientFilterAddressThresholdOpt, isResumedOpt) {
|
|
2010
|
+
function make$1(startBlock, endBlock, onEventRegistrations, addressStore, addressRows, maxAddrInPartition, chainId, onNotice, maxOnBlockBufferSize, knownHeight, progressBlockNumberOpt, onBlockRegistrationsOpt, blockLagOpt, blockThrottleOpt, firstEventBlockOpt, clientFilterAddressThresholdOpt, isResumedOpt, deferCreationBlockEventsOpt) {
|
|
1753
2011
|
let progressBlockNumber = progressBlockNumberOpt !== undefined ? progressBlockNumberOpt : startBlock - 1 | 0;
|
|
1754
2012
|
let onBlockRegistrations = onBlockRegistrationsOpt !== undefined ? onBlockRegistrationsOpt : [];
|
|
1755
2013
|
let blockLag = blockLagOpt !== undefined ? blockLagOpt : 0;
|
|
2014
|
+
let blockThrottle = blockThrottleOpt !== undefined ? blockThrottleOpt : 0;
|
|
1756
2015
|
let firstEventBlock = firstEventBlockOpt !== undefined ? Primitive_option.valFromOption(firstEventBlockOpt) : undefined;
|
|
1757
2016
|
let clientFilterAddressThreshold = clientFilterAddressThresholdOpt !== undefined ? Primitive_option.valFromOption(clientFilterAddressThresholdOpt) : undefined;
|
|
1758
2017
|
let isResumed = isResumedOpt !== undefined ? isResumedOpt : false;
|
|
2018
|
+
let deferCreationBlockEvents = deferCreationBlockEventsOpt !== undefined ? deferCreationBlockEventsOpt : false;
|
|
1759
2019
|
let notDependingOnAddresses = [];
|
|
1760
2020
|
let normalRegistrations = [];
|
|
1761
2021
|
let contractNamesWithNormalEvents = new Set();
|
|
@@ -1801,7 +2061,6 @@ function make$1(startBlock, endBlock, onEventRegistrations, addressStore, addres
|
|
|
1801
2061
|
requestedFromBlock: rejected.effectiveStartBlock
|
|
1802
2062
|
}));
|
|
1803
2063
|
let dynamicContracts = new Set();
|
|
1804
|
-
let clientFilteredContracts = new Set();
|
|
1805
2064
|
let registeringSetsByContract = {};
|
|
1806
2065
|
Array.from(contractNamesWithNormalEvents).forEach(contractName => {
|
|
1807
2066
|
if (addressStore.contractCount(contractName) > 0) {
|
|
@@ -1815,19 +2074,17 @@ function make$1(startBlock, endBlock, onEventRegistrations, addressStore, addres
|
|
|
1815
2074
|
return;
|
|
1816
2075
|
}
|
|
1817
2076
|
});
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
}
|
|
1824
|
-
});
|
|
1825
|
-
}
|
|
2077
|
+
let clientFilterPolicy = {
|
|
2078
|
+
addressThreshold: clientFilterAddressThreshold,
|
|
2079
|
+
allDynamicContracts: false
|
|
2080
|
+
};
|
|
2081
|
+
let clientFilteredContracts = switchToClientSideFiltering(new Set(), Object.keys(registeringSetsByContract), clientFilterPolicy, dynamicContracts, addressStore, onNotice, isResumed);
|
|
1826
2082
|
let optimizedPartitions = createPartitions(registeringSetsByContract, addressStore, dynamicContracts, clientFilteredContracts, normalSelection, maxAddrInPartition, partitions.length, partitions, progressBlockNumber, knownHeight);
|
|
1827
2083
|
if (optimizedPartitions.idsInAscOrder.length === 0 && Utils.$$Array.isEmpty(onBlockRegistrations$1)) {
|
|
1828
2084
|
Stdlib_JsError.throwWithMessage(`Invalid configuration: Nothing to fetch on chain ` + ChainId.toString(chainId) + `. ` + (`addresses=` + addressRows.addresses.length.toString() + `, `) + (`onEventRegistrations=` + onEventRegistrations.length.toString() + `, `) + (`normalRegistrations=` + normalRegistrations.length.toString() + `. `) + `Make sure that you provided at least one contract address to index, or have events with Wildcard mode enabled, or have onBlock handlers.`);
|
|
1829
2085
|
}
|
|
1830
2086
|
let buffer = [];
|
|
2087
|
+
let blockRegisterThrough = onBlockRegistrations$1.some(r => r.contractRegister !== undefined) ? progressBlockNumber : undefined;
|
|
1831
2088
|
let latestOnBlockBlockNumber;
|
|
1832
2089
|
let exit = 0;
|
|
1833
2090
|
if (onBlockRegistrations$1.length !== 0 || knownHeight <= 0) {
|
|
@@ -1840,7 +2097,8 @@ function make$1(startBlock, endBlock, onEventRegistrations, addressStore, addres
|
|
|
1840
2097
|
let id = optimizedPartitions.idsInAscOrder[0];
|
|
1841
2098
|
let latestFullyFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
|
|
1842
2099
|
let maxBlockNumber = latestFullyFetchedBlock !== undefined ? Primitive_int.min(latestFullyFetchedBlock, knownHeight) : knownHeight;
|
|
1843
|
-
|
|
2100
|
+
let maxBlockNumber$1 = blockRegisterThrough !== undefined ? Primitive_int.min(maxBlockNumber, blockRegisterThrough) : maxBlockNumber;
|
|
2101
|
+
latestOnBlockBlockNumber = appendOnBlockItems(buffer, onBlockRegistrations$1, startBlock, progressBlockNumber, maxBlockNumber$1, maxOnBlockBufferSize);
|
|
1844
2102
|
} else {
|
|
1845
2103
|
latestOnBlockBlockNumber = progressBlockNumber;
|
|
1846
2104
|
}
|
|
@@ -1853,12 +2111,15 @@ function make$1(startBlock, endBlock, onEventRegistrations, addressStore, addres
|
|
|
1853
2111
|
chainId: chainId,
|
|
1854
2112
|
latestOnBlockBlockNumber: latestOnBlockBlockNumber,
|
|
1855
2113
|
blockLag: blockLag,
|
|
2114
|
+
blockThrottle: blockThrottle,
|
|
1856
2115
|
buffer: buffer,
|
|
1857
2116
|
maxOnBlockBufferSize: maxOnBlockBufferSize,
|
|
1858
2117
|
onBlockRegistrations: onBlockRegistrations$1,
|
|
1859
2118
|
knownHeight: knownHeight,
|
|
1860
2119
|
firstEventBlock: firstEventBlock,
|
|
1861
|
-
|
|
2120
|
+
clientFilterPolicy: clientFilterPolicy,
|
|
2121
|
+
creationBlocks: deferCreationBlockEvents ? ({}) : undefined,
|
|
2122
|
+
blockRegisterThrough: blockRegisterThrough
|
|
1862
2123
|
};
|
|
1863
2124
|
}
|
|
1864
2125
|
|
|
@@ -1958,21 +2219,8 @@ function rollback(fetchState, rolledBackAddressStore, targetBlockNumber) {
|
|
|
1958
2219
|
}
|
|
1959
2220
|
}
|
|
1960
2221
|
let optimizedPartitions = createPartitions(registeringSetsByContract, rolledBackAddressStore, fetchState.optimizedPartitions.dynamicContracts, fetchState.optimizedPartitions.clientFilteredContracts, fetchState.normalSelection, fetchState.optimizedPartitions.maxAddrInPartition, nextKeptIdRef, keptPartitions, targetBlockNumber, fetchState.knownHeight);
|
|
1961
|
-
let
|
|
1962
|
-
|
|
1963
|
-
startBlock: fetchState.startBlock,
|
|
1964
|
-
endBlock: fetchState.endBlock,
|
|
1965
|
-
normalSelection: fetchState.normalSelection,
|
|
1966
|
-
chainId: fetchState.chainId,
|
|
1967
|
-
latestOnBlockBlockNumber: Primitive_int.min(fetchState.latestOnBlockBlockNumber, targetBlockNumber),
|
|
1968
|
-
blockLag: fetchState.blockLag,
|
|
1969
|
-
buffer: fetchState.buffer,
|
|
1970
|
-
maxOnBlockBufferSize: fetchState.maxOnBlockBufferSize,
|
|
1971
|
-
onBlockRegistrations: fetchState.onBlockRegistrations,
|
|
1972
|
-
knownHeight: fetchState.knownHeight,
|
|
1973
|
-
firstEventBlock: fetchState.firstEventBlock,
|
|
1974
|
-
clientFilterAddressThreshold: fetchState.clientFilterAddressThreshold
|
|
1975
|
-
}, optimizedPartitions, fetchState.buffer.filter(item => {
|
|
2222
|
+
let newrecord = {...fetchState};
|
|
2223
|
+
let rolledBack = updateInternal((newrecord.blockRegisterThrough = Stdlib_Option.map(fetchState.blockRegisterThrough, through => Primitive_int.min(through, targetBlockNumber)), newrecord.latestOnBlockBlockNumber = Primitive_int.min(fetchState.latestOnBlockBlockNumber, targetBlockNumber), newrecord), optimizedPartitions, fetchState.buffer.filter(item => {
|
|
1976
2224
|
let tmp;
|
|
1977
2225
|
tmp = item.kind === 0 ? item.blockNumber : item.blockNumber;
|
|
1978
2226
|
return tmp <= targetBlockNumber;
|
|
@@ -2005,29 +2253,17 @@ function resetPendingQueries(fetchState) {
|
|
|
2005
2253
|
};
|
|
2006
2254
|
}
|
|
2007
2255
|
}
|
|
2256
|
+
let newrecord = {...fetchState};
|
|
2008
2257
|
let init = fetchState.optimizedPartitions;
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
clientFilteredContracts: init.clientFilteredContracts
|
|
2017
|
-
},
|
|
2018
|
-
startBlock: fetchState.startBlock,
|
|
2019
|
-
endBlock: fetchState.endBlock,
|
|
2020
|
-
normalSelection: fetchState.normalSelection,
|
|
2021
|
-
chainId: fetchState.chainId,
|
|
2022
|
-
latestOnBlockBlockNumber: fetchState.latestOnBlockBlockNumber,
|
|
2023
|
-
blockLag: fetchState.blockLag,
|
|
2024
|
-
buffer: fetchState.buffer,
|
|
2025
|
-
maxOnBlockBufferSize: fetchState.maxOnBlockBufferSize,
|
|
2026
|
-
onBlockRegistrations: fetchState.onBlockRegistrations,
|
|
2027
|
-
knownHeight: fetchState.knownHeight,
|
|
2028
|
-
firstEventBlock: fetchState.firstEventBlock,
|
|
2029
|
-
clientFilterAddressThreshold: fetchState.clientFilterAddressThreshold
|
|
2258
|
+
newrecord.optimizedPartitions = {
|
|
2259
|
+
idsInAscOrder: init.idsInAscOrder,
|
|
2260
|
+
entities: newEntities,
|
|
2261
|
+
maxAddrInPartition: init.maxAddrInPartition,
|
|
2262
|
+
nextPartitionIndex: init.nextPartitionIndex,
|
|
2263
|
+
dynamicContracts: init.dynamicContracts,
|
|
2264
|
+
clientFilteredContracts: init.clientFilteredContracts
|
|
2030
2265
|
};
|
|
2266
|
+
return newrecord;
|
|
2031
2267
|
}
|
|
2032
2268
|
|
|
2033
2269
|
function isActivelyIndexing(fetchState) {
|
|
@@ -2044,21 +2280,37 @@ function isActivelyIndexing(fetchState) {
|
|
|
2044
2280
|
}
|
|
2045
2281
|
|
|
2046
2282
|
function isFetchingAtHead(fetchState) {
|
|
2047
|
-
let knownHeight = fetchState.knownHeight;
|
|
2048
|
-
let blockLag = fetchState.blockLag;
|
|
2049
2283
|
let endBlock = fetchState.endBlock;
|
|
2050
2284
|
let bufferBlockNumber$1 = bufferBlockNumber(fetchState);
|
|
2051
|
-
if (knownHeight !== 0) {
|
|
2285
|
+
if (fetchState.knownHeight !== 0) {
|
|
2052
2286
|
if (endBlock !== undefined && bufferBlockNumber$1 >= endBlock) {
|
|
2053
2287
|
return true;
|
|
2054
2288
|
} else {
|
|
2055
|
-
return bufferBlockNumber$1 >= (
|
|
2289
|
+
return bufferBlockNumber$1 >= headFetchTarget(fetchState);
|
|
2056
2290
|
}
|
|
2057
2291
|
} else {
|
|
2058
2292
|
return false;
|
|
2059
2293
|
}
|
|
2060
2294
|
}
|
|
2061
2295
|
|
|
2296
|
+
function isWithinHeadClientFilteringDistance(fetchState) {
|
|
2297
|
+
let knownHeight = fetchState.knownHeight;
|
|
2298
|
+
let endBlock = fetchState.endBlock;
|
|
2299
|
+
let optimizedPartitions = fetchState.optimizedPartitions;
|
|
2300
|
+
if (!(knownHeight !== 0 && (
|
|
2301
|
+
endBlock !== undefined ? endBlock > (knownHeight - fetchState.blockLag | 0) : true
|
|
2302
|
+
))) {
|
|
2303
|
+
return false;
|
|
2304
|
+
}
|
|
2305
|
+
let id = optimizedPartitions.idsInAscOrder[0];
|
|
2306
|
+
let latestFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
|
|
2307
|
+
if (latestFetchedBlock !== undefined) {
|
|
2308
|
+
return (headFetchTarget(fetchState) - latestFetchedBlock | 0) <= 200;
|
|
2309
|
+
} else {
|
|
2310
|
+
return true;
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2062
2314
|
function isReadyToEnterReorgThreshold(tolerance, fetchState) {
|
|
2063
2315
|
let knownHeight = fetchState.knownHeight;
|
|
2064
2316
|
let endBlock = fetchState.endBlock;
|
|
@@ -2145,6 +2397,8 @@ let maxChainConcurrency = Env.maxChainConcurrency;
|
|
|
2145
2397
|
|
|
2146
2398
|
let chunkRangeGrowthFactor = 1.8;
|
|
2147
2399
|
|
|
2400
|
+
let headClientFilteringDistance = 200;
|
|
2401
|
+
|
|
2148
2402
|
export {
|
|
2149
2403
|
deriveSelectionStartBlock,
|
|
2150
2404
|
makeSelection,
|
|
@@ -2163,18 +2417,30 @@ export {
|
|
|
2163
2417
|
getRegistrationIndex,
|
|
2164
2418
|
comparePath,
|
|
2165
2419
|
compareTiebreak,
|
|
2420
|
+
blockOrderRank,
|
|
2421
|
+
compareWithCalls,
|
|
2166
2422
|
compareBufferItem,
|
|
2167
2423
|
isSameLog,
|
|
2168
2424
|
mergeIntoBuffer,
|
|
2169
2425
|
appendOnBlockItems,
|
|
2170
2426
|
updateInternal,
|
|
2171
|
-
|
|
2427
|
+
switchToClientSideFiltering,
|
|
2172
2428
|
claimedFetchedBlock,
|
|
2173
2429
|
collapseClientFilteredContracts,
|
|
2174
2430
|
reportRejectedRegistration,
|
|
2175
2431
|
createPartitions,
|
|
2432
|
+
creationBlockKey,
|
|
2433
|
+
markCreationBlockEvents,
|
|
2434
|
+
creationRoundOfRegistration,
|
|
2176
2435
|
registerDynamicContracts,
|
|
2436
|
+
switchDynamicContractsToClientSideFiltering,
|
|
2177
2437
|
handleQueryResult,
|
|
2438
|
+
capAtEndBlock,
|
|
2439
|
+
canAdvanceBlockRegisters,
|
|
2440
|
+
blockRegisterItemsAfter,
|
|
2441
|
+
nextBlockRegisterItems,
|
|
2442
|
+
setBlockRegisterThrough,
|
|
2443
|
+
blockRegisterFrontier,
|
|
2178
2444
|
startFetchingQueries,
|
|
2179
2445
|
maxInFlightChunksPerPartition,
|
|
2180
2446
|
maxChainConcurrency,
|
|
@@ -2184,6 +2450,8 @@ export {
|
|
|
2184
2450
|
walkPartitionPending,
|
|
2185
2451
|
pushForwardCandidates,
|
|
2186
2452
|
acceptCandidates,
|
|
2453
|
+
blocksBehindHeadAllowedByThrottle,
|
|
2454
|
+
headFetchTarget,
|
|
2187
2455
|
getNextQuery,
|
|
2188
2456
|
hasReadyItem,
|
|
2189
2457
|
getReadyItemsCount,
|
|
@@ -2195,6 +2463,8 @@ export {
|
|
|
2195
2463
|
resetPendingQueries,
|
|
2196
2464
|
isActivelyIndexing,
|
|
2197
2465
|
isFetchingAtHead,
|
|
2466
|
+
headClientFilteringDistance,
|
|
2467
|
+
isWithinHeadClientFilteringDistance,
|
|
2198
2468
|
isReadyToEnterReorgThreshold,
|
|
2199
2469
|
getProgressPercentage,
|
|
2200
2470
|
sortForBatch,
|
package/src/FinalizeBackfill.res
CHANGED
|
@@ -40,7 +40,7 @@ let runOnce = async (state: IndexerState.t) => {
|
|
|
40
40
|
let storage = persistence->Persistence.getInitializedStorageOrThrow
|
|
41
41
|
let readyAt = Date.make()
|
|
42
42
|
|
|
43
|
-
await storage.finalizeBackfill(~
|
|
43
|
+
await storage.finalizeBackfill(~chainIds, ~readyAt)
|
|
44
44
|
|
|
45
45
|
// Only after the commit: in-memory readiness must never run ahead of the
|
|
46
46
|
// `ready_at` a restart would read back.
|
|
@@ -68,10 +68,8 @@ let run = (state: IndexerState.t) =>
|
|
|
68
68
|
// Best-effort and not awaited by the loop: indexing is already live and correct
|
|
69
69
|
// without the index, just slower.
|
|
70
70
|
let repairSchemaIndexes = (state: IndexerState.t) => {
|
|
71
|
-
let
|
|
72
|
-
let storage = persistence->Persistence.getInitializedStorageOrThrow
|
|
71
|
+
let storage = state->IndexerState.persistence->Persistence.getInitializedStorageOrThrow
|
|
73
72
|
storage.ensureSchemaIndexes(
|
|
74
|
-
~entities=persistence.allEntities,
|
|
75
73
|
~chainIds=state->IndexerState.crossChainState->CrossChainState.chainIds,
|
|
76
74
|
)
|
|
77
75
|
}
|