Skip to content

Commit

Permalink
refactor: AztecNode truly private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Sep 21, 2023
1 parent 8f67436 commit 9869247
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
24 changes: 12 additions & 12 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<bigint | undefined> {
const committedDb = await this.getWorldState();
const committedDb = await this.#getWorldState();
return committedDb.findLeafIndex(MerkleTreeId.CONTRACT_TREE, leafValue);
}

Expand All @@ -269,7 +269,7 @@ export class AztecNodeService implements AztecNode {
* @returns The sibling path for the leaf index.
*/
public async getContractPath(leafIndex: bigint): Promise<SiblingPath<typeof CONTRACT_TREE_HEIGHT>> {
const committedDb = await this.getWorldState();
const committedDb = await this.#getWorldState();
return committedDb.getSiblingPath(MerkleTreeId.CONTRACT_TREE, leafIndex);
}

Expand All @@ -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<bigint | undefined> {
const committedDb = await this.getWorldState();
const committedDb = await this.#getWorldState();
return committedDb.findLeafIndex(MerkleTreeId.PRIVATE_DATA_TREE, leafValue);
}

Expand All @@ -289,7 +289,7 @@ export class AztecNodeService implements AztecNode {
* @returns The sibling path for the leaf index.
*/
public async getDataTreePath(leafIndex: bigint): Promise<SiblingPath<typeof PRIVATE_DATA_TREE_HEIGHT>> {
const committedDb = await this.getWorldState();
const committedDb = await this.#getWorldState();
return committedDb.getSiblingPath(MerkleTreeId.PRIVATE_DATA_TREE, leafIndex);
}

Expand All @@ -301,7 +301,7 @@ export class AztecNodeService implements AztecNode {
*/
public async getL1ToL2MessageAndIndex(messageKey: Fr): Promise<L1ToL2MessageAndIndex> {
// 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 });
Expand All @@ -313,7 +313,7 @@ export class AztecNodeService implements AztecNode {
* @returns The sibling path.
*/
public async getL1ToL2MessagesTreePath(leafIndex: bigint): Promise<SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>> {
const committedDb = await this.getWorldState();
const committedDb = await this.#getWorldState();
return committedDb.getSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGES_TREE, leafIndex);
}

Expand All @@ -325,7 +325,7 @@ export class AztecNodeService implements AztecNode {
* Note: Aztec's version of `eth_getStorageAt`.
*/
public async getPublicStorageAt(contract: AztecAddress, slot: bigint): Promise<Buffer | undefined> {
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);
}
Expand All @@ -335,7 +335,7 @@ export class AztecNodeService implements AztecNode {
* @returns The current committed roots for the data trees.
*/
public async getTreeRoots(): Promise<Record<MerkleTreeId, Fr>> {
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] =
Expand Down Expand Up @@ -363,7 +363,7 @@ export class AztecNodeService implements AztecNode {
* @returns The current committed block data.
*/
public async getHistoricBlockData(): Promise<HistoricBlockData> {
const committedDb = await this.getWorldState();
const committedDb = await this.#getWorldState();
const [roots, globalsHash] = await Promise.all([this.getTreeRoots(), committedDb.getLatestGlobalVariablesHash()]);

return new HistoricBlockData(
Expand Down Expand Up @@ -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}`);
}
Expand All @@ -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);
}
Expand Down
4 changes: 1 addition & 3 deletions yarn-project/aztec-node/src/rpc/http_rpc_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -25,8 +25,6 @@ export function createAztecNodeRpcServer(node: AztecNode) {
'getDataTreePath',
'getL1ToL2MessageAndIndex',
'getL1ToL2MessagesTreePath',
'getWorldState',
'syncWorldState',
],
);
return rpc;
Expand Down

0 comments on commit 9869247

Please sign in to comment.