Skip to content

Commit

Permalink
cleanup comments, implementation for in-memory database
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchell Tracy authored and just-mitch committed Jan 9, 2024
1 parent 7621cc9 commit 618e770
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion yarn-project/pxe/src/contract_data_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 13 additions & 7 deletions yarn-project/pxe/src/database/memory_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MerkleTreeId, Fr> | undefined;
private globalVariablesHash: Fr | undefined;
private blockNumber: number | undefined;
Expand Down Expand Up @@ -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<void> {
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<DeferredNoteDao[]> {
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<DeferredNoteDao[]> {
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<void> {
Expand Down
1 change: 1 addition & 0 deletions yarn-project/pxe/src/database/pxe_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeferredNoteDao[]>;

Expand Down
3 changes: 1 addition & 2 deletions yarn-project/pxe/src/synchronizer/synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ export class Synchronizer {
protected async work(limit = 1): Promise<boolean> {
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;
Expand Down

0 comments on commit 618e770

Please sign in to comment.