@aztec/pxe 4.0.0-nightly.20260112 → 4.0.0-nightly.20260114

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 (78) hide show
  1. package/dest/block_synchronizer/block_synchronizer.d.ts +4 -2
  2. package/dest/block_synchronizer/block_synchronizer.d.ts.map +1 -1
  3. package/dest/block_synchronizer/block_synchronizer.js +19 -13
  4. package/dest/contract_function_simulator/oracle/interfaces.d.ts +3 -3
  5. package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts +4 -4
  7. package/dest/contract_function_simulator/oracle/note_packing_utils.d.ts.map +1 -1
  8. package/dest/contract_function_simulator/oracle/note_packing_utils.js +5 -5
  9. package/dest/contract_function_simulator/oracle/oracle.js +1 -1
  10. package/dest/contract_function_simulator/oracle/private_execution.d.ts +1 -1
  11. package/dest/contract_function_simulator/oracle/private_execution.d.ts.map +1 -1
  12. package/dest/contract_function_simulator/oracle/private_execution.js +1 -2
  13. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +1 -16
  14. package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
  15. package/dest/contract_function_simulator/oracle/private_execution_oracle.js +4 -31
  16. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +1 -1
  17. package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
  18. package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +15 -13
  19. package/dest/events/event_service.d.ts +1 -1
  20. package/dest/events/event_service.d.ts.map +1 -1
  21. package/dest/events/event_service.js +8 -12
  22. package/dest/logs/log_service.d.ts +3 -2
  23. package/dest/logs/log_service.d.ts.map +1 -1
  24. package/dest/logs/log_service.js +4 -2
  25. package/dest/notes/note_service.d.ts +2 -2
  26. package/dest/notes/note_service.d.ts.map +1 -1
  27. package/dest/notes/note_service.js +14 -22
  28. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts +2 -2
  29. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.d.ts.map +1 -1
  30. package/dest/private_kernel/hints/build_private_kernel_reset_private_inputs.js +2 -2
  31. package/dest/private_kernel/private_kernel_execution_prover.d.ts +1 -1
  32. package/dest/private_kernel/private_kernel_execution_prover.d.ts.map +1 -1
  33. package/dest/private_kernel/private_kernel_execution_prover.js +3 -4
  34. package/dest/private_kernel/private_kernel_oracle.d.ts +24 -28
  35. package/dest/private_kernel/private_kernel_oracle.d.ts.map +1 -1
  36. package/dest/private_kernel/private_kernel_oracle.js +92 -2
  37. package/dest/pxe.d.ts +7 -36
  38. package/dest/pxe.d.ts.map +1 -1
  39. package/dest/pxe.js +12 -59
  40. package/dest/storage/capsule_store/capsule_store.d.ts +24 -9
  41. package/dest/storage/capsule_store/capsule_store.d.ts.map +1 -1
  42. package/dest/storage/capsule_store/capsule_store.js +132 -23
  43. package/dest/storage/note_store/note_store.d.ts +6 -5
  44. package/dest/storage/note_store/note_store.d.ts.map +1 -1
  45. package/dest/storage/note_store/note_store.js +89 -94
  46. package/dest/storage/private_event_store/private_event_store.d.ts +13 -6
  47. package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
  48. package/dest/storage/private_event_store/private_event_store.js +70 -56
  49. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts +1 -1
  50. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.d.ts.map +1 -1
  51. package/dest/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.js +1 -1
  52. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts +1 -1
  53. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.d.ts.map +1 -1
  54. package/dest/tagging/sender_sync/utils/get_status_change_of_pending.js +2 -2
  55. package/package.json +16 -16
  56. package/src/block_synchronizer/block_synchronizer.ts +23 -12
  57. package/src/contract_function_simulator/oracle/interfaces.ts +2 -2
  58. package/src/contract_function_simulator/oracle/note_packing_utils.ts +6 -6
  59. package/src/contract_function_simulator/oracle/oracle.ts +1 -1
  60. package/src/contract_function_simulator/oracle/private_execution.ts +0 -2
  61. package/src/contract_function_simulator/oracle/private_execution_oracle.ts +2 -36
  62. package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +15 -10
  63. package/src/events/event_service.ts +12 -26
  64. package/src/logs/log_service.ts +2 -1
  65. package/src/notes/note_service.ts +14 -23
  66. package/src/private_kernel/hints/build_private_kernel_reset_private_inputs.ts +1 -2
  67. package/src/private_kernel/private_kernel_execution_prover.ts +2 -4
  68. package/src/private_kernel/private_kernel_oracle.ts +119 -36
  69. package/src/pxe.ts +10 -81
  70. package/src/storage/capsule_store/capsule_store.ts +159 -23
  71. package/src/storage/note_store/note_store.ts +98 -95
  72. package/src/storage/private_event_store/private_event_store.ts +92 -65
  73. package/src/tagging/recipient_sync/load_private_logs_for_sender_recipient_pair.ts +4 -1
  74. package/src/tagging/sender_sync/utils/get_status_change_of_pending.ts +6 -2
  75. package/dest/private_kernel/private_kernel_oracle_impl.d.ts +0 -46
  76. package/dest/private_kernel/private_kernel_oracle_impl.d.ts.map +0 -1
  77. package/dest/private_kernel/private_kernel_oracle_impl.js +0 -86
  78. package/src/private_kernel/private_kernel_oracle_impl.ts +0 -133
@@ -1,34 +1,120 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
3
  export class CapsuleStore {
4
+ storeName = 'capsule';
4
5
  #store;
5
6
  // Arbitrary data stored by contracts. Key is computed as `${contractAddress}:${key}`
6
7
  #capsules;
8
+ // jobId => `${contractAddress}:${key}` => capsule data
9
+ // when `#stagedCapsules.get('some-job-id').get('${some-contract-address:some-key') === null`,
10
+ // it signals that the capsule was deleted during the job, so it needs to be deleted on commit
11
+ #stagedCapsules;
7
12
  logger;
8
13
  constructor(store){
9
14
  this.#store = store;
10
15
  this.#capsules = this.#store.openMap('capsules');
16
+ this.#stagedCapsules = new Map();
11
17
  this.logger = createLogger('pxe:capsule-data-provider');
12
18
  }
13
19
  /**
20
+ * Given a job denoted by `jobId`, it returns the
21
+ * capsules that said job has interacted with.
22
+ *
23
+ * Capsules that haven't been committed to persistence KV storage
24
+ * are kept in-memory in `#stagedCapsules`, this method provides a convenient
25
+ * way to access that in-memory collection of data.
26
+ *
27
+ * @param jobId
28
+ * @returns
29
+ */ #getJobStagedCapsules(jobId) {
30
+ let jobStagedCapsules = this.#stagedCapsules.get(jobId);
31
+ if (!jobStagedCapsules) {
32
+ jobStagedCapsules = new Map();
33
+ this.#stagedCapsules.set(jobId, jobStagedCapsules);
34
+ }
35
+ return jobStagedCapsules;
36
+ }
37
+ /**
38
+ * Reads a capsule's slot from the staged version of the data associated to the given jobId.
39
+ *
40
+ * If it is not there, it reads it from the KV store.
41
+ */ async #getFromStage(jobId, dbSlotKey) {
42
+ const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
43
+ let staged = jobStagedCapsules.get(dbSlotKey);
44
+ // Note that if staged === null, we marked it for deletion, so we don't want to
45
+ // re-read it from DB
46
+ if (staged === undefined) {
47
+ // If we don't have a staged version of this dbSlotKey, first we check if there's one in DB
48
+ staged = await this.#loadCapsuleFromDb(dbSlotKey);
49
+ }
50
+ return staged;
51
+ }
52
+ /**
53
+ * Writes a capsule to the stage of a job.
54
+ */ #setOnStage(jobId, dbSlotKey, capsuleData) {
55
+ this.#getJobStagedCapsules(jobId).set(dbSlotKey, capsuleData);
56
+ }
57
+ /**
58
+ * Deletes a capsule on the stage of a job. Note the capsule will still
59
+ * exist in storage until the job is committed.
60
+ */ #deleteOnStage(jobId, dbSlotKey) {
61
+ this.#getJobStagedCapsules(jobId).set(dbSlotKey, null);
62
+ }
63
+ async #loadCapsuleFromDb(dbSlotKey) {
64
+ const dataBuffer = await this.#capsules.getAsync(dbSlotKey);
65
+ if (!dataBuffer) {
66
+ return null;
67
+ }
68
+ return dataBuffer;
69
+ }
70
+ /**
71
+ * Commits staged data to main storage.
72
+ * Called by JobCoordinator when a job completes successfully.
73
+ * Note: JobCoordinator wraps all commits in a single transaction, so we don't
74
+ * need our own transactionAsync here (and using one would deadlock on IndexedDB).
75
+ * @param jobId - The jobId identifying which staged data to commit
76
+ */ async commit(jobId) {
77
+ const jobStagedCapsules = this.#getJobStagedCapsules(jobId);
78
+ for (const [key, value] of jobStagedCapsules){
79
+ // In the write stage, we represent deleted capsules with null
80
+ // (as opposed to undefined, which denotes there was never a capsule there to begin with).
81
+ // So we delete from actual KV store here.
82
+ if (value === null) {
83
+ await this.#capsules.delete(key);
84
+ } else {
85
+ await this.#capsules.set(key, value);
86
+ }
87
+ }
88
+ this.#stagedCapsules.delete(jobId);
89
+ }
90
+ /**
91
+ * Discards staged data without committing.
92
+ */ discardStaged(jobId) {
93
+ this.#stagedCapsules.delete(jobId);
94
+ return Promise.resolve();
95
+ }
96
+ /**
14
97
  * Stores arbitrary information in a per-contract non-volatile database, which can later be retrieved with `loadCapsule`.
15
98
  * * If data was already stored at this slot, it is overwritten.
16
99
  * @param contractAddress - The contract address to scope the data under.
17
100
  * @param slot - The slot in the database in which to store the value. Slots need not be contiguous.
18
101
  * @param capsule - An array of field elements representing the capsule.
102
+ * @param jobId - The context in which this store will be visible until PXE decides to persist it to underlying KV store
19
103
  * @remarks A capsule is a "blob" of data that is passed to the contract through an oracle. It works similarly
20
104
  * to public contract storage in that it's indexed by the contract address and storage slot but instead of the global
21
105
  * network state it's backed by local PXE db.
22
- */ async storeCapsule(contractAddress, slot, capsule) {
23
- await this.#capsules.set(dbSlotToKey(contractAddress, slot), Buffer.concat(capsule.map((value)=>value.toBuffer())));
106
+ */ storeCapsule(contractAddress, slot, capsule, jobId) {
107
+ const dbSlotKey = dbSlotToKey(contractAddress, slot);
108
+ // A store overrides any pre-existing data on the slot
109
+ this.#setOnStage(jobId, dbSlotKey, Buffer.concat(capsule.map((value)=>value.toBuffer())));
24
110
  }
25
111
  /**
26
112
  * Returns data previously stored via `storeCapsule` in the per-contract non-volatile database.
27
113
  * @param contractAddress - The contract address under which the data is scoped.
28
114
  * @param slot - The slot in the database to read.
29
115
  * @returns The stored data or `null` if no data is stored under the slot.
30
- */ async loadCapsule(contractAddress, slot) {
31
- const dataBuffer = await this.#capsules.getAsync(dbSlotToKey(contractAddress, slot));
116
+ */ async loadCapsule(contractAddress, slot, jobId) {
117
+ const dataBuffer = await this.#getFromStage(jobId, dbSlotToKey(contractAddress, slot));
32
118
  if (!dataBuffer) {
33
119
  this.logger.trace(`Data not found for contract ${contractAddress.toString()} and slot ${slot.toString()}`);
34
120
  return null;
@@ -43,8 +129,9 @@ export class CapsuleStore {
43
129
  * Deletes data in the per-contract non-volatile database. Does nothing if no data was present.
44
130
  * @param contractAddress - The contract address under which the data is scoped.
45
131
  * @param slot - The slot in the database to delete.
46
- */ async deleteCapsule(contractAddress, slot) {
47
- await this.#capsules.delete(dbSlotToKey(contractAddress, slot));
132
+ */ deleteCapsule(contractAddress, slot, jobId) {
133
+ // When we commit this, we will interpret null as a deletion, so we'll propagate the delete to the KV store
134
+ this.#deleteOnStage(jobId, dbSlotToKey(contractAddress, slot));
48
135
  }
49
136
  /**
50
137
  * Copies a number of contiguous entries in the per-contract non-volatile database. This allows for efficient data
@@ -56,7 +143,11 @@ export class CapsuleStore {
56
143
  * @param srcSlot - The first slot to copy from.
57
144
  * @param dstSlot - The first slot to copy to.
58
145
  * @param numEntries - The number of entries to copy.
59
- */ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries) {
146
+ */ copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, jobId) {
147
+ // This transactional context gives us "copy atomicity":
148
+ // there shouldn't be concurrent writes to what's being copied here.
149
+ // Equally important: this in practice is expected to perform thousands of DB operations
150
+ // and not using a transaction here would heavily impact performance.
60
151
  return this.#store.transactionAsync(async ()=>{
61
152
  // In order to support overlapping source and destination regions, we need to check the relative positions of source
62
153
  // and destination. If destination is ahead of source, then by the time we overwrite source elements using forward
@@ -69,11 +160,11 @@ export class CapsuleStore {
69
160
  for (const i of indexes){
70
161
  const currentSrcSlot = dbSlotToKey(contractAddress, srcSlot.add(new Fr(i)));
71
162
  const currentDstSlot = dbSlotToKey(contractAddress, dstSlot.add(new Fr(i)));
72
- const toCopy = await this.#capsules.getAsync(currentSrcSlot);
163
+ const toCopy = await this.#getFromStage(jobId, currentSrcSlot);
73
164
  if (!toCopy) {
74
165
  throw new Error(`Attempted to copy empty slot ${currentSrcSlot} for contract ${contractAddress.toString()}`);
75
166
  }
76
- await this.#capsules.set(currentDstSlot, toCopy);
167
+ this.#setOnStage(jobId, currentDstSlot, toCopy);
77
168
  }
78
169
  });
79
170
  }
@@ -84,32 +175,42 @@ export class CapsuleStore {
84
175
  * @param contractAddress - The contract address that owns the capsule array
85
176
  * @param baseSlot - The slot where the array length is stored
86
177
  * @param content - Array of capsule data to append
87
- */ appendToCapsuleArray(contractAddress, baseSlot, content) {
178
+ */ appendToCapsuleArray(contractAddress, baseSlot, content, jobId) {
179
+ // We wrap this in a transaction to serialize concurrent calls from Promise.all.
180
+ // Without this, concurrent appends to the same array could race: both read length=0,
181
+ // both write at the same slots, one overwrites the other.
182
+ // Equally important: this in practice is expected to perform thousands of DB operations
183
+ // and not using a transaction here would heavily impact performance.
88
184
  return this.#store.transactionAsync(async ()=>{
89
185
  // Load current length, defaulting to 0 if not found
90
- const lengthData = await this.loadCapsule(contractAddress, baseSlot);
186
+ const lengthData = await this.loadCapsule(contractAddress, baseSlot, jobId);
91
187
  const currentLength = lengthData ? lengthData[0].toNumber() : 0;
92
188
  // Store each capsule at consecutive slots after baseSlot + 1 + currentLength
93
189
  for(let i = 0; i < content.length; i++){
94
190
  const nextSlot = arraySlot(baseSlot, currentLength + i);
95
- await this.storeCapsule(contractAddress, nextSlot, content[i]);
191
+ this.storeCapsule(contractAddress, nextSlot, content[i], jobId);
96
192
  }
97
193
  // Update length to include all new capsules
98
194
  const newLength = currentLength + content.length;
99
- await this.storeCapsule(contractAddress, baseSlot, [
195
+ this.storeCapsule(contractAddress, baseSlot, [
100
196
  new Fr(newLength)
101
- ]);
197
+ ], jobId);
102
198
  });
103
199
  }
104
- readCapsuleArray(contractAddress, baseSlot) {
200
+ readCapsuleArray(contractAddress, baseSlot, jobId) {
201
+ // I'm leaving this transactional context here though because I'm assuming this
202
+ // gives us "read array atomicity": there shouldn't be concurrent writes to what's being copied
203
+ // here.
204
+ // This is one point we should revisit in the future if we want to relax the concurrency
205
+ // of jobs: different calls running concurrently on the same contract may cause trouble.
105
206
  return this.#store.transactionAsync(async ()=>{
106
207
  // Load length, defaulting to 0 if not found
107
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot);
208
+ const maybeLength = await this.loadCapsule(contractAddress, baseSlot, jobId);
108
209
  const length = maybeLength ? maybeLength[0].toBigInt() : 0n;
109
210
  const values = [];
110
211
  // Read each capsule at consecutive slots after baseSlot
111
212
  for(let i = 0; i < length; i++){
112
- const currentValue = await this.loadCapsule(contractAddress, arraySlot(baseSlot, i));
213
+ const currentValue = await this.loadCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
113
214
  if (currentValue == undefined) {
114
215
  throw new Error(`Expected non-empty value at capsule array in base slot ${baseSlot} at index ${i} for contract ${contractAddress}`);
115
216
  }
@@ -118,22 +219,30 @@ export class CapsuleStore {
118
219
  return values;
119
220
  });
120
221
  }
121
- setCapsuleArray(contractAddress, baseSlot, content) {
222
+ setCapsuleArray(contractAddress, baseSlot, content, jobId) {
223
+ // This transactional context in theory isn't so critical now because we aren't
224
+ // writing to DB so if there's exceptions midway and it blows up, no visible impact
225
+ // to persistent storage will happen.
226
+ // I'm leaving this transactional context here though because I'm assuming this
227
+ // gives us "write array atomicity": there shouldn't be concurrent writes to what's being copied
228
+ // here.
229
+ // This is one point we should revisit in the future if we want to relax the concurrency
230
+ // of jobs: different calls running concurrently on the same contract may cause trouble.
122
231
  return this.#store.transactionAsync(async ()=>{
123
232
  // Load current length, defaulting to 0 if not found
124
- const maybeLength = await this.loadCapsule(contractAddress, baseSlot);
233
+ const maybeLength = await this.loadCapsule(contractAddress, baseSlot, jobId);
125
234
  const originalLength = maybeLength ? maybeLength[0].toNumber() : 0;
126
235
  // Set the new length
127
- await this.storeCapsule(contractAddress, baseSlot, [
236
+ this.storeCapsule(contractAddress, baseSlot, [
128
237
  new Fr(content.length)
129
- ]);
238
+ ], jobId);
130
239
  // Store the new content, possibly overwriting existing values
131
240
  for(let i = 0; i < content.length; i++){
132
- await this.storeCapsule(contractAddress, arraySlot(baseSlot, i), content[i]);
241
+ this.storeCapsule(contractAddress, arraySlot(baseSlot, i), content[i], jobId);
133
242
  }
134
243
  // Clear any stragglers
135
244
  for(let i = content.length; i < originalLength; i++){
136
- await this.deleteCapsule(contractAddress, arraySlot(baseSlot, i));
245
+ this.deleteCapsule(contractAddress, arraySlot(baseSlot, i), jobId);
137
246
  }
138
247
  });
139
248
  }
@@ -36,9 +36,8 @@ export declare class NoteStore {
36
36
  /**
37
37
  * Adds multiple notes to the data provider under the specified scope.
38
38
  *
39
- * Notes are stored using their index from the notes hash tree as the key, which provides
40
- * uniqueness and maintains creation order. Each note is indexed by multiple criteria
41
- * for efficient retrieval.
39
+ * Notes are stored using their siloedNullifier as the key, which provides uniqueness. Each note is indexed
40
+ * by multiple criteria for efficient retrieval.
42
41
  *
43
42
  * @param notes - Notes to store
44
43
  * @param scope - The scope (user/account) under which to store the notes
@@ -51,10 +50,12 @@ export declare class NoteStore {
51
50
  * specified block number. It restores any notes that were nullified after the given block
52
51
  * and deletes any active notes created after that block.
53
52
  *
53
+ * IMPORTANT: This method must be called within a transaction to ensure atomicity.
54
+ *
54
55
  * @param blockNumber - The new chain tip after a reorg
55
56
  * @param synchedBlockNumber - The block number up to which PXE managed to sync before the reorg happened.
56
57
  */
57
- rollbackNotesAndNullifiers(blockNumber: number, synchedBlockNumber: number): Promise<void>;
58
+ rollback(blockNumber: number, synchedBlockNumber: number): Promise<void>;
58
59
  /**
59
60
  * Retrieves notes based on the provided filter criteria.
60
61
  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AK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C;;;;;IAKI;AACJ,qBAAa,SAAS;;IA4BpB,OAAO,eAcN;IAED;;;;;;;;OAQG;IACH,OAAoB,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,CAOvE;IAED;;;;;;;;OAQG;IACU,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAY3D;IAED;;;;;;;;OAQG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAe7D;IAED;;;;;;;;;;;OAWG;IACU,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGpF;IAiFD;;;;;;;;;;;OAWG;IACG,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAmHtD;IAED;;;;;;;;;;OAUG;IACH,eAAe,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAoDjE;CACF"}
@@ -1,4 +1,3 @@
1
- import { toBufferBE } from '@aztec/foundation/bigint-buffer';
2
1
  import { toArray } from '@aztec/foundation/iterable';
3
2
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
3
  import { NoteStatus } from '@aztec/stdlib/note';
@@ -10,28 +9,25 @@ import { NoteDao } from '@aztec/stdlib/note';
10
9
  * and performs rollback handling in the case of a reorg.
11
10
  **/ export class NoteStore {
12
11
  #store;
13
- #notes;
14
- #nullifiedNotes;
15
- #nullifierToNoteId;
16
- #nullifiersByBlockNumber;
17
- #nullifiedNotesToScope;
18
- #nullifiedNotesByContract;
19
- #nullifiedNotesByStorageSlot;
20
- #nullifiedNotesByNullifier;
21
- #scopes;
22
- #notesToScope;
23
- #notesByContractAndScope;
24
- #notesByStorageSlotAndScope;
12
+ // Note that we use the siloedNullifier as the note id in the store as it's guaranteed to be unique.
13
+ /** noteId (siloedNullifier) -> NoteDao (serialized) */ #notes;
14
+ /** noteId (siloedNullifier) -> NoteDao (serialized) */ #nullifiedNotes;
15
+ /** blockNumber -> siloedNullifier */ #nullifiersByBlockNumber;
16
+ /** noteId (siloedNullifier) -> scope */ #nullifiedNotesToScope;
17
+ /** contractAddress -> noteId (siloedNullifier) */ #nullifiedNotesByContract;
18
+ /** storageSlot -> noteId (siloedNullifier) */ #nullifiedNotesByStorageSlot;
19
+ /** scope (AztecAddress) -> true */ #scopes;
20
+ /** noteId (siloedNullifier) -> scope */ #notesToScope;
21
+ /** scope -> MultiMap(contractAddress -> noteId) */ #notesByContractAndScope;
22
+ /** scope -> MultiMap(storageSlot -> noteId) */ #notesByStorageSlotAndScope;
25
23
  constructor(store){
26
24
  this.#store = store;
27
25
  this.#notes = store.openMap('notes');
28
26
  this.#nullifiedNotes = store.openMap('nullified_notes');
29
- this.#nullifierToNoteId = store.openMap('nullifier_to_note');
30
27
  this.#nullifiersByBlockNumber = store.openMultiMap('nullifier_to_block_number');
31
28
  this.#nullifiedNotesToScope = store.openMultiMap('nullified_notes_to_scope');
32
29
  this.#nullifiedNotesByContract = store.openMultiMap('nullified_notes_by_contract');
33
30
  this.#nullifiedNotesByStorageSlot = store.openMultiMap('nullified_notes_by_storage_slot');
34
- this.#nullifiedNotesByNullifier = store.openMap('nullified_notes_by_nullifier');
35
31
  this.#scopes = store.openMap('scopes');
36
32
  this.#notesToScope = store.openMultiMap('notes_to_scope');
37
33
  this.#notesByContractAndScope = new Map();
@@ -74,9 +70,8 @@ import { NoteDao } from '@aztec/stdlib/note';
74
70
  /**
75
71
  * Adds multiple notes to the data provider under the specified scope.
76
72
  *
77
- * Notes are stored using their index from the notes hash tree as the key, which provides
78
- * uniqueness and maintains creation order. Each note is indexed by multiple criteria
79
- * for efficient retrieval.
73
+ * Notes are stored using their siloedNullifier as the key, which provides uniqueness. Each note is indexed
74
+ * by multiple criteria for efficient retrieval.
80
75
  *
81
76
  * @param notes - Notes to store
82
77
  * @param scope - The scope (user/account) under which to store the notes
@@ -86,12 +81,11 @@ import { NoteDao } from '@aztec/stdlib/note';
86
81
  await this.addScope(scope);
87
82
  }
88
83
  for (const dao of notes){
89
- const noteIndex = toBufferBE(dao.index, 32).toString('hex');
90
- await this.#notes.set(noteIndex, dao.toBuffer());
91
- await this.#notesToScope.set(noteIndex, scope.toString());
92
- await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
93
- await this.#notesByContractAndScope.get(scope.toString()).set(dao.contractAddress.toString(), noteIndex);
94
- await this.#notesByStorageSlotAndScope.get(scope.toString()).set(dao.storageSlot.toString(), noteIndex);
84
+ const noteId = dao.siloedNullifier.toString();
85
+ await this.#notes.set(noteId, dao.toBuffer());
86
+ await this.#notesToScope.set(noteId, scope.toString());
87
+ await this.#notesByContractAndScope.get(scope.toString()).set(dao.contractAddress.toString(), noteId);
88
+ await this.#notesByStorageSlotAndScope.get(scope.toString()).set(dao.storageSlot.toString(), noteId);
95
89
  }
96
90
  });
97
91
  }
@@ -102,9 +96,11 @@ import { NoteDao } from '@aztec/stdlib/note';
102
96
  * specified block number. It restores any notes that were nullified after the given block
103
97
  * and deletes any active notes created after that block.
104
98
  *
99
+ * IMPORTANT: This method must be called within a transaction to ensure atomicity.
100
+ *
105
101
  * @param blockNumber - The new chain tip after a reorg
106
102
  * @param synchedBlockNumber - The block number up to which PXE managed to sync before the reorg happened.
107
- */ async rollbackNotesAndNullifiers(blockNumber, synchedBlockNumber) {
103
+ */ async rollback(blockNumber, synchedBlockNumber) {
108
104
  await this.#rewindNullifiersAfterBlock(blockNumber, synchedBlockNumber);
109
105
  await this.#deleteActiveNotesAfterBlock(blockNumber);
110
106
  }
@@ -115,24 +111,21 @@ import { NoteDao } from '@aztec/stdlib/note';
115
111
  * Note: This only affects #notes (active notes), not #nullifiedNotes.
116
112
  *
117
113
  * @param blockNumber - Notes created after this block number will be deleted
118
- */ #deleteActiveNotesAfterBlock(blockNumber) {
119
- return this.#store.transactionAsync(async ()=>{
120
- const notes = await toArray(this.#notes.valuesAsync());
121
- for (const note of notes){
122
- const noteDao = NoteDao.fromBuffer(note);
123
- if (noteDao.l2BlockNumber > blockNumber) {
124
- const noteIndex = toBufferBE(noteDao.index, 32).toString('hex');
125
- await this.#notes.delete(noteIndex);
126
- await this.#notesToScope.delete(noteIndex);
127
- await this.#nullifierToNoteId.delete(noteDao.siloedNullifier.toString());
128
- const scopes = await toArray(this.#scopes.keysAsync());
129
- for (const scope of scopes){
130
- await this.#notesByContractAndScope.get(scope).deleteValue(noteDao.contractAddress.toString(), noteIndex);
131
- await this.#notesByStorageSlotAndScope.get(scope).deleteValue(noteDao.storageSlot.toString(), noteIndex);
132
- }
114
+ */ async #deleteActiveNotesAfterBlock(blockNumber) {
115
+ const notes = await toArray(this.#notes.valuesAsync());
116
+ for (const note of notes){
117
+ const noteDao = NoteDao.fromBuffer(note);
118
+ if (noteDao.l2BlockNumber > blockNumber) {
119
+ const noteId = noteDao.siloedNullifier.toString();
120
+ await this.#notes.delete(noteId);
121
+ await this.#notesToScope.delete(noteId);
122
+ const scopes = await toArray(this.#scopes.keysAsync());
123
+ for (const scope of scopes){
124
+ await this.#notesByContractAndScope.get(scope).deleteValue(noteDao.contractAddress.toString(), noteId);
125
+ await this.#notesByStorageSlotAndScope.get(scope).deleteValue(noteDao.storageSlot.toString(), noteId);
133
126
  }
134
127
  }
135
- });
128
+ }
136
129
  }
137
130
  /**
138
131
  * Rewinds nullifications after a given block number.
@@ -144,39 +137,38 @@ import { NoteDao } from '@aztec/stdlib/note';
144
137
  * @param blockNumber - Revert nullifications that occurred after this block
145
138
  * @param synchedBlockNumber - Upper bound for the block range to process
146
139
  */ async #rewindNullifiersAfterBlock(blockNumber, synchedBlockNumber) {
147
- await this.#store.transactionAsync(async ()=>{
148
- const nullifiersToUndo = [];
149
- const currentBlockNumber = blockNumber + 1;
150
- for(let i = currentBlockNumber; i <= synchedBlockNumber; i++){
151
- nullifiersToUndo.push(...await toArray(this.#nullifiersByBlockNumber.getValuesAsync(i)));
140
+ const noteIdsToReinsert = [];
141
+ const currentBlockNumber = blockNumber + 1;
142
+ for(let i = currentBlockNumber; i <= synchedBlockNumber; i++){
143
+ // noteId === siloedNullifier.toString(), so we can use nullifiers directly as noteIds
144
+ noteIdsToReinsert.push(...await toArray(this.#nullifiersByBlockNumber.getValuesAsync(i)));
145
+ }
146
+ const nullifiedNoteBuffers = await Promise.all(noteIdsToReinsert.map((noteId)=>this.#nullifiedNotes.getAsync(noteId)));
147
+ const noteDaos = nullifiedNoteBuffers.filter((buffer)=>buffer != undefined).map((buffer)=>NoteDao.fromBuffer(buffer));
148
+ for (const dao of noteDaos){
149
+ const noteId = dao.siloedNullifier.toString();
150
+ const scopes = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteId));
151
+ if (scopes.length === 0) {
152
+ // We should never run into this error because notes always have a scope assigned to them - either on initial
153
+ // insertion via `addNotes` or when removing their nullifiers.
154
+ throw new Error(`No scopes found for nullified note with nullifier ${noteId}`);
152
155
  }
153
- const notesIndexesToReinsert = await Promise.all(nullifiersToUndo.map((nullifier)=>this.#nullifiedNotesByNullifier.getAsync(nullifier)));
154
- const notNullNoteIndexes = notesIndexesToReinsert.filter((noteIndex)=>noteIndex != undefined);
155
- const nullifiedNoteBuffers = await Promise.all(notNullNoteIndexes.map((noteIndex)=>this.#nullifiedNotes.getAsync(noteIndex)));
156
- const noteDaos = nullifiedNoteBuffers.filter((buffer)=>buffer != undefined).map((buffer)=>NoteDao.fromBuffer(buffer));
157
- for (const dao of noteDaos){
158
- const noteIndex = toBufferBE(dao.index, 32).toString('hex');
159
- await this.#notes.set(noteIndex, dao.toBuffer());
160
- await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
161
- const scopes = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex));
162
- if (scopes.length === 0) {
163
- // We should never run into this error because notes always have a scope assigned to them - either on initial
164
- // insertion via `addNotes` or when removing their nullifiers.
165
- throw new Error(`No scopes found for nullified note with index ${noteIndex}`);
166
- }
167
- for (const scope of scopes){
168
- await this.#notesByContractAndScope.get(scope.toString()).set(dao.contractAddress.toString(), noteIndex);
169
- await this.#notesByStorageSlotAndScope.get(scope.toString()).set(dao.storageSlot.toString(), noteIndex);
170
- await this.#notesToScope.set(noteIndex, scope);
171
- }
172
- await this.#nullifiedNotes.delete(noteIndex);
173
- await this.#nullifiedNotesToScope.delete(noteIndex);
174
- await this.#nullifiersByBlockNumber.deleteValue(dao.l2BlockNumber, dao.siloedNullifier.toString());
175
- await this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteIndex);
176
- await this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteIndex);
177
- await this.#nullifiedNotesByNullifier.delete(dao.siloedNullifier.toString());
156
+ for (const scope of scopes){
157
+ await Promise.all([
158
+ this.#notesByContractAndScope.get(scope.toString()).set(dao.contractAddress.toString(), noteId),
159
+ this.#notesByStorageSlotAndScope.get(scope.toString()).set(dao.storageSlot.toString(), noteId),
160
+ this.#notesToScope.set(noteId, scope)
161
+ ]);
178
162
  }
179
- });
163
+ await Promise.all([
164
+ this.#notes.set(noteId, dao.toBuffer()),
165
+ this.#nullifiedNotes.delete(noteId),
166
+ this.#nullifiedNotesToScope.delete(noteId),
167
+ this.#nullifiersByBlockNumber.deleteValue(dao.l2BlockNumber, dao.siloedNullifier.toString()),
168
+ this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteId),
169
+ this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteId)
170
+ ]);
171
+ }
180
172
  }
181
173
  /**
182
174
  * Retrieves notes based on the provided filter criteria.
@@ -257,6 +249,16 @@ import { NoteDao } from '@aztec/stdlib/note';
257
249
  deduplicated.push(note);
258
250
  }
259
251
  }
252
+ // Sort by block number, then by tx index within block, then by note index within tx
253
+ deduplicated.sort((a, b)=>{
254
+ if (a.l2BlockNumber !== b.l2BlockNumber) {
255
+ return a.l2BlockNumber - b.l2BlockNumber;
256
+ }
257
+ if (a.txIndexInBlock !== b.txIndexInBlock) {
258
+ return a.txIndexInBlock - b.txIndexInBlock;
259
+ }
260
+ return a.noteIndexInTx - b.noteIndexInTx;
261
+ });
260
262
  return deduplicated;
261
263
  }
262
264
  /**
@@ -277,21 +279,16 @@ import { NoteDao } from '@aztec/stdlib/note';
277
279
  const nullifiedNotes = [];
278
280
  for (const blockScopedNullifier of nullifiers){
279
281
  const { data: nullifier, l2BlockNumber: blockNumber } = blockScopedNullifier;
280
- const nullifierKey = nullifier.toString();
281
- const noteIndex = await this.#nullifierToNoteId.getAsync(nullifierKey);
282
- if (!noteIndex) {
283
- // Check if already nullified?
284
- const alreadyNullified = await this.#nullifiedNotesByNullifier.getAsync(nullifierKey);
285
- if (alreadyNullified) {
282
+ const noteId = nullifier.toString();
283
+ const noteBuffer = await this.#notes.getAsync(noteId);
284
+ if (!noteBuffer) {
285
+ // Check if already nullified (noteId === siloedNullifier, so we can check #nullifiedNotes directly)
286
+ if (await this.#nullifiedNotes.hasAsync(noteId)) {
286
287
  throw new Error(`Nullifier already applied in applyNullifiers`);
287
288
  }
288
289
  throw new Error('Nullifier not found in applyNullifiers');
289
290
  }
290
- const noteBuffer = noteIndex ? await this.#notes.getAsync(noteIndex) : undefined;
291
- if (!noteBuffer) {
292
- throw new Error('Note not found in applyNullifiers');
293
- }
294
- const noteScopes = await toArray(this.#notesToScope.getValuesAsync(noteIndex));
291
+ const noteScopes = await toArray(this.#notesToScope.getValuesAsync(noteId));
295
292
  if (noteScopes.length === 0) {
296
293
  // We should never run into this error because notes always have a scope assigned to them - either on initial
297
294
  // insertion via `addNotes` or when removing their nullifiers.
@@ -299,22 +296,20 @@ import { NoteDao } from '@aztec/stdlib/note';
299
296
  }
300
297
  const note = NoteDao.fromBuffer(noteBuffer);
301
298
  nullifiedNotes.push(note);
302
- await this.#notes.delete(noteIndex);
303
- await this.#notesToScope.delete(noteIndex);
299
+ await this.#notes.delete(noteId);
300
+ await this.#notesToScope.delete(noteId);
304
301
  const scopes = await toArray(this.#scopes.keysAsync());
305
302
  for (const scope of scopes){
306
- await this.#notesByContractAndScope.get(scope).deleteValue(note.contractAddress.toString(), noteIndex);
307
- await this.#notesByStorageSlotAndScope.get(scope).deleteValue(note.storageSlot.toString(), noteIndex);
303
+ await this.#notesByContractAndScope.get(scope).deleteValue(note.contractAddress.toString(), noteId);
304
+ await this.#notesByStorageSlotAndScope.get(scope).deleteValue(note.storageSlot.toString(), noteId);
308
305
  }
309
306
  for (const scope of noteScopes){
310
- await this.#nullifiedNotesToScope.set(noteIndex, scope);
307
+ await this.#nullifiedNotesToScope.set(noteId, scope);
311
308
  }
312
- await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
313
- await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
314
- await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
315
- await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
316
- await this.#nullifiedNotesByNullifier.set(nullifier.toString(), noteIndex);
317
- await this.#nullifierToNoteId.delete(nullifier.toString());
309
+ await this.#nullifiedNotes.set(noteId, note.toBuffer());
310
+ await this.#nullifiersByBlockNumber.set(blockNumber, noteId);
311
+ await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteId);
312
+ await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteId);
318
313
  }
319
314
  return nullifiedNotes;
320
315
  });
@@ -14,6 +14,10 @@ export type PrivateEventStoreFilter = {
14
14
  type PrivateEventMetadata = InTx & {
15
15
  contractAddress: AztecAddress;
16
16
  scope: AztecAddress;
17
+ /** The index of the tx within the block */
18
+ txIndexInBlock: number;
19
+ /** The index of the event within the tx (based on nullifier position) */
20
+ eventIndexInTx: number;
17
21
  };
18
22
  /**
19
23
  * Stores decrypted private event logs.
@@ -25,15 +29,16 @@ export declare class PrivateEventStore {
25
29
  /**
26
30
  * Store a private event log.
27
31
  * @param eventSelector - The event selector of the event.
32
+ * @param randomness - The randomness used for the event commitment.
28
33
  * @param msgContent - The content of the event.
29
- * @param eventCommitmentIndex - The index of the event commitment in the nullifier tree.
34
+ * @param siloedEventCommitment - The siloed event commitment (used as unique identifier).
30
35
  * @param metadata
31
36
  * contractAddress - The address of the contract that emitted the event.
32
37
  * scope - The address to which the event is scoped.
33
38
  * txHash - The transaction hash of the event log.
34
39
  * blockNumber - The block number in which the event was emitted.
35
40
  */
36
- storePrivateEventLog(eventSelector: EventSelector, randomness: Fr, msgContent: Fr[], eventCommitmentIndex: number, metadata: PrivateEventMetadata): Promise<void>;
41
+ storePrivateEventLog(eventSelector: EventSelector, randomness: Fr, msgContent: Fr[], siloedEventCommitment: Fr, metadata: PrivateEventMetadata): Promise<void>;
37
42
  /**
38
43
  * Returns the private events given search parameters.
39
44
  * @param eventSelector - The event selector to filter by.
@@ -42,15 +47,17 @@ export declare class PrivateEventStore {
42
47
  * fromBlock: The block number to search from (inclusive).
43
48
  * toBlock: The block number to search upto (exclusive).
44
49
  * scope: - The addresses that decrypted the logs.
45
- * @returns - The event log contents, augmented with metadata about
46
- * the transaction and block it the event was included in .
50
+ * @returns - The event log contents, augmented with metadata about the transaction and block in which the event was
51
+ * included.
47
52
  */
48
53
  getPrivateEvents(eventSelector: EventSelector, filter: PrivateEventStoreFilter): Promise<PackedPrivateEvent[]>;
49
54
  /**
50
55
  * Rolls back private events that were stored after a given `blockNumber` and up to `synchedBlockNumber` (the block
51
56
  * number up to which PXE managed to sync before the reorg happened).
57
+ *
58
+ * IMPORTANT: This method must be called within a transaction to ensure atomicity.
52
59
  */
53
- rollbackEventsAfterBlock(blockNumber: number, synchedBlockNumber: number): Promise<void>;
60
+ rollback(blockNumber: number, synchedBlockNumber: number): Promise<void>;
54
61
  }
55
62
  export {};
56
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJpdmF0ZV9ldmVudF9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3N0b3JhZ2UvcHJpdmF0ZV9ldmVudF9zdG9yZS9wcml2YXRlX2V2ZW50X3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUdwRCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUN2RCxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUVoRSxPQUFPLEVBQUUsS0FBSyxJQUFJLEVBQUUsTUFBTSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFckQsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSxjQUFjLENBQUM7QUFFdkQsTUFBTSxNQUFNLHVCQUF1QixHQUFHO0lBQ3BDLGVBQWUsRUFBRSxZQUFZLENBQUM7SUFDOUIsU0FBUyxFQUFFLE1BQU0sQ0FBQztJQUNsQixPQUFPLEVBQUUsTUFBTSxDQUFDO0lBQ2hCLE1BQU0sRUFBRSxZQUFZLEVBQUUsQ0FBQztJQUN2QixNQUFNLENBQUMsRUFBRSxNQUFNLENBQUM7Q0FDakIsQ0FBQztBQWFGLEtBQUssb0JBQW9CLEdBQUcsSUFBSSxHQUFHO0lBQ2pDLGVBQWUsRUFBRSxZQUFZLENBQUM7SUFDOUIsS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