From 8da281e220501cc9babd113755be8a2b47bdff07 Mon Sep 17 00:00:00 2001 From: Mitchell Tracy Date: Mon, 8 Jan 2024 13:03:02 -0500 Subject: [PATCH] cleanup comments, implementation for in-memory database --- .../pxe/src/contract_data_oracle/index.ts | 3 ++- yarn-project/pxe/src/database/memory_db.ts | 20 ++++++++++++------- yarn-project/pxe/src/database/pxe_database.ts | 1 + .../pxe/src/synchronizer/synchronizer.ts | 3 +-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/yarn-project/pxe/src/contract_data_oracle/index.ts b/yarn-project/pxe/src/contract_data_oracle/index.ts index 77a0adf6ac9a..5c1f07e03f09 100644 --- a/yarn-project/pxe/src/contract_data_oracle/index.ts +++ b/yarn-project/pxe/src/contract_data_oracle/index.ts @@ -52,7 +52,7 @@ export class ContractDataOracle { * * @param contractAddress - The AztecAddress representing the contract containing the function. * @param functionName - The name of the function. - * @returns The corresponding function's artifact as an object, or undefined if the function is not found. + * @returns The corresponding function's artifact as an object */ public async getFunctionArtifactByName( contractAddress: AztecAddress, @@ -94,6 +94,7 @@ export class ContractDataOracle { * @param contractAddress - The contract's address. * @param selector - The function selector. * @returns A Promise that resolves to a Buffer containing the bytecode of the specified function. + * @throws Error if the contract address is unknown or not found. */ public async getBytecode(contractAddress: AztecAddress, selector: FunctionSelector) { const tree = await this.getTree(contractAddress); diff --git a/yarn-project/pxe/src/database/memory_db.ts b/yarn-project/pxe/src/database/memory_db.ts index d1e105ea869f..6e0462a4c7a5 100644 --- a/yarn-project/pxe/src/database/memory_db.ts +++ b/yarn-project/pxe/src/database/memory_db.ts @@ -17,7 +17,7 @@ import { PxeDatabase } from './pxe_database.js'; */ export class MemoryDB extends MemoryContractDatabase implements PxeDatabase { private notesTable: NoteDao[] = []; - + private deferredNotesTable: DeferredNoteDao[] = []; private treeRoots: Record | undefined; private globalVariablesHash: Fr | undefined; private blockNumber: number | undefined; @@ -56,19 +56,25 @@ export class MemoryDB extends MemoryContractDatabase implements PxeDatabase { return Promise.resolve(); } - // eslint-disable-next-line @typescript-eslint/no-unused-vars public addDeferredNotes(notes: DeferredNoteDao[]): Promise { - throw new Error('Method not implemented.'); + this.deferredNotesTable.push(...notes); + return Promise.resolve(); } - // eslint-disable-next-line @typescript-eslint/no-unused-vars public getDeferredNotesByContract(contractAddress: AztecAddress): Promise { - throw new Error('Method not implemented.'); + return Promise.resolve(this.deferredNotesTable.filter(note => note.contractAddress.equals(contractAddress))); } - // eslint-disable-next-line @typescript-eslint/no-unused-vars public removeDeferredNotesByContract(contractAddress: AztecAddress): Promise { - throw new Error('Method not implemented.'); + const removed: DeferredNoteDao[] = []; + this.deferredNotesTable = this.deferredNotesTable.filter(note => { + if (note.contractAddress.equals(contractAddress)) { + removed.push(note); + return false; + } + return true; + }); + return Promise.resolve(removed); } public addCapsule(capsule: Fr[]): Promise { diff --git a/yarn-project/pxe/src/database/pxe_database.ts b/yarn-project/pxe/src/database/pxe_database.ts index 8e22726c7681..134b56aa4c3e 100644 --- a/yarn-project/pxe/src/database/pxe_database.ts +++ b/yarn-project/pxe/src/database/pxe_database.ts @@ -76,6 +76,7 @@ export interface PxeDatabase extends ContractDatabase { /** * Remove deferred notes for a given contract address. * @param contractAddress - The contract address to remove the deferred notes for. + * @returns an array of the removed deferred notes */ removeDeferredNotesByContract(contractAddress: AztecAddress): Promise; diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index 5e7a470b443f..36185e186df8 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -106,8 +106,7 @@ export class Synchronizer { protected async work(limit = 1): Promise { const from = this.getSynchedBlockNumber() + 1; try { - // TODO: is getting logs redundant? see getBlocks within lmdb_archiver_store.ts - // It seems that getBlocks already returns the logs. + // Possibly improve after https://github.com/AztecProtocol/aztec-packages/issues/3870 let encryptedLogs = await this.node.getLogs(from, limit, LogType.ENCRYPTED); if (!encryptedLogs.length) { return false;