diff --git a/yarn-project/aztec.js/src/utils/cheat_codes.ts b/yarn-project/aztec.js/src/utils/cheat_codes.ts index 507460ca4d9..284632a677b 100644 --- a/yarn-project/aztec.js/src/utils/cheat_codes.ts +++ b/yarn-project/aztec.js/src/utils/cheat_codes.ts @@ -256,7 +256,7 @@ export class AztecCheatCodes { * @returns The notes stored at the given slot */ public async loadPrivate(owner: AztecAddress, contract: AztecAddress, slot: Fr | bigint): Promise { - const extendedNotes = await this.pxe.getIncomingNotes({ + const extendedNotes = await this.pxe.getNotes({ owner, contractAddress: contract, storageSlot: new Fr(slot), diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 48199b08927..7087fc3414b 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -3,9 +3,9 @@ import { type EventMetadataDefinition, type ExtendedNote, type GetUnencryptedLogsResponse, - type IncomingNotesFilter, type L2Block, type LogFilter, + type NotesFilter, type PXE, type PXEInfo, type PrivateExecutionResult, @@ -134,8 +134,8 @@ export abstract class BaseWallet implements Wallet { getTxReceipt(txHash: TxHash): Promise { return this.pxe.getTxReceipt(txHash); } - getIncomingNotes(filter: IncomingNotesFilter): Promise { - return this.pxe.getIncomingNotes(filter); + getNotes(filter: NotesFilter): Promise { + return this.pxe.getNotes(filter); } getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise { return this.pxe.getPublicStorageAt(contract, storageSlot); diff --git a/yarn-project/circuit-types/src/interfaces/pxe.test.ts b/yarn-project/circuit-types/src/interfaces/pxe.test.ts index ad3018dc8d6..88af066544c 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.test.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.test.ts @@ -34,8 +34,8 @@ import { AuthWitness } from '../auth_witness.js'; import { type InBlock } from '../in_block.js'; import { L2Block } from '../l2_block.js'; import { ExtendedUnencryptedL2Log, type GetUnencryptedLogsResponse, type LogFilter } from '../logs/index.js'; -import { type IncomingNotesFilter } from '../notes/incoming_notes_filter.js'; import { ExtendedNote, UniqueNote } from '../notes/index.js'; +import { type NotesFilter } from '../notes/notes_filter.js'; import { PrivateExecutionResult } from '../private_execution_result.js'; import { type EpochProofQuote } from '../prover_coordination/epoch_proof_quote.js'; import { SiblingPath } from '../sibling_path/sibling_path.js'; @@ -190,8 +190,8 @@ describe('PXESchema', () => { expect(result).toBeInstanceOf(Fr); }); - it('getIncomingNotes', async () => { - const result = await context.client.getIncomingNotes({ contractAddress: address }); + it('getNotes', async () => { + const result = await context.client.getNotes({ contractAddress: address }); expect(result).toEqual([expect.any(UniqueNote)]); }); @@ -409,7 +409,7 @@ class MockPXE implements PXE { expect(slot).toBeInstanceOf(Fr); return Promise.resolve(Fr.random()); } - getIncomingNotes(filter: IncomingNotesFilter): Promise { + getNotes(filter: NotesFilter): Promise { expect(filter.contractAddress).toEqual(this.address); return Promise.resolve([UniqueNote.random()]); } diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index d70216ef15c..06669355b19 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -36,8 +36,8 @@ import { type LogFilter, LogFilterSchema, } from '../logs/index.js'; -import { type IncomingNotesFilter, IncomingNotesFilterSchema } from '../notes/incoming_notes_filter.js'; import { ExtendedNote, UniqueNote } from '../notes/index.js'; +import { type NotesFilter, NotesFilterSchema } from '../notes/notes_filter.js'; import { PrivateExecutionResult } from '../private_execution_result.js'; import { SiblingPath } from '../sibling_path/sibling_path.js'; import { Tx, TxHash, TxProvingResult, TxReceipt, TxSimulationResult } from '../tx/index.js'; @@ -232,11 +232,11 @@ export interface PXE { getPublicStorageAt(contract: AztecAddress, slot: Fr): Promise; /** - * Gets incoming notes of accounts registered in this PXE based on the provided filter. + * Gets notes registered in this PXE based on the provided filter. * @param filter - The filter to apply to the notes. * @returns The requested notes. */ - getIncomingNotes(filter: IncomingNotesFilter): Promise; + getNotes(filter: NotesFilter): Promise; /** * Fetches an L1 to L2 message from the node. @@ -483,7 +483,7 @@ export const PXESchema: ApiSchemaFor = { .args(TxHash.schema) .returns(z.union([inBlockSchemaFor(TxEffect.schema), z.undefined()])), getPublicStorageAt: z.function().args(schemas.AztecAddress, schemas.Fr).returns(schemas.Fr), - getIncomingNotes: z.function().args(IncomingNotesFilterSchema).returns(z.array(UniqueNote.schema)), + getNotes: z.function().args(NotesFilterSchema).returns(z.array(UniqueNote.schema)), getL1ToL2MembershipWitness: z .function() .args(schemas.AztecAddress, schemas.Fr, schemas.Fr) diff --git a/yarn-project/circuit-types/src/notes/index.ts b/yarn-project/circuit-types/src/notes/index.ts index d926d03e99a..925b57252ea 100644 --- a/yarn-project/circuit-types/src/notes/index.ts +++ b/yarn-project/circuit-types/src/notes/index.ts @@ -1,4 +1,4 @@ export * from './comparator.js'; export * from './extended_note.js'; -export * from './incoming_notes_filter.js'; +export * from './notes_filter.js'; export * from './note_status.js'; diff --git a/yarn-project/circuit-types/src/notes/incoming_notes_filter.ts b/yarn-project/circuit-types/src/notes/notes_filter.ts similarity index 82% rename from yarn-project/circuit-types/src/notes/incoming_notes_filter.ts rename to yarn-project/circuit-types/src/notes/notes_filter.ts index 0f2911c3a58..f2ce6696aeb 100644 --- a/yarn-project/circuit-types/src/notes/incoming_notes_filter.ts +++ b/yarn-project/circuit-types/src/notes/notes_filter.ts @@ -7,10 +7,10 @@ import { TxHash } from '../tx/tx_hash.js'; import { NoteStatus } from './note_status.js'; /** - * A filter used to fetch incoming notes. + * A filter used to fetch notes. * @remarks This filter is applied as an intersection of all its params. */ -export type IncomingNotesFilter = { +export type NotesFilter = { /** Hash of a transaction from which to fetch the notes. */ txHash?: TxHash; /** The contract address the note belongs to. */ @@ -23,11 +23,11 @@ export type IncomingNotesFilter = { status?: NoteStatus; /** The siloed nullifier for the note. */ siloedNullifier?: Fr; - /** The scopes in which to get incoming notes from. This defaults to all scopes. */ + /** The scopes in which to get notes from. This defaults to all scopes. */ scopes?: AztecAddress[]; }; -export const IncomingNotesFilterSchema: ZodFor = z.object({ +export const NotesFilterSchema: ZodFor = z.object({ txHash: TxHash.schema.optional(), contractAddress: schemas.AztecAddress.optional(), storageSlot: schemas.Fr.optional(), diff --git a/yarn-project/cli/src/utils/inspect.ts b/yarn-project/cli/src/utils/inspect.ts index 80c87f4c79d..a1a8148d559 100644 --- a/yarn-project/cli/src/utils/inspect.ts +++ b/yarn-project/cli/src/utils/inspect.ts @@ -39,10 +39,10 @@ export async function inspectTx( log: LogFn, opts: { includeBlockInfo?: boolean; artifactMap?: ArtifactMap } = {}, ) { - const [receipt, effectsInBlock, incomingNotes] = await Promise.all([ + const [receipt, effectsInBlock, getNotes] = await Promise.all([ pxe.getTxReceipt(txHash), pxe.getTxEffect(txHash), - pxe.getIncomingNotes({ txHash, status: NoteStatus.ACTIVE_OR_NULLIFIED }), + pxe.getNotes({ txHash, status: NoteStatus.ACTIVE_OR_NULLIFIED }), ]); // Base tx data log(`Tx ${txHash.toString()}`); @@ -88,10 +88,10 @@ export async function inspectTx( const notes = effects.noteHashes; if (notes.length > 0) { log(' Created notes:'); - log(` Total: ${notes.length}. Incoming: ${incomingNotes.length}.`); - if (incomingNotes.length) { - log(' Incoming notes:'); - for (const note of incomingNotes) { + log(` Total: ${notes.length}. Found: ${getNotes.length}.`); + if (getNotes.length) { + log(' Found notes:'); + for (const note of getNotes) { inspectNote(note, artifactMap, log); } } @@ -103,7 +103,7 @@ export async function inspectTx( if (nullifierCount > 0) { log(' Nullifiers:'); for (const nullifier of effects.nullifiers) { - const [note] = await pxe.getIncomingNotes({ siloedNullifier: nullifier }); + const [note] = await pxe.getNotes({ siloedNullifier: nullifier }); const deployed = deployNullifiers[nullifier.toString()]; const initialized = initNullifiers[nullifier.toString()]; const registered = classNullifiers[nullifier.toString()]; diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index c5f7b3134d9..5317a5ff336 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -244,9 +244,9 @@ describe('e2e_2_pxes', () => { .send() .wait(); await testContract.methods.sync_notes().simulate(); - const incomingNotes = await walletA.getIncomingNotes({ txHash: receipt.txHash }); - expect(incomingNotes).toHaveLength(1); - note = incomingNotes[0]; + const notes = await walletA.getNotes({ txHash: receipt.txHash }); + expect(notes).toHaveLength(1); + note = notes[0]; } // 3. Nullify the note diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/minting.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/minting.test.ts index 03aa384b685..010eb706ef1 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/minting.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/minting.test.ts @@ -98,9 +98,9 @@ describe('e2e_blacklist_token_contract mint', () => { // Trigger a note sync await asset.methods.sync_notes().simulate(); // 1 note should have been created containing `amount` of tokens - const visibleIncomingNotes = await wallets[0].getIncomingNotes({ txHash: receiptClaim.txHash }); - expect(visibleIncomingNotes.length).toBe(1); - expect(visibleIncomingNotes[0].note.items[0].toBigInt()).toBe(amount); + const visibleNotes = await wallets[0].getNotes({ txHash: receiptClaim.txHash }); + expect(visibleNotes.length).toBe(1); + expect(visibleNotes[0].note.items[0].toBigInt()).toBe(amount); }); }); diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index 8918c3eb74a..a56390821d8 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -172,12 +172,12 @@ describe('e2e_crowdfunding_and_claim', () => { // Get the notes emitted by the Crowdfunding contract and check that only 1 was emitted (the value note) await crowdfundingContract.withWallet(donorWallets[0]).methods.sync_notes().simulate(); - const incomingNotes = await donorWallets[0].getIncomingNotes({ txHash: donateTxReceipt.txHash }); - const notes = incomingNotes.filter(x => x.contractAddress.equals(crowdfundingContract.address)); - expect(notes!.length).toEqual(1); + const notes = await donorWallets[0].getNotes({ txHash: donateTxReceipt.txHash }); + const filteredNotes = notes.filter(x => x.contractAddress.equals(crowdfundingContract.address)); + expect(filteredNotes!.length).toEqual(1); // Set the value note in a format which can be passed to claim function - valueNote = processUniqueNote(notes![0]); + valueNote = processUniqueNote(filteredNotes![0]); } // 3) We claim the reward token via the Claim contract @@ -243,12 +243,12 @@ describe('e2e_crowdfunding_and_claim', () => { // Get the notes emitted by the Crowdfunding contract and check that only 1 was emitted (the value note) await crowdfundingContract.withWallet(donorWallets[0]).methods.sync_notes().simulate(); - const incomingNotes = await donorWallets[0].getIncomingNotes({ txHash: donateTxReceipt.txHash }); - const notes = incomingNotes.filter(x => x.contractAddress.equals(crowdfundingContract.address)); - expect(notes!.length).toEqual(1); + const notes = await donorWallets[0].getNotes({ txHash: donateTxReceipt.txHash }); + const filtered = notes.filter(x => x.contractAddress.equals(crowdfundingContract.address)); + expect(filtered!.length).toEqual(1); // Set the value note in a format which can be passed to claim function - const anotherDonationNote = processUniqueNote(notes![0]); + const anotherDonationNote = processUniqueNote(filtered![0]); // We create an unrelated pxe and wallet without access to the nsk_app that correlates to the npk_m specified in the proof note. let unrelatedWallet: AccountWallet; @@ -299,9 +299,9 @@ describe('e2e_crowdfunding_and_claim', () => { { const receipt = await inclusionsProofsContract.methods.create_note(owner, 5n).send().wait({ debug: true }); await inclusionsProofsContract.methods.sync_notes().simulate(); - const incomingNotes = await wallets[0].getIncomingNotes({ txHash: receipt.txHash }); - expect(incomingNotes.length).toEqual(1); - note = processUniqueNote(incomingNotes[0]); + const notes = await wallets[0].getNotes({ txHash: receipt.txHash }); + expect(notes.length).toEqual(1); + note = processUniqueNote(notes[0]); } // 3) Test the note was included diff --git a/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts b/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts index eb0d5d8b964..ebda8f38f1f 100644 --- a/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts @@ -294,8 +294,8 @@ describe('e2e_pending_note_hashes_contract', () => { await deployedContract.methods.sync_notes().simulate(); - const incomingNotes = await wallet.getIncomingNotes({ txHash: txReceipt.txHash }); + const notes = await wallet.getNotes({ txHash: txReceipt.txHash }); - expect(incomingNotes.length).toBe(1); + expect(notes.length).toBe(1); }); }); diff --git a/yarn-project/end-to-end/src/flakey_e2e_inclusion_proofs_contract.test.ts b/yarn-project/end-to-end/src/flakey_e2e_inclusion_proofs_contract.test.ts index 7fc07cea262..b93218fbd60 100644 --- a/yarn-project/end-to-end/src/flakey_e2e_inclusion_proofs_contract.test.ts +++ b/yarn-project/end-to-end/src/flakey_e2e_inclusion_proofs_contract.test.ts @@ -53,7 +53,7 @@ describe('e2e_inclusion_proofs_contract', () => { describe('proves note existence and its nullifier non-existence and nullifier non-existence failure case', () => { // Owner of a note let noteCreationBlockNumber: number; - let noteHashes, visibleIncomingNotes: ExtendedNote[]; + let noteHashes, visibleNotes: ExtendedNote[]; const value = 100n; let validNoteBlockNumber: any; @@ -65,13 +65,13 @@ describe('e2e_inclusion_proofs_contract', () => { ({ noteHashes } = receipt.debugInfo!); await contract.methods.sync_notes().simulate(); - visibleIncomingNotes = await wallets[0].getIncomingNotes({ txHash: receipt.txHash }); + visibleNotes = await wallets[0].getNotes({ txHash: receipt.txHash }); }); it('should return the correct values for creating a note', () => { expect(noteHashes.length).toBe(1); - expect(visibleIncomingNotes.length).toBe(1); - const [receivedValue, receivedOwner, _randomness] = visibleIncomingNotes[0].note.items; + expect(visibleNotes.length).toBe(1); + const [receivedValue, receivedOwner, _randomness] = visibleNotes[0].note.items; expect(receivedValue.toBigInt()).toBe(value); expect(receivedOwner).toEqual(owner.toField()); }); @@ -161,11 +161,11 @@ describe('e2e_inclusion_proofs_contract', () => { const { noteHashes } = receipt.debugInfo!; await contract.methods.sync_notes().simulate(); - const visibleIncomingNotes = await wallets[0].getIncomingNotes({ txHash: receipt.txHash }); + const visibleNotes = await wallets[0].getNotes({ txHash: receipt.txHash }); expect(noteHashes.length).toBe(1); - expect(visibleIncomingNotes.length).toBe(1); - const [receivedValue, receivedOwner, _randomness] = visibleIncomingNotes[0].note.items; + expect(visibleNotes.length).toBe(1); + const [receivedValue, receivedOwner, _randomness] = visibleNotes[0].note.items; expect(receivedValue.toBigInt()).toBe(value); expect(receivedOwner).toEqual(owner.toField()); } diff --git a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts index 6364517d223..d9cbf1f3553 100644 --- a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts +++ b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts @@ -107,7 +107,7 @@ describe('guides/dapp/testing', () => { it('checks private storage', async () => { // docs:start:private-storage await token.methods.sync_notes().simulate(); - const notes = await pxe.getIncomingNotes({ + const notes = await pxe.getNotes({ owner: owner.getAddress(), contractAddress: token.address, storageSlot: ownerSlot, diff --git a/yarn-project/pxe/src/database/incoming_note_dao.test.ts b/yarn-project/pxe/src/database/incoming_note_dao.test.ts deleted file mode 100644 index 1df9103e08f..00000000000 --- a/yarn-project/pxe/src/database/incoming_note_dao.test.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { IncomingNoteDao } from './incoming_note_dao.js'; - -describe('Incoming Note DAO', () => { - it('convert to and from buffer', () => { - const note = IncomingNoteDao.random(); - const buf = note.toBuffer(); - expect(IncomingNoteDao.fromBuffer(buf)).toEqual(note); - }); -}); diff --git a/yarn-project/pxe/src/database/kv_pxe_database.ts b/yarn-project/pxe/src/database/kv_pxe_database.ts index ebf1c07991c..ccff64cb229 100644 --- a/yarn-project/pxe/src/database/kv_pxe_database.ts +++ b/yarn-project/pxe/src/database/kv_pxe_database.ts @@ -1,4 +1,4 @@ -import { type InBlock, type IncomingNotesFilter, MerkleTreeId, NoteStatus } from '@aztec/circuit-types'; +import { type InBlock, MerkleTreeId, NoteStatus, type NotesFilter } from '@aztec/circuit-types'; import { AztecAddress, BlockHeader, @@ -22,7 +22,7 @@ import { } from '@aztec/kv-store'; import { contractArtifactFromBuffer, contractArtifactToBuffer } from '@aztec/types/abi'; -import { IncomingNoteDao } from './incoming_note_dao.js'; +import { NoteDao } from './note_dao.js'; import { type PxeDatabase } from './pxe_database.js'; /** @@ -185,17 +185,17 @@ export class KVPxeDatabase implements PxeDatabase { return val?.map(b => Fr.fromBuffer(b)); } - async addNote(note: IncomingNoteDao, scope?: AztecAddress): Promise { + async addNote(note: NoteDao, scope?: AztecAddress): Promise { await this.addNotes([note], scope); } - async addNotes(incomingNotes: IncomingNoteDao[], scope: AztecAddress = AztecAddress.ZERO): Promise { + async addNotes(notes: NoteDao[], scope: AztecAddress = AztecAddress.ZERO): Promise { if (!(await this.#scopes.hasAsync(scope.toString()))) { await this.#addScope(scope); } return this.db.transactionAsync(async () => { - for (const dao of incomingNotes) { + for (const dao of notes) { // store notes by their index in the notes hash tree // this provides the uniqueness we need to store individual notes // and should also return notes in the order that they were created. @@ -217,7 +217,7 @@ export class KVPxeDatabase implements PxeDatabase { return this.db.transactionAsync(async () => { const notes = await toArray(this.#notes.valuesAsync()); for (const note of notes) { - const noteDao = IncomingNoteDao.fromBuffer(note); + const noteDao = NoteDao.fromBuffer(note); if (noteDao.l2BlockNumber > blockNumber) { const noteIndex = toBufferBE(noteDao.index, 32).toString('hex'); await this.#notes.delete(noteIndex); @@ -252,7 +252,7 @@ export class KVPxeDatabase implements PxeDatabase { ); const noteDaos = nullifiedNoteBuffers .filter(buffer => buffer != undefined) - .map(buffer => IncomingNoteDao.fromBuffer(buffer!)); + .map(buffer => NoteDao.fromBuffer(buffer!)); await this.db.transactionAsync(async () => { for (const dao of noteDaos) { @@ -286,7 +286,7 @@ export class KVPxeDatabase implements PxeDatabase { }); } - async getIncomingNotes(filter: IncomingNotesFilter): Promise { + async getNotes(filter: NotesFilter): Promise { const publicKey: PublicKey | undefined = filter.owner ? filter.owner.toAddressPoint() : undefined; filter.status = filter.status ?? NoteStatus.ACTIVE; @@ -348,7 +348,7 @@ export class KVPxeDatabase implements PxeDatabase { }); } - const result: IncomingNoteDao[] = []; + const result: NoteDao[] = []; for (const { ids, notes } of candidateNoteSources) { for (const id of ids) { const serializedNote = await notes.getAsync(id); @@ -356,7 +356,7 @@ export class KVPxeDatabase implements PxeDatabase { continue; } - const note = IncomingNoteDao.fromBuffer(serializedNote); + const note = NoteDao.fromBuffer(serializedNote); if (filter.contractAddress && !note.contractAddress.equals(filter.contractAddress)) { continue; } @@ -384,13 +384,13 @@ export class KVPxeDatabase implements PxeDatabase { return result; } - removeNullifiedNotes(nullifiers: InBlock[], accountAddressPoint: PublicKey): Promise { + removeNullifiedNotes(nullifiers: InBlock[], accountAddressPoint: PublicKey): Promise { if (nullifiers.length === 0) { return Promise.resolve([]); } return this.db.transactionAsync(async () => { - const nullifiedNotes: IncomingNoteDao[] = []; + const nullifiedNotes: NoteDao[] = []; for (const blockScopedNullifier of nullifiers) { const { data: nullifier, l2BlockNumber: blockNumber } = blockScopedNullifier; @@ -406,7 +406,7 @@ export class KVPxeDatabase implements PxeDatabase { continue; } const noteScopes = (await toArray(this.#notesToScope.getValuesAsync(noteIndex))) ?? []; - const note = IncomingNoteDao.fromBuffer(noteBuffer); + const note = NoteDao.fromBuffer(noteBuffer); if (!note.addressPoint.equals(accountAddressPoint)) { // tried to nullify someone else's note continue; @@ -445,7 +445,7 @@ export class KVPxeDatabase implements PxeDatabase { }); } - async addNullifiedNote(note: IncomingNoteDao): Promise { + async addNullifiedNote(note: NoteDao): Promise { const noteIndex = toBufferBE(note.index, 32).toString('hex'); await this.#nullifiedNotes.set(noteIndex, note.toBuffer()); @@ -563,7 +563,7 @@ export class KVPxeDatabase implements PxeDatabase { } async estimateSize(): Promise { - const incomingNotesSize = (await this.getIncomingNotes({})).reduce((sum, note) => sum + note.getSize(), 0); + const noteSize = (await this.getNotes({})).reduce((sum, note) => sum + note.getSize(), 0); const authWitsSize = (await toArray(this.#authWitnesses.valuesAsync())).reduce( (sum, value) => sum + value.length * Fr.SIZE_IN_BYTES, @@ -572,7 +572,7 @@ export class KVPxeDatabase implements PxeDatabase { const addressesSize = (await this.#completeAddresses.lengthAsync()) * CompleteAddress.SIZE_IN_BYTES; const treeRootsSize = Object.keys(MerkleTreeId).length * Fr.SIZE_IN_BYTES; - return incomingNotesSize + treeRootsSize + authWitsSize + addressesSize; + return noteSize + treeRootsSize + authWitsSize + addressesSize; } async setTaggingSecretsIndexesAsSender(indexedSecrets: IndexedTaggingSecret[]): Promise { diff --git a/yarn-project/pxe/src/database/note_dao.test.ts b/yarn-project/pxe/src/database/note_dao.test.ts new file mode 100644 index 00000000000..599519e310d --- /dev/null +++ b/yarn-project/pxe/src/database/note_dao.test.ts @@ -0,0 +1,9 @@ +import { NoteDao } from './note_dao.js'; + +describe('Note DAO', () => { + it('convert to and from buffer', () => { + const note = NoteDao.random(); + const buf = note.toBuffer(); + expect(NoteDao.fromBuffer(buf)).toEqual(note); + }); +}); diff --git a/yarn-project/pxe/src/database/incoming_note_dao.ts b/yarn-project/pxe/src/database/note_dao.ts similarity index 70% rename from yarn-project/pxe/src/database/incoming_note_dao.ts rename to yarn-project/pxe/src/database/note_dao.ts index 93464386ec9..b4cb311fd46 100644 --- a/yarn-project/pxe/src/database/incoming_note_dao.ts +++ b/yarn-project/pxe/src/database/note_dao.ts @@ -8,40 +8,57 @@ import { type NoteData } from '@aztec/simulator/acvm'; import { type NoteInfo } from '../note_decryption_utils/index.js'; /** - * A note with contextual data which was decrypted as incoming. + * A Note Data Access Object, representing a note that was comitted to the note hash tree, holding all of the + * information required to use it during execution and manage its state. */ -export class IncomingNoteDao implements NoteData { +export class NoteDao implements NoteData { constructor( - /** The note as emitted from the Noir contract. */ + // Note information + + /** The serialized content of the note, as will be returned in the getNotes oracle. */ public note: Note, - /** The contract address this note is created in. */ + /** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */ public contractAddress: AztecAddress, - /** The specific storage location of the note on the contract. */ + /** + * The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot + * since contracts typically make queries based on it. + * */ public storageSlot: Fr, - /** The note type identifier for the contract. */ - public noteTypeId: NoteSelector, - /** The hash of the tx the note was created in. */ - public txHash: TxHash, - /** The L2 block number in which the tx with this note was included. */ - public l2BlockNumber: number, - /** The L2 block hash in which the tx with this note was included. */ - public l2BlockHash: string, - /** The nonce of the note. */ + /** The kernel-provided nonce of the note, required to compute the uniqueNoteHash. */ public nonce: Fr, + + // Computed values /** - * A hash of the note. This is customizable by the app circuit. - * We can use this value to compute siloedNoteHash and uniqueSiloedNoteHash. + * The inner hash (non-unique, non-siloed) of the note. Each contract determines how the note content is hashed. Can + * be used alongside contractAddress and nonce to compute the uniqueNoteHash and the siloedNoteHash. */ public noteHash: Fr, /** - * The nullifier of the note (siloed by contract address). + * The nullifier of the note, siloed by contract address. * Note: Might be set as 0 if the note was added to PXE as nullified. */ public siloedNullifier: Fr, - /** The location of the relevant note in the note hash tree. */ + + // Metadata + /** The hash of the tx in which this note was created. Knowing the tx hash allows for efficient node queries e.g. + * when searching for txEffects. + */ + public txHash: TxHash, + /** The L2 block number in which the tx with this note was included. Used for note management while processing + * reorgs.*/ + public l2BlockNumber: number, + /** The L2 block hash in which the tx with this note was included. Used for note management while processing + * reorgs.*/ + public l2BlockHash: string, + /** The index of the leaf in the global note hash tree the note is stored at */ public index: bigint, - /** The public key with which the note was encrypted. */ + /** The public key with which the note content was encrypted during delivery. */ public addressPoint: PublicKey, + + /** The note type identifier for the contract. + * TODO: remove + */ + public noteTypeId: NoteSelector, ) {} static fromPayloadAndNoteInfo( @@ -54,19 +71,19 @@ export class IncomingNoteDao implements NoteData { addressPoint: PublicKey, ) { const noteHashIndexInTheWholeTree = BigInt(dataStartIndexForTx + noteInfo.noteHashIndex); - return new IncomingNoteDao( + return new NoteDao( note, payload.contractAddress, payload.storageSlot, - payload.noteTypeId, - noteInfo.txHash, - l2BlockNumber, - l2BlockHash, noteInfo.nonce, noteInfo.noteHash, noteInfo.siloedNullifier, + noteInfo.txHash, + l2BlockNumber, + l2BlockHash, noteHashIndexInTheWholeTree, addressPoint, + payload.noteTypeId, ); } @@ -75,15 +92,15 @@ export class IncomingNoteDao implements NoteData { this.note, this.contractAddress, this.storageSlot, - this.noteTypeId, - this.txHash, - this.l2BlockNumber, - Fr.fromHexString(this.l2BlockHash), this.nonce, this.noteHash, this.siloedNullifier, + this.txHash, + this.l2BlockNumber, + Fr.fromHexString(this.l2BlockHash), this.index, this.addressPoint, + this.noteTypeId, ]); } @@ -93,29 +110,29 @@ export class IncomingNoteDao implements NoteData { const note = Note.fromBuffer(reader); const contractAddress = AztecAddress.fromBuffer(reader); const storageSlot = Fr.fromBuffer(reader); - const noteTypeId = reader.readObject(NoteSelector); - const txHash = reader.readObject(TxHash); - const l2BlockNumber = reader.readNumber(); - const l2BlockHash = Fr.fromBuffer(reader).toString(); const nonce = Fr.fromBuffer(reader); const noteHash = Fr.fromBuffer(reader); const siloedNullifier = Fr.fromBuffer(reader); + const txHash = reader.readObject(TxHash); + const l2BlockNumber = reader.readNumber(); + const l2BlockHash = Fr.fromBuffer(reader).toString(); const index = toBigIntBE(reader.readBytes(32)); const publicKey = Point.fromBuffer(reader); + const noteTypeId = reader.readObject(NoteSelector); - return new IncomingNoteDao( + return new NoteDao( note, contractAddress, storageSlot, - noteTypeId, - txHash, - l2BlockNumber, - l2BlockHash, nonce, noteHash, siloedNullifier, + txHash, + l2BlockNumber, + l2BlockHash, index, publicKey, + noteTypeId, ); } @@ -125,7 +142,7 @@ export class IncomingNoteDao implements NoteData { static fromString(str: string) { const hex = str.replace(/^0x/, ''); - return IncomingNoteDao.fromBuffer(Buffer.from(hex, 'hex')); + return NoteDao.fromBuffer(Buffer.from(hex, 'hex')); } /** @@ -141,30 +158,30 @@ export class IncomingNoteDao implements NoteData { static random({ note = Note.random(), contractAddress = AztecAddress.random(), - txHash = randomTxHash(), storageSlot = Fr.random(), - noteTypeId = NoteSelector.random(), nonce = Fr.random(), - l2BlockNumber = Math.floor(Math.random() * 1000), - l2BlockHash = Fr.random().toString(), noteHash = Fr.random(), siloedNullifier = Fr.random(), + txHash = randomTxHash(), + l2BlockNumber = Math.floor(Math.random() * 1000), + l2BlockHash = Fr.random().toString(), index = Fr.random().toBigInt(), addressPoint = Point.random(), - }: Partial = {}) { - return new IncomingNoteDao( + noteTypeId = NoteSelector.random(), + }: Partial = {}) { + return new NoteDao( note, contractAddress, storageSlot, - noteTypeId, - txHash, - l2BlockNumber, - l2BlockHash, nonce, noteHash, siloedNullifier, + txHash, + l2BlockNumber, + l2BlockHash, index, addressPoint, + noteTypeId, ); } } diff --git a/yarn-project/pxe/src/database/outgoing_note_dao.test.ts b/yarn-project/pxe/src/database/outgoing_note_dao.test.ts deleted file mode 100644 index 0c293ba13eb..00000000000 --- a/yarn-project/pxe/src/database/outgoing_note_dao.test.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { OutgoingNoteDao } from './outgoing_note_dao.js'; - -describe('Outgoing Note DAO', () => { - it('convert to and from buffer', () => { - const note = OutgoingNoteDao.random(); - const buf = note.toBuffer(); - expect(OutgoingNoteDao.fromBuffer(buf)).toEqual(note); - }); -}); diff --git a/yarn-project/pxe/src/database/pxe_database.ts b/yarn-project/pxe/src/database/pxe_database.ts index 6926b2c02af..8a8b2f8cd61 100644 --- a/yarn-project/pxe/src/database/pxe_database.ts +++ b/yarn-project/pxe/src/database/pxe_database.ts @@ -1,4 +1,4 @@ -import { type InBlock, type IncomingNotesFilter } from '@aztec/circuit-types'; +import { type InBlock, type NotesFilter } from '@aztec/circuit-types'; import { type BlockHeader, type CompleteAddress, @@ -12,7 +12,7 @@ import { type Fr } from '@aztec/foundation/fields'; import { type ContractArtifactDatabase } from './contracts/contract_artifact_db.js'; import { type ContractInstanceDatabase } from './contracts/contract_instance_db.js'; -import { type IncomingNoteDao } from './incoming_note_dao.js'; +import { type NoteDao } from './note_dao.js'; /** * A database interface that provides methods for retrieving, adding, and removing transactional data related to Aztec @@ -50,11 +50,11 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD popCapsule(): Promise; /** - * Gets incoming notes based on the provided filter. + * Gets notes based on the provided filter. * @param filter - The filter to apply to the notes. * @returns The requested notes. */ - getIncomingNotes(filter: IncomingNotesFilter): Promise; + getNotes(filter: NotesFilter): Promise; /** * Adds a note to DB. @@ -62,24 +62,24 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD * @param scope - The scope to add the note under. Currently optional. * @remark - Will create a database for the scope if it does not already exist. */ - addNote(note: IncomingNoteDao, scope?: AztecAddress): Promise; + addNote(note: NoteDao, scope?: AztecAddress): Promise; /** * Adds a nullified note to DB. * @param note - The note to add. */ - addNullifiedNote(note: IncomingNoteDao): Promise; + addNullifiedNote(note: NoteDao): Promise; /** * Adds an array of notes to DB. * This function is used to insert multiple notes to the database at once, * which can improve performance when dealing with large numbers of transactions. * - * @param incomingNotes - An array of notes which were decrypted as incoming. + * @param notes - An array of notes. * @param scope - The scope to add the notes under. Currently optional. * @remark - Will create a database for the scope if it does not already exist. */ - addNotes(incomingNotes: IncomingNoteDao[], scope?: AztecAddress): Promise; + addNotes(notes: NoteDao[], scope?: AztecAddress): Promise; /** * Remove nullified notes associated with the given account and nullifiers. @@ -88,7 +88,7 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD * @param account - A PublicKey instance representing the account for which the records are being removed. * @returns Removed notes. */ - removeNullifiedNotes(nullifiers: InBlock[], account: PublicKey): Promise; + removeNullifiedNotes(nullifiers: InBlock[], account: PublicKey): Promise; /** * Gets the most recently processed block number. diff --git a/yarn-project/pxe/src/database/pxe_database_test_suite.ts b/yarn-project/pxe/src/database/pxe_database_test_suite.ts index ac14fa97c53..78c7cf2f110 100644 --- a/yarn-project/pxe/src/database/pxe_database_test_suite.ts +++ b/yarn-project/pxe/src/database/pxe_database_test_suite.ts @@ -1,4 +1,4 @@ -import { type IncomingNotesFilter, NoteStatus, randomTxHash } from '@aztec/circuit-types'; +import { NoteStatus, type NotesFilter, randomTxHash } from '@aztec/circuit-types'; import { AztecAddress, CompleteAddress, @@ -13,7 +13,7 @@ import { Fr, Point } from '@aztec/foundation/fields'; import { BenchmarkingContractArtifact } from '@aztec/noir-contracts.js/Benchmarking'; import { TestContractArtifact } from '@aztec/noir-contracts.js/Test'; -import { IncomingNoteDao } from './incoming_note_dao.js'; +import { NoteDao } from './note_dao.js'; import { type PxeDatabase } from './pxe_database.js'; /** @@ -78,9 +78,9 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { let owners: CompleteAddress[]; let contractAddresses: AztecAddress[]; let storageSlots: Fr[]; - let notes: IncomingNoteDao[]; + let notes: NoteDao[]; - const filteringTests: [() => IncomingNotesFilter, () => IncomingNoteDao[]][] = [ + const filteringTests: [() => NotesFilter, () => NoteDao[]][] = [ [() => ({}), () => notes], [ @@ -119,7 +119,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { storageSlots = Array.from({ length: 2 }).map(() => Fr.random()); notes = Array.from({ length: 10 }).map((_, i) => - IncomingNoteDao.random({ + NoteDao.random({ contractAddress: contractAddresses[i % contractAddresses.length], storageSlot: storageSlots[i % storageSlots.length], addressPoint: owners[i % owners.length].address.toAddressPoint(), @@ -135,7 +135,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { it.each(filteringTests)('stores notes in bulk and retrieves notes', async (getFilter, getExpected) => { await database.addNotes(notes); - const returnedNotes = await database.getIncomingNotes(getFilter()); + const returnedNotes = await database.getNotes(getFilter()); expect(returnedNotes.sort()).toEqual(getExpected().sort()); }); @@ -145,7 +145,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { await database.addNote(note); } - const returnedNotes = await database.getIncomingNotes(getFilter()); + const returnedNotes = await database.getNotes(getFilter()); expect(returnedNotes.sort()).toEqual(getExpected().sort()); }); @@ -166,9 +166,9 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { ); } - await expect( - database.getIncomingNotes({ ...getFilter(), status: NoteStatus.ACTIVE_OR_NULLIFIED }), - ).resolves.toEqual(getExpected()); + await expect(database.getNotes({ ...getFilter(), status: NoteStatus.ACTIVE_OR_NULLIFIED })).resolves.toEqual( + getExpected(), + ); }); it('skips nullified notes by default or when requesting active', async () => { @@ -184,8 +184,8 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { notesToNullify, ); - const actualNotesWithDefault = await database.getIncomingNotes({}); - const actualNotesWithActive = await database.getIncomingNotes({ status: NoteStatus.ACTIVE }); + const actualNotesWithDefault = await database.getNotes({}); + const actualNotesWithActive = await database.getNotes({ status: NoteStatus.ACTIVE }); expect(actualNotesWithDefault).toEqual(actualNotesWithActive); expect(actualNotesWithActive).toEqual(notes.filter(note => !notesToNullify.includes(note))); @@ -206,7 +206,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { ); await expect(database.unnullifyNotesAfter(98)).resolves.toEqual(undefined); - const result = await database.getIncomingNotes({ status: NoteStatus.ACTIVE, owner: owners[0].address }); + const result = await database.getNotes({ status: NoteStatus.ACTIVE, owner: owners[0].address }); expect(result.sort()).toEqual([...notesToNullify].sort()); }); @@ -224,7 +224,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { notesToNullify, ); - const result = await database.getIncomingNotes({ + const result = await database.getNotes({ status: NoteStatus.ACTIVE_OR_NULLIFIED, }); @@ -242,23 +242,23 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { await database.addNote(note, owners[1].address); } - const owner0IncomingNotes = await database.getIncomingNotes({ + const owner0Notes = await database.getNotes({ scopes: [owners[0].address], }); - expect(owner0IncomingNotes.sort()).toEqual(notes.slice(0, 5).sort()); + expect(owner0Notes.sort()).toEqual(notes.slice(0, 5).sort()); - const owner1IncomingNotes = await database.getIncomingNotes({ + const owner1Notes = await database.getNotes({ scopes: [owners[1].address], }); - expect(owner1IncomingNotes.sort()).toEqual(notes.slice(5).sort()); + expect(owner1Notes.sort()).toEqual(notes.slice(5).sort()); - const bothOwnerIncomingNotes = await database.getIncomingNotes({ + const bothOwnerNotes = await database.getNotes({ scopes: [owners[0].address, owners[1].address], }); - expect(bothOwnerIncomingNotes.sort()).toEqual(notes.sort()); + expect(bothOwnerNotes.sort()).toEqual(notes.sort()); }); it('a nullified note removes notes from all accounts in the pxe', async () => { @@ -266,12 +266,12 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { await database.addNote(notes[0], owners[1].address); await expect( - database.getIncomingNotes({ + database.getNotes({ scopes: [owners[0].address], }), ).resolves.toEqual([notes[0]]); await expect( - database.getIncomingNotes({ + database.getNotes({ scopes: [owners[1].address], }), ).resolves.toEqual([notes[0]]); @@ -290,12 +290,12 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { ).resolves.toEqual([notes[0]]); await expect( - database.getIncomingNotes({ + database.getNotes({ scopes: [owners[0].address], }), ).resolves.toEqual([]); await expect( - database.getIncomingNotes({ + database.getNotes({ scopes: [owners[1].address], }), ).resolves.toEqual([]); @@ -305,7 +305,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { await database.addNotes(notes, owners[0].address); await database.removeNotesAfter(5); - const result = await database.getIncomingNotes({ scopes: [owners[0].address] }); + const result = await database.getNotes({ scopes: [owners[0].address] }); expect(new Set(result)).toEqual(new Set(notes.slice(0, 6))); }); }); diff --git a/yarn-project/pxe/src/note_decryption_utils/produce_note_daos.ts b/yarn-project/pxe/src/note_decryption_utils/produce_note_daos.ts index ca05f03cfa8..7e1f94abe03 100644 --- a/yarn-project/pxe/src/note_decryption_utils/produce_note_daos.ts +++ b/yarn-project/pxe/src/note_decryption_utils/produce_note_daos.ts @@ -3,7 +3,7 @@ import { type Fr } from '@aztec/foundation/fields'; import { type Logger } from '@aztec/foundation/log'; import { type AcirSimulator } from '@aztec/simulator/client'; -import { IncomingNoteDao } from '../database/incoming_note_dao.js'; +import { NoteDao } from '../database/note_dao.js'; import { type PxeDatabase } from '../database/pxe_database.js'; import { produceNoteDaosForKey } from './produce_note_daos_for_key.js'; @@ -37,15 +37,15 @@ export async function produceNoteDaos( dataStartIndexForTx: number, excludedIndices: Set, logger: Logger, -): Promise<{ incomingNote: IncomingNoteDao | undefined }> { +): Promise<{ note: NoteDao | undefined }> { if (!addressPoint) { throw new Error('addressPoint is undefined. Cannot create note.'); } - let incomingNote: IncomingNoteDao | undefined; + let note: NoteDao | undefined; if (addressPoint) { - incomingNote = await produceNoteDaosForKey( + note = await produceNoteDaosForKey( simulator, db, addressPoint, @@ -57,11 +57,11 @@ export async function produceNoteDaos( dataStartIndexForTx, excludedIndices, logger, - IncomingNoteDao.fromPayloadAndNoteInfo, + NoteDao.fromPayloadAndNoteInfo, ); } return { - incomingNote, + note, }; } diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 4bf9f3bccf5..b57ea54df95 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -7,11 +7,11 @@ import { type FunctionCall, type GetUnencryptedLogsResponse, type InBlock, - type IncomingNotesFilter, L1EventPayload, type L2Block, type LogFilter, MerkleTreeId, + type NotesFilter, type PXE, type PXEInfo, type PrivateExecutionResult, @@ -71,8 +71,8 @@ import { inspect } from 'util'; import { type PXEServiceConfig } from '../config/index.js'; import { getPackageInfo } from '../config/package_info.js'; import { ContractDataOracle } from '../contract_data_oracle/index.js'; -import { IncomingNoteDao } from '../database/incoming_note_dao.js'; import { type PxeDatabase } from '../database/index.js'; +import { NoteDao } from '../database/note_dao.js'; import { KernelOracle } from '../kernel_oracle/index.js'; import { KernelProver } from '../kernel_prover/kernel_prover.js'; import { TestPrivateKernelProver } from '../kernel_prover/test/test_circuit_prover.js'; @@ -273,8 +273,8 @@ export class PXEService implements PXE { return await this.node.getPublicStorageAt(contract, slot, 'latest'); } - public async getIncomingNotes(filter: IncomingNotesFilter): Promise { - const noteDaos = await this.db.getIncomingNotes(filter); + public async getNotes(filter: NotesFilter): Promise { + const noteDaos = await this.db.getNotes(filter); const extendedNotes = noteDaos.map(async dao => { let owner = filter.owner; @@ -343,19 +343,19 @@ export class PXEService implements PXE { } await this.db.addNote( - new IncomingNoteDao( + new NoteDao( note.note, note.contractAddress, note.storageSlot, - note.noteTypeId, - note.txHash, - l2BlockNumber, - l2BlockHash, nonce, noteHash, siloedNullifier, + note.txHash, + l2BlockNumber, + l2BlockHash, index, owner.address.toAddressPoint(), + note.noteTypeId, ), scope, ); @@ -388,19 +388,19 @@ export class PXEService implements PXE { } await this.db.addNullifiedNote( - new IncomingNoteDao( + new NoteDao( note.note, note.contractAddress, note.storageSlot, - note.noteTypeId, - note.txHash, - l2BlockNumber, - l2BlockHash, nonce, noteHash, Fr.ZERO, // We are not able to derive + note.txHash, + l2BlockNumber, + l2BlockHash, index, note.owner.toAddressPoint(), + note.noteTypeId, ), ); } diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index f19f840a343..137b4137d95 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -34,8 +34,8 @@ import { MessageLoadOracleInputs } from '@aztec/simulator/acvm'; import { type AcirSimulator, type DBOracle } from '@aztec/simulator/client'; import { type ContractDataOracle } from '../contract_data_oracle/index.js'; -import { type IncomingNoteDao } from '../database/incoming_note_dao.js'; import { type PxeDatabase } from '../database/index.js'; +import { type NoteDao } from '../database/note_dao.js'; import { produceNoteDaos } from '../note_decryption_utils/produce_note_daos.js'; import { getAcirSimulator } from '../simulator/index.js'; import { WINDOW_HALF_SIZE, getIndexedTaggingSecretsForTheWindow, getInitialIndexesMap } from './tagging_utils.js'; @@ -92,7 +92,7 @@ export class SimulatorOracle implements DBOracle { } async getNotes(contractAddress: AztecAddress, storageSlot: Fr, status: NoteStatus, scopes?: AztecAddress[]) { - const noteDaos = await this.db.getIncomingNotes({ + const noteDaos = await this.db.getNotes({ contractAddress, storageSlot, status, @@ -569,17 +569,17 @@ export class SimulatorOracle implements DBOracle { // Since we could have notes with the same index for different txs, we need // to keep track of them scoping by txHash const excludedIndices: Map> = new Map(); - const incomingNotes: IncomingNoteDao[] = []; + const notes: NoteDao[] = []; const txEffectsCache = new Map | undefined>(); for (const scopedLog of scopedLogs) { - const incomingNotePayload = scopedLog.isFromPublic + const notePayload = scopedLog.isFromPublic ? L1NotePayload.decryptAsIncomingFromPublic(scopedLog.logData, addressSecret) : L1NotePayload.decryptAsIncoming(PrivateLog.fromBuffer(scopedLog.logData), addressSecret); - if (incomingNotePayload) { - const payload = incomingNotePayload; + if (notePayload) { + const payload = notePayload; const txEffect = txEffectsCache.get(scopedLog.txHash.toString()) ?? (await this.aztecNode.getTxEffect(scopedLog.txHash)); @@ -594,13 +594,13 @@ export class SimulatorOracle implements DBOracle { if (!excludedIndices.has(scopedLog.txHash.toString())) { excludedIndices.set(scopedLog.txHash.toString(), new Set()); } - const { incomingNote } = await produceNoteDaos( + const { note } = await produceNoteDaos( // I don't like this at all, but we need a simulator to run `computeNoteHashAndOptionallyANullifier`. This generates // a chicken-and-egg problem due to this oracle requiring a simulator, which in turn requires this oracle. Furthermore, since jest doesn't allow // mocking ESM exports, we have to pollute the method even more by providing a simulator parameter so tests can inject a fake one. simulator ?? getAcirSimulator(this.db, this.aztecNode, this.keyStore, this.contractDataOracle), this.db, - incomingNotePayload ? recipient.toAddressPoint() : undefined, + notePayload ? recipient.toAddressPoint() : undefined, payload!, txEffect.data.txHash, txEffect.l2BlockNumber, @@ -611,12 +611,12 @@ export class SimulatorOracle implements DBOracle { this.log, ); - if (incomingNote) { - incomingNotes.push(incomingNote); + if (note) { + notes.push(note); } } } - return { incomingNotes }; + return { notes }; } /** @@ -629,10 +629,10 @@ export class SimulatorOracle implements DBOracle { recipient: AztecAddress, simulator?: AcirSimulator, ): Promise { - const { incomingNotes } = await this.#decryptTaggedLogs(logs, recipient, simulator); - if (incomingNotes.length) { - await this.db.addNotes(incomingNotes, recipient); - incomingNotes.forEach(noteDao => { + const { notes } = await this.#decryptTaggedLogs(logs, recipient, simulator); + if (notes.length) { + await this.db.addNotes(notes, recipient); + notes.forEach(noteDao => { this.log.verbose(`Added incoming note for contract ${noteDao.contractAddress} at slot ${noteDao.storageSlot}`, { contract: noteDao.contractAddress, slot: noteDao.storageSlot, @@ -644,7 +644,7 @@ export class SimulatorOracle implements DBOracle { public async removeNullifiedNotes(contractAddress: AztecAddress) { for (const recipient of await this.keyStore.getAccounts()) { - const currentNotesForRecipient = await this.db.getIncomingNotes({ contractAddress, owner: recipient }); + const currentNotesForRecipient = await this.db.getNotes({ contractAddress, owner: recipient }); const nullifiersToCheck = currentNotesForRecipient.map(note => note.siloedNullifier); const nullifierIndexes = await this.aztecNode.findNullifiersIndexesWithBlock('latest', nullifiersToCheck); diff --git a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts index e7007268753..e4e95f0ada5 100644 --- a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts +++ b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts @@ -32,9 +32,9 @@ import { jest } from '@jest/globals'; import { type MockProxy, mock } from 'jest-mock-extended'; import times from 'lodash.times'; -import { type IncomingNoteDao } from '../database/incoming_note_dao.js'; import { type PxeDatabase } from '../database/index.js'; import { KVPxeDatabase } from '../database/kv_pxe_database.js'; +import { type NoteDao } from '../database/note_dao.js'; import { ContractDataOracle } from '../index.js'; import { SimulatorOracle } from './index.js'; import { WINDOW_HALF_SIZE } from './tagging_utils.js'; @@ -461,13 +461,13 @@ describe('Simulator oracle', () => { describe('Process notes', () => { let addNotesSpy: any; - let getIncomingNotesSpy: any; + let getNotesSpy: any; let removeNullifiedNotesSpy: any; let simulator: MockProxy; beforeEach(() => { addNotesSpy = jest.spyOn(database, 'addNotes'); - getIncomingNotesSpy = jest.spyOn(database, 'getIncomingNotes'); + getNotesSpy = jest.spyOn(database, 'getNotes'); removeNullifiedNotesSpy = jest.spyOn(database, 'removeNullifiedNotes'); removeNullifiedNotesSpy.mockImplementation(() => Promise.resolve([])); simulator = mock(); @@ -483,7 +483,7 @@ describe('Simulator oracle', () => { afterEach(() => { addNotesSpy.mockReset(); - getIncomingNotesSpy.mockReset(); + getNotesSpy.mockReset(); removeNullifiedNotesSpy.mockReset(); simulator.computeNoteHashAndOptionallyANullifier.mockReset(); aztecNode.getTxEffect.mockReset(); @@ -642,10 +642,10 @@ describe('Simulator oracle', () => { await simulatorOracle.processTaggedLogs(taggedLogs, recipient.address, simulator); - // Check incoming + // Check notes { - const addedIncoming: IncomingNoteDao[] = addNotesSpy.mock.calls[0][0]; - expect(addedIncoming.map(dao => dao)).toEqual([ + const addedNotes: NoteDao[] = addNotesSpy.mock.calls[0][0]; + expect(addedNotes.map(dao => dao)).toEqual([ expect.objectContaining({ ...requests[0].snippetOfNoteDao, index: requests[0].indexWithinNoteHashTree }), expect.objectContaining({ ...requests[1].snippetOfNoteDao, index: requests[1].indexWithinNoteHashTree }), expect.objectContaining({ ...requests[2].snippetOfNoteDao, index: requests[2].indexWithinNoteHashTree }), @@ -655,7 +655,7 @@ describe('Simulator oracle', () => { // Check that every note has a different nonce. const nonceSet = new Set(); - addedIncoming.forEach(info => nonceSet.add(info.nonce.value)); + addedNotes.forEach(info => nonceSet.add(info.nonce.value)); expect(nonceSet.size).toBe(requests.length); } }); @@ -667,7 +667,7 @@ describe('Simulator oracle', () => { new MockNoteRequest(getRandomNoteLogPayload(Fr.random(), contractAddress), 12, 3, 2, recipient.address), ]; - getIncomingNotesSpy.mockResolvedValueOnce( + getNotesSpy.mockResolvedValueOnce( Promise.resolve(requests.map(request => ({ siloedNullifier: Fr.random(), ...request.snippetOfNoteDao }))), ); let requestedNullifier;