Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Oct 27, 2024
1 parent 6b18887 commit 8fe5d2c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 35 deletions.
8 changes: 4 additions & 4 deletions yarn-project/pxe/src/database/kv_pxe_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,12 @@ export class KVPxeDatabase implements PxeDatabase {
return Promise.resolve(Array.from(this.#addresses).map(v => CompleteAddress.fromBuffer(v)));
}

getSynchedBlockNumberForPublicKey(publicKey: Point): number | undefined {
return this.#syncedBlockPerPublicKey.get(publicKey.toString());
getSynchedBlockNumberForAccount(account: AztecAddress): number | undefined {
return this.#syncedBlockPerPublicKey.get(account.toString());
}

setSynchedBlockNumberForPublicKey(publicKey: Point, blockNumber: number): Promise<void> {
return this.#syncedBlockPerPublicKey.set(publicKey.toString(), blockNumber);
setSynchedBlockNumberForAccount(account: AztecAddress, blockNumber: number): Promise<void> {
return this.#syncedBlockPerPublicKey.set(account.toString(), blockNumber);
}

async estimateSize(): Promise<number> {
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/pxe/src/database/pxe_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD

/**
* Updates up to which block number we have processed notes for a given public key.
* @param publicKey - The public key to set the synched block number for.
* @param account - The account to set the synched block number for.
* @param blockNumber - The block number to set.
*/
setSynchedBlockNumberForPublicKey(publicKey: PublicKey, blockNumber: number): Promise<void>;
setSynchedBlockNumberForAccount(account: AztecAddress, blockNumber: number): Promise<void>;

/**
* Get the synched block number for a given public key.
* @param publicKey - The public key to get the synched block number for.
* @param account - The account to get the synched block number for.
*/
getSynchedBlockNumberForPublicKey(publicKey: PublicKey): number | undefined;
getSynchedBlockNumberForAccount(account: AztecAddress): number | undefined;

/**
* Returns the estimated size in bytes of this db.
Expand Down
41 changes: 14 additions & 27 deletions yarn-project/pxe/src/note_processor/note_processor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { type AztecNode, L1NotePayload, type L2Block } from '@aztec/circuit-types';
import { type NoteProcessorStats } from '@aztec/circuit-types/stats';
import {
type CompleteAddress,
INITIAL_L2_BLOCK_NUM,
MAX_NOTE_HASHES_PER_TX,
type PublicKey,
computeAddressSecret,
} from '@aztec/circuits.js';
import { type CompleteAddress, computeAddressSecret, INITIAL_L2_BLOCK_NUM, MAX_NOTE_HASHES_PER_TX } 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';
Expand Down Expand Up @@ -54,10 +48,6 @@ export class NoteProcessor {

private constructor(
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. */
private readonly ovpkM: PublicKey,
private keyStore: KeyStore,
private db: PxeDatabase,
private node: AztecNode,
Expand All @@ -66,7 +56,7 @@ export class NoteProcessor {
private log: Logger,
) {}

public static async create(
public static create(
account: CompleteAddress,
keyStore: KeyStore,
db: PxeDatabase,
Expand All @@ -75,10 +65,7 @@ export class NoteProcessor {
simulator = getAcirSimulator(db, node, keyStore),
log = createDebugLogger('aztec:note_processor'),
) {
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);
return new NoteProcessor(account, keyStore, db, node, startingBlock, simulator, log);
}

/**
Expand All @@ -101,7 +88,7 @@ export class NoteProcessor {
}

private getSyncedToBlock(): number {
return this.db.getSynchedBlockNumberForPublicKey(this.ivpkM) ?? this.startingBlock - 1;
return this.db.getSynchedBlockNumberForAccount(this.account.address) ?? this.startingBlock - 1;
}

/**
Expand All @@ -120,10 +107,10 @@ export class NoteProcessor {
const deferredIncomingNotes: DeferredNoteDao[] = [];
const deferredOutgoingNotes: DeferredNoteDao[] = [];

const ivskM = await this.keyStore.getMasterSecretKey(this.ivpkM);
const ivskM = await this.keyStore.getMasterSecretKey(this.account.publicKeys.masterIncomingViewingPublicKey);
const addressSecret = computeAddressSecret(this.account.getPreaddress(), ivskM);

const ovskM = await this.keyStore.getMasterSecretKey(this.ovpkM);
const ovskM = await this.keyStore.getMasterSecretKey(this.account.publicKeys.masterOutgoingViewingPublicKey);

// Iterate over both blocks and encrypted logs.
for (const block of blocks) {
Expand Down Expand Up @@ -176,8 +163,8 @@ export class NoteProcessor {
await produceNoteDaos(
this.simulator,
this.db,
incomingNotePayload ? this.ivpkM : undefined,
outgoingNotePayload ? this.ovpkM : undefined,
incomingNotePayload ? this.account.publicKeys.ivpkM : undefined,
outgoingNotePayload ? this.account.publicKeys.ovpkM : undefined,
payload!,
txEffect.txHash,
noteHashes,
Expand Down Expand Up @@ -224,7 +211,7 @@ export class NoteProcessor {
await this.processDeferredNotes(deferredIncomingNotes, deferredOutgoingNotes);

const syncedToBlock = blocks[blocks.length - 1].number;
await this.db.setSynchedBlockNumberForPublicKey(this.ivpkM, syncedToBlock);
await this.db.setSynchedBlockNumberForAccount(this.account.address, syncedToBlock);

this.log.debug(`Synched block ${syncedToBlock}`);
}
Expand Down Expand Up @@ -258,7 +245,7 @@ export class NoteProcessor {
const nullifiers: Fr[] = blocksAndNotes.flatMap(b =>
b.block.body.txEffects.flatMap(txEffect => txEffect.nullifiers),
);
const removedNotes = await this.db.removeNullifiedNotes(nullifiers, this.ivpkM);
const removedNotes = await this.db.removeNullifiedNotes(nullifiers, this.account.publicKeys.masterIncomingViewingPublicKey);
removedNotes.forEach(noteDao => {
this.log.verbose(
`Removed note for contract ${noteDao.contractAddress} at slot ${
Expand Down Expand Up @@ -317,8 +304,8 @@ export class NoteProcessor {
for (const deferredNote of deferredNoteDaos) {
const { publicKey, payload, txHash, noteHashes, dataStartIndexForTx, unencryptedLogs } = deferredNote;

const isIncoming = publicKey.equals(this.ivpkM);
const isOutgoing = publicKey.equals(this.ovpkM);
const isIncoming = publicKey.equals(this.account.publicKeys.masterIncomingViewingPublicKey);
const isOutgoing = publicKey.equals(this.account.publicKeys.masterOutgoingViewingPublicKey);

if (!isIncoming && !isOutgoing) {
// The note does not belong to this note processor
Expand All @@ -328,8 +315,8 @@ export class NoteProcessor {
const { incomingNote, outgoingNote } = await produceNoteDaos(
this.simulator,
this.db,
isIncoming ? this.ivpkM : undefined,
isOutgoing ? this.ovpkM : undefined,
isIncoming ? this.account.publicKeys.masterIncomingViewingPublicKey : undefined,
isOutgoing ? this.account.publicKeys.masterOutgoingViewingPublicKey : undefined,
payload,
txHash,
noteHashes,
Expand Down

0 comments on commit 8fe5d2c

Please sign in to comment.