Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Gas Utils for L1 operations #9834

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
type L1_TO_L2_MSG_TREE_HEIGHT,
type NOTE_HASH_TREE_HEIGHT,
type NULLIFIER_TREE_HEIGHT,
type NodeInfo,
type NullifierLeafPreimage,
type PUBLIC_DATA_TREE_HEIGHT,
type ProtocolContractAddresses,
Expand Down Expand Up @@ -230,6 +231,29 @@ export class AztecNodeService implements AztecNode {
return Promise.resolve(this.p2pClient.isReady() ?? false);
}

public async getNodeInfo(): Promise<NodeInfo> {
const [nodeVersion, protocolVersion, chainId, enr, contractAddresses, protocolContractAddresses] =
await Promise.all([
this.getNodeVersion(),
this.getVersion(),
this.getChainId(),
this.getEncodedEnr(),
this.getL1ContractAddresses(),
this.getProtocolContractAddresses(),
]);

const nodeInfo: NodeInfo = {
nodeVersion,
l1ChainId: chainId,
protocolVersion,
enr,
l1ContractAddresses: contractAddresses,
protocolContractAddresses: protocolContractAddresses,
};

return nodeInfo;
}

/**
* Get a block specified by its number.
* @param number - The block number being requested.
Expand Down
20 changes: 20 additions & 0 deletions yarn-project/circuit-types/src/interfaces/aztec-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
L1_TO_L2_MSG_TREE_HEIGHT,
NOTE_HASH_TREE_HEIGHT,
NULLIFIER_TREE_HEIGHT,
type NodeInfo,
PUBLIC_DATA_TREE_HEIGHT,
type ProtocolContractAddresses,
ProtocolContractsNames,
Expand Down Expand Up @@ -155,6 +156,11 @@ describe('AztecNodeApiSchema', () => {
expect(response).toBe(true);
});

it('getNodeInfo', async () => {
const response = await context.client.getNodeInfo();
expect(response).toEqual(await handler.getNodeInfo());
});

it('getBlocks', async () => {
const response = await context.client.getBlocks(1, 1);
expect(response).toHaveLength(1);
Expand Down Expand Up @@ -404,6 +410,20 @@ class MockAztecNode implements AztecNode {
isReady(): Promise<boolean> {
return Promise.resolve(true);
}
getNodeInfo(): Promise<NodeInfo> {
return Promise.resolve({
nodeVersion: '1.0',
l1ChainId: 1,
protocolVersion: 1,
enr: 'enr',
l1ContractAddresses: Object.fromEntries(
L1ContractsNames.map(name => [name, EthAddress.random()]),
) as L1ContractAddresses,
protocolContractAddresses: Object.fromEntries(
ProtocolContractsNames.map(name => [name, AztecAddress.random()]),
) as ProtocolContractAddresses,
});
}
getBlocks(from: number, limit: number): Promise<L2Block[]> {
return Promise.resolve(times(limit, i => L2Block.random(from + i)));
}
Expand Down
11 changes: 11 additions & 0 deletions yarn-project/circuit-types/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
L1_TO_L2_MSG_TREE_HEIGHT,
NOTE_HASH_TREE_HEIGHT,
NULLIFIER_TREE_HEIGHT,
type NodeInfo,
NodeInfoSchema,
PUBLIC_DATA_TREE_HEIGHT,
type ProtocolContractAddresses,
ProtocolContractAddressesSchema,
Expand Down Expand Up @@ -197,6 +199,13 @@ export interface AztecNode extends ProverCoordination {
*/
isReady(): Promise<boolean>;

/**
* Returns the information about the server's node. Includes current Node version, compatible Noir version,
* L1 chain identifier, protocol version, and L1 address of the rollup contract.
* @returns - The node information.
*/
getNodeInfo(): Promise<NodeInfo>;

/**
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
* @param from - The start of the range of blocks to return.
Expand Down Expand Up @@ -456,6 +465,8 @@ export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {

isReady: z.function().returns(z.boolean()),

getNodeInfo: z.function().returns(NodeInfoSchema),

getBlocks: z.function().args(z.number(), z.number()).returns(z.array(L2Block.schema)),

getNodeVersion: z.function().returns(z.string()),
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/cli/src/cmds/l1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
'test test test test test test test test test test test junk',
)
.addOption(l1ChainIdOption)
.option('--validator <addresse>', 'ethereum address of the validator', parseEthereumAddress)
.option('--validator <address>', 'ethereum address of the validator', parseEthereumAddress)
.option('--rollup <address>', 'ethereum address of the rollup contract', parseEthereumAddress)
.action(async options => {
const { removeL1Validator } = await import('./update_l1_validators.js');
Expand Down
17 changes: 13 additions & 4 deletions yarn-project/cli/src/cmds/l1/update_l1_validators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EthCheatCodes } from '@aztec/aztec.js';
import { type EthAddress } from '@aztec/circuits.js';
import { createEthereumChain, getL1ContractsConfigEnvVars } from '@aztec/ethereum';
import { createEthereumChain, getL1ContractsConfigEnvVars, isAnvilTestChain } from '@aztec/ethereum';
import { type DebugLogger, type LogFn } from '@aztec/foundation/log';
import { RollupAbi } from '@aztec/l1-artifacts';

Expand Down Expand Up @@ -53,9 +53,18 @@ export async function addL1Validator({
const txHash = await rollup.write.addValidator([validatorAddress.toString()]);
dualLog(`Transaction hash: ${txHash}`);
await publicClient.waitForTransactionReceipt({ hash: txHash });
dualLog(`Funding validator on L1`);
const cheatCodes = new EthCheatCodes(rpcUrl, debugLogger);
await cheatCodes.setBalance(validatorAddress, 10n ** 20n);
if (isAnvilTestChain(chainId)) {
dualLog(`Funding validator on L1`);
const cheatCodes = new EthCheatCodes(rpcUrl, debugLogger);
await cheatCodes.setBalance(validatorAddress, 10n ** 20n);
} else {
const balance = await publicClient.getBalance({ address: validatorAddress.toString() });
const balanceInEth = Number(balance) / 10 ** 18;
dualLog(`Validator balance: ${balanceInEth.toFixed(6)} ETH`);
if (balanceInEth === 0) {
dualLog(`WARNING: Validator has no balance. Remember to fund it!`);
}
}
}

export async function removeL1Validator({
Expand Down
11 changes: 8 additions & 3 deletions yarn-project/cli/src/cmds/pxe/get_node_info.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { createCompatibleClient } from '@aztec/aztec.js';
import { type AztecNode, type PXE, createAztecNodeClient, createCompatibleClient } from '@aztec/aztec.js';
import { type DebugLogger, type LogFn } from '@aztec/foundation/log';

export async function getNodeInfo(rpcUrl: string, debugLogger: DebugLogger, log: LogFn) {
const client = await createCompatibleClient(rpcUrl, debugLogger);
export async function getNodeInfo(rpcUrl: string, pxeRequest: boolean, debugLogger: DebugLogger, log: LogFn) {
let client: AztecNode | PXE;
if (pxeRequest) {
client = await createCompatibleClient(rpcUrl, debugLogger);
} else {
client = createAztecNodeClient(rpcUrl);
}
const info = await client.getNodeInfo();
log(`Node Version: ${info.nodeVersion}`);
log(`Chain Id: ${info.l1ChainId}`);
Expand Down
15 changes: 12 additions & 3 deletions yarn-project/cli/src/cmds/pxe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { type DebugLogger, type LogFn } from '@aztec/foundation/log';
import { type Command } from 'commander';

import {
LOCALHOST,
logJson,
makePxeOption,
parseAztecAddress,
parseEthereumAddress,
parseField,
Expand Down Expand Up @@ -133,11 +135,18 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL

program
.command('get-node-info')
.description('Gets the information of an aztec node at a URL.')
.addOption(pxeOption)
.description('Gets the information of an Aztec node from a PXE or directly from an Aztec node.')
.option('--node-url <string>', 'URL of the node.', `http://${LOCALHOST}:8080`)
.addOption(makePxeOption(false))
.action(async options => {
const { getNodeInfo } = await import('./get_node_info.js');
await getNodeInfo(options.rpcUrl, debugLogger, log);
let url: string;
if (options.nodeUrl) {
url = options.nodeUrl;
} else {
url = options.rpcUrl;
}
await getNodeInfo(url, options.pxe, debugLogger, log);
});

program
Expand Down
1 change: 1 addition & 0 deletions yarn-project/end-to-end/scripts/e2e_test_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ tests:
test_path: 'e2e_fees/private_payments.test.ts'
e2e_keys: {}
e2e_l1_with_wall_time: {}
e2e_l1_gas: {}
e2e_lending_contract: {}
e2e_event_logs: {}
e2e_max_block_number: {}
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/end-to-end/scripts/native-network/boot-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exec > >(tee -a "$(dirname $0)/logs/${SCRIPT_NAME}.log") 2> >(tee -a "$(dirname
export PORT=${PORT:-"8080"}
export DEBUG=${DEBUG:-"aztec:*,-aztec:avm_simulator*,-aztec:libp2p_service*,-aztec:circuits:artifact_hash,-json-rpc*,-aztec:l2_block_stream,-aztec:world-state:*"}
export LOG_LEVEL=${LOG_LEVEL:-"debug"}
export ETHEREUM_HOST="http://127.0.0.1:8545"
export ETHEREUM_HOST=${ETHEREUM_HOST:-"http://127.0.0.1:8545"}
export P2P_ENABLED="true"
export VALIDATOR_DISABLED="true"
export SEQ_MAX_SECONDS_BETWEEN_BLOCKS="0"
Expand All @@ -26,11 +26,11 @@ export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT="${OTEL_EXPORTER_OTLP_METRICS_ENDPOIN
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT:-}"
export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT="${OTEL_EXPORTER_OTLP_LOGS_ENDPOINT:-}"
export OTEL_RESOURCE_ATTRIBUTES="service.name=boot-node"
export VALIDATOR_PRIVATE_KEY="0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a"
export VALIDATOR_PRIVATE_KEY=${VALIDATOR_PRIVATE_KEY:-"0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a"}
REPO=$(git rev-parse --show-toplevel)

echo "Waiting for l1 contracts to be deployed..."
until [ -f "$REPO"/yarn-project/end-to-end/scripts/native-network/state/l1-contracts.env ] ; do
until [ -f "$REPO"/yarn-project/end-to-end/scripts/native-network/state/l1-contracts.env ]; do
sleep 1
done
echo "Done waiting."
Expand All @@ -42,4 +42,4 @@ function filter_noise() {
}

# Start the Aztec node with the sequencer and archiver
node --no-warnings "$REPO"/yarn-project/aztec/dest/bin/index.js start --node --archiver --sequencer --pxe 2>&1 | filter_noise
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were starting an entire PXE just to answer getNodeInfo? Damn.

node --no-warnings "$REPO"/yarn-project/aztec/dest/bin/index.js start --node --archiver --sequencer 2>&1 | filter_noise
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,33 @@ else
INIT_VALIDATORS="false"
fi

echo "Waiting for Anvil to be up at port 8545..."
export ETHEREUM_HOST=${ETHEREUM_HOST:-"http://127.0.0.1:8545"}
export L1_CHAIN_ID=${L1_CHAIN_ID:-"31337"}
export PRIVATE_KEY=${PRIVATE_KEY:-""}
export SALT=${SALT:-"1337"}

echo "Waiting for Ethereum node to be up..."
until curl -s -X POST -H 'Content-Type: application/json' \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
http://127.0.0.1:8545 2>/dev/null | grep -q 'result' ; do
$ETHEREUM_HOST 2>/dev/null | grep -q 'result'; do
sleep 1
done
echo "Done waiting."

# Run the deploy-l1-contracts command and capture the output
export ETHEREUM_HOST="http://127.0.0.1:8545"
if [ "$INIT_VALIDATORS" = "true" ]; then
output=$(node --no-warnings $(git rev-parse --show-toplevel)/yarn-project/aztec/dest/bin/index.js deploy-l1-contracts --validators "$VALIDATOR_ADDRESSES" --salt 1337)
else
output=$(node --no-warnings $(git rev-parse --show-toplevel)/yarn-project/aztec/dest/bin/index.js deploy-l1-contracts --salt 1337)
fi
# Construct base command
COMMAND="node --no-warnings $(git rev-parse --show-toplevel)/yarn-project/aztec/dest/bin/index.js \
deploy-l1-contracts \
--rpc-url $ETHEREUM_HOST \
--l1-chain-id $L1_CHAIN_ID \
--salt $SALT"

# Add validators if specified
[ "$INIT_VALIDATORS" = "true" ] && COMMAND="$COMMAND --validators $VALIDATOR_ADDRESSES"

# Add private key if provided
[ -n "$PRIVATE_KEY" ] && COMMAND="$COMMAND --private-key $PRIVATE_KEY"

output=$($COMMAND)

echo "$output"

Expand All @@ -48,9 +60,8 @@ REWARD_DISTRIBUTOR_CONTRACT_ADDRESS=$(echo "$output" | grep -oP 'RewardDistribut
GOVERNANCE_PROPOSER_CONTRACT_ADDRESS=$(echo "$output" | grep -oP 'GovernanceProposer Address: \K0x[a-fA-F0-9]{40}')
GOVERNANCE_CONTRACT_ADDRESS=$(echo "$output" | grep -oP 'Governance Address: \K0x[a-fA-F0-9]{40}')


# Save contract addresses to state/l1-contracts.env
cat << EOCONFIG > $(git rev-parse --show-toplevel)/yarn-project/end-to-end/scripts/native-network/state/l1-contracts.env
cat <<EOCONFIG >$(git rev-parse --show-toplevel)/yarn-project/end-to-end/scripts/native-network/state/l1-contracts.env
export ROLLUP_CONTRACT_ADDRESS=$ROLLUP_CONTRACT_ADDRESS
export REGISTRY_CONTRACT_ADDRESS=$REGISTRY_CONTRACT_ADDRESS
export INBOX_CONTRACT_ADDRESS=$INBOX_CONTRACT_ADDRESS
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/end-to-end/scripts/native-network/prover-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ exec > >(tee -a "$(dirname $0)/logs/${SCRIPT_NAME}.log") 2> >(tee -a "$(dirname
REPO=$(git rev-parse --show-toplevel)

echo "Waiting for l1 contracts to be deployed..."
until [ -f "$REPO"/yarn-project/end-to-end/scripts/native-network/state/l1-contracts.env ] ; do
until [ -f "$REPO"/yarn-project/end-to-end/scripts/native-network/state/l1-contracts.env ]; do
sleep 1
done
echo "Waiting for Aztec Node..."
until curl -s http://127.0.0.1:8080/status >/dev/null ; do
until curl -s http://127.0.0.1:8080/status >/dev/null; do
sleep 1
done
echo "Done waiting."
Expand All @@ -34,9 +34,9 @@ export BOOTSTRAP_NODES=$(echo "$output" | grep -oP 'Node ENR: \K.*')
# Set environment variables
export LOG_LEVEL=${LOG_LEVEL:-"debug"}
export DEBUG=${DEBUG:-"aztec:*,-aztec:avm_simulator*,-aztec:libp2p_service*,-aztec:circuits:artifact_hash,-json-rpc*,-aztec:l2_block_stream,-aztec:world-state:*"}
export ETHEREUM_HOST="http://127.0.0.1:8545"
export ETHEREUM_HOST=${ETHEREUM_HOST:-"http://127.0.0.1:8545"}
export PROVER_AGENT_ENABLED="true"
export PROVER_PUBLISHER_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
export PROVER_PUBLISHER_PRIVATE_KEY=${PROVER_PUBLISHER_PRIVATE_KEY:-"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"}
export PROVER_COORDINATION_NODE_URL="http://127.0.0.1:8080"
export AZTEC_NODE_URL="http://127.0.0.1:8080"
export PROVER_JOB_SOURCE_URL="http://127.0.0.1:$PORT"
Expand Down
11 changes: 6 additions & 5 deletions yarn-project/end-to-end/scripts/native-network/pxe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ exec > >(tee -a "$(dirname $0)/logs/${SCRIPT_NAME}.log") 2> >(tee -a "$(dirname

# Starts the PXE (Private eXecution Environment) service
# Set environment variables
export ETHEREUM_HOST="http://127.0.0.1:8545"
export AZTEC_NODE_URL="http://127.0.0.1:8080"
export ETHEREUM_HOST=${ETHEREUM_HOST:-"http://127.0.0.1:8545"}
export AZTEC_NODE_URL=${AZTEC_NODE_URL:-"http://127.0.0.1:8080"}
export VALIDATOR_NODE_URL=${VALIDATOR_NODE_URL:-"http://127.0.0.1:8081"}
export LOG_LEVEL=${LOG_LEVEL:-"debug"}
export DEBUG="aztec:*"

echo "Waiting for Aztec Node..."
until curl -s http://127.0.0.1:8080/status >/dev/null ; do
until curl -s $AZTEC_NODE_URL/status >/dev/null; do
sleep 1
done
# We need to also wait for the validator, as the initial node cannot
# Produce blocks on it's own
echo "Waiting for Validator 0..."
until curl -s http://127.0.0.1:8081/status >/dev/null ; do
until curl -s $VALIDATOR_NODE_URL/status >/dev/null; do
sleep 1
done
echo "Done waiting."
Expand All @@ -31,4 +32,4 @@ function filter_noise() {
}

# Start the PXE service
node --no-warnings $(git rev-parse --show-toplevel)/yarn-project/aztec/dest/bin/index.js start --port=8079 --pxe 2>&1 | filter_noise
node --no-warnings $(git rev-parse --show-toplevel)/yarn-project/aztec/dest/bin/index.js start --port=8079 --pxe 2>&1 | filter_noise
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exec > >(tee -a "$(dirname $0)/logs/${SCRIPT_NAME}.log") 2> >(tee -a "$(dirname
export BOOTNODE_URL=${BOOTNODE_URL:-http://127.0.0.1:8080}
export PXE_URL=${PXE_URL:-http://127.0.0.1:8079}
export ETHEREUM_HOST=${ETHEREUM_HOST:-http://127.0.0.1:8545}
export K8S=${K8S:-false}

REPO=$(git rev-parse --show-toplevel)
# Run our test assuming the port in pxe.sh
Expand Down
Loading
Loading