From 63459c14e35e1d051b333e817d6fa4ed8941428a Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 9 Oct 2024 16:43:24 +0000 Subject: [PATCH] init --- .../pxe/src/note_processor/note_processor.test.ts | 4 ++-- .../pxe/src/note_processor/note_processor.ts | 12 ++++++------ yarn-project/pxe/src/pxe_service/pxe_service.ts | 10 +++++++--- .../pxe/src/synchronizer/synchronizer.test.ts | 14 +++++++------- yarn-project/pxe/src/synchronizer/synchronizer.ts | 14 +++++--------- 5 files changed, 27 insertions(+), 27 deletions(-) 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 18abf9faaea..dd8fd4e278e 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.test.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.test.ts @@ -163,7 +163,7 @@ describe('Note Processor', () => { keyStore.getMasterOutgoingViewingPublicKey.mockResolvedValue(account.publicKeys.masterOutgoingViewingPublicKey); noteProcessor = await NoteProcessor.create( - account.address, + account, keyStore, database, aztecNode, @@ -342,7 +342,7 @@ describe('Note Processor', () => { await noteProcessor.process(blocks); const newNoteProcessor = await NoteProcessor.create( - account.address, + account, keyStore, database, aztecNode, diff --git a/yarn-project/pxe/src/note_processor/note_processor.ts b/yarn-project/pxe/src/note_processor/note_processor.ts index 8a12764ff66..a69fecfcf69 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.ts @@ -1,6 +1,6 @@ import { type AztecNode, L1NotePayload, type L2Block } from '@aztec/circuit-types'; import { type NoteProcessorStats } from '@aztec/circuit-types/stats'; -import { type AztecAddress, INITIAL_L2_BLOCK_NUM, MAX_NOTE_HASHES_PER_TX, type PublicKey } from '@aztec/circuits.js'; +import { type AztecAddress, type CompleteAddress, INITIAL_L2_BLOCK_NUM, MAX_NOTE_HASHES_PER_TX, type PublicKey } from '@aztec/circuits.js'; import { type Fr } from '@aztec/foundation/fields'; import { type Logger, createDebugLogger } from '@aztec/foundation/log'; import { Timer } from '@aztec/foundation/timer'; @@ -47,7 +47,7 @@ export class NoteProcessor { }; private constructor( - public readonly account: AztecAddress, + public readonly account: CompleteAddress, /** The public counterpart to the secret key to be used in the decryption of incoming note logs. */ private readonly ivpkM: PublicKey, /** The public counterpart to the secret key to be used in the decryption of outgoing note logs. */ @@ -61,7 +61,7 @@ export class NoteProcessor { ) {} public static async create( - account: AztecAddress, + account: CompleteAddress, keyStore: KeyStore, db: PxeDatabase, node: AztecNode, @@ -69,8 +69,8 @@ export class NoteProcessor { simulator = getAcirSimulator(db, node, keyStore), log = createDebugLogger('aztec:note_processor'), ) { - const ivpkM = await keyStore.getMasterIncomingViewingPublicKey(account); - const ovpkM = await keyStore.getMasterOutgoingViewingPublicKey(account); + const ivpkM = await keyStore.getMasterIncomingViewingPublicKey(account.address); + const ovpkM = await keyStore.getMasterOutgoingViewingPublicKey(account.address); return new NoteProcessor(account, ivpkM, ovpkM, keyStore, db, node, startingBlock, simulator, log); } @@ -225,7 +225,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, this.account); + await this.db.addNotes(incomingNotes, outgoingNotes, this.account.address); incomingNotes.forEach(noteDao => { this.log.verbose( `Added incoming note for contract ${noteDao.contractAddress} at slot ${ diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 140f3d57459..787d41b0bdf 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -136,7 +136,7 @@ export class PXEService implements PXE { } count++; - await this.synchronizer.addAccount(address.address, this.keyStore, this.config.l2StartingBlock); + await this.synchronizer.addAccount(address, this.keyStore, this.config.l2StartingBlock); } if (count > 0) { @@ -195,7 +195,7 @@ export class PXEService implements PXE { this.log.info(`Account:\n "${accountCompleteAddress.address.toString()}"\n already registered.`); return accountCompleteAddress; } else { - await this.synchronizer.addAccount(accountCompleteAddress.address, this.keyStore, this.config.l2StartingBlock); + await this.synchronizer.addAccount(accountCompleteAddress, this.keyStore, this.config.l2StartingBlock); this.log.info(`Registered account ${accountCompleteAddress.address.toString()}`); this.log.debug(`Registered account\n ${accountCompleteAddress.toReadableString()}`); } @@ -871,7 +871,11 @@ export class PXEService implements PXE { } public async isAccountStateSynchronized(account: AztecAddress) { - return await this.synchronizer.isAccountStateSynchronized(account); + const completeAddress = await this.db.getCompleteAddress(account); + if (!completeAddress) { + throw new Error(`Checking if account is synched is not possible for ${account} because it is not registered.`); + } + return await this.synchronizer.isAccountStateSynchronized(completeAddress); } public getSyncStatus() { diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.test.ts b/yarn-project/pxe/src/synchronizer/synchronizer.test.ts index 66ae6d0d88d..8fb9b081280 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.test.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.test.ts @@ -120,7 +120,7 @@ describe('Synchronizer', () => { const partialAddress = Fr.random(); const completeAddress = await keyStore.addAccount(secretKey, partialAddress); await database.addCompleteAddress(completeAddress); - await synchronizer.addAccount(completeAddress.address, keyStore, startingBlockNum); + await synchronizer.addAccount(completeAddress, keyStore, startingBlockNum); return completeAddress; }; @@ -132,15 +132,15 @@ describe('Synchronizer', () => { await synchronizer.workNoteProcessorCatchUp(); - expect(await synchronizer.isAccountStateSynchronized(completeAddressA.address)).toBe(false); - expect(await synchronizer.isAccountStateSynchronized(completeAddressB.address)).toBe(false); - expect(await synchronizer.isAccountStateSynchronized(completeAddressC.address)).toBe(false); + expect(await synchronizer.isAccountStateSynchronized(completeAddressA)).toBe(false); + expect(await synchronizer.isAccountStateSynchronized(completeAddressB)).toBe(false); + expect(await synchronizer.isAccountStateSynchronized(completeAddressC)).toBe(false); await synchronizer.workNoteProcessorCatchUp(); - expect(await synchronizer.isAccountStateSynchronized(completeAddressA.address)).toBe(true); - expect(await synchronizer.isAccountStateSynchronized(completeAddressB.address)).toBe(true); - expect(await synchronizer.isAccountStateSynchronized(completeAddressC.address)).toBe(true); + expect(await synchronizer.isAccountStateSynchronized(completeAddressA)).toBe(true); + expect(await synchronizer.isAccountStateSynchronized(completeAddressB)).toBe(true); + expect(await synchronizer.isAccountStateSynchronized(completeAddressC)).toBe(true); }); }); diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index 0ddfcc191aa..cbc88d6b228 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -1,6 +1,6 @@ import { type AztecNode, type L2Block, MerkleTreeId, type TxHash } from '@aztec/circuit-types'; import { type NoteProcessorCaughtUpStats } from '@aztec/circuit-types/stats'; -import { type AztecAddress, type Fr, INITIAL_L2_BLOCK_NUM, type PublicKey } from '@aztec/circuits.js'; +import { type AztecAddress, CompleteAddress, type Fr, INITIAL_L2_BLOCK_NUM, type PublicKey } from '@aztec/circuits.js'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { type SerialQueue } from '@aztec/foundation/queue'; import { RunningPromise } from '@aztec/foundation/running-promise'; @@ -243,7 +243,7 @@ export class Synchronizer { * @param startingBlock - The block where to start scanning for notes for this accounts. * @returns A promise that resolves once the account is added to the Synchronizer. */ - public async addAccount(account: AztecAddress, keyStore: KeyStore, startingBlock: number) { + public async addAccount(account: CompleteAddress, keyStore: KeyStore, startingBlock: number) { const predicate = (x: NoteProcessor) => x.account.equals(account); const processor = this.noteProcessors.find(predicate) ?? this.noteProcessorsToCatchUp.find(predicate); if (processor) { @@ -261,12 +261,8 @@ export class Synchronizer { * retrieved information from contracts might be old/stale (e.g. old token balance). * @throws If checking a sync status of account which is not registered. */ - public async isAccountStateSynchronized(account: AztecAddress) { - const completeAddress = await this.db.getCompleteAddress(account); - if (!completeAddress) { - throw new Error(`Checking if account is synched is not possible for ${account} because it is not registered.`); - } - const findByAccountAddress = (x: NoteProcessor) => x.account.equals(completeAddress.address); + public async isAccountStateSynchronized(account: CompleteAddress) { + const findByAccountAddress = (x: NoteProcessor) => x.account.equals(account); const processor = this.noteProcessors.find(findByAccountAddress) ?? this.noteProcessorsToCatchUp.find(findByAccountAddress); if (!processor) { @@ -341,7 +337,7 @@ export class Synchronizer { const { incomingNotes: inNotes, outgoingNotes: outNotes } = await processor.decodeDeferredNotes(deferredNotes); incomingNotes.push(...inNotes); - await this.db.addNotes(inNotes, outNotes, processor.account); + await this.db.addNotes(inNotes, outNotes, processor.account.address); inNotes.forEach(noteDao => { this.log.debug(