@aztec/pxe 0.0.1-commit.54489865 → 0.0.1-commit.592b9384
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/contract_function_simulator/contract_function_simulator.d.ts +2 -4
- package/dest/contract_function_simulator/contract_function_simulator.d.ts.map +1 -1
- package/dest/contract_function_simulator/contract_function_simulator.js +3 -5
- package/dest/contract_function_simulator/oracle/interfaces.d.ts +7 -7
- package/dest/contract_function_simulator/oracle/interfaces.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.d.ts +3 -3
- package/dest/contract_function_simulator/oracle/oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/oracle.js +9 -9
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts +2 -3
- package/dest/contract_function_simulator/oracle/private_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/private_execution_oracle.js +4 -4
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts +15 -11
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.d.ts.map +1 -1
- package/dest/contract_function_simulator/oracle/utility_execution_oracle.js +23 -19
- package/dest/entrypoints/client/bundle/utils.d.ts +1 -1
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/bundle/utils.js +2 -1
- package/dest/entrypoints/client/lazy/utils.d.ts +1 -1
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -1
- package/dest/entrypoints/client/lazy/utils.js +2 -1
- package/dest/events/event_service.d.ts +4 -5
- package/dest/events/event_service.d.ts.map +1 -1
- package/dest/events/event_service.js +5 -6
- package/dest/logs/log_service.d.ts +4 -4
- package/dest/logs/log_service.d.ts.map +1 -1
- package/dest/logs/log_service.js +7 -10
- package/dest/notes/note_service.d.ts +4 -5
- package/dest/notes/note_service.d.ts.map +1 -1
- package/dest/notes/note_service.js +6 -7
- package/dest/oracle_version.d.ts +3 -3
- package/dest/oracle_version.d.ts.map +1 -1
- package/dest/oracle_version.js +2 -2
- package/dest/pxe.d.ts +1 -1
- package/dest/pxe.d.ts.map +1 -1
- package/dest/pxe.js +1 -1
- package/dest/storage/address_store/address_store.d.ts +1 -1
- package/dest/storage/address_store/address_store.d.ts.map +1 -1
- package/dest/storage/address_store/address_store.js +12 -11
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts +9 -1
- package/dest/storage/anchor_block_store/anchor_block_store.d.ts.map +1 -1
- package/dest/storage/anchor_block_store/anchor_block_store.js +8 -1
- package/dest/storage/capsule_store/capsule_store.js +6 -8
- package/dest/storage/contract_store/contract_store.d.ts +1 -1
- package/dest/storage/contract_store/contract_store.d.ts.map +1 -1
- package/dest/storage/contract_store/contract_store.js +22 -13
- package/dest/storage/metadata.d.ts +1 -1
- package/dest/storage/metadata.js +1 -1
- package/dest/storage/note_store/note_store.d.ts +11 -1
- package/dest/storage/note_store/note_store.d.ts.map +1 -1
- package/dest/storage/note_store/note_store.js +169 -129
- package/dest/storage/private_event_store/private_event_store.d.ts +1 -1
- package/dest/storage/private_event_store/private_event_store.d.ts.map +1 -1
- package/dest/storage/private_event_store/private_event_store.js +126 -101
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/recipient_tagging_store.js +31 -19
- package/dest/storage/tagging_store/sender_address_book_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_address_book_store.js +20 -14
- package/dest/storage/tagging_store/sender_tagging_store.d.ts +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.d.ts.map +1 -1
- package/dest/storage/tagging_store/sender_tagging_store.js +183 -113
- package/package.json +16 -16
- package/src/contract_function_simulator/contract_function_simulator.ts +0 -4
- package/src/contract_function_simulator/oracle/interfaces.ts +8 -8
- package/src/contract_function_simulator/oracle/oracle.ts +21 -11
- package/src/contract_function_simulator/oracle/private_execution_oracle.ts +1 -5
- package/src/contract_function_simulator/oracle/utility_execution_oracle.ts +24 -20
- package/src/entrypoints/client/bundle/utils.ts +3 -1
- package/src/entrypoints/client/lazy/utils.ts +3 -1
- package/src/events/event_service.ts +4 -6
- package/src/logs/log_service.ts +6 -9
- package/src/notes/note_service.ts +5 -7
- package/src/oracle_version.ts +2 -2
- package/src/pxe.ts +0 -1
- package/src/storage/address_store/address_store.ts +15 -15
- package/src/storage/anchor_block_store/anchor_block_store.ts +8 -0
- package/src/storage/capsule_store/capsule_store.ts +8 -8
- package/src/storage/contract_store/contract_store.ts +22 -11
- package/src/storage/metadata.ts +1 -1
- package/src/storage/note_store/note_store.ts +185 -150
- package/src/storage/private_event_store/private_event_store.ts +151 -128
- package/src/storage/tagging_store/recipient_tagging_store.ts +31 -21
- package/src/storage/tagging_store/sender_address_book_store.ts +20 -14
- package/src/storage/tagging_store/sender_tagging_store.ts +210 -126
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { toArray } from '@aztec/foundation/iterable';
|
|
2
1
|
import { Semaphore } from '@aztec/foundation/queue';
|
|
3
2
|
import type { Fr } from '@aztec/foundation/schemas';
|
|
4
3
|
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
|
|
@@ -18,6 +17,8 @@ import { StoredNote } from './stored_note.js';
|
|
|
18
17
|
export class NoteStore implements StagedStore {
|
|
19
18
|
readonly storeName: string = 'note';
|
|
20
19
|
|
|
20
|
+
#store: AztecAsyncKVStore;
|
|
21
|
+
|
|
21
22
|
// Note that we use the siloedNullifier as the note id in the store as it's guaranteed to be unique.
|
|
22
23
|
|
|
23
24
|
// Main storage for notes. Avoid performing full scans on it as it contains all notes PXE knows, use
|
|
@@ -46,6 +47,7 @@ export class NoteStore implements StagedStore {
|
|
|
46
47
|
#jobLocks: Map<string, Semaphore>;
|
|
47
48
|
|
|
48
49
|
constructor(store: AztecAsyncKVStore) {
|
|
50
|
+
this.#store = store;
|
|
49
51
|
this.#notes = store.openMap('notes');
|
|
50
52
|
this.#nullifiersByContractAddress = store.openMultiMap('note_nullifiers_by_contract');
|
|
51
53
|
this.#nullifiersByNullificationBlockNumber = store.openMultiMap('note_block_number_to_nullifier');
|
|
@@ -65,32 +67,26 @@ export class NoteStore implements StagedStore {
|
|
|
65
67
|
* @param jobId - The job context for staged writes
|
|
66
68
|
*/
|
|
67
69
|
public addNotes(notes: NoteDao[], scope: AztecAddress, jobId: string): Promise<void[]> {
|
|
68
|
-
return this.#withJobLock(jobId, () =>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
return this.#withJobLock(jobId, () =>
|
|
71
|
+
this.#store.transactionAsync(() =>
|
|
72
|
+
Promise.all(
|
|
73
|
+
notes.map(async note => {
|
|
74
|
+
const noteForJob =
|
|
75
|
+
(await this.#readNote(note.siloedNullifier.toString(), jobId)) ?? new StoredNote(note, new Set());
|
|
76
|
+
noteForJob.addScope(scope.toString());
|
|
77
|
+
this.#writeNote(noteForJob, jobId);
|
|
78
|
+
}),
|
|
79
|
+
),
|
|
80
|
+
),
|
|
81
|
+
);
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
async #readNote(nullifier: string, jobId: string): Promise<StoredNote | undefined> {
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
if (noteForJob) {
|
|
84
|
-
return noteForJob;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Then check persistent storage
|
|
85
|
+
// Always issue DB read to keep IndexedDB transaction alive (they auto-commit when a new micro-task starts and there
|
|
86
|
+
// are no pending read requests). The staged value still takes precedence if it exists.
|
|
88
87
|
const noteBuffer = await this.#notes.getAsync(nullifier);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return undefined;
|
|
88
|
+
const noteForJob = this.#getNotesForJob(jobId).get(nullifier);
|
|
89
|
+
return noteForJob ?? (noteBuffer ? StoredNote.fromBuffer(noteBuffer) : undefined);
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
#writeNote(note: StoredNote, jobId: string) {
|
|
@@ -109,57 +105,98 @@ export class NoteStore implements StagedStore {
|
|
|
109
105
|
* returned once if this is the case)
|
|
110
106
|
* @throws If filtering by an empty scopes array. Scopes have to be set to undefined or to a non-empty array.
|
|
111
107
|
*/
|
|
112
|
-
|
|
108
|
+
getNotes(filter: NotesFilter, jobId: string): Promise<NoteDao[]> {
|
|
113
109
|
if (filter.scopes !== undefined && filter.scopes.length === 0) {
|
|
114
|
-
|
|
110
|
+
return Promise.reject(new Error('Trying to get notes with an empty scopes array'));
|
|
115
111
|
}
|
|
116
112
|
|
|
117
|
-
|
|
113
|
+
return this.#store.transactionAsync(async () => {
|
|
114
|
+
const targetStatus = filter.status ?? NoteStatus.ACTIVE;
|
|
115
|
+
|
|
116
|
+
// The code below might read a bit unnatural, the reason is that we need to be careful in how we use `await` inside
|
|
117
|
+
// `transactionAsync`, otherwise browsers might choose to auto-commit the IndexedDB transaction forcing us to
|
|
118
|
+
// explicitly handle that condition. The rule we need to honor is: do not await unless you generate a database
|
|
119
|
+
// read or write or you're done using the DB for the remainder of the transaction. The following sequence is
|
|
120
|
+
// unsafe in IndexedDB:
|
|
121
|
+
//
|
|
122
|
+
// 1. start transactionAsync()
|
|
123
|
+
// 2. await readDb() <-- OK, transaction alive because we issued DB ops
|
|
124
|
+
// 3. run a bunch of computations (no await involved) <-- OK, tx alive because we are in the same microtask
|
|
125
|
+
// 4. await doSthNotInDb() <-- no DB ops issued in this task, browser's free to decide to commit the tx
|
|
126
|
+
// 5. await readDb() <-- BOOM, TransactionInactiveError
|
|
127
|
+
//
|
|
128
|
+
// Note that the real issue is in step number 5: we try to continue using a transaction that the browser might
|
|
129
|
+
// have already committed.
|
|
130
|
+
//
|
|
131
|
+
// We need to read candidate notes which are either indexed by contract address in the DB (in
|
|
132
|
+
// #nullifiersByContractAddress), or lie in memory for the not yet committed `jobId`.
|
|
133
|
+
// So we collect promises based on both sources without awaiting for them.
|
|
134
|
+
const noteReadPromises: Map<string, Promise<StoredNote | undefined>> = new Map();
|
|
135
|
+
|
|
136
|
+
// Awaiting the getValuesAsync iterator is fine because it's reading from the DB
|
|
137
|
+
for await (const nullifier of this.#nullifiersByContractAddress.getValuesAsync(
|
|
138
|
+
filter.contractAddress.toString(),
|
|
139
|
+
)) {
|
|
140
|
+
// Each #readNote will perform a DB read
|
|
141
|
+
noteReadPromises.set(nullifier, this.#readNote(nullifier, jobId));
|
|
142
|
+
}
|
|
118
143
|
|
|
119
|
-
|
|
144
|
+
// Add staged nullifiers from job, no awaits involved, so we are fine
|
|
145
|
+
for (const storedNote of this.#getNotesForJob(jobId).values()) {
|
|
146
|
+
if (storedNote.noteDao.contractAddress.equals(filter.contractAddress)) {
|
|
147
|
+
const nullifier = storedNote.noteDao.siloedNullifier.toString();
|
|
148
|
+
if (!noteReadPromises.has(nullifier)) {
|
|
149
|
+
noteReadPromises.set(nullifier, Promise.resolve(storedNote));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
120
153
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const note = await this.#readNote(nullifier, jobId);
|
|
154
|
+
// By now we have pending DB requests from all the #readNote calls. Await them all together.
|
|
155
|
+
const notes = await Promise.all(noteReadPromises.values());
|
|
124
156
|
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
throw new Error('PXE note database is corrupted.');
|
|
128
|
-
}
|
|
157
|
+
// The rest of the function is await-free, and just deals with filtering and sorting our findings.
|
|
158
|
+
const foundNotes: Map<string, NoteDao> = new Map();
|
|
129
159
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
160
|
+
for (const note of notes) {
|
|
161
|
+
// Defensive: hitting this case means we're mishandling contract indices or in-memory job data
|
|
162
|
+
if (!note) {
|
|
163
|
+
throw new Error('PXE note database is corrupted.');
|
|
164
|
+
}
|
|
134
165
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
166
|
+
// Apply filters
|
|
167
|
+
if (targetStatus === NoteStatus.ACTIVE && note.isNullified()) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
138
170
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
171
|
+
if (filter.owner && !note.noteDao.owner.equals(filter.owner)) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
142
174
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
175
|
+
if (filter.storageSlot && !note.noteDao.storageSlot.equals(filter.storageSlot)) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
146
178
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
179
|
+
if (filter.siloedNullifier && !note.noteDao.siloedNullifier.equals(filter.siloedNullifier)) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
150
182
|
|
|
151
|
-
|
|
152
|
-
|
|
183
|
+
if (filter.scopes && note.scopes.intersection(new Set(filter.scopes.map(s => s.toString()))).size === 0) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
153
186
|
|
|
154
|
-
|
|
155
|
-
return [...foundNotes.values()].sort((a, b) => {
|
|
156
|
-
if (a.l2BlockNumber !== b.l2BlockNumber) {
|
|
157
|
-
return a.l2BlockNumber - b.l2BlockNumber;
|
|
158
|
-
}
|
|
159
|
-
if (a.txIndexInBlock !== b.txIndexInBlock) {
|
|
160
|
-
return a.txIndexInBlock - b.txIndexInBlock;
|
|
187
|
+
foundNotes.set(note.noteDao.siloedNullifier.toString(), note.noteDao);
|
|
161
188
|
}
|
|
162
|
-
|
|
189
|
+
|
|
190
|
+
// Sort by block number, then by tx index within block, then by note index within tx
|
|
191
|
+
return [...foundNotes.values()].sort((a, b) => {
|
|
192
|
+
if (a.l2BlockNumber !== b.l2BlockNumber) {
|
|
193
|
+
return a.l2BlockNumber - b.l2BlockNumber;
|
|
194
|
+
}
|
|
195
|
+
if (a.txIndexInBlock !== b.txIndexInBlock) {
|
|
196
|
+
return a.txIndexInBlock - b.txIndexInBlock;
|
|
197
|
+
}
|
|
198
|
+
return a.noteIndexInTx - b.noteIndexInTx;
|
|
199
|
+
});
|
|
163
200
|
});
|
|
164
201
|
}
|
|
165
202
|
|
|
@@ -179,41 +216,42 @@ export class NoteStore implements StagedStore {
|
|
|
179
216
|
* @throws Error if any nullifier is not found in this notes store
|
|
180
217
|
*/
|
|
181
218
|
applyNullifiers(nullifiers: DataInBlock<Fr>[], jobId: string): Promise<NoteDao[]> {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
219
|
+
if (nullifiers.length === 0) {
|
|
220
|
+
return Promise.resolve([]);
|
|
221
|
+
}
|
|
186
222
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
223
|
+
return this.#withJobLock(jobId, () =>
|
|
224
|
+
this.#store.transactionAsync(async () => {
|
|
225
|
+
const notesToNullify = await Promise.all(
|
|
226
|
+
nullifiers.map(async nullifierInBlock => {
|
|
227
|
+
const nullifier = nullifierInBlock.data.toString();
|
|
190
228
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
229
|
+
const storedNote = await this.#readNote(nullifier, jobId);
|
|
230
|
+
if (!storedNote) {
|
|
231
|
+
throw new Error(`Attempted to mark a note as nullified which does not exist in PXE DB`);
|
|
232
|
+
}
|
|
195
233
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
234
|
+
return { storedNote, blockNumber: nullifierInBlock.l2BlockNumber };
|
|
235
|
+
}),
|
|
236
|
+
);
|
|
199
237
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const note = noteToNullify.storedNote!;
|
|
238
|
+
const notesNullifiedInThisCall: Map<string, NoteDao> = new Map();
|
|
239
|
+
for (const noteToNullify of notesToNullify) {
|
|
240
|
+
const note = noteToNullify.storedNote;
|
|
204
241
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
242
|
+
// Skip already nullified notes
|
|
243
|
+
if (note.isNullified()) {
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
209
246
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
247
|
+
note.markAsNullified(noteToNullify.blockNumber);
|
|
248
|
+
this.#writeNote(note, jobId);
|
|
249
|
+
notesNullifiedInThisCall.set(note.noteDao.siloedNullifier.toString(), note.noteDao);
|
|
250
|
+
}
|
|
214
251
|
|
|
215
|
-
|
|
216
|
-
|
|
252
|
+
return [...notesNullifiedInThisCall.values()];
|
|
253
|
+
}),
|
|
254
|
+
);
|
|
217
255
|
}
|
|
218
256
|
|
|
219
257
|
/**
|
|
@@ -244,18 +282,23 @@ export class NoteStore implements StagedStore {
|
|
|
244
282
|
* @param blockNumber - Notes created after this block number will be deleted
|
|
245
283
|
*/
|
|
246
284
|
async #deleteActiveNotesAfterBlock(blockNumber: number): Promise<void> {
|
|
247
|
-
|
|
248
|
-
|
|
285
|
+
// Collect notes to delete during iteration to keep IndexedDB transaction alive.
|
|
286
|
+
const notesToDelete: { nullifier: string; contractAddress: string }[] = [];
|
|
287
|
+
for await (const noteBuffer of this.#notes.valuesAsync()) {
|
|
249
288
|
const storedNote = StoredNote.fromBuffer(noteBuffer);
|
|
250
289
|
if (storedNote.noteDao.l2BlockNumber > blockNumber) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
noteNullifier,
|
|
256
|
-
);
|
|
290
|
+
notesToDelete.push({
|
|
291
|
+
nullifier: storedNote.noteDao.siloedNullifier.toString(),
|
|
292
|
+
contractAddress: storedNote.noteDao.contractAddress.toString(),
|
|
293
|
+
});
|
|
257
294
|
}
|
|
258
295
|
}
|
|
296
|
+
|
|
297
|
+
// Delete all collected notes. Each delete is a DB operation that keeps the transaction alive.
|
|
298
|
+
for (const { nullifier, contractAddress } of notesToDelete) {
|
|
299
|
+
await this.#notes.delete(nullifier);
|
|
300
|
+
await this.#nullifiersByContractAddress.deleteValue(contractAddress, nullifier);
|
|
301
|
+
}
|
|
259
302
|
}
|
|
260
303
|
|
|
261
304
|
/**
|
|
@@ -268,62 +311,69 @@ export class NoteStore implements StagedStore {
|
|
|
268
311
|
* @param anchorBlockNumber - Upper bound for the block range to process
|
|
269
312
|
*/
|
|
270
313
|
async #rewindNullifiedNotesAfterBlock(blockNumber: number, anchorBlockNumber: number): Promise<void> {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
return note;
|
|
286
|
-
}),
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
const storedNotes = nullifiedNoteBuffers.map(buffer => StoredNote.fromBuffer(buffer));
|
|
314
|
+
// First pass: collect all nullifiers for all blocks, starting reads during iteration to keep tx alive.
|
|
315
|
+
const nullifiersByBlock: Map<number, { nullifier: string; noteReadPromise: Promise<Buffer | undefined> }[]> =
|
|
316
|
+
new Map();
|
|
317
|
+
|
|
318
|
+
for (let i = blockNumber + 1; i <= anchorBlockNumber; i++) {
|
|
319
|
+
const blockNullifiers: { nullifier: string; noteReadPromise: Promise<Buffer | undefined> }[] = [];
|
|
320
|
+
for await (const nullifier of this.#nullifiersByNullificationBlockNumber.getValuesAsync(i)) {
|
|
321
|
+
// Start read immediately during iteration to keep IndexedDB transaction alive
|
|
322
|
+
blockNullifiers.push({ nullifier, noteReadPromise: this.#notes.getAsync(nullifier) });
|
|
323
|
+
}
|
|
324
|
+
if (blockNullifiers.length > 0) {
|
|
325
|
+
nullifiersByBlock.set(i, blockNullifiers);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
290
328
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
329
|
+
// Second pass: await reads and perform writes
|
|
330
|
+
for (const [block, nullifiers] of nullifiersByBlock) {
|
|
331
|
+
for (const { nullifier, noteReadPromise } of nullifiers) {
|
|
332
|
+
const noteBuffer = await noteReadPromise;
|
|
333
|
+
if (!noteBuffer) {
|
|
334
|
+
throw new Error(`PXE DB integrity error: no note found with nullifier ${nullifier}`);
|
|
335
|
+
}
|
|
294
336
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
throw new Error(`No scopes found for nullified note with nullifier ${noteNullifier}`);
|
|
337
|
+
const storedNote = StoredNote.fromBuffer(noteBuffer);
|
|
338
|
+
if (storedNote.scopes.size === 0) {
|
|
339
|
+
throw new Error(`No scopes found for nullified note with nullifier ${nullifier}`);
|
|
299
340
|
}
|
|
300
341
|
|
|
301
342
|
storedNote.markAsActive();
|
|
302
343
|
|
|
303
344
|
await Promise.all([
|
|
304
|
-
this.#notes.set(
|
|
305
|
-
this.#nullifiersByNullificationBlockNumber.deleteValue(
|
|
345
|
+
this.#notes.set(nullifier, storedNote.toBuffer()),
|
|
346
|
+
this.#nullifiersByNullificationBlockNumber.deleteValue(block, nullifier),
|
|
306
347
|
]);
|
|
307
348
|
}
|
|
308
349
|
}
|
|
309
350
|
}
|
|
310
351
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
352
|
+
/**
|
|
353
|
+
* Commits in memory job data to persistent storage.
|
|
354
|
+
*
|
|
355
|
+
* Called by JobCoordinator when a job completes successfully.
|
|
356
|
+
*
|
|
357
|
+
* Note: JobCoordinator wraps all commits in a single transaction, so we don't need our own transactionAsync here
|
|
358
|
+
* (and using one would throw on IndexedDB as it does not support nested txs).
|
|
359
|
+
*
|
|
360
|
+
* @param jobId - The jobId identifying which staged data to commit
|
|
361
|
+
*/
|
|
362
|
+
async commit(jobId: string): Promise<void> {
|
|
363
|
+
for (const [nullifier, storedNote] of this.#getNotesForJob(jobId)) {
|
|
364
|
+
await this.#notes.set(nullifier, storedNote.toBuffer());
|
|
365
|
+
await this.#nullifiersByContractAddress.set(storedNote.noteDao.contractAddress.toString(), nullifier);
|
|
366
|
+
if (storedNote.nullifiedAt !== undefined) {
|
|
367
|
+
await this.#nullifiersByNullificationBlockNumber.set(storedNote.nullifiedAt, nullifier);
|
|
319
368
|
}
|
|
369
|
+
}
|
|
320
370
|
|
|
321
|
-
|
|
322
|
-
});
|
|
371
|
+
this.#clearJobData(jobId);
|
|
323
372
|
}
|
|
324
373
|
|
|
325
374
|
discardStaged(jobId: string): Promise<void> {
|
|
326
|
-
|
|
375
|
+
this.#clearJobData(jobId);
|
|
376
|
+
return Promise.resolve();
|
|
327
377
|
}
|
|
328
378
|
|
|
329
379
|
#clearJobData(jobId: string) {
|
|
@@ -358,19 +408,4 @@ export class NoteStore implements StagedStore {
|
|
|
358
408
|
}
|
|
359
409
|
return notesForJob;
|
|
360
410
|
}
|
|
361
|
-
|
|
362
|
-
async #nullifiersOfContract(contractAddress: AztecAddress, jobId: string): Promise<Set<string>> {
|
|
363
|
-
// Collect persisted nullifiers for this contract
|
|
364
|
-
const persistedNullifiers: string[] = await toArray(
|
|
365
|
-
this.#nullifiersByContractAddress.getValuesAsync(contractAddress.toString()),
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
// Collect staged nullifiers from the job where the note's contract matches
|
|
369
|
-
const stagedNullifiers = this.#getNotesForJob(jobId)
|
|
370
|
-
.values()
|
|
371
|
-
.filter(storedNote => storedNote.noteDao.contractAddress.equals(contractAddress))
|
|
372
|
-
.map(storedNote => storedNote.noteDao.siloedNullifier.toString());
|
|
373
|
-
|
|
374
|
-
return new Set([...persistedNullifiers, ...stagedNullifiers]);
|
|
375
|
-
}
|
|
376
411
|
}
|