@aztec/pxe 0.0.1-commit.321f6a9 → 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 (124) hide show
  1. package/dest/bin/check_oracle_version.js +2 -38
  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 +1 -15
  6. package/dest/bin/oracle_version_helpers.d.ts.map +1 -1
  7. package/dest/bin/oracle_version_helpers.js +0 -21
  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/contract/contract_class_service.d.ts +1 -8
  12. package/dest/contract/contract_class_service.d.ts.map +1 -1
  13. package/dest/contract/contract_class_service.js +8 -40
  14. package/dest/contract_function_simulator/contract_function_simulator.d.ts +1 -8
  15. package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
  16. package/dest/contract_function_simulator/contract_function_simulator.js +0 -17
  17. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts +1 -1
  18. package/dest/contract_function_simulator/oracle/oracle_type_mappings.d.ts.map +1 -1
  19. package/dest/contract_function_simulator/oracle/oracle_type_mappings.js +11 -1
  20. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -1
  21. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  22. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +6 -2
  23. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +10 -2
  24. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  25. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +128 -38
  26. package/dest/events/event_service.d.ts +13 -6
  27. package/dest/events/event_service.d.ts.map +1 -1
  28. package/dest/events/event_service.js +13 -13
  29. package/dest/logs/log_service.d.ts +13 -5
  30. package/dest/logs/log_service.d.ts.map +1 -1
  31. package/dest/logs/log_service.js +20 -36
  32. package/dest/messages/tx_resolver_service.d.ts +18 -7
  33. package/dest/messages/tx_resolver_service.d.ts.map +1 -1
  34. package/dest/messages/tx_resolver_service.js +9 -8
  35. package/dest/node/benchmarked_node.d.ts +20 -0
  36. package/dest/node/benchmarked_node.d.ts.map +1 -0
  37. package/dest/node/benchmarked_node.js +94 -0
  38. package/dest/node/caching_aztec_node.d.ts +24 -0
  39. package/dest/node/caching_aztec_node.d.ts.map +1 -0
  40. package/dest/node/caching_aztec_node.js +267 -0
  41. package/dest/notes/note_service.d.ts +12 -6
  42. package/dest/notes/note_service.d.ts.map +1 -1
  43. package/dest/notes/note_service.js +9 -9
  44. package/dest/oracle_version.js +2 -2
  45. package/dest/pxe.d.ts +1 -1
  46. package/dest/pxe.d.ts.map +1 -1
  47. package/dest/pxe.js +31 -14
  48. package/dest/storage/contract_store/contract_store.d.ts +1 -1
  49. package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
  50. package/dest/storage/contract_store/contract_store.js +2 -2
  51. package/dest/storage/fact_store/origin_state.d.ts +1 -1
  52. package/dest/storage/fact_store/origin_state.js +1 -1
  53. package/dest/storage/tagging_store/sender_tagging_store.d.ts +23 -8
  54. package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
  55. package/dest/storage/tagging_store/sender_tagging_store.js +33 -18
  56. package/dest/tagging/constants.d.ts +9 -1
  57. package/dest/tagging/constants.d.ts.map +1 -1
  58. package/dest/tagging/constants.js +10 -0
  59. package/dest/tagging/get_all_logs_by_tags.d.ts +29 -8
  60. package/dest/tagging/get_all_logs_by_tags.d.ts.map +1 -1
  61. package/dest/tagging/get_all_logs_by_tags.js +29 -10
  62. package/dest/tagging/index.d.ts +2 -2
  63. package/dest/tagging/index.d.ts.map +1 -1
  64. package/dest/tagging/index.js +1 -1
  65. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts +2 -2
  66. package/dest/tagging/recipient_sync/sync_tagged_private_logs.d.ts.map +1 -1
  67. package/dest/tagging/recipient_sync/sync_tagged_private_logs.js +13 -17
  68. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts +6 -3
  69. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.d.ts.map +1 -1
  70. package/dest/tagging/sender_sync/sync_sender_tagging_indexes.js +23 -38
  71. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts +22 -0
  72. package/dest/tagging/sender_sync/utils/classify_pending_txs.d.ts.map +1 -0
  73. package/dest/tagging/sender_sync/utils/classify_pending_txs.js +61 -0
  74. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts +15 -5
  75. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.d.ts.map +1 -1
  76. package/dest/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.js +30 -33
  77. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts +29 -0
  78. package/dest/tagging/sender_sync/utils/resolve_pending_txs.d.ts.map +1 -0
  79. package/dest/tagging/sender_sync/utils/resolve_pending_txs.js +41 -0
  80. package/dest/tagging/sender_sync/utils/test_utils.d.ts +16 -0
  81. package/dest/tagging/sender_sync/utils/test_utils.d.ts.map +1 -0
  82. package/dest/tagging/sender_sync/utils/test_utils.js +24 -0
  83. package/package.json +17 -17
  84. package/src/bin/check_oracle_version.ts +2 -46
  85. package/src/bin/index.ts +1 -1
  86. package/src/bin/oracle_version_helpers.ts +0 -24
  87. package/src/block_synchronizer/block_synchronizer.ts +6 -23
  88. package/src/contract/contract_class_service.ts +8 -46
  89. package/src/contract_function_simulator/contract_function_simulator.ts +0 -17
  90. package/src/contract_function_simulator/oracle/oracle_type_mappings.ts +16 -1
  91. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +7 -2
  92. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +130 -40
  93. package/src/events/event_service.ts +24 -14
  94. package/src/logs/log_service.ts +37 -44
  95. package/src/messages/tx_resolver_service.ts +22 -11
  96. package/src/node/benchmarked_node.ts +140 -0
  97. package/src/node/caching_aztec_node.ts +406 -0
  98. package/src/notes/note_service.ts +19 -13
  99. package/src/oracle_version.ts +2 -2
  100. package/src/pxe.ts +32 -16
  101. package/src/storage/contract_store/contract_store.ts +2 -1
  102. package/src/storage/fact_store/origin_state.ts +1 -1
  103. package/src/storage/tagging_store/sender_tagging_store.ts +51 -26
  104. package/src/tagging/constants.ts +12 -0
  105. package/src/tagging/get_all_logs_by_tags.ts +47 -11
  106. package/src/tagging/index.ts +6 -1
  107. package/src/tagging/recipient_sync/sync_tagged_private_logs.ts +19 -22
  108. package/src/tagging/sender_sync/sync_sender_tagging_indexes.ts +27 -57
  109. package/src/tagging/sender_sync/utils/classify_pending_txs.ts +91 -0
  110. package/src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts +40 -38
  111. package/src/tagging/sender_sync/utils/resolve_pending_txs.ts +64 -0
  112. package/src/tagging/sender_sync/utils/test_utils.ts +46 -0
  113. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts +0 -39
  114. package/dest/contract_function_simulator/aztec_node_read_cache.d.ts.map +0 -1
  115. package/dest/contract_function_simulator/aztec_node_read_cache.js +0 -60
  116. package/dest/contract_function_simulator/benchmarked_node.d.ts +0 -9
  117. package/dest/contract_function_simulator/benchmarked_node.d.ts.map +0 -1
  118. package/dest/contract_function_simulator/benchmarked_node.js +0 -77
  119. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +0 -17
  120. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +0 -1
  121. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +0 -60
  122. package/src/contract_function_simulator/aztec_node_read_cache.ts +0 -89
  123. package/src/contract_function_simulator/benchmarked_node.ts +0 -103
  124. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +0 -66
@@ -0,0 +1,61 @@
1
+ import { TxHash, TxStatus } from '@aztec/stdlib/tx';
2
+ /** Groups a window's pending txs by what its logs say about them. */ export function classifyPendingTxsFromLogs(pendingTxs, txsInLogs, finalizedBlockNumber) {
3
+ const txHashesFinalized = [];
4
+ const txHashesWithExecutionReverted = [];
5
+ const txHashesAbsent = [];
6
+ for (const pendingTx of pendingTxs){
7
+ const txHash = TxHash.fromString(pendingTx.txHash);
8
+ const txInLogs = txsInLogs.get(pendingTx.txHash);
9
+ if (!txInLogs) {
10
+ txHashesAbsent.push(txHash);
11
+ } else if (txInLogs.blockNumber > finalizedBlockNumber) {
12
+ // A tx in the logs is mined in the log's block, so it is finalized exactly when that block is at or below the
13
+ // finalized tip. This one is not, so it belongs to no group until the tip catches up.
14
+ } else if (txInLogs.taggingIndexes.includes(pendingTx.highestIndex)) {
15
+ txHashesFinalized.push(txHash);
16
+ } else {
17
+ // A partially reverted tx: the revert dropped the logs carrying its higher indexes.
18
+ txHashesWithExecutionReverted.push(txHash);
19
+ }
20
+ }
21
+ return {
22
+ txHashesFinalized,
23
+ txHashesWithExecutionReverted,
24
+ txHashesAbsent
25
+ };
26
+ }
27
+ /** Groups pending txs by what their receipts say, for the txs the logs could not resolve. */ export async function classifyPendingTxsFromReceipts(pending, aztecNode) {
28
+ const receipts = await Promise.all(pending.map((pendingTxHash)=>aztecNode.getTxReceipt(pendingTxHash)));
29
+ const txHashesFinalized = [];
30
+ const txHashesDropped = [];
31
+ const txHashesWithExecutionReverted = [];
32
+ for(let i = 0; i < receipts.length; i++){
33
+ const receipt = receipts[i];
34
+ const txHash = pending[i];
35
+ if (receipt.status === TxStatus.FINALIZED) {
36
+ // Tx has been included in a block and the corresponding block is finalized
37
+ if (receipt.hasExecutionSucceeded()) {
38
+ // No part of execution reverted - we just finalize all the indexes.
39
+ txHashesFinalized.push(txHash);
40
+ } else if (receipt.hasExecutionReverted()) {
41
+ // Tx was mined but execution reverted (app logic, teardown, or both). Some logs from the non-revertible
42
+ // phase may still be onchain. We check which tags made it onchain and finalize those; drop the rest.
43
+ txHashesWithExecutionReverted.push(txHash);
44
+ } else {
45
+ // Defensive check - this branch should never be triggered
46
+ throw new Error('Both hasExecutionSucceeded and hasExecutionReverted on the receipt returned false. This should never happen and it implies a bug. Please open an issue.');
47
+ }
48
+ } else if (receipt.isDropped()) {
49
+ // Tx was dropped from the mempool --> we drop the corresponding pending indexes.
50
+ txHashesDropped.push(txHash);
51
+ } else {
52
+ // Tx is still pending, not yet finalized, or was mined successfully but not yet finalized --> we don't do
53
+ // anything.
54
+ }
55
+ }
56
+ return {
57
+ txHashesFinalized,
58
+ txHashesDropped,
59
+ txHashesWithExecutionReverted
60
+ };
61
+ }
@@ -1,9 +1,12 @@
1
- import type { BlockHash } from '@aztec/stdlib/block';
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import type { AztecNode } from '@aztec/stdlib/interfaces/server';
3
3
  import { type AppTaggingSecret } from '@aztec/stdlib/logs';
4
4
  import type { SenderTaggingStore } from '../../../storage/tagging_store/sender_tagging_store.js';
5
+ import { type LogQueryAnchor } from '../../get_all_logs_by_tags.js';
5
6
  /**
6
- * Loads tagging indexes from the Aztec node and stores them in the tagging data provider.
7
+ * Loads tagging indexes from the Aztec node and stores them in the tagging data provider. Returns the txs the
8
+ * window's logs carried, keyed by tx hash string, with the block each was mined in and the window indexes it used,
9
+ * so the caller can classify their finalization status without further node queries.
7
10
  * @remarks This function is one of two places by which a pending index can get to the tagging data provider. The other
8
11
  * place is when a tx is being sent from this PXE.
9
12
  * @param extendedSecret - The app tagging secret whose indexes are being synced.
@@ -11,9 +14,16 @@ import type { SenderTaggingStore } from '../../../storage/tagging_store/sender_t
11
14
  * @param end - The ending index (exclusive) of the window to process.
12
15
  * @param aztecNode - The Aztec node instance to query for logs.
13
16
  * @param taggingStore - The data provider to store pending indexes.
14
- * @param anchorBlockHash - Hash of a block to use as reference block when querying node.
17
+ * @param anchor - Block the log query is anchored to.
15
18
  * @param jobId - Job identifier, used to keep writes in-memory until they can be persisted in a data integrity
16
19
  * preserving way.
17
20
  */
18
- export declare function loadAndStoreNewTaggingIndexes(extendedSecret: AppTaggingSecret, start: number, end: number, aztecNode: AztecNode, taggingStore: SenderTaggingStore, anchorBlockHash: BlockHash, jobId: string): Promise<void>;
19
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9hZF9hbmRfc3RvcmVfbmV3X3RhZ2dpbmdfaW5kZXhlcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RhZ2dpbmcvc2VuZGVyX3N5bmMvdXRpbHMvbG9hZF9hbmRfc3RvcmVfbmV3X3RhZ2dpbmdfaW5kZXhlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUNyRCxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNqRSxPQUFPLEVBQUUsS0FBSyxnQkFBZ0IsRUFBYSxNQUFNLG9CQUFvQixDQUFDO0FBR3RFLE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLE1BQU0sd0RBQXdELENBQUM7QUFHakc7Ozs7Ozs7Ozs7OztHQVlHO0FBQ0gsd0JBQXNCLDZCQUE2QixDQUNqRCxjQUFjLEVBQUUsZ0JBQWdCLEVBQ2hDLEtBQUssRUFBRSxNQUFNLEVBQ2IsR0FBRyxFQUFFLE1BQU0sRUFDWCxTQUFTLEVBQUUsU0FBUyxFQUNwQixZQUFZLEVBQUUsa0JBQWtCLEVBQ2hDLGVBQWUsRUFBRSxTQUFTLEVBQzFCLEtBQUssRUFBRSxNQUFNLGlCQW9CZCJ9
21
+ export declare function loadAndStoreNewTaggingIndexes(extendedSecret: AppTaggingSecret, start: number, end: number, aztecNode: AztecNode, taggingStore: SenderTaggingStore, anchor: LogQueryAnchor, jobId: string): Promise<Map<string, TxInLogs>>;
22
+ /** A tx that a sync window's logs carried. */
23
+ export type TxInLogs = {
24
+ /** The block the tx was mined in, which decides whether it is finalized. */
25
+ blockNumber: BlockNumber;
26
+ /** The window's tagging indexes whose siloed tags this tx's logs carried. */
27
+ taggingIndexes: number[];
28
+ };
29
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9hZF9hbmRfc3RvcmVfbmV3X3RhZ2dpbmdfaW5kZXhlcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RhZ2dpbmcvc2VuZGVyX3N5bmMvdXRpbHMvbG9hZF9hbmRfc3RvcmVfbmV3X3RhZ2dpbmdfaW5kZXhlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNqRSxPQUFPLEVBQUUsS0FBSyxnQkFBZ0IsRUFBNkIsTUFBTSxvQkFBb0IsQ0FBQztBQUd0RixPQUFPLEtBQUssRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHdEQUF3RCxDQUFDO0FBQ2pHLE9BQU8sRUFBRSxLQUFLLGNBQWMsRUFBMkIsTUFBTSwrQkFBK0IsQ0FBQztBQUU3Rjs7Ozs7Ozs7Ozs7Ozs7R0FjRztBQUNILHdCQUFzQiw2QkFBNkIsQ0FDakQsY0FBYyxFQUFFLGdCQUFnQixFQUNoQyxLQUFLLEVBQUUsTUFBTSxFQUNiLEdBQUcsRUFBRSxNQUFNLEVBQ1gsU0FBUyxFQUFFLFNBQVMsRUFDcEIsWUFBWSxFQUFFLGtCQUFrQixFQUNoQyxNQUFNLEVBQUUsY0FBYyxFQUN0QixLQUFLLEVBQUUsTUFBTSxHQUNaLE9BQU8sQ0FBQyxHQUFHLENBQUMsTUFBTSxFQUFFLFFBQVEsQ0FBQyxDQUFDLENBNkJoQztBQUVELDhDQUE4QztBQUM5QyxNQUFNLE1BQU0sUUFBUSxHQUFHO0lBQ3JCLDRFQUE0RTtJQUM1RSxXQUFXLEVBQUUsV0FBVyxDQUFDO0lBQ3pCLDZFQUE2RTtJQUM3RSxjQUFjLEVBQUUsTUFBTSxFQUFFLENBQUM7Q0FDMUIsQ0FBQyJ9
@@ -1 +1 @@
1
- {"version":3,"file":"load_and_store_new_tagging_indexes.d.ts","sourceRoot":"","sources":["../../../../src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,KAAK,gBAAgB,EAAa,MAAM,oBAAoB,CAAC;AAGtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wDAAwD,CAAC;AAGjG;;;;;;;;;;;;GAYG;AACH,wBAAsB,6BAA6B,CACjD,cAAc,EAAE,gBAAgB,EAChC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,kBAAkB,EAChC,eAAe,EAAE,SAAS,EAC1B,KAAK,EAAE,MAAM,iBAoBd"}
1
+ {"version":3,"file":"load_and_store_new_tagging_indexes.d.ts","sourceRoot":"","sources":["../../../../src/tagging/sender_sync/utils/load_and_store_new_tagging_indexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,KAAK,gBAAgB,EAA6B,MAAM,oBAAoB,CAAC;AAGtF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wDAAwD,CAAC;AACjG,OAAO,EAAE,KAAK,cAAc,EAA2B,MAAM,+BAA+B,CAAC;AAE7F;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,6BAA6B,CACjD,cAAc,EAAE,gBAAgB,EAChC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,kBAAkB,EAChC,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CA6BhC;AAED,8CAA8C;AAC9C,MAAM,MAAM,QAAQ,GAAG;IACrB,4EAA4E;IAC5E,WAAW,EAAE,WAAW,CAAC;IACzB,6EAA6E;IAC7E,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC"}
@@ -2,7 +2,9 @@ import { SiloedTag } from '@aztec/stdlib/logs';
2
2
  import { TxHash } from '@aztec/stdlib/tx';
3
3
  import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
4
4
  /**
5
- * Loads tagging indexes from the Aztec node and stores them in the tagging data provider.
5
+ * Loads tagging indexes from the Aztec node and stores them in the tagging data provider. Returns the txs the
6
+ * window's logs carried, keyed by tx hash string, with the block each was mined in and the window indexes it used,
7
+ * so the caller can classify their finalization status without further node queries.
6
8
  * @remarks This function is one of two places by which a pending index can get to the tagging data provider. The other
7
9
  * place is when a tx is being sent from this PXE.
8
10
  * @param extendedSecret - The app tagging secret whose indexes are being synced.
@@ -10,10 +12,10 @@ import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
10
12
  * @param end - The ending index (exclusive) of the window to process.
11
13
  * @param aztecNode - The Aztec node instance to query for logs.
12
14
  * @param taggingStore - The data provider to store pending indexes.
13
- * @param anchorBlockHash - Hash of a block to use as reference block when querying node.
15
+ * @param anchor - Block the log query is anchored to.
14
16
  * @param jobId - Job identifier, used to keep writes in-memory until they can be persisted in a data integrity
15
17
  * preserving way.
16
- */ export async function loadAndStoreNewTaggingIndexes(extendedSecret, start, end, aztecNode, taggingStore, anchorBlockHash, jobId) {
18
+ */ export async function loadAndStoreNewTaggingIndexes(extendedSecret, start, end, aztecNode, taggingStore, anchor, jobId) {
17
19
  // We compute the tags for the current window of indexes
18
20
  const siloedTagsForWindow = await Promise.all(Array.from({
19
21
  length: end - start
@@ -21,56 +23,51 @@ import { getAllPrivateLogsByTags } from '../../get_all_logs_by_tags.js';
21
23
  extendedSecret,
22
24
  index: start + i
23
25
  })));
24
- const txsForTags = await getTxsContainingTags(siloedTagsForWindow, aztecNode, anchorBlockHash);
25
- const txIndexesMap = getTxIndexesMap(txsForTags, start, siloedTagsForWindow.length);
26
+ const allLogs = await getAllPrivateLogsByTags(aztecNode, siloedTagsForWindow, anchor);
27
+ if (allLogs.length !== siloedTagsForWindow.length) {
28
+ throw new Error(`Number of log arrays does not match number of tags. ${allLogs.length} !== ${siloedTagsForWindow.length}`);
29
+ }
30
+ const txsInLogs = getTxsInLogs(allLogs, start);
26
31
  // Now we iterate over the map, construct the tagging index ranges and store them in the db. A tx already tracked
27
32
  // in the store is merged rather than range-checked: if this PXE sent the tx and it partially reverted, the chain
28
33
  // only shows the surviving sub-range of the prove-time entry (the finalized receipt step of the sync owns
29
34
  // resolving that difference), and a tx from another PXE may straddle a sync window boundary, in which case the
30
35
  // entry is widened so the next index choice covers the full onchain range.
31
- for (const [txHashStr, indexes] of txIndexesMap.entries()){
36
+ for (const [txHashStr, { taggingIndexes }] of txsInLogs.entries()){
32
37
  const txHash = TxHash.fromString(txHashStr);
33
38
  const ranges = [
34
39
  {
35
40
  extendedSecret,
36
- lowestIndex: Math.min(...indexes),
37
- highestIndex: Math.max(...indexes)
41
+ lowestIndex: Math.min(...taggingIndexes),
42
+ highestIndex: Math.max(...taggingIndexes)
38
43
  }
39
44
  ];
40
45
  await taggingStore.mergePendingIndexes(ranges, txHash, jobId);
41
46
  }
47
+ return txsInLogs;
42
48
  }
43
- // Returns txs that used the given tags. A tag might have been used in multiple txs and for this reason we return
44
- // an array for each tag.
45
- async function getTxsContainingTags(tags, aztecNode, anchorBlockHash) {
46
- // We use the utility function below to retrieve all logs for the tags across all pages, so we don't need to handle
47
- // pagination here. Sender sync only needs `txHash` from each log, so we leave `includeEffects` off.
48
- const allLogs = await getAllPrivateLogsByTags(aztecNode, tags, anchorBlockHash);
49
- return allLogs.map((logs)=>logs.map((log)=>log.txHash));
50
- }
51
- // Returns a map of txHash to all indexes for that txHash.
52
- function getTxIndexesMap(txHashesForTags, start, count) {
53
- if (txHashesForTags.length !== count) {
54
- throw new Error(`Number of tx hashes arrays does not match number of tags. ${txHashesForTags.length} !== ${count}`);
55
- }
56
- const indexesMap = new Map();
49
+ // Returns a map of txHash to the block it was mined in and all window indexes used by it.
50
+ function getTxsInLogs(logsForTags, start) {
51
+ const txsInLogs = new Map();
57
52
  // Iterate over indexes
58
- for(let i = 0; i < txHashesForTags.length; i++){
53
+ for(let i = 0; i < logsForTags.length; i++){
59
54
  const taggingIndex = start + i;
60
- const txHashesForTag = txHashesForTags[i];
61
- // iterate over tx hashes that used that index (tag)
62
- for (const txHash of txHashesForTag){
63
- const key = txHash.toString();
64
- const existing = indexesMap.get(key);
55
+ // iterate over logs that used that index (tag)
56
+ for (const log of logsForTags[i]){
57
+ const key = log.txHash.toString();
58
+ const existing = txsInLogs.get(key);
65
59
  // Add the index to the tx's indexes
66
60
  if (existing) {
67
- existing.push(taggingIndex);
61
+ existing.taggingIndexes.push(taggingIndex);
68
62
  } else {
69
- indexesMap.set(key, [
70
- taggingIndex
71
- ]);
63
+ txsInLogs.set(key, {
64
+ blockNumber: log.blockNumber,
65
+ taggingIndexes: [
66
+ taggingIndex
67
+ ]
68
+ });
72
69
  }
73
70
  }
74
71
  }
75
- return indexesMap;
72
+ return txsInLogs;
76
73
  }
@@ -0,0 +1,29 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import type { AztecNode } from '@aztec/stdlib/interfaces/server';
3
+ import { type MinedTxReceipt, type TxHash } from '@aztec/stdlib/tx';
4
+ import type { PendingTx } from '../../../storage/tagging_store/sender_tagging_store.js';
5
+ import type { TxInLogs } from './load_and_store_new_tagging_indexes.js';
6
+ /** What a window's node reads established about each of its pending txs. */
7
+ export type ResolvedPendingTxs = {
8
+ txHashesFinalizedFromLogs: TxHash[];
9
+ txHashesFinalizedFromReceipts: TxHash[];
10
+ txHashesDropped: TxHash[];
11
+ /** Both sources land here: the logs when a surviving tag fell inside the window, a receipt otherwise. */
12
+ receiptsWithExecutionReverted: MinedTxReceipt<{
13
+ includeTxEffect: true;
14
+ }>[];
15
+ };
16
+ /**
17
+ * Resolves a window's pending txs. All of the window's node reads happen here.
18
+ *
19
+ * The logs it is handed settle most txs on their own, as {@link classifyPendingTxsFromLogs} explains. Two groups are
20
+ * left over, and share one further round trip:
21
+ *
22
+ * - txs absent from the logs, whose receipt is what tells whether they are still in the mempool, dropped, or reverted;
23
+ * - txs the logs show as reverted, which only their tx effect resolves.
24
+ *
25
+ * A third round trip is paid only when those receipts reveal a reverted tx, since its effect cannot be requested
26
+ * before its status says it reverted.
27
+ */
28
+ export declare function resolvePendingTxs(pendingTxs: PendingTx[], txsInLogs: Map<string, TxInLogs>, finalizedBlockNumber: BlockNumber, aztecNode: AztecNode): Promise<ResolvedPendingTxs>;
29
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVzb2x2ZV9wZW5kaW5nX3R4cy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RhZ2dpbmcvc2VuZGVyX3N5bmMvdXRpbHMvcmVzb2x2ZV9wZW5kaW5nX3R4cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNqRSxPQUFPLEVBQUUsS0FBSyxjQUFjLEVBQUUsS0FBSyxNQUFNLEVBQTRCLE1BQU0sa0JBQWtCLENBQUM7QUFFOUYsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0sd0RBQXdELENBQUM7QUFFeEYsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUFFLE1BQU0seUNBQXlDLENBQUM7QUFFeEUsNEVBQTRFO0FBQzVFLE1BQU0sTUFBTSxrQkFBa0IsR0FBRztJQUMvQix5QkFBeUIsRUFBRSxNQUFNLEVBQUUsQ0FBQztJQUNwQyw2QkFBNkIsRUFBRSxNQUFNLEVBQUUsQ0FBQztJQUN4QyxlQUFlLEVBQUUsTUFBTSxFQUFFLENBQUM7SUFDMUIseUdBQXlHO0lBQ3pHLDZCQUE2QixFQUFFLGNBQWMsQ0FBQztRQUFFLGVBQWUsRUFBRSxJQUFJLENBQUE7S0FBRSxDQUFDLEVBQUUsQ0FBQztDQUM1RSxDQUFDO0FBRUY7Ozs7Ozs7Ozs7O0dBV0c7QUFDSCx3QkFBc0IsaUJBQWlCLENBQ3JDLFVBQVUsRUFBRSxTQUFTLEVBQUUsRUFDdkIsU0FBUyxFQUFFLEdBQUcsQ0FBQyxNQUFNLEVBQUUsUUFBUSxDQUFDLEVBQ2hDLG9CQUFvQixFQUFFLFdBQVcsRUFDakMsU0FBUyxFQUFFLFNBQVMsR0FDbkIsT0FBTyxDQUFDLGtCQUFrQixDQUFDLENBbUI3QiJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve_pending_txs.d.ts","sourceRoot":"","sources":["../../../../src/tagging/sender_sync/utils/resolve_pending_txs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,MAAM,EAA4B,MAAM,kBAAkB,CAAC;AAE9F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wDAAwD,CAAC;AAExF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yCAAyC,CAAC;AAExE,4EAA4E;AAC5E,MAAM,MAAM,kBAAkB,GAAG;IAC/B,yBAAyB,EAAE,MAAM,EAAE,CAAC;IACpC,6BAA6B,EAAE,MAAM,EAAE,CAAC;IACxC,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,yGAAyG;IACzG,6BAA6B,EAAE,cAAc,CAAC;QAAE,eAAe,EAAE,IAAI,CAAA;KAAE,CAAC,EAAE,CAAC;CAC5E,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,SAAS,EAAE,EACvB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,EAChC,oBAAoB,EAAE,WAAW,EACjC,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,kBAAkB,CAAC,CAmB7B"}
@@ -0,0 +1,41 @@
1
+ import { TxStatus } from '@aztec/stdlib/tx';
2
+ import { classifyPendingTxsFromLogs, classifyPendingTxsFromReceipts } from './classify_pending_txs.js';
3
+ /**
4
+ * Resolves a window's pending txs. All of the window's node reads happen here.
5
+ *
6
+ * The logs it is handed settle most txs on their own, as {@link classifyPendingTxsFromLogs} explains. Two groups are
7
+ * left over, and share one further round trip:
8
+ *
9
+ * - txs absent from the logs, whose receipt is what tells whether they are still in the mempool, dropped, or reverted;
10
+ * - txs the logs show as reverted, which only their tx effect resolves.
11
+ *
12
+ * A third round trip is paid only when those receipts reveal a reverted tx, since its effect cannot be requested
13
+ * before its status says it reverted.
14
+ */ export async function resolvePendingTxs(pendingTxs, txsInLogs, finalizedBlockNumber, aztecNode) {
15
+ const statusFromLogs = classifyPendingTxsFromLogs(pendingTxs, txsInLogs, finalizedBlockNumber);
16
+ const [statusOfAbsent, receiptsOfRevertedInLogs] = await Promise.all([
17
+ classifyPendingTxsFromReceipts(statusFromLogs.txHashesAbsent, aztecNode),
18
+ getReceiptsWithEffect(statusFromLogs.txHashesWithExecutionReverted, aztecNode)
19
+ ]);
20
+ const receiptsOfRevertedAbsent = await getReceiptsWithEffect(statusOfAbsent.txHashesWithExecutionReverted, aztecNode);
21
+ return {
22
+ txHashesFinalizedFromLogs: statusFromLogs.txHashesFinalized,
23
+ txHashesFinalizedFromReceipts: statusOfAbsent.txHashesFinalized,
24
+ txHashesDropped: statusOfAbsent.txHashesDropped,
25
+ // Both groups were judged finalized before this fetch, the first off our own tip and the second off an earlier
26
+ // receipt, so both are confirmed against what the node says now. Finalizing off a reorgeable block would burn
27
+ // the indexes.
28
+ receiptsWithExecutionReverted: [
29
+ ...receiptsOfRevertedInLogs,
30
+ ...receiptsOfRevertedAbsent
31
+ ].filter(isFinalized)
32
+ };
33
+ }
34
+ function getReceiptsWithEffect(txHashes, aztecNode) {
35
+ return Promise.all(txHashes.map((txHash)=>aztecNode.getTxReceipt(txHash, {
36
+ includeTxEffect: true
37
+ })));
38
+ }
39
+ function isFinalized(receipt) {
40
+ return receipt.status === TxStatus.FINALIZED;
41
+ }
@@ -0,0 +1,16 @@
1
+ import type { MinedTxStatus, TxEffect, TxHash } from '@aztec/stdlib/tx';
2
+ import { MinedTxReceipt, TxExecutionResult } from '@aztec/stdlib/tx';
3
+ import type { PendingTx } from '../../../storage/tagging_store/sender_tagging_store.js';
4
+ import type { TxInLogs } from './load_and_store_new_tagging_indexes.js';
5
+ /** A tx the store holds as pending, tracked up to the given index. */
6
+ export declare function pendingTx(txHash: TxHash, highestIndex: number): PendingTx;
7
+ /** One tx as a window's logs show it: the block it was mined in and the tagging indexes its logs carried. */
8
+ export declare function minedIn(blockNumber: number, taggingIndexes: number[]): TxInLogs;
9
+ /** Builds the tx-hash-keyed map a window's logs would produce. */
10
+ export declare function txsInLogs(...entries: [TxHash, TxInLogs][]): Map<string, TxInLogs>;
11
+ /** The receipt of a mined tx, successful and without a tx effect unless stated otherwise. */
12
+ export declare function minedReceipt(txHash: TxHash, status: MinedTxStatus, blockNumber: number, { executionResult, txEffect }?: {
13
+ executionResult?: TxExecutionResult;
14
+ txEffect?: TxEffect;
15
+ }): MinedTxReceipt;
16
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdF91dGlscy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL3RhZ2dpbmcvc2VuZGVyX3N5bmMvdXRpbHMvdGVzdF91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsUUFBUSxFQUFFLE1BQU0sRUFBRSxNQUFNLGtCQUFrQixDQUFDO0FBQ3hFLE9BQU8sRUFBRSxjQUFjLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUVyRSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSx3REFBd0QsQ0FBQztBQUN4RixPQUFPLEtBQUssRUFBRSxRQUFRLEVBQUUsTUFBTSx5Q0FBeUMsQ0FBQztBQUV4RSxzRUFBc0U7QUFDdEUsd0JBQWdCLFNBQVMsQ0FBQyxNQUFNLEVBQUUsTUFBTSxFQUFFLFlBQVksRUFBRSxNQUFNLEdBQUcsU0FBUyxDQUV6RTtBQUVELDZHQUE2RztBQUM3Ryx3QkFBZ0IsT0FBTyxDQUFDLFdBQVcsRUFBRSxNQUFNLEVBQUUsY0FBYyxFQUFFLE1BQU0sRUFBRSxHQUFHLFFBQVEsQ0FFL0U7QUFFRCxrRUFBa0U7QUFDbEUsd0JBQWdCLFNBQVMsQ0FBQyxHQUFHLE9BQU8sRUFBRSxDQUFDLE1BQU0sRUFBRSxRQUFRLENBQUMsRUFBRSxHQUFHLEdBQUcsQ0FBQyxNQUFNLEVBQUUsUUFBUSxDQUFDLENBRWpGO0FBRUQsNkZBQTZGO0FBQzdGLHdCQUFnQixZQUFZLENBQzFCLE1BQU0sRUFBRSxNQUFNLEVBQ2QsTUFBTSxFQUFFLGFBQWEsRUFDckIsV0FBVyxFQUFFLE1BQU0sRUFDbkIsRUFDRSxlQUEyQyxFQUMzQyxRQUFRLEVBQ1QsR0FBRTtJQUFFLGVBQWUsQ0FBQyxFQUFFLGlCQUFpQixDQUFDO0lBQUMsUUFBUSxDQUFDLEVBQUUsUUFBUSxDQUFBO0NBQU8sR0FDbkUsY0FBYyxDQWFoQiJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test_utils.d.ts","sourceRoot":"","sources":["../../../../src/tagging/sender_sync/utils/test_utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wDAAwD,CAAC;AACxF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yCAAyC,CAAC;AAExE,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,SAAS,CAEzE;AAED,6GAA6G;AAC7G,wBAAgB,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,QAAQ,CAE/E;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,GAAG,OAAO,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAEjF;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,MAAM,EACnB,EACE,eAA2C,EAC3C,QAAQ,EACT,GAAE;IAAE,eAAe,CAAC,EAAE,iBAAiB,CAAC;IAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAAO,GACnE,cAAc,CAahB"}
@@ -0,0 +1,24 @@
1
+ import { BlockNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { BlockHash } from '@aztec/stdlib/block';
3
+ import { MinedTxReceipt, TxExecutionResult } from '@aztec/stdlib/tx';
4
+ /** A tx the store holds as pending, tracked up to the given index. */ export function pendingTx(txHash, highestIndex) {
5
+ return {
6
+ txHash: txHash.toString(),
7
+ highestIndex
8
+ };
9
+ }
10
+ /** One tx as a window's logs show it: the block it was mined in and the tagging indexes its logs carried. */ export function minedIn(blockNumber, taggingIndexes) {
11
+ return {
12
+ blockNumber: BlockNumber(blockNumber),
13
+ taggingIndexes
14
+ };
15
+ }
16
+ /** Builds the tx-hash-keyed map a window's logs would produce. */ export function txsInLogs(...entries) {
17
+ return new Map(entries.map(([txHash, txInLogs])=>[
18
+ txHash.toString(),
19
+ txInLogs
20
+ ]));
21
+ }
22
+ /** The receipt of a mined tx, successful and without a tx effect unless stated otherwise. */ export function minedReceipt(txHash, status, blockNumber, { executionResult = TxExecutionResult.SUCCESS, txEffect } = {}) {
23
+ return new MinedTxReceipt(txHash, status, executionResult, 1n, BlockHash.random(), BlockNumber(blockNumber), SlotNumber(Number(blockNumber)), 0, EpochNumber(1), txEffect);
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/pxe",
3
- "version": "0.0.1-commit.321f6a9",
3
+ "version": "0.0.1-commit.330febf",
4
4
  "type": "module",
5
5
  "typedocOptions": {
6
6
  "entryPoints": [
@@ -71,20 +71,20 @@
71
71
  ]
72
72
  },
73
73
  "dependencies": {
74
- "@aztec/bb-prover": "0.0.1-commit.321f6a9",
75
- "@aztec/bb.js": "0.0.1-commit.321f6a9",
76
- "@aztec/builder": "0.0.1-commit.321f6a9",
77
- "@aztec/constants": "0.0.1-commit.321f6a9",
78
- "@aztec/ethereum": "0.0.1-commit.321f6a9",
79
- "@aztec/foundation": "0.0.1-commit.321f6a9",
80
- "@aztec/key-store": "0.0.1-commit.321f6a9",
81
- "@aztec/kv-store": "0.0.1-commit.321f6a9",
82
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.321f6a9",
83
- "@aztec/noir-types": "0.0.1-commit.321f6a9",
84
- "@aztec/protocol-contracts": "0.0.1-commit.321f6a9",
85
- "@aztec/simulator": "0.0.1-commit.321f6a9",
86
- "@aztec/standard-contracts": "0.0.1-commit.321f6a9",
87
- "@aztec/stdlib": "0.0.1-commit.321f6a9",
74
+ "@aztec/bb-prover": "0.0.1-commit.330febf",
75
+ "@aztec/bb.js": "6.0.0-nightly.20260807",
76
+ "@aztec/builder": "0.0.1-commit.330febf",
77
+ "@aztec/constants": "0.0.1-commit.330febf",
78
+ "@aztec/ethereum": "0.0.1-commit.330febf",
79
+ "@aztec/foundation": "0.0.1-commit.330febf",
80
+ "@aztec/key-store": "0.0.1-commit.330febf",
81
+ "@aztec/kv-store": "0.0.1-commit.330febf",
82
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.330febf",
83
+ "@aztec/noir-types": "0.0.1-commit.330febf",
84
+ "@aztec/protocol-contracts": "0.0.1-commit.330febf",
85
+ "@aztec/simulator": "0.0.1-commit.330febf",
86
+ "@aztec/standard-contracts": "0.0.1-commit.330febf",
87
+ "@aztec/stdlib": "0.0.1-commit.330febf",
88
88
  "koa": "^2.16.1",
89
89
  "koa-router": "^13.1.1",
90
90
  "lodash.omit": "^4.5.0",
@@ -93,8 +93,8 @@
93
93
  "viem": "npm:@aztec/viem@2.38.2"
94
94
  },
95
95
  "devDependencies": {
96
- "@aztec/noir-test-contracts.js": "0.0.1-commit.321f6a9",
97
- "@aztec/world-state": "0.0.1-commit.321f6a9",
96
+ "@aztec/noir-test-contracts.js": "0.0.1-commit.330febf",
97
+ "@aztec/world-state": "0.0.1-commit.330febf",
98
98
  "@jest/globals": "^30.0.0",
99
99
  "@types/jest": "^30.0.0",
100
100
  "@types/lodash.omit": "^4.5.7",
@@ -1,11 +1,8 @@
1
1
  import { keccak256String } from '@aztec/foundation/crypto/keccak';
2
2
 
3
- import { dirname, join } from 'path';
4
- import { fileURLToPath } from 'url';
5
-
6
3
  import { ORACLE_REGISTRY } from '../contract_function_simulator/index.js';
7
- import { ORACLE_INTERFACE_HASH, ORACLE_VERSION_MAJOR } from '../oracle_version.js';
8
- import { getOracleRegistrySignature, readNumericGlobal } from './oracle_version_helpers.js';
4
+ import { ORACLE_INTERFACE_HASH } from '../oracle_version.js';
5
+ import { getOracleRegistrySignature } from './oracle_version_helpers.js';
9
6
 
10
7
  /**
11
8
  * Verifies that the Oracle interface matches the expected interface hash.
@@ -28,45 +25,4 @@ function assertOracleInterfaceMatches(): void {
28
25
  }
29
26
  }
30
27
 
31
- /**
32
- * Verifies that `ORACLE_VERSION_MAJOR` is identical across all of its hand-maintained copies.
33
- *
34
- * The major version is duplicated across the PXE TypeScript constant and two Noir constants (Aztec.nr and the protocol
35
- * contracts' `aztec_sublib`) because those layers can't import each other. This static check fails fast at build time,
36
- * naming each file and its value.
37
- *
38
- * Only the major version is checked: the minor version legitimately diverges under the "environment minor >= contract
39
- * minor" tolerance, so asserting minor equality would false-positive.
40
- */
41
- function assertContractOracleVersionMajorInSync(): void {
42
- const currentDir = dirname(fileURLToPath(import.meta.url));
43
- // Go up from dest/bin/ or src/bin/ to the package root (pxe/), then up two more to the git root.
44
- const packageRoot = dirname(dirname(currentDir));
45
- const gitRoot = join(packageRoot, '..', '..');
46
-
47
- const copies = [
48
- { label: 'pxe/src/oracle_version.ts', value: ORACLE_VERSION_MAJOR },
49
- {
50
- label: 'aztec-nr/aztec/src/oracle/version.nr',
51
- value: readNumericGlobal(
52
- join(gitRoot, 'noir-projects/aztec-nr/aztec/src/oracle/version.nr'),
53
- 'ORACLE_VERSION_MAJOR',
54
- ),
55
- },
56
- {
57
- label: 'aztec_sublib/src/oracle/version.nr',
58
- value: readNumericGlobal(
59
- join(gitRoot, 'noir-projects/noir-contracts/contracts/protocol/aztec_sublib/src/oracle/version.nr'),
60
- 'ORACLE_VERSION_MAJOR',
61
- ),
62
- },
63
- ];
64
-
65
- if (new Set(copies.map(copy => copy.value)).size > 1) {
66
- const details = copies.map(copy => `${copy.label}=${copy.value}`).join(', ');
67
- throw new Error(`ORACLE_VERSION_MAJOR is out of sync: ${details}. Bump all copies together.`);
68
- }
69
- }
70
-
71
28
  assertOracleInterfaceMatches();
72
- assertContractOracleVersionMajorInSync();
package/src/bin/index.ts CHANGED
@@ -1 +1 @@
1
- export { getOracleRegistrySignature, readNumericGlobal } from './oracle_version_helpers.js';
1
+ export { getOracleRegistrySignature } from './oracle_version_helpers.js';
@@ -1,5 +1,3 @@
1
- import { readFileSync } from 'fs';
2
-
3
1
  import type { OracleRegistryEntry } from '../contract_function_simulator/index.js';
4
2
 
5
3
  /**
@@ -30,25 +28,3 @@ export function getOracleRegistrySignature(registry: Record<string, OracleRegist
30
28
 
31
29
  return oracleSignatures.join('\n');
32
30
  }
33
-
34
- /**
35
- * Reads an integer-valued global constant from a Noir or TypeScript source file.
36
- *
37
- * Matches both the Noir form (`pub global NAME: Field = N;`) and the TypeScript form (`export const NAME = N;`). This
38
- * lets us compare a version constant that is hand-duplicated across the TS and Noir layers (which can't import each
39
- * other) without depending on either compiler. Only the assignment form `NAME = N` matches, so later usages of the
40
- * constant are ignored regardless of their order in the file.
41
- *
42
- * @param sourcePath - Absolute path to the source file to read.
43
- * @param name - Name of the global constant whose integer value should be extracted.
44
- * @returns The integer value assigned to the constant.
45
- * @throws If the constant's declaration is not found in the file.
46
- */
47
- export function readNumericGlobal(sourcePath: string, name: string): number {
48
- const sourceCode = readFileSync(sourcePath, 'utf-8');
49
- const match = sourceCode.match(new RegExp(`\\b${name}\\s*(?::\\s*\\w+\\s*)?=\\s*(\\d+)`));
50
- if (!match) {
51
- throw new Error(`Could not find numeric global '${name}' in ${sourcePath}.`);
52
- }
53
- return Number(match[1]);
54
- }
@@ -4,12 +4,11 @@ import { SerialQueue } from '@aztec/foundation/queue';
4
4
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
5
5
  import type { L2TipsKVStore } from '@aztec/kv-store/stores';
6
6
  import { BlockHash, L2BlockStream, type L2BlockStreamEvent, type L2BlockStreamEventHandler } from '@aztec/stdlib/block';
7
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
8
7
  import type { BlockHeader } from '@aztec/stdlib/tx';
9
8
 
10
9
  import type { BlockSynchronizerConfig } from '../config/index.js';
11
- import type { ContractClassService } from '../contract/contract_class_service.js';
12
10
  import type { ContractSyncService } from '../contract/contract_sync_service.js';
11
+ import type { CachingAztecNode } from '../node/caching_aztec_node.js';
13
12
  import type { AnchorBlockStore } from '../storage/anchor_block_store/index.js';
14
13
  import type { FactStore } from '../storage/fact_store/fact_store.js';
15
14
  import type { NoteStore } from '../storage/note_store/index.js';
@@ -28,7 +27,7 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
28
27
  protected readonly blockStream: L2BlockStream;
29
28
 
30
29
  constructor(
31
- private readonly node: AztecNode,
30
+ private readonly node: CachingAztecNode,
32
31
  private readonly store: AztecAsyncKVStore,
33
32
  private readonly anchorBlockStore: AnchorBlockStore,
34
33
  private readonly noteStore: NoteStore,
@@ -36,7 +35,6 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
36
35
  private readonly factStore: FactStore,
37
36
  private readonly l2TipsStore: L2TipsKVStore,
38
37
  private readonly contractSyncService: ContractSyncService,
39
- private readonly contractClassService: ContractClassService,
40
38
  private readonly config: Partial<BlockSynchronizerConfig> = {},
41
39
  bindings?: LoggerBindings,
42
40
  ) {
@@ -68,21 +66,7 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
68
66
  switch (event.type) {
69
67
  case 'chain-proposed': {
70
68
  if (this.config.syncChainTip === undefined || this.config.syncChainTip === 'proposed') {
71
- // Fetch the proposed tip header by hash. By-hash is safer than by-number against a same-height reorg.
72
- const block = await this.node.getBlockData(BlockHash.fromString(event.block.hash));
73
- if (!block) {
74
- // The node served a proposed tip whose block data it cannot return — a node inconsistency, since the
75
- // stream events and the block data come from the same node (same reasoning as the chain-pruned throw
76
- // below). Throwing here propagates before the tips-store cursor advances, so the cursor stays put and the
77
- // next sync re-emits chain-proposed (at-least-once). Were we to warn-and-skip, the cursor would advance and
78
- // a quiet chain would never re-emit, leaving the anchor stale indefinitely.
79
- throw new Error(
80
- `Block header for proposed block ${event.block.number} and hash ${event.block.hash} not found. This ` +
81
- `likely indicates a bug in the node, as we receive block stream events and fetch block headers from ` +
82
- `the same node.`,
83
- );
84
- }
85
- await this.updateAnchorBlockHeader(block.header);
69
+ await this.updateAnchorBlockHeader(event.header);
86
70
  }
87
71
  break;
88
72
  }
@@ -180,10 +164,9 @@ export class BlockSynchronizer implements L2BlockStreamEventHandler {
180
164
  // execution.
181
165
  this.contractSyncService.wipe();
182
166
 
183
- // The contract class service keeps a per-block cache - since updating our anchor means it is very unlikely we'd
184
- // ever re-simulate at past anchors, we wipe its cache to prevent runaway memory growth on very long-lived PXE
185
- // instances.
186
- this.contractClassService.wipe();
167
+ // Cached node reads stay correct indefinitely, so this wipe is only about bounding memory growth. An anchor
168
+ // update is the recurring trigger PXE already has.
169
+ this.node.wipeCache();
187
170
 
188
171
  this.log.verbose(`Updated pxe last block to ${blockHeader.getBlockNumber()}`, blockHeader.toInspect());
189
172
  await this.anchorBlockStore.setHeader(blockHeader);
@@ -14,14 +14,6 @@ import type { ContractStore } from '../storage/contract_store/contract_store.js'
14
14
  * falling back to a local instance if no upgrades were scheduled.
15
15
  */
16
16
  export class ContractClassService {
17
- /**
18
- * Class ids are cached per `(address, anchorHash)`. This avoid unnecessary network roundtrips in scenarios where
19
- * multiple executions are done on the same anchor block (e.g. simulation followed by witgen), or when the same
20
- * contract is invoked multiple times in an execution (e.g. authwit checks).
21
- * It also means the callers don't need to worry about caching this service's return values, simplifying callsites.
22
- */
23
- #cache: Map<string, Promise<Fr | undefined>> = new Map();
24
-
25
17
  constructor(
26
18
  private node: AztecNode,
27
19
  private contractStore: ContractStore,
@@ -40,44 +32,14 @@ export class ContractClassService {
40
32
  return instance?.originalContractClassId;
41
33
  }
42
34
 
43
- const key = `${address.toString()}:${(await anchorBlockHeader.hash()).toString()}`;
44
- let promise = this.#cache.get(key);
45
- if (!promise) {
46
- promise = (async () => {
47
- // The node resolves the current class from the same scheduled value change the AVM enforces against the public
48
- // data tree. If the contract was upgraded the node returns a non-undefined instance; an undefined result means
49
- // no upgrade happened (or the node has no record of it, e.g. it was never publicly deployed), so the original
50
- // class is current.
51
-
52
- const nodeInstance = await this.node.getContract(address, await anchorBlockHeader.hash());
53
-
54
- if (nodeInstance) {
55
- return nodeInstance.currentContractClassId;
56
- } else {
57
- return (await this.contractStore.getContractInstance(address))?.originalContractClassId;
58
- }
59
- })().catch(err => {
60
- this.#cache.delete(key);
61
- throw err;
62
- });
63
- this.#cache.set(key, promise);
64
- }
65
-
66
- const classId = await promise;
67
- if (classId === undefined) {
68
- // Don't memoize a missing instance: it may be registered later in this PXE (e.g. via contract sync
69
- // mid-execution), and a cached miss would then hide it. Only successful resolutions stay cached.
70
- this.#cache.delete(key);
35
+ // The node resolves the current class from the same scheduled value change the AVM enforces against the public
36
+ // data tree. If the contract was upgraded the node returns a non-undefined instance; an undefined result means no
37
+ // upgrade happened (or the node has no record of it, e.g. it was never publicly deployed), so the original class
38
+ // is current.
39
+ const nodeInstance = await this.node.getContract(address, await anchorBlockHeader.hash());
40
+ if (nodeInstance) {
41
+ return nodeInstance.currentContractClassId;
71
42
  }
72
- return classId;
73
- }
74
-
75
- /**
76
- * Clears the cache.
77
- *
78
- * This is not required for correctness, only to limit how much memory the cache uses. The cache is resilient against
79
- * reorgs etc. as it is based on block hashes, not block numbers. */
80
- wipe(): void {
81
- this.#cache.clear();
43
+ return (await this.contractStore.getContractInstance(address))?.originalContractClassId;
82
44
  }
83
45
  }