From e08b568850034a46a4c19a2fb1262c2e5797b094 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Fri, 2 Aug 2024 14:57:08 +0000 Subject: [PATCH] init --- .../circuit-types/src/interfaces/pxe.ts | 15 +++++++-- .../src/note_processor/note_processor.test.ts | 4 ++- .../pxe/src/note_processor/note_processor.ts | 2 +- .../pxe/src/synchronizer/synchronizer.ts | 31 ++++++++++--------- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index abb9c049c82d..3f8ca23d0b24 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -186,7 +186,12 @@ export interface PXE { * @throws If the code for the functions executed in this transaction has not been made available via `addContracts`. * Also throws if simulatePublic is true and public simulation reverts. */ - simulateTx(txRequest: TxExecutionRequest, simulatePublic: boolean, msgSender?: AztecAddress, scopes?: AztecAddress[]): Promise; + simulateTx( + txRequest: TxExecutionRequest, + simulatePublic: boolean, + msgSender?: AztecAddress, + scopes?: AztecAddress[], + ): Promise; /** * Sends a transaction to an Aztec node to be broadcasted to the network and mined. @@ -285,7 +290,13 @@ export interface PXE { * @param scopes - (Optional) The accounts whose notes we can access in this call. Currently optional and will default to all. * @returns The result of the view function call, structured based on the function ABI. */ - simulateUnconstrained(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress, scopes?: AztecAddress[]): Promise; + simulateUnconstrained( + functionName: string, + args: any[], + to: AztecAddress, + from?: AztecAddress, + scopes?: AztecAddress[], + ): Promise; /** * Gets unencrypted logs based on the provided filter. diff --git a/yarn-project/pxe/src/note_processor/note_processor.test.ts b/yarn-project/pxe/src/note_processor/note_processor.test.ts index 3757a1c41711..ea92c4ff4733 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.test.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.test.ts @@ -200,6 +200,7 @@ describe('Note Processor', () => { }), ], [], + account.address, ); }, 25_000); @@ -211,7 +212,7 @@ describe('Note Processor', () => { expect(addNotesSpy).toHaveBeenCalledTimes(1); // For outgoing notes, the resulting DAO does not contain index. - expect(addNotesSpy).toHaveBeenCalledWith([], [expect.objectContaining(request.note.payload)]); + expect(addNotesSpy).toHaveBeenCalledWith([], [expect.objectContaining(request.note.payload)], account.address); }, 25_000); it('should store multiple notes that belong to us', async () => { @@ -249,6 +250,7 @@ describe('Note Processor', () => { expect.objectContaining(requests[1].note.payload), expect.objectContaining(requests[4].note.payload), ], + account.address, ); }, 30_000); diff --git a/yarn-project/pxe/src/note_processor/note_processor.ts b/yarn-project/pxe/src/note_processor/note_processor.ts index 5fb9b4623cf5..13ed58e52276 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.ts @@ -227,7 +227,7 @@ export class NoteProcessor { const incomingNotes = blocksAndNotes.flatMap(b => b.incomingNotes); const outgoingNotes = blocksAndNotes.flatMap(b => b.outgoingNotes); if (incomingNotes.length || outgoingNotes.length) { - await this.db.addNotes(incomingNotes, outgoingNotes); + await this.db.addNotes(incomingNotes, outgoingNotes, this.account); incomingNotes.forEach(noteDao => { this.log.verbose( `Added incoming note for contract ${noteDao.contractAddress} at slot ${ diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index 7b301889b04d..d38d449d1c88 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -343,26 +343,27 @@ export class Synchronizer { const { incomingNotes: inNotes, outgoingNotes: outNotes } = await processor.decodeDeferredNotes(deferredNotes); incomingNotes.push(...inNotes); outgoingNotes.push(...outNotes); + + await this.db.addNotes(inNotes, outNotes, processor.account); + + incomingNotes.forEach(noteDao => { + this.log.debug( + `Decoded deferred incoming note for contract ${noteDao.contractAddress} at slot ${ + noteDao.storageSlot + } with nullifier ${noteDao.siloedNullifier.toString()}`, + ); + }); + + outgoingNotes.forEach(noteDao => { + this.log.debug( + `Decoded deferred outgoing note for contract ${noteDao.contractAddress} at slot ${noteDao.storageSlot}`, + ); + }); } } // now drop the deferred notes, and add the decoded notes await this.db.removeDeferredNotesByContract(contractAddress); - await this.db.addNotes(incomingNotes, outgoingNotes); - - incomingNotes.forEach(noteDao => { - this.log.debug( - `Decoded deferred incoming note for contract ${noteDao.contractAddress} at slot ${ - noteDao.storageSlot - } with nullifier ${noteDao.siloedNullifier.toString()}`, - ); - }); - - outgoingNotes.forEach(noteDao => { - this.log.debug( - `Decoded deferred outgoing note for contract ${noteDao.contractAddress} at slot ${noteDao.storageSlot}`, - ); - }); await this.#removeNullifiedNotes(incomingNotes); }