Skip to content

Commit

Permalink
feat: aztec-node looks up contract paths (#98)
Browse files Browse the repository at this point in the history
* chore: Add world-state to circleci

* feat: aztec node contract path lookup

* Merge
  • Loading branch information
ludamad authored Mar 28, 2023
1 parent 115c9a5 commit f544403
Showing 1 changed file with 19 additions and 29 deletions.
48 changes: 19 additions & 29 deletions yarn-project/aztec-node/src/aztec-node/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { default as levelup } from 'levelup';
import { default as memdown } from 'memdown';
import { L2BlockSource, Archiver } from '@aztec/archiver';
import { P2P, P2PClient, Tx } from '@aztec/p2p';
import { MerkleTrees, WorldStateSynchroniser, ServerWorldStateSynchroniser } from '@aztec/world-state';
import { MerkleTrees, WorldStateSynchroniser, ServerWorldStateSynchroniser, MerkleTreeId } from '@aztec/world-state';
import { SequencerClient } from '@aztec/sequencer-client';
import { AztecNodeConfig } from './config.js';
import { SiblingPath } from '@aztec/merkle-tree';

/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
Expand All @@ -15,11 +16,11 @@ export const createMemDown = () => memdown();
*/
export class AztecNode {
constructor(
private p2pClient?: P2P,
private blockSource?: L2BlockSource,
private merkleTreeDB?: MerkleTrees,
private worldStateSynchroniser?: WorldStateSynchroniser,
private sequencer?: SequencerClient,
private p2pClient: P2P,
private blockSource: L2BlockSource,
private merkleTreeDB: MerkleTrees,
private worldStateSynchroniser: WorldStateSynchroniser,
private sequencer: SequencerClient,
) {}

/**
Expand Down Expand Up @@ -51,7 +52,7 @@ export class AztecNode {
* @returns - Flag indicating the readiness for tx submission.
*/
public async isReady() {
return (await this.p2pClient?.isReady()) ?? false;
return (await this.p2pClient.isReady()) ?? false;
}

/**
Expand All @@ -61,28 +62,26 @@ export class AztecNode {
* @returns The blocks requested.
*/
public async getBlocks(from: number, take: number) {
this.verifyInitialised();
return (await this.blockSource?.getL2Blocks(from, take)) ?? [];
return (await this.blockSource.getL2Blocks(from, take)) ?? [];
}

/**
* Method to submit a transaction to the p2p pool.
* @param tx - The transaction to be submitted.
*/
public async sendTx(tx: Tx) {
this.verifyInitialised();
await this.p2pClient!.sendTx(tx);
}

/**
* Method to stop the aztec node.
*/
public async stop() {
await this.p2pClient?.stop();
await this.worldStateSynchroniser?.stop();
await this.merkleTreeDB?.stop();
await this.sequencer?.stop();
await this.blockSource?.stop();
await this.p2pClient.stop();
await this.worldStateSynchroniser.stop();
await this.merkleTreeDB.stop();
await this.sequencer.stop();
await this.blockSource.stop();
}

/**
Expand All @@ -93,19 +92,10 @@ export class AztecNode {
return await this.p2pClient!.getTxs();
}

/**
* Method to verify that we are initialised, throws if not.
*/
private verifyInitialised() {
const invalid = [
this.blockSource,
this.merkleTreeDB,
this.p2pClient,
this.worldStateSynchroniser,
this.sequencer,
].findIndex(x => !x);
if (invalid != -1) {
throw new Error('Aztec Node not initialised');
}
public findContractIndex(leafValue: Buffer): Promise<bigint | undefined> {
return this.merkleTreeDB.findLeafIndex(MerkleTreeId.CONTRACT_TREE, leafValue);
}
public getContractPath(leafIndex: bigint): Promise<SiblingPath> {
return this.merkleTreeDB.getSiblingPath(MerkleTreeId.CONTRACT_TREE, leafIndex);
}
}

0 comments on commit f544403

Please sign in to comment.