@aztec/pxe 0.0.1-commit.3100065 → 0.0.1-commit.330febf

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 (207) hide show
  1. package/dest/bin/check_oracle_version.js +5 -46
  2. package/dest/bin/index.d.ts +2 -2
  3. package/dest/bin/index.d.ts.map +1 -1
  4. package/dest/bin/index.js +1 -1
  5. package/dest/bin/oracle_version_helpers.d.ts +8 -39
  6. package/dest/bin/oracle_version_helpers.d.ts.map +1 -1
  7. package/dest/bin/oracle_version_helpers.js +10 -239
  8. package/dest/block_synchronizer/block_synchronizer.d.ts +3 -5
  9. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  10. package/dest/block_synchronizer/block_synchronizer.js +5 -18
  11. package/dest/config/package_info.js +1 -1
  12. package/dest/contract/contract_class_service.d.ts +1 -8
  13. package/dest/contract/contract_class_service.d.ts.map +1 -1
  14. package/dest/contract/contract_class_service.js +8 -40
  15. package/dest/contract/helpers.d.ts +1 -1
  16. package/dest/contract/helpers.d.ts.map +1 -1
  17. package/dest/contract/helpers.js +3 -3
  18. package/dest/contract/skip_sync_contracts.d.ts +11 -0
  19. package/dest/contract/skip_sync_contracts.d.ts.map +1 -0
  20. package/dest/contract/skip_sync_contracts.js +18 -0
  21. package/dest/contract_function_simulator/contract_function_simulator.d.ts +1 -8
  22. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  23. package/dest/contract_function_simulator/contract_function_simulator.js +5 -20
  24. package/dest/contract_function_simulator/index.d.ts +3 -3
  25. package/dest/contract_function_simulator/index.d.ts.map +1 -1
  26. package/dest/contract_function_simulator/index.js +1 -2
  27. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts +7 -9
  28. package/dest/contract_function_simulator/noir-structs/resolved_tx.d.ts.map +1 -1
  29. package/dest/contract_function_simulator/noir-structs/resolved_tx.js +3 -44
  30. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts +5 -4
  31. package/dest/contract_function_simulator/noir-structs/tx_effect_data.d.ts.map +1 -1
  32. package/dest/contract_function_simulator/noir-structs/tx_effect_data.js +2 -2
  33. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts +4 -3
  34. package/dest/contract_function_simulator/oracle/oracle_registry.d.ts.map +1 -1
  35. package/dest/contract_function_simulator/oracle/oracle_registry.js +15 -6
  36. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +87 -35
  37. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
  38. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +297 -287
  39. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -1
  40. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  41. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +11 -8
  42. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +15 -4
  43. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  44. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +168 -53
  45. package/dest/entrypoints/client/bundle/index.d.ts +2 -1
  46. package/dest/entrypoints/client/bundle/index.d.ts.map +1 -1
  47. package/dest/entrypoints/client/bundle/index.js +1 -0
  48. package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
  49. package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
  50. package/dest/entrypoints/client/bundle/utils.js +10 -4
  51. package/dest/entrypoints/client/lazy/index.d.ts +2 -1
  52. package/dest/entrypoints/client/lazy/index.d.ts.map +1 -1
  53. package/dest/entrypoints/client/lazy/index.js +1 -0
  54. package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
  55. package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
  56. package/dest/entrypoints/client/lazy/utils.js +10 -4
  57. package/dest/entrypoints/client/store.d.ts +14 -0
  58. package/dest/entrypoints/client/store.d.ts.map +1 -0
  59. package/dest/entrypoints/client/store.js +42 -0
  60. package/dest/entrypoints/server/index.d.ts +2 -1
  61. package/dest/entrypoints/server/index.d.ts.map +1 -1
  62. package/dest/entrypoints/server/index.js +1 -0
  63. package/dest/entrypoints/server/store.d.ts +18 -0
  64. package/dest/entrypoints/server/store.d.ts.map +1 -0
  65. package/dest/entrypoints/server/store.js +28 -0
  66. package/dest/entrypoints/server/utils.d.ts +1 -1
  67. package/dest/entrypoints/server/utils.d.ts.map +1 -1
  68. package/dest/entrypoints/server/utils.js +8 -2
  69. package/dest/events/event_service.d.ts +13 -6
  70. package/dest/events/event_service.d.ts.map +1 -1
  71. package/dest/events/event_service.js +13 -13
  72. package/dest/logs/log_service.d.ts +15 -6
  73. package/dest/logs/log_service.d.ts.map +1 -1
  74. package/dest/logs/log_service.js +25 -32
  75. package/dest/messages/tx_resolver_service.d.ts +18 -7
  76. package/dest/messages/tx_resolver_service.d.ts.map +1 -1
  77. package/dest/messages/tx_resolver_service.js +13 -7
  78. package/dest/node/benchmarked_node.d.ts +20 -0
  79. package/dest/node/benchmarked_node.d.ts.map +1 -0
  80. package/dest/node/benchmarked_node.js +94 -0
  81. package/dest/node/caching_aztec_node.d.ts +24 -0
  82. package/dest/node/caching_aztec_node.d.ts.map +1 -0
  83. package/dest/node/caching_aztec_node.js +267 -0
  84. package/dest/notes/note_service.d.ts +13 -7
  85. package/dest/notes/note_service.d.ts.map +1 -1
  86. package/dest/notes/note_service.js +10 -10
  87. package/dest/oracle_version.d.ts +2 -2
  88. package/dest/oracle_version.js +5 -5
  89. package/dest/private_kernel/batch_planner.d.ts +1 -1
  90. package/dest/private_kernel/batch_planner.d.ts.map +1 -1
  91. package/dest/private_kernel/batch_planner.js +1 -1
  92. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  93. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  94. package/dest/private_kernel/private_kernel_execution_prover.js +45 -5
  95. package/dest/pxe.d.ts +1 -1
  96. package/dest/pxe.d.ts.map +1 -1
  97. package/dest/pxe.js +39 -19
  98. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  99. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  100. package/dest/storage/contract_store/contract_store.js +2 -2
  101. package/dest/storage/fact_store/fact_store.d.ts +1 -1
  102. package/dest/storage/fact_store/fact_store.js +1 -1
  103. package/dest/storage/fact_store/index.d.ts +2 -2
  104. package/dest/storage/fact_store/index.d.ts.map +1 -1
  105. package/dest/storage/fact_store/index.js +1 -1
  106. package/dest/storage/fact_store/origin_state.d.ts +4 -2
  107. package/dest/storage/fact_store/origin_state.d.ts.map +1 -1
  108. package/dest/storage/fact_store/origin_state.js +8 -1
  109. package/dest/storage/store_identity.d.ts +35 -0
  110. package/dest/storage/store_identity.d.ts.map +1 -0
  111. package/dest/storage/store_identity.js +44 -0
  112. package/dest/storage/tagging_store/sender_tagging_store.d.ts +41 -10
  113. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  114. package/dest/storage/tagging_store/sender_tagging_store.js +81 -29
  115. package/dest/tagging/constants.d.ts +10 -1
  116. package/dest/tagging/constants.d.ts.map +1 -1
  117. package/dest/tagging/constants.js +19 -0
  118. package/dest/tagging/get_all_logs_by_tags.d.ts +29 -8
  119. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  120. package/dest/tagging/get_all_logs_by_tags.js +29 -10
  121. package/dest/tagging/index.d.ts +3 -3
  122. package/dest/tagging/index.d.ts.map +1 -1
  123. package/dest/tagging/index.js +2 -2
  124. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +10 -5
  125. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -1
  126. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +69 -38
  127. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +6 -3
  128. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  129. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +23 -38
  130. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts +22 -0
  131. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts.map +1 -0
  132. package/dest/tagging/sender_sync/utils/classify_pending_txs.js +61 -0
  133. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +15 -5
  134. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  135. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +36 -35
  136. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts +29 -0
  137. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts.map +1 -0
  138. package/dest/tagging/sender_sync/utils/resolve_pending_txs.js +41 -0
  139. package/dest/tagging/sender_sync/utils/test_utils.d.ts +16 -0
  140. package/dest/tagging/sender_sync/utils/test_utils.d.ts.map +1 -0
  141. package/dest/tagging/sender_sync/utils/test_utils.js +24 -0
  142. package/dest/tagging/testing/tag_query_test_utils.d.ts +6 -0
  143. package/dest/tagging/testing/tag_query_test_utils.d.ts.map +1 -0
  144. package/dest/tagging/testing/tag_query_test_utils.js +10 -0
  145. package/package.json +17 -17
  146. package/src/bin/check_oracle_version.ts +5 -56
  147. package/src/bin/index.ts +1 -5
  148. package/src/bin/oracle_version_helpers.ts +11 -292
  149. package/src/block_synchronizer/block_synchronizer.ts +6 -23
  150. package/src/config/package_info.ts +1 -1
  151. package/src/contract/contract_class_service.ts +8 -46
  152. package/src/contract/helpers.ts +3 -3
  153. package/src/contract/skip_sync_contracts.ts +23 -0
  154. package/src/contract_function_simulator/contract_function_simulator.ts +5 -20
  155. package/src/contract_function_simulator/index.ts +23 -3
  156. package/src/contract_function_simulator/noir-structs/resolved_tx.ts +11 -45
  157. package/src/contract_function_simulator/noir-structs/tx_effect_data.ts +4 -3
  158. package/src/contract_function_simulator/oracle/oracle_registry.ts +12 -8
  159. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +301 -198
  160. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +19 -9
  161. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +184 -56
  162. package/src/entrypoints/client/bundle/index.ts +1 -0
  163. package/src/entrypoints/client/bundle/utils.ts +15 -3
  164. package/src/entrypoints/client/lazy/index.ts +1 -0
  165. package/src/entrypoints/client/lazy/utils.ts +15 -3
  166. package/src/entrypoints/client/store.ts +54 -0
  167. package/src/entrypoints/server/index.ts +1 -0
  168. package/src/entrypoints/server/store.ts +47 -0
  169. package/src/entrypoints/server/utils.ts +21 -7
  170. package/src/events/event_service.ts +24 -14
  171. package/src/logs/log_service.ts +41 -39
  172. package/src/messages/tx_resolver_service.ts +26 -15
  173. package/src/node/benchmarked_node.ts +140 -0
  174. package/src/node/caching_aztec_node.ts +406 -0
  175. package/src/notes/note_service.ts +20 -14
  176. package/src/oracle_version.ts +5 -5
  177. package/src/private_kernel/batch_planner.ts +0 -1
  178. package/src/private_kernel/private_kernel_execution_prover.ts +90 -4
  179. package/src/pxe.ts +40 -21
  180. package/src/storage/contract_store/contract_store.ts +2 -1
  181. package/src/storage/fact_store/fact_store.ts +1 -1
  182. package/src/storage/fact_store/index.ts +1 -0
  183. package/src/storage/fact_store/origin_state.ts +10 -1
  184. package/src/storage/store_identity.ts +72 -0
  185. package/src/storage/tagging_store/sender_tagging_store.ts +113 -41
  186. package/src/tagging/constants.ts +22 -0
  187. package/src/tagging/get_all_logs_by_tags.ts +47 -11
  188. package/src/tagging/index.ts +7 -2
  189. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +116 -62
  190. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +27 -57
  191. package/src/tagging/sender_sync/utils/classify_pending_txs.ts +91 -0
  192. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +46 -40
  193. package/src/tagging/sender_sync/utils/resolve_pending_txs.ts +64 -0
  194. package/src/tagging/sender_sync/utils/test_utils.ts +46 -0
  195. package/src/tagging/testing/tag_query_test_utils.ts +11 -0
  196. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +0 -39
  197. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +0 -1
  198. package/dest/contract_function_simulator/aztec_node_read_cache.js +0 -60
  199. package/dest/contract_function_simulator/benchmarked_node.d.ts +0 -9
  200. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +0 -1
  201. package/dest/contract_function_simulator/benchmarked_node.js +0 -77
  202. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +0 -17
  203. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +0 -1
  204. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +0 -60
  205. package/src/contract_function_simulator/aztec_node_read_cache.ts +0 -89
  206. package/src/contract_function_simulator/benchmarked_node.ts +0 -103
  207. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +0 -66
@@ -0,0 +1,47 @@
1
+ import type { EthAddress } from '@aztec/foundation/eth-address';
2
+ import { type LoggerBindings, createLogger } from '@aztec/foundation/log';
3
+ import { type AztecLMDBStoreV2, openStoreAt } from '@aztec/kv-store/lmdb-v2';
4
+
5
+ import { mkdir } from 'fs/promises';
6
+ import { join } from 'path';
7
+
8
+ import { storeIdentitySlug } from '../../storage/store_identity.js';
9
+
10
+ /** Location and identity inputs for opening an identity-partitioned PXE-side store. */
11
+ export type IdentityStoreConfig = {
12
+ dataDirectory: string;
13
+ /** Maximum LMDB map size in KB. When omitted, the kv-store default map size applies. */
14
+ dataStoreMapSizeKb?: number;
15
+ l1ChainId: number;
16
+ rollupAddress: EthAddress;
17
+ };
18
+
19
+ /**
20
+ * Opens the persistent LMDB store selected by `name` and identity triple `(l1ChainId, rollupAddress, schemaVersion)`.
21
+ * A store exists per identity: reopening with the same identity returns the same data, a different identity selects
22
+ * a different (possibly fresh) store. Callers wanting an ephemeral store use `openTmpStore` explicitly instead.
23
+ */
24
+ export async function openStore(
25
+ name: string,
26
+ schemaVersion: number,
27
+ config: IdentityStoreConfig,
28
+ bindings?: LoggerBindings,
29
+ ): Promise<AztecLMDBStoreV2> {
30
+ // Stores live under `<dataDirectory>/<name>-stores/<l1ChainId>-<rollupAddress>-v<schemaVersion>`, a sibling of the
31
+ // legacy `<dataDirectory>/<name>` directory: older binaries reset the legacy directory on a rollup mismatch, so
32
+ // per-identity stores must not nest inside it.
33
+ const subDir = join(
34
+ config.dataDirectory,
35
+ `${name}-stores`,
36
+ storeIdentitySlug({ l1ChainId: config.l1ChainId, rollupAddress: config.rollupAddress, schemaVersion }),
37
+ );
38
+ await mkdir(subDir, { recursive: true });
39
+
40
+ createLogger(`pxe:data:${name}`, bindings).info(`Opening ${name} data store (LMDB v2)`, {
41
+ storeName: name,
42
+ subDir,
43
+ dataStoreMapSizeKb: config.dataStoreMapSizeKb,
44
+ });
45
+
46
+ return openStoreAt(subDir, config.dataStoreMapSizeKb, undefined, bindings);
47
+ }
@@ -1,7 +1,7 @@
1
1
  import { BBBundlePrivateKernelProver } from '@aztec/bb-prover/client/bundle';
2
2
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
- import { createStore } from '@aztec/kv-store/lmdb-v2';
4
+ import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
5
5
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
6
6
  import { WASMSimulator } from '@aztec/simulator/client';
7
7
  import { MemoryCircuitRecorder, SimulatorRecorderWrapper } from '@aztec/simulator/server';
@@ -15,6 +15,7 @@ import type { PXEConfig } from '../../config/index.js';
15
15
  import { PXE } from '../../pxe.js';
16
16
  import { PXE_DATA_SCHEMA_VERSION } from '../../storage/index.js';
17
17
  import { type PXECreationOptions, isPrivateKernelProver } from '../pxe_creation_options.js';
18
+ import { openStore } from './store.js';
18
19
 
19
20
  type PXEConfigWithoutDefaults = Omit<
20
21
  PXEConfig,
@@ -46,12 +47,25 @@ export async function createPXE(
46
47
 
47
48
  if (!options.store) {
48
49
  const storeLogger = loggers.store ?? createLogger('pxe:data:lmdb', { actor });
49
- options.store = await createStore(
50
- 'pxe_data',
51
- PXE_DATA_SCHEMA_VERSION,
52
- configWithContracts,
53
- storeLogger.getBindings(),
54
- );
50
+ options.store = configWithContracts.dataDirectory
51
+ ? await openStore(
52
+ 'pxe_data',
53
+ PXE_DATA_SCHEMA_VERSION,
54
+ {
55
+ dataDirectory: configWithContracts.dataDirectory,
56
+ dataStoreMapSizeKb: configWithContracts.dataStoreMapSizeKb,
57
+ l1ChainId,
58
+ rollupAddress: l1ContractAddresses.rollupAddress,
59
+ },
60
+ storeLogger.getBindings(),
61
+ )
62
+ : await openTmpStore(
63
+ 'pxe_data',
64
+ true,
65
+ configWithContracts.dataStoreMapSizeKb,
66
+ undefined,
67
+ storeLogger.getBindings(),
68
+ );
55
69
  }
56
70
  const proverLogger = loggers.prover ?? createLogger('pxe:bb:native', { actor });
57
71
 
@@ -1,8 +1,10 @@
1
+ import type { Fr } from '@aztec/foundation/curves/bn254';
1
2
  import { createLogger } from '@aztec/foundation/log';
2
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { InBlock } from '@aztec/stdlib/block';
3
5
  import { computePrivateEventCommitment, siloNullifier } from '@aztec/stdlib/hash';
4
6
  import type { AztecNode } from '@aztec/stdlib/interfaces/server';
5
- import type { BlockHeader, IndexedTxEffect } from '@aztec/stdlib/tx';
7
+ import type { BlockHeader } from '@aztec/stdlib/tx';
6
8
 
7
9
  import type { EventValidationRequest } from '../contract_function_simulator/noir-structs/event_validation_request.js';
8
10
  import { PrivateEventStore } from '../storage/private_event_store/private_event_store.js';
@@ -17,17 +19,17 @@ export class EventService {
17
19
  ) {}
18
20
 
19
21
  /**
20
- * Validates and stores a batch of private events against pre-fetched tx effects.
22
+ * Validates and stores a batch of private events against the pre-fetched onchain context of their txs.
21
23
  *
22
24
  * @param requests - The events to validate and store.
23
25
  * @param scope - The scope under which the events are being stored.
24
- * @param txEffects - Pre-fetched tx effects keyed by `TxHash.toString()`. Must contain entries for every request's
25
- * txHash; missing entries are treated as a node bug and cause an error.
26
+ * @param validationTxData - The onchain context of each request's tx, keyed by `TxHash.toString()`. Must contain
27
+ * entries for every request's txHash; missing entries are treated as a node bug and cause an error.
26
28
  */
27
29
  public async validateAndStoreEvents(
28
30
  requests: EventValidationRequest[],
29
31
  scope: AztecAddress,
30
- txEffects: Map<string, IndexedTxEffect>,
32
+ validationTxData: ReadonlyMap<string, EventValidationTxData>,
31
33
  ): Promise<void> {
32
34
  if (requests.length === 0) {
33
35
  return;
@@ -35,13 +37,15 @@ export class EventService {
35
37
 
36
38
  const anchorBlockNumber = this.anchorBlockHeader.getBlockNumber();
37
39
 
38
- await Promise.all(requests.map(req => this.#validateAndStoreEvent(req, scope, txEffects, anchorBlockNumber)));
40
+ await Promise.all(
41
+ requests.map(req => this.#validateAndStoreEvent(req, scope, validationTxData, anchorBlockNumber)),
42
+ );
39
43
  }
40
44
 
41
45
  async #validateAndStoreEvent(
42
46
  request: EventValidationRequest,
43
47
  scope: AztecAddress,
44
- txEffects: Map<string, IndexedTxEffect>,
48
+ validationTxData: ReadonlyMap<string, EventValidationTxData>,
45
49
  anchorBlockNumber: number,
46
50
  ): Promise<void> {
47
51
  const {
@@ -71,15 +75,15 @@ export class EventService {
71
75
  // since `fetchTaggedLogs` only processes logs up to the synced block.
72
76
  const siloedEventCommitment = await siloNullifier(contractAddress, eventCommitment);
73
77
 
74
- const txEffect = txEffects.get(txHash.toString());
75
- if (!txEffect) {
78
+ const txData = validationTxData.get(txHash.toString());
79
+ if (!txData) {
76
80
  // We error out instead of just logging a warning and skipping the event because this would indicate a bug. This
77
81
  // is because the node has already served info about this tx either when obtaining the log (LogResult carries
78
82
  // the tx info) or when getting metadata for the offchain message (before the message got passed to `process_log`).
79
83
  throw new Error(`Could not find tx effect for tx hash ${txHash} when processing an event.`);
80
84
  }
81
85
 
82
- if (txEffect.l2BlockNumber > anchorBlockNumber) {
86
+ if (txData.l2BlockNumber > anchorBlockNumber) {
83
87
  // We should never process a message from a tx past the anchor block. If we got here, a preprocessing step made
84
88
  // a mistake.
85
89
  throw new Error(
@@ -88,7 +92,7 @@ export class EventService {
88
92
  }
89
93
 
90
94
  // Find the index of the event commitment in the nullifiers array to determine event ordering within the tx
91
- const eventIndexInTx = txEffect.data.nullifiers.findIndex(n => n.equals(siloedEventCommitment));
95
+ const eventIndexInTx = txData.nullifiers.findIndex(n => n.equals(siloedEventCommitment));
92
96
  if (eventIndexInTx === -1) {
93
97
  // Unlike in NoteService, this might not be a bug since the commitment hasn't been verified yet in the message
94
98
  // processing pipeline. A malformed or malicious message could trigger this condition. Because of this we don't
@@ -108,12 +112,18 @@ export class EventService {
108
112
  contractAddress,
109
113
  scope,
110
114
  txHash,
111
- l2BlockNumber: txEffect.l2BlockNumber,
112
- l2BlockHash: txEffect.l2BlockHash,
113
- txIndexInBlock: txEffect.txIndexInBlock,
115
+ l2BlockNumber: txData.l2BlockNumber,
116
+ l2BlockHash: txData.l2BlockHash,
117
+ txIndexInBlock: txData.txIndexInBlock,
114
118
  eventIndexInTx,
115
119
  },
116
120
  this.jobId,
117
121
  );
118
122
  }
119
123
  }
124
+
125
+ /** The onchain context of the tx an event validation request points at: where it was mined and its nullifiers. */
126
+ export type EventValidationTxData = InBlock & {
127
+ nullifiers: Fr[];
128
+ txIndexInBlock: number;
129
+ };
@@ -1,10 +1,10 @@
1
- import { PRIVATE_LOG_CIPHERTEXT_LEN } from '@aztec/constants';
2
1
  import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import type { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import type { GrumpkinScalar, Point } from '@aztec/foundation/curves/grumpkin';
4
4
  import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
5
5
  import type { KeyStore } from '@aztec/key-store';
6
6
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
7
- import type { BlockHash, L2TipsProvider } from '@aztec/stdlib/block';
7
+ import type { L2TipsProvider } from '@aztec/stdlib/block';
8
8
  import type { CompleteAddress } from '@aztec/stdlib/contract';
9
9
  import type { AztecNode } from '@aztec/stdlib/interfaces/server';
10
10
  import {
@@ -15,20 +15,22 @@ import {
15
15
  computeSharedTaggingSecret,
16
16
  } from '@aztec/stdlib/logs';
17
17
  import type { BlockHeader } from '@aztec/stdlib/tx';
18
+ import type { UInt64 } from '@aztec/stdlib/types';
18
19
 
19
20
  import {
20
21
  type LogRetrievalRequest,
21
22
  LogSource,
22
23
  } from '../contract_function_simulator/noir-structs/log_retrieval_request.js';
23
- import type { LogRetrievalResponse } from '../contract_function_simulator/noir-structs/log_retrieval_response.js';
24
- import type { PendingTaggedLog } from '../contract_function_simulator/noir-structs/pending_tagged_log.js';
25
- import { ResolvedTx } from '../contract_function_simulator/noir-structs/resolved_tx.js';
24
+ import type { TxOnchainContext } from '../messages/tx_resolver_service.js';
26
25
  import { AddressStore } from '../storage/address_store/address_store.js';
26
+ import { assertAllowedScope } from '../storage/allowed_scopes.js';
27
27
  import type { RecipientTaggingStore } from '../storage/tagging_store/recipient_tagging_store.js';
28
28
  import type { TaggingSecretSourcesStore } from '../storage/tagging_store/tagging_secret_sources_store.js';
29
29
  import {
30
+ type LogQueryAnchor,
30
31
  getAllPrivateLogsByTags,
31
32
  getAllPublicLogsByTagsFromContract,
33
+ logQueryAnchorOf,
32
34
  syncTaggedPrivateLogs,
33
35
  } from '../tagging/index.js';
34
36
 
@@ -47,6 +49,7 @@ export class LogService {
47
49
  private readonly recipientTaggingStore: RecipientTaggingStore,
48
50
  private readonly taggingSecretSourcesStore: TaggingSecretSourcesStore,
49
51
  private readonly addressStore: AddressStore,
52
+ private readonly scopes: AztecAddress[],
50
53
  private readonly jobId: string,
51
54
  bindings?: LoggerBindings,
52
55
  ) {
@@ -57,7 +60,7 @@ export class LogService {
57
60
  public async fetchLogsByTag(
58
61
  contractAddress: AztecAddress,
59
62
  logRetrievalRequests: LogRetrievalRequest[],
60
- ): Promise<LogRetrievalResponse[][]> {
63
+ ): Promise<RetrievedTaggedLog[][]> {
61
64
  for (const request of logRetrievalRequests) {
62
65
  if (!contractAddress.equals(request.contractAddress)) {
63
66
  throw new Error(`Got a log retrieval request from ${request.contractAddress}, expected ${contractAddress}`);
@@ -68,23 +71,23 @@ export class LogService {
68
71
  return [];
69
72
  }
70
73
 
71
- const anchorBlockHash = await this.anchorBlockHeader.hash();
74
+ const anchor = await logQueryAnchorOf(this.anchorBlockHeader);
72
75
 
73
76
  const [publicLogsPerRequest, privateLogsPerRequest] = await Promise.all([
74
- this.#fetchPublicLogs(contractAddress, logRetrievalRequests, anchorBlockHash),
75
- this.#fetchPrivateLogs(logRetrievalRequests, anchorBlockHash),
77
+ this.#fetchPublicLogs(contractAddress, logRetrievalRequests, anchor),
78
+ this.#fetchPrivateLogs(logRetrievalRequests, anchor),
76
79
  ]);
77
80
 
78
81
  return logRetrievalRequests.map((_request, i) => [
79
- ...publicLogsPerRequest[i].map(LogService.#toLogRetrievalResponse),
80
- ...privateLogsPerRequest[i].map(LogService.#toLogRetrievalResponse),
82
+ ...publicLogsPerRequest[i].map(LogService.#toRetrievedTaggedLog),
83
+ ...privateLogsPerRequest[i].map(LogService.#toRetrievedTaggedLog),
81
84
  ]);
82
85
  }
83
86
 
84
87
  async #fetchPublicLogs(
85
88
  contractAddress: AztecAddress,
86
89
  requests: LogRetrievalRequest[],
87
- anchorBlockHash: BlockHash,
90
+ anchor: LogQueryAnchor,
88
91
  ): Promise<LogResult[][]> {
89
92
  const indices = requests.flatMap((r, i) => (r.source !== LogSource.PRIVATE ? [i] : []));
90
93
  if (indices.length === 0) {
@@ -97,13 +100,11 @@ export class LogService {
97
100
  await Promise.all(
98
101
  Array.from(groups.values()).map(async group => {
99
102
  const tags = group.entries.map(e => e.request.tag);
100
- const results = await getAllPublicLogsByTagsFromContract(
101
- this.aztecNode,
102
- contractAddress,
103
- tags,
104
- anchorBlockHash,
105
- { fromBlock: group.fromBlock, toBlock: group.toBlock, includeEffects: true },
106
- );
103
+ const results = await getAllPublicLogsByTagsFromContract(this.aztecNode, contractAddress, tags, anchor, {
104
+ fromBlock: group.fromBlock,
105
+ toBlock: group.toBlock,
106
+ includeEffects: true,
107
+ });
107
108
  group.entries.forEach((entry, i) => {
108
109
  resultsPerRequest[entry.index] = results[i];
109
110
  });
@@ -113,7 +114,7 @@ export class LogService {
113
114
  return resultsPerRequest;
114
115
  }
115
116
 
116
- async #fetchPrivateLogs(requests: LogRetrievalRequest[], anchorBlockHash: BlockHash): Promise<LogResult[][]> {
117
+ async #fetchPrivateLogs(requests: LogRetrievalRequest[], anchor: LogQueryAnchor): Promise<LogResult[][]> {
117
118
  const indices = requests.flatMap((r, i) => (r.source !== LogSource.PUBLIC ? [i] : []));
118
119
  if (indices.length === 0) {
119
120
  return requests.map(() => []);
@@ -127,7 +128,7 @@ export class LogService {
127
128
  const siloedTags = await Promise.all(
128
129
  group.entries.map(e => SiloedTag.computeFromTagAndApp(e.request.tag, e.request.contractAddress)),
129
130
  );
130
- const results = await getAllPrivateLogsByTags(this.aztecNode, siloedTags, anchorBlockHash, {
131
+ const results = await getAllPrivateLogsByTags(this.aztecNode, siloedTags, anchor, {
131
132
  fromBlock: group.fromBlock,
132
133
  toBlock: group.toBlock,
133
134
  includeEffects: true,
@@ -163,7 +164,7 @@ export class LogService {
163
164
  return groups;
164
165
  }
165
166
 
166
- static #toLogRetrievalResponse(log: LogResult): LogRetrievalResponse {
167
+ static #toRetrievedTaggedLog(log: LogResult): RetrievedTaggedLog {
167
168
  // includeEffects: true was used, so noteHashes and nullifiers are populated. Every tx has at least one nullifier
168
169
  // (the first nullifier derived from the tx hash); empty here would indicate a buggy node.
169
170
  const noteHashes = log.noteHashes!;
@@ -172,23 +173,27 @@ export class LogService {
172
173
  throw new Error(`Log for tx ${log.txHash} returned no nullifiers from the node`);
173
174
  }
174
175
  return {
175
- // Skip the tag, and clip to the wire cap: public logs can exceed PRIVATE_LOG_CIPHERTEXT_LEN, which is the fixed
176
- // size of the oracle's BoundedVec slot. A no-op for private logs, which are already within the cap.
177
- logPayload: log.logData.slice(1, 1 + PRIVATE_LOG_CIPHERTEXT_LEN),
176
+ logData: log.logData,
178
177
  txHash: log.txHash,
179
- uniqueNoteHashesInTx: noteHashes,
180
- firstNullifierInTx: nullifiers[0],
178
+ noteHashes,
179
+ nullifiers,
181
180
  blockNumber: log.blockNumber,
182
181
  blockTimestamp: log.blockTimestamp,
183
182
  blockHash: log.blockHash,
183
+ // The log index and the tx receipt both count the tx's position in `block.body.txEffects`, so this is the same
184
+ // index a receipt reports. Note ordering depends on the two staying in agreement.
185
+ txIndexInBlock: log.txIndexWithinBlock,
184
186
  };
185
187
  }
186
188
 
189
+ /** Fetches the pending tagged logs for a recipient across all its tagging secrets for the contract. */
187
190
  public async fetchTaggedLogs(
188
191
  contractAddress: AztecAddress,
189
192
  recipient: AztecAddress,
190
193
  providedSecrets: AppTaggingSecret[],
191
- ): Promise<PendingTaggedLog[]> {
194
+ ): Promise<RetrievedTaggedLog[]> {
195
+ assertAllowedScope(recipient, this.scopes);
196
+
192
197
  this.log.verbose(
193
198
  `Fetching tagged logs for contract ${contractAddress.toString()} and recipient ${recipient.toString()}`,
194
199
  );
@@ -213,17 +218,7 @@ export class LogService {
213
218
  this.jobId,
214
219
  );
215
220
 
216
- return logs.map(log => {
217
- const noteHashes = log.noteHashes!;
218
- const nullifiers = log.nullifiers!;
219
- if (nullifiers.length === 0) {
220
- throw new Error(`Log for tx ${log.txHash} returned no nullifiers from the node`);
221
- }
222
- return {
223
- log: log.logData,
224
- context: new ResolvedTx(log.txHash, noteHashes, nullifiers[0], log.blockNumber, log.blockHash.toFr()),
225
- };
226
- });
221
+ return logs.map(log => LogService.#toRetrievedTaggedLog(log));
227
222
  }
228
223
 
229
224
  /**
@@ -289,3 +284,10 @@ export class LogService {
289
284
  );
290
285
  }
291
286
  }
287
+
288
+ /** A tagged log fetched from the node, together with the onchain context of the tx that emitted it. */
289
+ export type RetrievedTaggedLog = TxOnchainContext & {
290
+ /** The raw log payload, tag included. */
291
+ logData: Fr[];
292
+ blockTimestamp: UInt64;
293
+ };
@@ -1,22 +1,22 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { uniqueBy } from '@aztec/foundation/collection';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import type { BlockHash } from '@aztec/stdlib/block';
3
5
  import type { AztecNode } from '@aztec/stdlib/interfaces/server';
4
6
  import { type IndexedTxEffect, TxHash } from '@aztec/stdlib/tx';
5
7
 
6
- import { ResolvedTx } from '../contract_function_simulator/noir-structs/resolved_tx.js';
7
-
8
- /** Resolves transaction hashes into their on-chain context (note hashes, first nullifier, and mined block). */
8
+ /** Resolves transaction hashes into their on-chain context (note hashes, nullifiers, and mined position). */
9
9
  export class TxResolverService {
10
10
  constructor(private readonly aztecNode: AztecNode) {}
11
11
 
12
12
  /**
13
13
  * Resolves a list of tx hashes into their on-chain context.
14
14
  *
15
- * For each tx hash, looks up the corresponding tx effect and extracts the note hashes, first nullifier, and the
16
- * number and hash of the block it was mined in. Returns `null` for tx hashes that are zero, not yet available, or in
17
- * blocks beyond the anchor block.
15
+ * For each tx hash, looks up the corresponding tx effect and extracts its note hashes and nullifiers, and the
16
+ * position it was mined at. Returns `null` for tx hashes that are zero, not yet available, or in blocks beyond the
17
+ * anchor block.
18
18
  */
19
- async resolveTxs(txHashes: Fr[], anchorBlockNumber: number): Promise<(ResolvedTx | null)[]> {
19
+ async resolveTxs(txHashes: Fr[], anchorBlockNumber: number): Promise<(TxOnchainContext | null)[]> {
20
20
  const nonZeroTxHashes = txHashes.filter(h => !h.isZero()).map(h => TxHash.fromField(h));
21
21
  const uniqueTxHashes = uniqueBy(nonZeroTxHashes, h => h.toString());
22
22
  const fetched = await Promise.all(
@@ -51,19 +51,30 @@ export class TxResolverService {
51
51
  }
52
52
 
53
53
  // Every tx has at least one nullifier (the first nullifier derived from the tx hash). Hitting this condition
54
- // would mean a buggy node, but since we need to access data.nullifiers[0], the defensive check does no harm.
54
+ // would mean a buggy node, but since consumers rely on nullifiers[0], the defensive check does no harm.
55
55
  const data = txEffect.data;
56
56
  if (data.nullifiers.length === 0) {
57
57
  throw new Error(`Tx effect for ${txHash} has no nullifiers`);
58
58
  }
59
59
 
60
- return new ResolvedTx(
61
- data.txHash,
62
- data.noteHashes,
63
- data.nullifiers[0],
64
- txEffect.l2BlockNumber,
65
- txEffect.l2BlockHash.toFr(),
66
- );
60
+ return {
61
+ txHash: data.txHash,
62
+ noteHashes: data.noteHashes,
63
+ nullifiers: data.nullifiers,
64
+ blockNumber: txEffect.l2BlockNumber,
65
+ blockHash: txEffect.l2BlockHash,
66
+ txIndexInBlock: txEffect.txIndexInBlock,
67
+ };
67
68
  });
68
69
  }
69
70
  }
71
+
72
+ /** The onchain context of a tx: the position it was mined at, and the effects it produced. */
73
+ export type TxOnchainContext = {
74
+ txHash: TxHash;
75
+ noteHashes: Fr[];
76
+ nullifiers: Fr[];
77
+ blockNumber: BlockNumber;
78
+ blockHash: BlockHash;
79
+ txIndexInBlock: number;
80
+ };
@@ -0,0 +1,140 @@
1
+ import { Timer } from '@aztec/foundation/timer';
2
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
3
+ import type { NodeStats } from '@aztec/stdlib/tx';
4
+
5
+ /*
6
+ * Proxy generator for an AztecNode that tracks the time taken for each RPC call and the number of round trips (actual
7
+ * blocking waits for node responses).
8
+ *
9
+ * A round trip is counted when we transition from 0 to 1 in-flight calls, and ends when all concurrent calls complete.
10
+ * This means parallel calls in Promise.all count as a single round trip.
11
+ *
12
+ * Note that batching of RPC calls in `safe_json_rpc_client.ts` could affect the round trip counts but in places we
13
+ * currently use this information we do not even use HTTP as we have direct access to the Aztec Node instance in TS
14
+ * (i.e. not running against external node) so this is not a problem for now.
15
+ *
16
+ * If you want to use this against external node and the info gets skewed by batching you can set the `maxBatchSize`
17
+ * value in `safe_json_rpc_client.ts` to 1 (the main motivation for batching was to get around parallel http requests
18
+ * limits in web browsers which is not a problem when debugging in node.js).
19
+ */
20
+ export interface Recording {
21
+ /** Closes the recording and returns what it saw. Reads served after this are not recorded. */
22
+ stop(): NodeStats;
23
+ }
24
+
25
+ /** An {@link AztecNode} wrapper that can report the reads it serves. */
26
+ export interface BenchmarkedAztecNode extends AztecNode {
27
+ /**
28
+ * Opens a recording of the reads this wrapper serves, until {@link Recording.stop}. Recordings are independent, so
29
+ * several may run at once: one measuring a whole run sees the same reads as one measuring a single operation.
30
+ *
31
+ * Nothing is measured while none is open, which is what keeps a long-lived wrapper from accumulating a run's worth
32
+ * of timings nobody asked for.
33
+ */
34
+ startRecording(): Recording;
35
+ }
36
+
37
+ /** Wraps `node` so that the reads it answers can be recorded. */
38
+ export function withRecording(node: AztecNode): BenchmarkedAztecNode {
39
+ // The stats of every recording currently open
40
+ const open = new Set<NodeStats>();
41
+
42
+ // Round trip tracking
43
+ let inFlightCount = 0;
44
+ let currentRoundTripTimer: Timer | null = null;
45
+ let currentRoundTripMethods: string[] = [];
46
+
47
+ return new Proxy(node, {
48
+ get(target, prop) {
49
+ if (prop === 'startRecording') {
50
+ return (): Recording => {
51
+ const stats: NodeStats = {
52
+ perMethod: {},
53
+ roundTrips: { roundTrips: 0, totalBlockingTime: 0, roundTripDurations: [], roundTripMethods: [] },
54
+ };
55
+ open.add(stats);
56
+ return {
57
+ stop: () => {
58
+ open.delete(stats);
59
+ return stats;
60
+ },
61
+ };
62
+ };
63
+ }
64
+
65
+ const value = Reflect.get(target, prop);
66
+ if (typeof value !== 'function' || typeof prop !== 'string') {
67
+ return value;
68
+ }
69
+
70
+ return (...args: unknown[]) => {
71
+ // With no recording open there is nobody to report to, so the read is left untimed.
72
+ if (open.size === 0) {
73
+ return value.apply(target, args);
74
+ }
75
+
76
+ // Start of a new round trip batch?
77
+ if (inFlightCount === 0) {
78
+ currentRoundTripTimer = new Timer();
79
+ currentRoundTripMethods = [];
80
+ }
81
+ inFlightCount++;
82
+ currentRoundTripMethods.push(prop);
83
+
84
+ const callTimer = new Timer();
85
+ const result = value.apply(target, args);
86
+
87
+ // Handle completion - called when the call finishes (after Promise resolves)
88
+ const handleCompletion = () => {
89
+ const callTime = callTimer.ms();
90
+ for (const stats of open) {
91
+ timesFor(stats, prop).push(callTime);
92
+ }
93
+
94
+ inFlightCount--;
95
+
96
+ // End of round trip batch - all concurrent calls completed
97
+ if (inFlightCount === 0 && currentRoundTripTimer) {
98
+ const roundTripTime = currentRoundTripTimer.ms();
99
+ for (const { roundTrips } of open) {
100
+ roundTrips.roundTrips++;
101
+ roundTrips.totalBlockingTime += roundTripTime;
102
+ roundTrips.roundTripDurations.push(roundTripTime);
103
+ roundTrips.roundTripMethods.push(currentRoundTripMethods);
104
+ }
105
+ currentRoundTripTimer = null;
106
+ currentRoundTripMethods = [];
107
+ }
108
+ };
109
+
110
+ // If the result is a Promise, chain the completion handler
111
+ if (isThenable(result)) {
112
+ return result.then(
113
+ resolved => {
114
+ handleCompletion();
115
+ return resolved;
116
+ },
117
+ error => {
118
+ handleCompletion();
119
+ throw error;
120
+ },
121
+ );
122
+ } else {
123
+ // Synchronous method - handle completion immediately
124
+ handleCompletion();
125
+ return result;
126
+ }
127
+ };
128
+ },
129
+ }) as BenchmarkedAztecNode;
130
+ }
131
+
132
+ /** The times `stats` holds for `method`, added on first use. */
133
+ function timesFor(stats: NodeStats, method: string) {
134
+ return (stats.perMethod[method as keyof AztecNode] ??= { times: [] }).times;
135
+ }
136
+
137
+ /** Whether completion can be chained onto `value` with `.then`, which a promise from any implementation allows. */
138
+ function isThenable(value: unknown): value is PromiseLike<unknown> {
139
+ return typeof value === 'object' && value !== null && 'then' in value && typeof value.then === 'function';
140
+ }