Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init
Browse files Browse the repository at this point in the history
sklppy88 committed Oct 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 1e5a92b commit ba1b8d3
Showing 5 changed files with 33 additions and 34 deletions.
11 changes: 2 additions & 9 deletions yarn-project/pxe/src/note_processor/note_processor.test.ts
Original file line number Diff line number Diff line change
@@ -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,
18 changes: 12 additions & 6 deletions yarn-project/pxe/src/note_processor/note_processor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
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 +53,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,16 +67,16 @@ export class NoteProcessor {
) {}

public static async create(
account: AztecAddress,
account: CompleteAddress,
keyStore: KeyStore,
db: PxeDatabase,
node: AztecNode,
startingBlock: number = INITIAL_L2_BLOCK_NUM,
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 +231,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 ${
10 changes: 7 additions & 3 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
@@ -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() {
14 changes: 7 additions & 7 deletions yarn-project/pxe/src/synchronizer/synchronizer.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

14 changes: 5 additions & 9 deletions yarn-project/pxe/src/synchronizer/synchronizer.ts
Original file line number Diff line number Diff line change
@@ -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(

0 comments on commit ba1b8d3

Please sign in to comment.