Skip to content

Commit fb46111

Browse files
authored
refactor!: nuking Aztec Node proxy methods from PXE (#17098)
Having these methods exposed on PXE is a relic of a past. PXE JSON RPC server will soon be nuked and we will no longer pass a PXE_URL around and we will just pass NODE_URL. Note that in some places this results in a worse devex as now it's necessary to pass on the input both AZTEC_NODE_URL and PXE_URL. This is only temporary so would not worry about this. ## Follow-up work In this PR I don't touch the `PXE` proxy methods that were exposed on `Wallet` as well as it's not yet resolved what to do with those. I also didn't yet touch `getCurrentBaseFees` as that is used by `Wallet` implementations and that would then force me to pass `AztecNode` on the input of those implementations which is a huge change. For this reason plan on doing that in a PR up the stack.
2 parents b02bf7d + c4b4e8d commit fb46111

File tree

62 files changed

+417
-574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+417
-574
lines changed

yarn-project/aztec.js/src/contract/wait_for_proven.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { retryUntil } from '@aztec/foundation/retry';
2-
import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client';
2+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
33

44
import type { TxReceipt } from '../index.js';
55
import { DefaultWaitOpts } from './sent_tx.js';
@@ -22,13 +22,13 @@ export const DefaultWaitForProvenOpts: WaitForProvenOpts = {
2222
/**
2323
* Wait for a transaction to be proven by polling the node
2424
*/
25-
export async function waitForProven(pxeOrNode: PXE | AztecNode, receipt: TxReceipt, opts?: WaitForProvenOpts) {
25+
export async function waitForProven(node: AztecNode, receipt: TxReceipt, opts?: WaitForProvenOpts) {
2626
if (!receipt.blockNumber) {
2727
throw new Error(`Cannot wait for proven: receipt of tx ${receipt.txHash} does not have a block number`);
2828
}
2929
return await retryUntil(
3030
async () => {
31-
const provenBlock = await pxeOrNode.getProvenBlockNumber();
31+
const provenBlock = await node.getProvenBlockNumber();
3232
return provenBlock >= receipt.blockNumber! ? provenBlock : undefined;
3333
},
3434
'isProven',

yarn-project/aztec.js/src/utils/cross_chain.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import type { Fr } from '@aztec/foundation/fields';
22
import { retryUntil } from '@aztec/foundation/retry';
3-
4-
import type { PXE } from '../api/interfaces.js';
3+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
54

65
/**
76
* Waits for the L1 to L2 message to be ready to be consumed.
8-
* @param pxe - PXE instance
7+
* @param node - Aztec node instance used to obtain the information about the message
98
* @param l1ToL2MessageHash - Hash of the L1 to L2 message
109
* @param opts - Options
1110
*/
1211
export async function waitForL1ToL2MessageReady(
13-
pxe: Pick<PXE, 'getBlockNumber' | 'getL1ToL2MessageBlock'>,
12+
node: Pick<AztecNode, 'getBlockNumber' | 'getL1ToL2MessageBlock'>,
1413
l1ToL2MessageHash: Fr,
1514
opts: {
1615
/** Timeout for the operation in seconds */ timeoutSeconds: number;
1716
/** True if the message is meant to be consumed from a public function */ forPublicConsumption: boolean;
1817
},
1918
) {
20-
const messageBlockNumber = await pxe.getL1ToL2MessageBlock(l1ToL2MessageHash);
19+
const messageBlockNumber = await node.getL1ToL2MessageBlock(l1ToL2MessageHash);
2120
return retryUntil(
22-
() => isL1ToL2MessageReady(pxe, l1ToL2MessageHash, { ...opts, messageBlockNumber }),
21+
() => isL1ToL2MessageReady(node, l1ToL2MessageHash, { ...opts, messageBlockNumber }),
2322
`L1 to L2 message ${l1ToL2MessageHash.toString()} ready`,
2423
opts.timeoutSeconds,
2524
1,
@@ -28,21 +27,21 @@ export async function waitForL1ToL2MessageReady(
2827

2928
/**
3029
* Returns whether the L1 to L2 message is ready to be consumed.
31-
* @param pxe - PXE instance
30+
* @param node - Aztec node instance used to obtain the information about the message
3231
* @param l1ToL2MessageHash - Hash of the L1 to L2 message
3332
* @param opts - Options
3433
* @returns True if the message is ready to be consumed, false otherwise
3534
*/
3635
export async function isL1ToL2MessageReady(
37-
pxe: Pick<PXE, 'getBlockNumber' | 'getL1ToL2MessageBlock'>,
36+
node: Pick<AztecNode, 'getBlockNumber' | 'getL1ToL2MessageBlock'>,
3837
l1ToL2MessageHash: Fr,
3938
opts: {
4039
/** True if the message is meant to be consumed from a public function */ forPublicConsumption: boolean;
4140
/** Cached synced block number for the message (will be fetched from PXE otherwise) */ messageBlockNumber?: number;
4241
},
4342
): Promise<boolean> {
44-
const blockNumber = await pxe.getBlockNumber();
45-
const messageBlockNumber = opts.messageBlockNumber ?? (await pxe.getL1ToL2MessageBlock(l1ToL2MessageHash));
43+
const blockNumber = await node.getBlockNumber();
44+
const messageBlockNumber = opts.messageBlockNumber ?? (await node.getL1ToL2MessageBlock(l1ToL2MessageHash));
4645
if (messageBlockNumber === undefined) {
4746
return false;
4847
}

yarn-project/aztec.js/src/utils/fee_juice.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { Fr } from '@aztec/foundation/fields';
22
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
33
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
44
import { deriveStorageSlotInMap } from '@aztec/stdlib/hash';
5-
import type { PXE } from '@aztec/stdlib/interfaces/client';
5+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
66

77
/**
88
* Returns the owner's fee juice balance.
9+
* Note: This is used only e2e_sandbox_example test. TODO: Consider nuking.
910
*/
10-
export async function getFeeJuiceBalance(owner: AztecAddress, pxe: PXE): Promise<bigint> {
11+
export async function getFeeJuiceBalance(owner: AztecAddress, node: AztecNode): Promise<bigint> {
1112
const slot = await deriveStorageSlotInMap(new Fr(1), owner);
12-
return (await pxe.getPublicStorageAt(ProtocolContractAddress.FeeJuice, slot)).toBigInt();
13+
return (await node.getPublicStorageAt('latest', ProtocolContractAddress.FeeJuice, slot)).toBigInt();
1314
}

yarn-project/aztec/src/bin/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
import { injectCommands as injectBuilderCommands } from '@aztec/builder';
44
import { injectCommands as injectWalletCommands } from '@aztec/cli-wallet';
5+
import { injectCommands as injectAztecNodeCommands } from '@aztec/cli/aztec_node';
56
import { enrichEnvironmentWithChainConfig } from '@aztec/cli/config';
67
import { injectCommands as injectContractCommands } from '@aztec/cli/contracts';
78
import { injectCommands as injectDevnetCommands } from '@aztec/cli/devnet';
@@ -50,6 +51,7 @@ async function main() {
5051
program = injectInfrastructureCommands(program, userLog, debugLogger);
5152
program = injectL1Commands(program, userLog, debugLogger);
5253
program = injectPXECommands(program, userLog, debugLogger);
54+
program = injectAztecNodeCommands(program, userLog, debugLogger);
5355
program = injectMiscCommands(program, userLog);
5456
program = injectDevnetCommands(program, userLog, debugLogger);
5557
program = injectWalletCommands(program, userLog, debugLogger);

yarn-project/aztec/src/testing/aztec_cheat_codes.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Fr } from '@aztec/foundation/fields';
22
import { createLogger } from '@aztec/foundation/log';
33
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
44
import { deriveStorageSlotInMap } from '@aztec/stdlib/hash';
5-
import type { PXE } from '@aztec/stdlib/interfaces/client';
5+
import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client';
66
import type { Note } from '@aztec/stdlib/note';
77

88
/**
@@ -14,6 +14,10 @@ export class AztecCheatCodes {
1414
* The PXE Service to use for interacting with the chain
1515
*/
1616
public pxe: PXE,
17+
/**
18+
* The Aztec Node to use for interacting with the chain
19+
*/
20+
public node: AztecNode,
1721
/**
1822
* The logger to use for the aztec cheatcodes
1923
*/
@@ -36,15 +40,15 @@ export class AztecCheatCodes {
3640
* @returns The current block number
3741
*/
3842
public async blockNumber(): Promise<number> {
39-
return await this.pxe.getBlockNumber();
43+
return await this.node.getBlockNumber();
4044
}
4145

4246
/**
4347
* Get the current timestamp
4448
* @returns The current timestamp
4549
*/
4650
public async timestamp(): Promise<number> {
47-
const res = await this.pxe.getBlock(await this.blockNumber());
51+
const res = await this.node.getBlock(await this.blockNumber());
4852
return Number(res?.header.globalVariables.timestamp ?? 0);
4953
}
5054

@@ -55,7 +59,7 @@ export class AztecCheatCodes {
5559
* @returns The value stored at the given slot
5660
*/
5761
public async loadPublic(who: AztecAddress, slot: Fr | bigint): Promise<Fr> {
58-
const storageValue = await this.pxe.getPublicStorageAt(who, new Fr(slot));
62+
const storageValue = await this.node.getPublicStorageAt('latest', who, new Fr(slot));
5963
return storageValue;
6064
}
6165

yarn-project/aztec/src/testing/cheat_codes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export class CheatCodes {
1818
public rollup: RollupCheatCodes,
1919
) {}
2020

21-
static async create(rpcUrls: string[], pxe: PXE): Promise<CheatCodes> {
21+
static async create(rpcUrls: string[], pxe: PXE, node: AztecNode): Promise<CheatCodes> {
2222
const ethCheatCodes = new EthCheatCodes(rpcUrls);
23-
const aztecCheatCodes = new AztecCheatCodes(pxe);
23+
const aztecCheatCodes = new AztecCheatCodes(pxe, node);
2424
const rollupCheatCodes = new RollupCheatCodes(
2525
ethCheatCodes,
2626
await pxe.getNodeInfo().then(n => n.l1ContractAddresses),

yarn-project/bot/src/amm_bot.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ type Balances = { token0: bigint; token1: bigint };
1515

1616
export class AmmBot extends BaseBot {
1717
protected constructor(
18-
pxe: PXE,
18+
node: AztecNode,
1919
wallet: Wallet,
2020
defaultAccountAddress: AztecAddress,
2121
public readonly amm: AMMContract,
2222
public readonly token0: TokenContract,
2323
public readonly token1: TokenContract,
2424
config: BotConfig,
2525
) {
26-
super(pxe, wallet, defaultAccountAddress, config);
26+
super(node, wallet, defaultAccountAddress, config);
2727
}
2828

2929
static async create(
3030
config: BotConfig,
3131
dependencies: { pxe?: PXE; node?: AztecNode; nodeAdmin?: AztecNodeAdmin },
3232
): Promise<AmmBot> {
33-
const { pxe, wallet, defaultAccountAddress, token0, token1, amm } = await new BotFactory(
33+
const { node, wallet, defaultAccountAddress, token0, token1, amm } = await new BotFactory(
3434
config,
3535
dependencies,
3636
).setupAmm();
37-
return new AmmBot(pxe, wallet, defaultAccountAddress, amm, token0, token1, config);
37+
return new AmmBot(node, wallet, defaultAccountAddress, amm, token0, token1, config);
3838
}
3939

4040
protected async createAndSendTx(logCtx: object): Promise<SentTx> {

yarn-project/bot/src/base_bot.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
waitForProven,
1212
} from '@aztec/aztec.js';
1313
import { Gas } from '@aztec/stdlib/gas';
14-
import type { PXE } from '@aztec/stdlib/interfaces/client';
14+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
1515

1616
import type { BotConfig } from './config.js';
1717

@@ -22,7 +22,7 @@ export abstract class BaseBot {
2222
protected successes: number = 0;
2323

2424
protected constructor(
25-
public readonly pxe: PXE,
25+
public readonly node: AztecNode,
2626
public readonly wallet: Wallet,
2727
public readonly defaultAccountAddress: AztecAddress,
2828
public config: BotConfig,
@@ -51,7 +51,7 @@ export abstract class BaseBot {
5151
timeout: txMinedWaitSeconds,
5252
});
5353
if (followChain === 'PROVEN') {
54-
await waitForProven(this.pxe, receipt, { provenTimeout: txMinedWaitSeconds });
54+
await waitForProven(this.node, receipt, { provenTimeout: txMinedWaitSeconds });
5555
}
5656
this.successes++;
5757
this.log.info(

yarn-project/bot/src/bot.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,25 @@ const TRANSFER_AMOUNT = 1;
1313

1414
export class Bot extends BaseBot {
1515
protected constructor(
16-
pxe: PXE,
16+
node: AztecNode,
1717
wallet: Wallet,
1818
defaultAccountAddress: AztecAddress,
1919
public readonly token: TokenContract | PrivateTokenContract,
2020
public readonly recipient: AztecAddress,
2121
config: BotConfig,
2222
) {
23-
super(pxe, wallet, defaultAccountAddress, config);
23+
super(node, wallet, defaultAccountAddress, config);
2424
}
2525

2626
static async create(
2727
config: BotConfig,
2828
dependencies: { pxe?: PXE; node?: AztecNode; nodeAdmin?: AztecNodeAdmin },
2929
): Promise<Bot> {
30-
const { pxe, wallet, defaultAccountAddress, token, recipient } = await new BotFactory(config, dependencies).setup();
31-
return new Bot(pxe, wallet, defaultAccountAddress, token, recipient, config);
30+
const { node, wallet, defaultAccountAddress, token, recipient } = await new BotFactory(
31+
config,
32+
dependencies,
33+
).setup();
34+
return new Bot(node, wallet, defaultAccountAddress, token, recipient, config);
3235
}
3336

3437
public updateConfig(config: Partial<BotConfig>) {

yarn-project/bot/src/factory.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
FeeJuicePaymentMethodWithClaim,
1111
L1FeeJuicePortalManager,
1212
type PXE,
13+
createAztecNodeClient,
1314
createLogger,
1415
createPXEClient,
1516
waitForL1ToL2MessageReady,
@@ -34,7 +35,7 @@ const MIN_BALANCE = 1e3;
3435
export class BotFactory {
3536
private pxe: PXE;
3637
private wallet: TestWallet;
37-
private node?: AztecNode;
38+
private node: AztecNode;
3839
private nodeAdmin?: AztecNodeAdmin;
3940
private log = createLogger('bot');
4041

@@ -56,7 +57,6 @@ export class BotFactory {
5657
throw new Error(`Either a PXE client or a PXE URL must be provided`);
5758
}
5859

59-
this.node = dependencies.node;
6060
this.nodeAdmin = dependencies.nodeAdmin;
6161

6262
if (dependencies.pxe) {
@@ -66,6 +66,13 @@ export class BotFactory {
6666
this.log.info(`Using remote PXE at ${config.pxeUrl!}`);
6767
this.pxe = createPXEClient(config.pxeUrl!, getVersions(), makeTracedFetch([1, 2, 3], false));
6868
}
69+
70+
if (dependencies.node) {
71+
this.node = dependencies.node;
72+
} else {
73+
this.node = createAztecNodeClient(config.nodeUrl!, getVersions(), makeTracedFetch([1, 2, 3], false));
74+
}
75+
6976
this.wallet = new TestWallet(this.pxe);
7077
}
7178

@@ -78,7 +85,7 @@ export class BotFactory {
7885
const defaultAccountAddress = await this.setupAccount();
7986
const token = await this.setupToken(defaultAccountAddress);
8087
await this.mintTokens(token, defaultAccountAddress);
81-
return { wallet: this.wallet, defaultAccountAddress, token, pxe: this.pxe, recipient };
88+
return { wallet: this.wallet, defaultAccountAddress, token, node: this.node, recipient };
8289
}
8390

8491
public async setupAmm() {
@@ -102,7 +109,7 @@ export class BotFactory {
102109
await this.fundAmm(defaultAccountAddress, defaultAccountAddress, amm, token0, token1, liquidityToken);
103110
this.log.info(`AMM initialized and funded`);
104111

105-
return { wallet: this.wallet, defaultAccountAddress, amm, token0, token1, pxe: this.pxe };
112+
return { wallet: this.wallet, defaultAccountAddress, amm, token0, token1, node: this.node };
106113
}
107114

108115
/**
@@ -398,7 +405,7 @@ export class BotFactory {
398405
const claim = await portal.bridgeTokensPublic(recipient, mintAmount, true /* mint */);
399406

400407
await this.withNoMinTxsPerBlock(() =>
401-
waitForL1ToL2MessageReady(this.pxe, Fr.fromHexString(claim.messageHash), {
408+
waitForL1ToL2MessageReady(this.node, Fr.fromHexString(claim.messageHash), {
402409
timeoutSeconds: this.config.l1ToL2MessageTimeoutSeconds,
403410
forPublicConsumption: false,
404411
}),

0 commit comments

Comments
 (0)