From 1269227bc289cb7837e6d935dcabe6609c85cb60 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Wed, 9 Oct 2024 16:43:24 +0000 Subject: [PATCH] init --- yarn-project/aztec.js/src/utils/account.ts | 3 ++- .../src/note_processor/note_processor.test.ts | 11 ++-------- .../pxe/src/note_processor/note_processor.ts | 12 +++++----- .../pxe/src/pxe_service/pxe_service.ts | 10 ++++++--- .../pxe/src/synchronizer/synchronizer.test.ts | 2 +- .../pxe/src/synchronizer/synchronizer.ts | 22 ++++++++++--------- yarn-project/world-state/package.local.json | 2 +- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/yarn-project/aztec.js/src/utils/account.ts b/yarn-project/aztec.js/src/utils/account.ts index cfc1c5bf479..5f11c192ede 100644 --- a/yarn-project/aztec.js/src/utils/account.ts +++ b/yarn-project/aztec.js/src/utils/account.ts @@ -1,4 +1,5 @@ -import { type CompleteAddress, type PXE } from '@aztec/circuit-types'; +import { type PXE } from '@aztec/circuit-types'; +import { type CompleteAddress } from '@aztec/circuits.js'; import { retryUntil } from '@aztec/foundation/retry'; import { DefaultWaitOpts, type WaitOpts } from '../contract/sent_tx.js'; 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..686fd09c7f8 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.test.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.test.ts @@ -162,14 +162,7 @@ describe('Note Processor', () => { keyStore.getMasterIncomingViewingPublicKey.mockResolvedValue(account.publicKeys.masterIncomingViewingPublicKey); keyStore.getMasterOutgoingViewingPublicKey.mockResolvedValue(account.publicKeys.masterOutgoingViewingPublicKey); - noteProcessor = await NoteProcessor.create( - account.address, - keyStore, - database, - aztecNode, - INITIAL_L2_BLOCK_NUM, - simulator, - ); + noteProcessor = await NoteProcessor.create(account, keyStore, database, aztecNode, INITIAL_L2_BLOCK_NUM, simulator); simulator.computeNoteHashAndOptionallyANullifier.mockImplementation((...args) => Promise.resolve({ @@ -342,7 +335,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..b5bd723dc6d 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 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..4f640c7a069 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.address); } public getSyncStatus() { diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.test.ts b/yarn-project/pxe/src/synchronizer/synchronizer.test.ts index 66ae6d0d88d..25fb06f7c3a 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; }; diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index 0ddfcc191aa..5bef1301e85 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -1,6 +1,12 @@ 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, + type 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 +249,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) { @@ -262,11 +268,7 @@ export class Synchronizer { * @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); + const findByAccountAddress = (x: NoteProcessor) => x.account.address.equals(account); const processor = this.noteProcessors.find(findByAccountAddress) ?? this.noteProcessorsToCatchUp.find(findByAccountAddress); if (!processor) { @@ -300,7 +302,7 @@ export class Synchronizer { const lastBlockNumber = this.getSynchedBlockNumber(); return { blocks: lastBlockNumber, - notes: Object.fromEntries(this.noteProcessors.map(n => [n.account.toString(), n.status.syncedToBlock])), + notes: Object.fromEntries(this.noteProcessors.map(n => [n.account.address.toString(), n.status.syncedToBlock])), }; } @@ -309,7 +311,7 @@ export class Synchronizer { * @returns The note processor stats for notes for each public key being tracked. */ public getSyncStats() { - return Object.fromEntries(this.noteProcessors.map(n => [n.account.toString(), n.stats])); + return Object.fromEntries(this.noteProcessors.map(n => [n.account.address.toString(), n.stats])); } /** @@ -341,7 +343,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( diff --git a/yarn-project/world-state/package.local.json b/yarn-project/world-state/package.local.json index 181680c78a4..c211795716a 100644 --- a/yarn-project/world-state/package.local.json +++ b/yarn-project/world-state/package.local.json @@ -4,4 +4,4 @@ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests", "clean": "rm -rf ./dest ./build .tsbuildinfo" } -} \ No newline at end of file +}