envio 3.3.0-alpha.1 → 3.3.0-alpha.3

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.
Files changed (84) hide show
  1. package/index.d.ts +23 -21
  2. package/package.json +6 -6
  3. package/src/Batch.res +0 -6
  4. package/src/Batch.res.mjs +0 -11
  5. package/src/BatchProcessing.res +2 -12
  6. package/src/BatchProcessing.res.mjs +2 -7
  7. package/src/ChainFetching.res +42 -6
  8. package/src/ChainFetching.res.mjs +30 -11
  9. package/src/ChainMetadata.res +1 -11
  10. package/src/ChainMetadata.res.mjs +1 -10
  11. package/src/ChainState.res +150 -1
  12. package/src/ChainState.res.mjs +138 -9
  13. package/src/ChainState.resi +51 -1
  14. package/src/Config.res +3 -6
  15. package/src/Config.res.mjs +2 -3
  16. package/src/Core.res +7 -0
  17. package/src/CrossChainState.res +24 -26
  18. package/src/CrossChainState.res.mjs +19 -16
  19. package/src/Ecosystem.res +6 -3
  20. package/src/Envio.res +3 -2
  21. package/src/EventConfigBuilder.res +61 -23
  22. package/src/EventConfigBuilder.res.mjs +27 -13
  23. package/src/EventProcessing.res +63 -21
  24. package/src/EventProcessing.res.mjs +47 -22
  25. package/src/FetchState.res +53 -43
  26. package/src/FetchState.res.mjs +71 -54
  27. package/src/HandlerLoader.res +10 -1
  28. package/src/HandlerLoader.res.mjs +15 -8
  29. package/src/Internal.res +46 -7
  30. package/src/Internal.res.mjs +19 -1
  31. package/src/LoadLayer.res +5 -5
  32. package/src/LoadLayer.res.mjs +6 -6
  33. package/src/Main.res +3 -50
  34. package/src/Main.res.mjs +2 -23
  35. package/src/PgStorage.res +4 -4
  36. package/src/PgStorage.res.mjs +5 -5
  37. package/src/Prometheus.res +10 -10
  38. package/src/Prometheus.res.mjs +9 -9
  39. package/src/PruneStaleHistory.res +2 -2
  40. package/src/PruneStaleHistory.res.mjs +3 -3
  41. package/src/Rollback.res +3 -3
  42. package/src/Rollback.res.mjs +4 -4
  43. package/src/SimulateItems.res +80 -15
  44. package/src/SimulateItems.res.mjs +65 -21
  45. package/src/TestIndexer.res +48 -36
  46. package/src/TestIndexer.res.mjs +35 -28
  47. package/src/bindings/Performance.res +7 -0
  48. package/src/bindings/Performance.res.mjs +21 -0
  49. package/src/bindings/Performance.resi +7 -0
  50. package/src/sources/EventRouter.res +17 -21
  51. package/src/sources/EventRouter.res.mjs +6 -9
  52. package/src/sources/Evm.res +47 -67
  53. package/src/sources/Evm.res.mjs +42 -65
  54. package/src/sources/Fuel.res +3 -3
  55. package/src/sources/Fuel.res.mjs +1 -6
  56. package/src/sources/HyperFuelSource.res +15 -11
  57. package/src/sources/HyperFuelSource.res.mjs +13 -11
  58. package/src/sources/HyperSync.res +7 -1
  59. package/src/sources/HyperSync.res.mjs +6 -3
  60. package/src/sources/HyperSync.resi +2 -0
  61. package/src/sources/HyperSyncClient.res +14 -79
  62. package/src/sources/HyperSyncClient.res.mjs +1 -22
  63. package/src/sources/HyperSyncSource.res +44 -27
  64. package/src/sources/HyperSyncSource.res.mjs +32 -27
  65. package/src/sources/RpcSource.res +14 -10
  66. package/src/sources/RpcSource.res.mjs +11 -9
  67. package/src/sources/SimulateSource.res +4 -2
  68. package/src/sources/SimulateSource.res.mjs +1 -0
  69. package/src/sources/Source.res +5 -1
  70. package/src/sources/SourceManager.res +17 -16
  71. package/src/sources/SourceManager.res.mjs +10 -15
  72. package/src/sources/Svm.res +23 -6
  73. package/src/sources/Svm.res.mjs +24 -6
  74. package/src/sources/SvmHyperSyncClient.res +3 -29
  75. package/src/sources/SvmHyperSyncSource.res +78 -96
  76. package/src/sources/SvmHyperSyncSource.res.mjs +79 -91
  77. package/src/sources/TransactionStore.res +128 -0
  78. package/src/sources/TransactionStore.res.mjs +97 -0
  79. package/src/tui/Tui.res +13 -16
  80. package/src/tui/Tui.res.mjs +12 -14
  81. package/svm.schema.json +30 -37
  82. package/src/bindings/Hrtime.res +0 -58
  83. package/src/bindings/Hrtime.res.mjs +0 -90
  84. package/src/bindings/Hrtime.resi +0 -30
@@ -14,6 +14,16 @@ function deriveEffectiveStartBlock(registrationBlock, contractStartBlock) {
14
14
  return Primitive_int.max(Primitive_int.max(registrationBlock, 0), Stdlib_Option.getOr(contractStartBlock, 0));
15
15
  }
16
16
 
17
+ function deriveContractNameByAddress(addressesByContractName) {
18
+ let result = {};
19
+ Utils.Dict.forEachWithKey(addressesByContractName, (addresses, contractName) => {
20
+ for (let i = 0, i_finish = addresses.length; i < i_finish; ++i) {
21
+ result[addresses[i]] = contractName;
22
+ }
23
+ });
24
+ return result;
25
+ }
26
+
17
27
  function calculateEstResponseSize(p, fromBlock, toBlock, maxQueryBlockNumber) {
18
28
  if (p.prevQueryRange <= 0) {
19
29
  return 10000;
@@ -72,6 +82,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
72
82
  latestFetchedBlock: p1.latestFetchedBlock,
73
83
  selection: p1.selection,
74
84
  addressesByContractName: p1.addressesByContractName,
85
+ contractNameByAddress: p1.contractNameByAddress,
75
86
  mergeBlock: potentialMergeBlock,
76
87
  dynamicContract: p1.dynamicContract,
77
88
  mutPendingQueries: p1.mutPendingQueries,
@@ -85,6 +96,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
85
96
  latestFetchedBlock: p2.latestFetchedBlock,
86
97
  selection: p2.selection,
87
98
  addressesByContractName: p2.addressesByContractName,
99
+ contractNameByAddress: p2.contractNameByAddress,
88
100
  mergeBlock: potentialMergeBlock,
89
101
  dynamicContract: p2.dynamicContract,
90
102
  mutPendingQueries: p2.mutPendingQueries,
@@ -107,6 +119,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
107
119
  },
108
120
  selection: p1.selection,
109
121
  addressesByContractName: {},
122
+ contractNameByAddress: {},
110
123
  mergeBlock: undefined,
111
124
  dynamicContract: contractName,
112
125
  mutPendingQueries: [],
@@ -121,6 +134,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
121
134
  latestFetchedBlock: p1.latestFetchedBlock,
122
135
  selection: p1.selection,
123
136
  addressesByContractName: p1.addressesByContractName,
137
+ contractNameByAddress: p1.contractNameByAddress,
124
138
  mergeBlock: potentialMergeBlock,
125
139
  dynamicContract: p1.dynamicContract,
126
140
  mutPendingQueries: p1.mutPendingQueries,
@@ -137,6 +151,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
137
151
  latestFetchedBlock: p2.latestFetchedBlock,
138
152
  selection: p2.selection,
139
153
  addressesByContractName: p2.addressesByContractName,
154
+ contractNameByAddress: p2.contractNameByAddress,
140
155
  mergeBlock: potentialMergeBlock,
141
156
  dynamicContract: p2.dynamicContract,
142
157
  mutPendingQueries: p2.mutPendingQueries,
@@ -161,6 +176,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
161
176
  latestFetchedBlock: continuingBase.latestFetchedBlock,
162
177
  selection: continuingBase.selection,
163
178
  addressesByContractName: abcFull,
179
+ contractNameByAddress: continuingBase.contractNameByAddress,
164
180
  mergeBlock: continuingBase.mergeBlock,
165
181
  dynamicContract: continuingBase.dynamicContract,
166
182
  mutPendingQueries: continuingBase.mutPendingQueries,
@@ -176,6 +192,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
176
192
  latestFetchedBlock: continuingBase.latestFetchedBlock,
177
193
  selection: continuingBase.selection,
178
194
  addressesByContractName: abcRest,
195
+ contractNameByAddress: continuingBase.contractNameByAddress,
179
196
  mergeBlock: continuingBase.mergeBlock,
180
197
  dynamicContract: continuingBase.dynamicContract,
181
198
  mutPendingQueries: [],
@@ -193,6 +210,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
193
210
  latestFetchedBlock: continuingBase.latestFetchedBlock,
194
211
  selection: continuingBase.selection,
195
212
  addressesByContractName: abc,
213
+ contractNameByAddress: continuingBase.contractNameByAddress,
196
214
  mergeBlock: continuingBase.mergeBlock,
197
215
  dynamicContract: continuingBase.dynamicContract,
198
216
  mutPendingQueries: continuingBase.mutPendingQueries,
@@ -291,7 +309,20 @@ function make(partitions, maxAddrInPartition, nextPartitionIndex, dynamicContrac
291
309
  for (let idx$2 = 0; idx$2 < partitionsCount; ++idx$2) {
292
310
  let p$1 = newPartitions[idx$2];
293
311
  idsInAscOrder[idx$2] = p$1.id;
294
- entities[p$1.id] = p$1;
312
+ entities[p$1.id] = {
313
+ id: p$1.id,
314
+ latestFetchedBlock: p$1.latestFetchedBlock,
315
+ selection: p$1.selection,
316
+ addressesByContractName: p$1.addressesByContractName,
317
+ contractNameByAddress: deriveContractNameByAddress(p$1.addressesByContractName),
318
+ mergeBlock: p$1.mergeBlock,
319
+ dynamicContract: p$1.dynamicContract,
320
+ mutPendingQueries: p$1.mutPendingQueries,
321
+ prevQueryRange: p$1.prevQueryRange,
322
+ prevPrevQueryRange: p$1.prevPrevQueryRange,
323
+ prevRangeSize: p$1.prevRangeSize,
324
+ latestBlockRangeUpdateBlock: p$1.latestBlockRangeUpdateBlock
325
+ };
295
326
  }
296
327
  return {
297
328
  idsInAscOrder: idsInAscOrder,
@@ -385,6 +416,7 @@ function handleQueryResponse(optimizedPartitions, query, knownHeight, itemsCount
385
416
  let updatedMainPartition_id = p$1.id;
386
417
  let updatedMainPartition_selection = p$1.selection;
387
418
  let updatedMainPartition_addressesByContractName = p$1.addressesByContractName;
419
+ let updatedMainPartition_contractNameByAddress = p$1.contractNameByAddress;
388
420
  let updatedMainPartition_mergeBlock = p$1.mergeBlock;
389
421
  let updatedMainPartition_dynamicContract = p$1.dynamicContract;
390
422
  let updatedMainPartition_mutPendingQueries = p$1.mutPendingQueries;
@@ -394,6 +426,7 @@ function handleQueryResponse(optimizedPartitions, query, knownHeight, itemsCount
394
426
  latestFetchedBlock: updatedLatestFetchedBlock,
395
427
  selection: updatedMainPartition_selection,
396
428
  addressesByContractName: updatedMainPartition_addressesByContractName,
429
+ contractNameByAddress: updatedMainPartition_contractNameByAddress,
397
430
  mergeBlock: updatedMainPartition_mergeBlock,
398
431
  dynamicContract: updatedMainPartition_dynamicContract,
399
432
  mutPendingQueries: updatedMainPartition_mutPendingQueries,
@@ -641,6 +674,7 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
641
674
  latestFetchedBlock: latestFetchedBlock,
642
675
  selection: normalSelection,
643
676
  addressesByContractName: addressesByContractName,
677
+ contractNameByAddress: {},
644
678
  mergeBlock: undefined,
645
679
  dynamicContract: isDynamic ? contractName : undefined,
646
680
  mutPendingQueries: [],
@@ -692,6 +726,7 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
692
726
  latestFetchedBlock: currentP.latestFetchedBlock,
693
727
  selection: currentP.selection,
694
728
  addressesByContractName: currentP.addressesByContractName,
729
+ contractNameByAddress: currentP.contractNameByAddress,
695
730
  mergeBlock: currentPBlock < nextPBlock ? nextPBlock : undefined,
696
731
  dynamicContract: currentP.dynamicContract,
697
732
  mutPendingQueries: currentP.mutPendingQueries,
@@ -705,6 +740,7 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
705
740
  latestFetchedBlock: nextP.latestFetchedBlock,
706
741
  selection: nextP.selection,
707
742
  addressesByContractName: mergedAddresses,
743
+ contractNameByAddress: nextP.contractNameByAddress,
708
744
  mergeBlock: nextP.mergeBlock,
709
745
  dynamicContract: nextP.dynamicContract,
710
746
  mutPendingQueries: nextP.mutPendingQueries,
@@ -719,6 +755,7 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
719
755
  latestFetchedBlock: currentP.latestFetchedBlock,
720
756
  selection: currentP.selection,
721
757
  addressesByContractName: mergedAddresses,
758
+ contractNameByAddress: currentP.contractNameByAddress,
722
759
  mergeBlock: currentP.mergeBlock,
723
760
  dynamicContract: currentP.dynamicContract,
724
761
  mutPendingQueries: currentP.mutPendingQueries,
@@ -864,6 +901,7 @@ function registerDynamicContracts(fetchState, items) {
864
901
  latestFetchedBlock: p.latestFetchedBlock,
865
902
  selection: p.selection,
866
903
  addressesByContractName: restAddressesByContractName,
904
+ contractNameByAddress: p.contractNameByAddress,
867
905
  mergeBlock: p.mergeBlock,
868
906
  dynamicContract: p.dynamicContract,
869
907
  mutPendingQueries: p.mutPendingQueries,
@@ -879,6 +917,7 @@ function registerDynamicContracts(fetchState, items) {
879
917
  latestFetchedBlock: p.latestFetchedBlock,
880
918
  selection: fetchState.normalSelection,
881
919
  addressesByContractName: addressesByContractName,
920
+ contractNameByAddress: {},
882
921
  mergeBlock: undefined,
883
922
  dynamicContract: contractName,
884
923
  mutPendingQueries: p.mutPendingQueries,
@@ -894,6 +933,7 @@ function registerDynamicContracts(fetchState, items) {
894
933
  latestFetchedBlock: p.latestFetchedBlock,
895
934
  selection: p.selection,
896
935
  addressesByContractName: p.addressesByContractName,
936
+ contractNameByAddress: p.contractNameByAddress,
897
937
  mergeBlock: p.mergeBlock,
898
938
  dynamicContract: contractName,
899
939
  mutPendingQueries: p.mutPendingQueries,
@@ -965,8 +1005,8 @@ function startFetchingQueries(param, queries) {
965
1005
  }
966
1006
  }
967
1007
 
968
- function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber, maybeChunkRange, partition, selection, addressesByContractName, indexingAddresses) {
969
- if (rangeFromBlock > maxQueryBlockNumber) {
1008
+ function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber, maybeChunkRange, maxChunks, partition, selection, addressesByContractName) {
1009
+ if (!(rangeFromBlock <= maxQueryBlockNumber && maxChunks > 0)) {
970
1010
  return;
971
1011
  }
972
1012
  if (rangeEndBlock !== undefined && rangeFromBlock > rangeEndBlock) {
@@ -975,19 +1015,11 @@ function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock
975
1015
  if (maybeChunkRange !== undefined) {
976
1016
  let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : maxQueryBlockNumber;
977
1017
  let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
978
- let probeSize = Js_math.ceil_int(maybeChunkRange * 0.9);
979
- let getChunkSize = chunkIdx => {
980
- if (chunkIdx < 2) {
981
- return probeSize;
982
- } else {
983
- return chunkSize;
984
- }
985
- };
986
- if ((((rangeFromBlock + probeSize | 0) + probeSize | 0) - 1 | 0) <= maxBlock) {
1018
+ if (((rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0) <= maxBlock) {
987
1019
  let chunkFromBlock = rangeFromBlock;
988
1020
  let chunkIdx = 0;
989
- while (chunkIdx < 5 && ((chunkFromBlock + getChunkSize(chunkIdx) | 0) - 1 | 0) <= maxBlock) {
990
- let chunkToBlock = (chunkFromBlock + getChunkSize(chunkIdx) | 0) - 1 | 0;
1021
+ while (chunkIdx < maxChunks && ((chunkFromBlock + chunkSize | 0) - 1 | 0) <= maxBlock) {
1022
+ let chunkToBlock = (chunkFromBlock + chunkSize | 0) - 1 | 0;
991
1023
  queries.push({
992
1024
  partitionId: partitionId,
993
1025
  fromBlock: chunkFromBlock,
@@ -998,7 +1030,7 @@ function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock
998
1030
  progress: 0,
999
1031
  selection: selection,
1000
1032
  addressesByContractName: addressesByContractName,
1001
- indexingAddresses: indexingAddresses
1033
+ contractNameByAddress: partition.contractNameByAddress
1002
1034
  });
1003
1035
  chunkFromBlock = chunkToBlock + 1 | 0;
1004
1036
  chunkIdx = chunkIdx + 1 | 0;
@@ -1015,7 +1047,7 @@ function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock
1015
1047
  progress: 0,
1016
1048
  selection: selection,
1017
1049
  addressesByContractName: addressesByContractName,
1018
- indexingAddresses: indexingAddresses
1050
+ contractNameByAddress: partition.contractNameByAddress
1019
1051
  });
1020
1052
  return;
1021
1053
  }
@@ -1029,14 +1061,13 @@ function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock
1029
1061
  progress: 0,
1030
1062
  selection: selection,
1031
1063
  addressesByContractName: addressesByContractName,
1032
- indexingAddresses: indexingAddresses
1064
+ contractNameByAddress: partition.contractNameByAddress
1033
1065
  });
1034
1066
  }
1035
1067
 
1036
1068
  function getNextQuery(fetchState, budget, chainPendingBudget) {
1037
1069
  let knownHeight = fetchState.knownHeight;
1038
1070
  let blockLag = fetchState.blockLag;
1039
- let indexingAddresses = fetchState.indexingAddresses;
1040
1071
  let optimizedPartitions = fetchState.optimizedPartitions;
1041
1072
  let headBlockNumber = knownHeight - blockLag | 0;
1042
1073
  if (headBlockNumber <= 0) {
@@ -1083,9 +1114,10 @@ function getNextQuery(fetchState, budget, chainPendingBudget) {
1083
1114
  if (pq.fromBlock > cursor) {
1084
1115
  let addressesByContractName = p.addressesByContractName;
1085
1116
  let selection = p.selection;
1117
+ let maxChunks = (10 - pendingCount | 0) - (queries.length - partitionQueriesStart | 0) | 0;
1086
1118
  let rangeEndBlock = Utils.$$Math.minOptInt(pq.fromBlock - 1 | 0, queryEndBlock$2);
1087
1119
  let rangeFromBlock = cursor;
1088
- if (rangeFromBlock <= maxQueryBlockNumber) {
1120
+ if (rangeFromBlock <= maxQueryBlockNumber && maxChunks > 0) {
1089
1121
  let exit = 0;
1090
1122
  if (!(rangeEndBlock !== undefined && rangeFromBlock > rangeEndBlock)) {
1091
1123
  exit = 1;
@@ -1094,19 +1126,11 @@ function getNextQuery(fetchState, budget, chainPendingBudget) {
1094
1126
  if (maybeChunkRange !== undefined) {
1095
1127
  let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : maxQueryBlockNumber;
1096
1128
  let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
1097
- let probeSize = Js_math.ceil_int(maybeChunkRange * 0.9);
1098
- let getChunkSize = chunkIdx => {
1099
- if (chunkIdx < 2) {
1100
- return probeSize;
1101
- } else {
1102
- return chunkSize;
1103
- }
1104
- };
1105
- if ((((rangeFromBlock + getChunkSize(0) | 0) + getChunkSize(1) | 0) - 1 | 0) <= maxBlock) {
1129
+ if (((rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0) <= maxBlock) {
1106
1130
  let chunkFromBlock = rangeFromBlock;
1107
1131
  let chunkIdx = 0;
1108
- while (chunkIdx < 5 && ((chunkFromBlock + getChunkSize(chunkIdx) | 0) - 1 | 0) <= maxBlock) {
1109
- let chunkToBlock = (chunkFromBlock + getChunkSize(chunkIdx) | 0) - 1 | 0;
1132
+ while (chunkIdx < maxChunks && ((chunkFromBlock + chunkSize | 0) - 1 | 0) <= maxBlock) {
1133
+ let chunkToBlock = (chunkFromBlock + chunkSize | 0) - 1 | 0;
1110
1134
  queries.push({
1111
1135
  partitionId: partitionId,
1112
1136
  fromBlock: chunkFromBlock,
@@ -1117,7 +1141,7 @@ function getNextQuery(fetchState, budget, chainPendingBudget) {
1117
1141
  progress: 0,
1118
1142
  selection: selection,
1119
1143
  addressesByContractName: addressesByContractName,
1120
- indexingAddresses: indexingAddresses
1144
+ contractNameByAddress: p.contractNameByAddress
1121
1145
  });
1122
1146
  chunkFromBlock = chunkToBlock + 1 | 0;
1123
1147
  chunkIdx = chunkIdx + 1 | 0;
@@ -1133,7 +1157,7 @@ function getNextQuery(fetchState, budget, chainPendingBudget) {
1133
1157
  progress: 0,
1134
1158
  selection: selection,
1135
1159
  addressesByContractName: addressesByContractName,
1136
- indexingAddresses: indexingAddresses
1160
+ contractNameByAddress: p.contractNameByAddress
1137
1161
  });
1138
1162
  }
1139
1163
  } else {
@@ -1147,7 +1171,7 @@ function getNextQuery(fetchState, budget, chainPendingBudget) {
1147
1171
  progress: 0,
1148
1172
  selection: selection,
1149
1173
  addressesByContractName: addressesByContractName,
1150
- indexingAddresses: indexingAddresses
1174
+ contractNameByAddress: p.contractNameByAddress
1151
1175
  });
1152
1176
  }
1153
1177
  }
@@ -1170,8 +1194,9 @@ function getNextQuery(fetchState, budget, chainPendingBudget) {
1170
1194
  if (canContinue) {
1171
1195
  let addressesByContractName$1 = p.addressesByContractName;
1172
1196
  let selection$1 = p.selection;
1197
+ let maxChunks$1 = (10 - pendingCount | 0) - (queries.length - partitionQueriesStart | 0) | 0;
1173
1198
  let rangeFromBlock$1 = cursor;
1174
- if (rangeFromBlock$1 <= maxQueryBlockNumber) {
1199
+ if (rangeFromBlock$1 <= maxQueryBlockNumber && maxChunks$1 > 0) {
1175
1200
  let exit$1 = 0;
1176
1201
  if (!(queryEndBlock$2 !== undefined && rangeFromBlock$1 > queryEndBlock$2)) {
1177
1202
  exit$1 = 1;
@@ -1180,19 +1205,11 @@ function getNextQuery(fetchState, budget, chainPendingBudget) {
1180
1205
  if (maybeChunkRange !== undefined) {
1181
1206
  let maxBlock$1 = queryEndBlock$2 !== undefined ? queryEndBlock$2 : maxQueryBlockNumber;
1182
1207
  let chunkSize$1 = Js_math.ceil_int(maybeChunkRange * 1.8);
1183
- let probeSize$1 = Js_math.ceil_int(maybeChunkRange * 0.9);
1184
- let getChunkSize$1 = chunkIdx => {
1185
- if (chunkIdx < 2) {
1186
- return probeSize$1;
1187
- } else {
1188
- return chunkSize$1;
1189
- }
1190
- };
1191
- if ((((rangeFromBlock$1 + getChunkSize$1(0) | 0) + getChunkSize$1(1) | 0) - 1 | 0) <= maxBlock$1) {
1208
+ if (((rangeFromBlock$1 + (chunkSize$1 << 1) | 0) - 1 | 0) <= maxBlock$1) {
1192
1209
  let chunkFromBlock$1 = rangeFromBlock$1;
1193
1210
  let chunkIdx$1 = 0;
1194
- while (chunkIdx$1 < 5 && ((chunkFromBlock$1 + getChunkSize$1(chunkIdx$1) | 0) - 1 | 0) <= maxBlock$1) {
1195
- let chunkToBlock$1 = (chunkFromBlock$1 + getChunkSize$1(chunkIdx$1) | 0) - 1 | 0;
1211
+ while (chunkIdx$1 < maxChunks$1 && ((chunkFromBlock$1 + chunkSize$1 | 0) - 1 | 0) <= maxBlock$1) {
1212
+ let chunkToBlock$1 = (chunkFromBlock$1 + chunkSize$1 | 0) - 1 | 0;
1196
1213
  queries.push({
1197
1214
  partitionId: partitionId,
1198
1215
  fromBlock: chunkFromBlock$1,
@@ -1203,7 +1220,7 @@ function getNextQuery(fetchState, budget, chainPendingBudget) {
1203
1220
  progress: 0,
1204
1221
  selection: selection$1,
1205
1222
  addressesByContractName: addressesByContractName$1,
1206
- indexingAddresses: indexingAddresses
1223
+ contractNameByAddress: p.contractNameByAddress
1207
1224
  });
1208
1225
  chunkFromBlock$1 = chunkToBlock$1 + 1 | 0;
1209
1226
  chunkIdx$1 = chunkIdx$1 + 1 | 0;
@@ -1219,7 +1236,7 @@ function getNextQuery(fetchState, budget, chainPendingBudget) {
1219
1236
  progress: 0,
1220
1237
  selection: selection$1,
1221
1238
  addressesByContractName: addressesByContractName$1,
1222
- indexingAddresses: indexingAddresses
1239
+ contractNameByAddress: p.contractNameByAddress
1223
1240
  });
1224
1241
  }
1225
1242
  } else {
@@ -1233,17 +1250,12 @@ function getNextQuery(fetchState, budget, chainPendingBudget) {
1233
1250
  progress: 0,
1234
1251
  selection: selection$1,
1235
1252
  addressesByContractName: addressesByContractName$1,
1236
- indexingAddresses: indexingAddresses
1253
+ contractNameByAddress: p.contractNameByAddress
1237
1254
  });
1238
1255
  }
1239
1256
  }
1240
1257
  }
1241
1258
  }
1242
- let maxNewChunks = Primitive_int.max(0, 10 - pendingCount | 0);
1243
- let generatedCount = queries.length - partitionQueriesStart | 0;
1244
- if (generatedCount > maxNewChunks) {
1245
- queries.splice(partitionQueriesStart + maxNewChunks | 0, generatedCount - maxNewChunks | 0);
1246
- }
1247
1259
  idxRef = idxRef + 1 | 0;
1248
1260
  };
1249
1261
  if (Utils.$$Array.isEmpty(queries)) {
@@ -1340,6 +1352,7 @@ function make$1(startBlock, endBlock, eventConfigs, addresses, maxAddrInPartitio
1340
1352
  dependsOnAddresses: false
1341
1353
  },
1342
1354
  addressesByContractName: {},
1355
+ contractNameByAddress: {},
1343
1356
  mergeBlock: undefined,
1344
1357
  dynamicContract: undefined,
1345
1358
  mutPendingQueries: [],
@@ -1516,6 +1529,7 @@ function rollback(fetchState, targetBlockNumber) {
1516
1529
  latestFetchedBlock: p.latestFetchedBlock,
1517
1530
  selection: p.selection,
1518
1531
  addressesByContractName: rollbackedAddressesByContractName,
1532
+ contractNameByAddress: p.contractNameByAddress,
1519
1533
  mergeBlock: mergeBlock$1,
1520
1534
  dynamicContract: p.dynamicContract,
1521
1535
  mutPendingQueries: rollbackPendingQueries(p.mutPendingQueries, targetBlockNumber),
@@ -1537,6 +1551,7 @@ function rollback(fetchState, targetBlockNumber) {
1537
1551
  }) : p.latestFetchedBlock,
1538
1552
  selection: p.selection,
1539
1553
  addressesByContractName: p.addressesByContractName,
1554
+ contractNameByAddress: p.contractNameByAddress,
1540
1555
  mergeBlock: p.mergeBlock,
1541
1556
  dynamicContract: p.dynamicContract,
1542
1557
  mutPendingQueries: rollbackPendingQueries(p.mutPendingQueries, targetBlockNumber),
@@ -1582,6 +1597,7 @@ function resetPendingQueries(fetchState) {
1582
1597
  latestFetchedBlock: partition.latestFetchedBlock,
1583
1598
  selection: partition.selection,
1584
1599
  addressesByContractName: partition.addressesByContractName,
1600
+ contractNameByAddress: partition.contractNameByAddress,
1585
1601
  mergeBlock: partition.mergeBlock,
1586
1602
  dynamicContract: partition.dynamicContract,
1587
1603
  mutPendingQueries: kept,
@@ -1748,6 +1764,7 @@ let maxPendingChunksPerPartition = 10;
1748
1764
 
1749
1765
  export {
1750
1766
  deriveEffectiveStartBlock,
1767
+ deriveContractNameByAddress,
1751
1768
  defaultEstResponseSize,
1752
1769
  calculateEstResponseSize,
1753
1770
  getMinHistoryRange,
@@ -1767,8 +1784,8 @@ export {
1767
1784
  registerDynamicContracts,
1768
1785
  handleQueryResult,
1769
1786
  startFetchingQueries,
1770
- pushQueriesForRange,
1771
1787
  maxPendingChunksPerPartition,
1788
+ pushQueriesForRange,
1772
1789
  getNextQuery,
1773
1790
  hasReadyItem,
1774
1791
  getReadyItemsCount,
@@ -103,6 +103,7 @@ let applyRegistrations = (~config: Config.t): Config.t => {
103
103
  isWildcard,
104
104
  handler,
105
105
  contractRegister,
106
+ clientAddressFilter: ?EventConfigBuilder.buildAddressFilter([], ~isWildcard),
106
107
  dependsOnAddresses: Internal.dependsOnAddresses(
107
108
  ~isWildcard,
108
109
  ~filterByAddresses=false,
@@ -144,7 +145,10 @@ let applyRegistrations = (~config: Config.t): Config.t => {
144
145
  contractRegister,
145
146
  getEventFiltersOrThrow,
146
147
  filterByAddresses,
147
- clientAddressFilter: ?EventConfigBuilder.buildAddressFilter(addressFilterParamGroups),
148
+ clientAddressFilter: ?EventConfigBuilder.buildAddressFilter(
149
+ addressFilterParamGroups,
150
+ ~isWildcard,
151
+ ),
148
152
  dependsOnAddresses: Internal.dependsOnAddresses(~isWildcard, ~filterByAddresses),
149
153
  } :> Internal.eventConfig)
150
154
  | Svm =>
@@ -155,6 +159,11 @@ let applyRegistrations = (~config: Config.t): Config.t => {
155
159
  isWildcard,
156
160
  handler,
157
161
  contractRegister,
162
+ clientAddressFilter: ?EventConfigBuilder.buildAddressFilter(
163
+ [],
164
+ ~isWildcard,
165
+ ~srcAddressExpr="event.programId",
166
+ ),
158
167
  dependsOnAddresses: Internal.dependsOnAddresses(
159
168
  ~isWildcard,
160
169
  ~filterByAddresses=false,
@@ -79,21 +79,28 @@ function applyRegistrations(config) {
79
79
  newrecord.getEventFiltersOrThrow = match$1.getEventFiltersOrThrow;
80
80
  newrecord.contractRegister = contractRegister;
81
81
  newrecord.handler = handler;
82
- newrecord.clientAddressFilter = EventConfigBuilder.buildAddressFilter(match$1.addressFilterParamGroups);
82
+ newrecord.clientAddressFilter = EventConfigBuilder.buildAddressFilter(match$1.addressFilterParamGroups, isWildcard, undefined);
83
83
  newrecord.dependsOnAddresses = Internal.dependsOnAddresses(isWildcard, filterByAddresses);
84
84
  newrecord.filterByAddresses = filterByAddresses;
85
85
  newrecord.isWildcard = isWildcard;
86
86
  return newrecord;
87
87
  case "fuel" :
88
+ let newrecord$1 = {...ev};
89
+ newrecord$1.contractRegister = contractRegister;
90
+ newrecord$1.handler = handler;
91
+ newrecord$1.clientAddressFilter = EventConfigBuilder.buildAddressFilter([], isWildcard, undefined);
92
+ newrecord$1.dependsOnAddresses = Internal.dependsOnAddresses(isWildcard, false);
93
+ newrecord$1.isWildcard = isWildcard;
94
+ return newrecord$1;
88
95
  case "svm" :
89
- break;
96
+ let newrecord$2 = {...ev};
97
+ newrecord$2.contractRegister = contractRegister;
98
+ newrecord$2.handler = handler;
99
+ newrecord$2.clientAddressFilter = EventConfigBuilder.buildAddressFilter([], isWildcard, "event.programId");
100
+ newrecord$2.dependsOnAddresses = Internal.dependsOnAddresses(isWildcard, false);
101
+ newrecord$2.isWildcard = isWildcard;
102
+ return newrecord$2;
90
103
  }
91
- let newrecord$1 = {...ev};
92
- newrecord$1.contractRegister = contractRegister;
93
- newrecord$1.handler = handler;
94
- newrecord$1.dependsOnAddresses = Internal.dependsOnAddresses(isWildcard, false);
95
- newrecord$1.isWildcard = isWildcard;
96
- return newrecord$1;
97
104
  });
98
105
  return {
99
106
  name: contract.name,
package/src/Internal.res CHANGED
@@ -58,7 +58,6 @@ type evmTransactionField =
58
58
  | @as("root") Root
59
59
  | @as("status") Status
60
60
  | @as("yParity") YParity
61
- | @as("accessList") AccessList
62
61
  | @as("maxFeePerBlobGas") MaxFeePerBlobGas
63
62
  | @as("blobVersionedHashes") BlobVersionedHashes
64
63
  | @as("type") Type
@@ -67,6 +66,7 @@ type evmTransactionField =
67
66
  | @as("l1GasUsed") L1GasUsed
68
67
  | @as("l1FeeScalar") L1FeeScalar
69
68
  | @as("gasUsedForL1") GasUsedForL1
69
+ | @as("accessList") AccessList
70
70
  | @as("authorizationList") AuthorizationList
71
71
 
72
72
  let allEvmBlockFields: array<evmBlockField> = [
@@ -123,7 +123,6 @@ let allEvmTransactionFields: array<evmTransactionField> = [
123
123
  Root,
124
124
  Status,
125
125
  YParity,
126
- AccessList,
127
126
  MaxFeePerBlobGas,
128
127
  BlobVersionedHashes,
129
128
  Type,
@@ -132,10 +131,41 @@ let allEvmTransactionFields: array<evmTransactionField> = [
132
131
  L1GasUsed,
133
132
  L1FeeScalar,
134
133
  GasUsedForL1,
134
+ AccessList,
135
135
  AuthorizationList,
136
136
  ]
137
137
  let evmTransactionFieldSchema = S.enum(allEvmTransactionFields)
138
138
 
139
+ // SVM transaction fields. Order mirrors the Rust `SvmTxField` ordinals (the bit
140
+ // position in the selection mask) and `Svm.res` `transactionFields`.
141
+ type svmTransactionField =
142
+ | @as("transactionIndex") TransactionIndex
143
+ | @as("signatures") Signatures
144
+ | @as("feePayer") FeePayer
145
+ | @as("success") Success
146
+ | @as("err") Err
147
+ | @as("fee") Fee
148
+ | @as("computeUnitsConsumed") ComputeUnitsConsumed
149
+ | @as("accountKeys") AccountKeys
150
+ | @as("recentBlockhash") RecentBlockhash
151
+ | @as("version") Version
152
+ | @as("tokenBalances") TokenBalances
153
+
154
+ let allSvmTransactionFields: array<svmTransactionField> = [
155
+ TransactionIndex,
156
+ Signatures,
157
+ FeePayer,
158
+ Success,
159
+ Err,
160
+ Fee,
161
+ ComputeUnitsConsumed,
162
+ AccountKeys,
163
+ RecentBlockhash,
164
+ Version,
165
+ TokenBalances,
166
+ ]
167
+ let svmTransactionFieldSchema = S.enum(allSvmTransactionFields)
168
+
139
169
  // Static sets of nullable field names — used by RpcSource and HyperSyncSource to wrap schemas with S.nullable
140
170
  let evmNullableBlockFields = Utils.Set.fromArray(
141
171
  (
@@ -277,7 +307,10 @@ type event
277
307
  // modules, not here, and are distinct per ecosystem.
278
308
  type eventPayload
279
309
 
280
- external payloadToEvent: eventPayload => event = "%identity"
310
+ // Generic access to the payload's `transaction`, written at batch prep for
311
+ // store-backed ecosystems (HyperSync) and present inline otherwise.
312
+ @get external getPayloadTransaction: eventPayload => Nullable.t<eventTransaction> = "transaction"
313
+ @set external setPayloadTransaction: (eventPayload, eventTransaction) => unit = "transaction"
281
314
 
282
315
  type genericLoaderArgs<'event, 'context> = {
283
316
  event: 'event,
@@ -382,6 +415,11 @@ type eventConfig = private {
382
415
  paramsRawEventSchema: S.schema<eventParams>,
383
416
  simulateParamsSchema: S.schema<eventParams>,
384
417
  startBlock: option<int>,
418
+ // Field names selected for the chain's transaction-store materialisation
419
+ // (camelCase, matching the ecosystem's `transactionFields`). Stored as a
420
+ // string set so the shared mask logic is ecosystem-agnostic; sources recover
421
+ // the typed view where they need it.
422
+ selectedTransactionFields: Utils.Set.t<string>,
385
423
  }
386
424
 
387
425
  type fuelEventKind =
@@ -419,7 +457,6 @@ type evmEventConfig = {
419
457
  ...eventConfig,
420
458
  getEventFiltersOrThrow: ChainMap.Chain.t => eventFilters,
421
459
  selectedBlockFields: Utils.Set.t<evmBlockField>,
422
- selectedTransactionFields: Utils.Set.t<evmTransactionField>,
423
460
  sighash: string,
424
461
  topicCount: int,
425
462
  paramsMetadata: array<paramMeta>,
@@ -456,9 +493,7 @@ type svmInstructionEventConfig = {
456
493
  `dN` selector at query time and the dispatch-key precomputation in the
457
494
  router. */
458
495
  discriminatorByteLen: int,
459
- includeTransaction: bool,
460
496
  includeLogs: bool,
461
- includeTokenBalances: bool,
462
497
  /** Disjunctive normal form: outer array is OR of AND-groups, inner array is
463
498
  AND across positions. Empty outer array means "no account filter". */
464
499
  accountFilters: array<svmAccountFilterGroup>,
@@ -502,6 +537,9 @@ type eventItem = private {
502
537
  blockNumber: int,
503
538
  blockHash: string,
504
539
  logIndex: int,
540
+ // Within-block transaction index — the key into the per-chain transaction
541
+ // store. Unused (0) for ecosystems that carry the transaction inline (Fuel).
542
+ transactionIndex: int,
505
543
  payload: eventPayload,
506
544
  }
507
545
 
@@ -554,6 +592,7 @@ type item =
554
592
  blockNumber: int,
555
593
  blockHash: string,
556
594
  logIndex: int,
595
+ transactionIndex: int,
557
596
  payload: eventPayload,
558
597
  })
559
598
  | @as(1) Block({onBlockConfig: onBlockConfig, blockNumber: int, logIndex: int})
@@ -653,7 +692,7 @@ type effect = {
653
692
  input: S.t<effectInput>,
654
693
  // The number of functions that are currently running.
655
694
  mutable activeCallsCount: int,
656
- mutable prevCallStartTimerRef: Hrtime.timeRef,
695
+ mutable prevCallStartTimerRef: Performance.timeRef,
657
696
  rateLimit: option<rateLimitState>,
658
697
  }
659
698
  let cacheTablePrefix = "envio_effect_"
@@ -60,7 +60,6 @@ let allEvmTransactionFields = [
60
60
  "root",
61
61
  "status",
62
62
  "yParity",
63
- "accessList",
64
63
  "maxFeePerBlobGas",
65
64
  "blobVersionedHashes",
66
65
  "type",
@@ -69,11 +68,28 @@ let allEvmTransactionFields = [
69
68
  "l1GasUsed",
70
69
  "l1FeeScalar",
71
70
  "gasUsedForL1",
71
+ "accessList",
72
72
  "authorizationList"
73
73
  ];
74
74
 
75
75
  let evmTransactionFieldSchema = S$RescriptSchema.$$enum(allEvmTransactionFields);
76
76
 
77
+ let allSvmTransactionFields = [
78
+ "transactionIndex",
79
+ "signatures",
80
+ "feePayer",
81
+ "success",
82
+ "err",
83
+ "fee",
84
+ "computeUnitsConsumed",
85
+ "accountKeys",
86
+ "recentBlockhash",
87
+ "version",
88
+ "tokenBalances"
89
+ ];
90
+
91
+ let svmTransactionFieldSchema = S$RescriptSchema.$$enum(allSvmTransactionFields);
92
+
77
93
  let evmNullableBlockFields = new Set([
78
94
  "nonce",
79
95
  "difficulty",
@@ -160,6 +176,8 @@ export {
160
176
  evmBlockFieldSchema,
161
177
  allEvmTransactionFields,
162
178
  evmTransactionFieldSchema,
179
+ allSvmTransactionFields,
180
+ svmTransactionFieldSchema,
163
181
  evmNullableBlockFields,
164
182
  evmNullableTransactionFields,
165
183
  dependsOnAddresses,