From 9869247b1596dc417ee48c5cffb836b80c1e31c2 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Thu, 21 Sep 2023 09:30:10 +0100 Subject: [PATCH] refactor: AztecNode truly private methods --- .../aztec-node/src/aztec-node/server.ts | 24 +++++++++---------- .../aztec-node/src/rpc/http_rpc_server.ts | 4 +--- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index f457247f9dbb..fcf509ff6cb2 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -259,7 +259,7 @@ export class AztecNodeService implements AztecNode { * @returns The index of the given leaf in the contracts tree or undefined if not found. */ public async findContractIndex(leafValue: Buffer): Promise { - const committedDb = await this.getWorldState(); + const committedDb = await this.#getWorldState(); return committedDb.findLeafIndex(MerkleTreeId.CONTRACT_TREE, leafValue); } @@ -269,7 +269,7 @@ export class AztecNodeService implements AztecNode { * @returns The sibling path for the leaf index. */ public async getContractPath(leafIndex: bigint): Promise> { - const committedDb = await this.getWorldState(); + const committedDb = await this.#getWorldState(); return committedDb.getSiblingPath(MerkleTreeId.CONTRACT_TREE, leafIndex); } @@ -279,7 +279,7 @@ export class AztecNodeService implements AztecNode { * @returns The index of the given leaf in the private data tree or undefined if not found. */ public async findCommitmentIndex(leafValue: Buffer): Promise { - const committedDb = await this.getWorldState(); + const committedDb = await this.#getWorldState(); return committedDb.findLeafIndex(MerkleTreeId.PRIVATE_DATA_TREE, leafValue); } @@ -289,7 +289,7 @@ export class AztecNodeService implements AztecNode { * @returns The sibling path for the leaf index. */ public async getDataTreePath(leafIndex: bigint): Promise> { - const committedDb = await this.getWorldState(); + const committedDb = await this.#getWorldState(); return committedDb.getSiblingPath(MerkleTreeId.PRIVATE_DATA_TREE, leafIndex); } @@ -301,7 +301,7 @@ export class AztecNodeService implements AztecNode { */ public async getL1ToL2MessageAndIndex(messageKey: Fr): Promise { // todo: #697 - make this one lookup. - const committedDb = await this.getWorldState(); + const committedDb = await this.#getWorldState(); const message = await this.l1ToL2MessageSource.getConfirmedL1ToL2Message(messageKey); const index = (await committedDb.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGES_TREE, messageKey.toBuffer()))!; return Promise.resolve({ message, index }); @@ -313,7 +313,7 @@ export class AztecNodeService implements AztecNode { * @returns The sibling path. */ public async getL1ToL2MessagesTreePath(leafIndex: bigint): Promise> { - const committedDb = await this.getWorldState(); + const committedDb = await this.#getWorldState(); return committedDb.getSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGES_TREE, leafIndex); } @@ -325,7 +325,7 @@ export class AztecNodeService implements AztecNode { * Note: Aztec's version of `eth_getStorageAt`. */ public async getPublicStorageAt(contract: AztecAddress, slot: bigint): Promise { - const committedDb = await this.getWorldState(); + const committedDb = await this.#getWorldState(); const leafIndex = computePublicDataTreeLeafIndex(contract, new Fr(slot), await CircuitsWasm.get()); return committedDb.getLeafValue(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex); } @@ -335,7 +335,7 @@ export class AztecNodeService implements AztecNode { * @returns The current committed roots for the data trees. */ public async getTreeRoots(): Promise> { - const committedDb = await this.getWorldState(); + const committedDb = await this.#getWorldState(); const getTreeRoot = async (id: MerkleTreeId) => Fr.fromBuffer((await committedDb.getTreeInfo(id)).root); const [privateDataTree, nullifierTree, contractTree, l1ToL2MessagesTree, blocksTree, publicDataTree] = @@ -363,7 +363,7 @@ export class AztecNodeService implements AztecNode { * @returns The current committed block data. */ public async getHistoricBlockData(): Promise { - const committedDb = await this.getWorldState(); + const committedDb = await this.#getWorldState(); const [roots, globalsHash] = await Promise.all([this.getTreeRoots(), committedDb.getLatestGlobalVariablesHash()]); return new HistoricBlockData( @@ -413,10 +413,10 @@ export class AztecNodeService implements AztecNode { * Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched * @returns An instance of a committed MerkleTreeOperations */ - private async getWorldState() { + async #getWorldState() { try { // Attempt to sync the world state if necessary - await this.syncWorldState(); + await this.#syncWorldState(); } catch (err) { this.log.error(`Error getting world state: ${err}`); } @@ -427,7 +427,7 @@ export class AztecNodeService implements AztecNode { * Ensure we fully sync the world state * @returns A promise that fulfils once the world state is synced */ - private async syncWorldState() { + async #syncWorldState() { const blockSourceHeight = await this.blockSource.getBlockNumber(); await this.worldStateSynchroniser.syncImmediate(blockSourceHeight); } diff --git a/yarn-project/aztec-node/src/rpc/http_rpc_server.ts b/yarn-project/aztec-node/src/rpc/http_rpc_server.ts index 7d01a1ddf6d5..e1fb672952be 100644 --- a/yarn-project/aztec-node/src/rpc/http_rpc_server.ts +++ b/yarn-project/aztec-node/src/rpc/http_rpc_server.ts @@ -16,7 +16,7 @@ export function createAztecNodeRpcServer(node: AztecNode) { { AztecAddress, EthAddress, ExtendedContractData, ContractData, Fr, HistoricBlockData, L2Block, L2Tx, TxHash }, { Tx, L2BlockL2Logs }, false, - // disable private methods and methods not part of the AztecNode interface + // disable methods not part of the AztecNode interface [ 'start', 'stop', @@ -25,8 +25,6 @@ export function createAztecNodeRpcServer(node: AztecNode) { 'getDataTreePath', 'getL1ToL2MessageAndIndex', 'getL1ToL2MessagesTreePath', - 'getWorldState', - 'syncWorldState', ], ); return rpc;