From 9b02d53af11b8f14d5972c619293c33c0eaf8004 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Fri, 8 Sep 2023 09:34:04 +0000 Subject: [PATCH 01/39] WIP --- .gitignore | 1 + iac/main.tf | 247 ++++++++++++++++++++++ iac/variables.tf | 3 + yarn-project/rollup-provider/Dockerfile | 2 +- yarn-project/rollup-provider/src/index.ts | 4 +- 5 files changed, 254 insertions(+), 3 deletions(-) create mode 100644 iac/main.tf create mode 100644 iac/variables.tf diff --git a/.gitignore b/.gitignore index 16bc8821c57..7d77f0832cf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ node_modules build/ .idea cmake-build-debug +.terraform diff --git a/iac/main.tf b/iac/main.tf new file mode 100644 index 00000000000..6eb2b99d13d --- /dev/null +++ b/iac/main.tf @@ -0,0 +1,247 @@ +terraform { + backend "s3" { + bucket = "aztec-terraform" + region = "eu-west-2" + } + required_providers { + aws = { + source = "hashicorp/aws" + version = "3.74.2" + } + } +} + +# Define provider and region +provider "aws" { + region = "eu-west-2" +} + +data "terraform_remote_state" "setup_iac" { + backend = "s3" + config = { + bucket = "aztec-terraform" + key = "setup/setup-iac" + region = "eu-west-2" + } +} + +data "terraform_remote_state" "aztec2_iac" { + backend = "s3" + config = { + bucket = "aztec-terraform" + key = "aztec2/iac" + region = "eu-west-2" + } +} + + +resource "aws_cloudwatch_log_group" "aztec_node_log_group" { + name = "/fargate/service/${var.DEPLOY_TAG}/aztec-node" + retention_in_days = 14 +} + +resource "aws_service_discovery_service" "aztec-node" { + name = "${var.DEPLOY_TAG}-aztec-node" + + health_check_custom_config { + failure_threshold = 1 + } + + dns_config { + namespace_id = data.terraform_remote_state.setup_iac.outputs.local_service_discovery_id + + dns_records { + ttl = 60 + type = "A" + } + + dns_records { + ttl = 60 + type = "SRV" + } + + routing_policy = "MULTIVALUE" + } + + # Terraform just fails if this resource changes and you have registered instances. + provisioner "local-exec" { + when = destroy + command = "${path.module}/../servicediscovery-drain.sh ${self.id}" + } +} + +# Define task definition and service. +resource "aws_ecs_task_definition" "aztec-node" { + family = "${var.DEPLOY_TAG}-aztec-node" + requires_compatibilities = ["FARGATE"] + network_mode = "awsvpc" + cpu = "2048" + memory = "4096" + execution_role_arn = data.terraform_remote_state.setup_iac.outputs.ecs_task_execution_role_arn + task_role_arn = data.terraform_remote_state.aztec2_iac.outputs.cloudwatch_logging_ecs_role_arn + + container_definitions = < /dev/null FROM node:18-alpine COPY --from=builder /usr/src /usr/src WORKDIR /usr/src/yarn-project/rollup-provider -ENTRYPOINT ["yarn"] \ No newline at end of file +ENTRYPOINT ["yarn", "start"] \ No newline at end of file diff --git a/yarn-project/rollup-provider/src/index.ts b/yarn-project/rollup-provider/src/index.ts index b64dcd6b306..0ffc47a8c8e 100644 --- a/yarn-project/rollup-provider/src/index.ts +++ b/yarn-project/rollup-provider/src/index.ts @@ -8,7 +8,7 @@ import { appFactory } from './app.js'; const logger = createDebugLogger('aztec:rollup_provider'); -const { SERVER_PORT = 9000 } = process.env; +const { SERVER_PORT = 9000, API_PREFIX = '' } = process.env; /** * Entrypoint for the rollup provider service @@ -27,7 +27,7 @@ async function main() { process.once('SIGINT', shutdown); process.once('SIGTERM', shutdown); - const app = appFactory(node, ''); + const app = appFactory(node, API_PREFIX); const httpServer = http.createServer(app.callback()); httpServer.listen(SERVER_PORT); From 5798a4a29ffccc85b123dddef66aee13483d4e59 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 11 Sep 2023 08:34:41 +0000 Subject: [PATCH 02/39] WIP --- yarn-project/aztec-sandbox/src/bin/index.ts | 37 ++++++-- yarn-project/aztec-sandbox/src/sandbox.ts | 96 ++++++++++++++++++--- 2 files changed, 115 insertions(+), 18 deletions(-) diff --git a/yarn-project/aztec-sandbox/src/bin/index.ts b/yarn-project/aztec-sandbox/src/bin/index.ts index f9ac88c3964..69a0aaa7896 100644 --- a/yarn-project/aztec-sandbox/src/bin/index.ts +++ b/yarn-project/aztec-sandbox/src/bin/index.ts @@ -7,14 +7,39 @@ import { readFileSync } from 'fs'; import { dirname, resolve } from 'path'; import { setupFileDebugLog } from '../logging.js'; -import { createSandbox } from '../sandbox.js'; +import { createP2PSandbox, createSandbox } from '../sandbox.js'; import { startHttpRpcServer } from '../server.js'; import { github, splash } from '../splash.js'; -const { SERVER_PORT = 8080 } = process.env; +const { SERVER_PORT = 8080, P2P_ENABLED = 'false' } = process.env; const logger = createDebugLogger('aztec:sandbox'); +/** + * Creates the sandbox from provided config and deploys any initial L1 and L2 contracts + * @param isP2PSandbox - Flag indicating if this sandbox is to connect to a P2P network + */ +async function createAndDeploySandbox(isP2PSandbox: boolean) { + if (!isP2PSandbox) { + const { l1Contracts, rpcServer, stop } = await createSandbox(); + logger.info('Setting up test accounts...'); + const accounts = await deployInitialSandboxAccounts(rpcServer); + return { + l1Contracts, + rpcServer, + stop, + accounts, + }; + } + const { l1Contracts, rpcServer, stop } = await createP2PSandbox(); + return { + l1Contracts, + rpcServer, + stop, + accounts: [], + }; +} + /** * Create and start a new Aztec RCP HTTP Server */ @@ -25,10 +50,12 @@ async function main() { logger.info(`Setting up Aztec Sandbox v${version}, please stand by...`); - const { l1Contracts, rpcServer, stop } = await createSandbox(); + const p2pSandbox = P2P_ENABLED === 'true'; + if (p2pSandbox) { + logger.info(`Setting up Aztec Sandbox as P2P Node`); + } - logger.info('Setting up test accounts...'); - const accounts = await deployInitialSandboxAccounts(rpcServer); + const { l1Contracts, rpcServer, stop, accounts } = await createAndDeploySandbox(p2pSandbox); const shutdown = async () => { logger.info('Shutting down...'); diff --git a/yarn-project/aztec-sandbox/src/sandbox.ts b/yarn-project/aztec-sandbox/src/sandbox.ts index 8d25be5a200..3de9e127ceb 100644 --- a/yarn-project/aztec-sandbox/src/sandbox.ts +++ b/yarn-project/aztec-sandbox/src/sandbox.ts @@ -1,28 +1,69 @@ #!/usr/bin/env -S node --no-warnings import { AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; -import { createAztecRPCServer, getConfigEnvVars as getRpcConfigEnvVars } from '@aztec/aztec-rpc'; -import { deployL1Contracts } from '@aztec/ethereum'; +import { EthAddress, createAztecRPCServer, getConfigEnvVars as getRpcConfigEnvVars } from '@aztec/aztec-rpc'; +import { DeployL1Contracts, createEthereumChain, deployL1Contracts } from '@aztec/ethereum'; import { createDebugLogger } from '@aztec/foundation/log'; import { retryUntil } from '@aztec/foundation/retry'; -import { HDAccount, createPublicClient, http as httpViemTransport } from 'viem'; -import { mnemonicToAccount } from 'viem/accounts'; +import { + Account, + Chain, + HDAccount, + HttpTransport, + createPublicClient, + createWalletClient, + http, + http as httpViemTransport, +} from 'viem'; +import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts'; import { foundry } from 'viem/chains'; -const { MNEMONIC = 'test test test test test test test test test test test junk' } = process.env; +const { + MNEMONIC = 'test test test test test test test test test test test junk', + OUTBOX_CONTRACT_ADDRESS = '', + REGISTRY_CONTRACT_ADDRESS = '', +} = process.env; const logger = createDebugLogger('aztec:sandbox'); const localAnvil = foundry; +/** + * Helper function that retrieves the addresses of configured deployed contracts. + */ +function retrieveL1Contracts(config: AztecNodeConfig, account: Account): Promise { + const chain = createEthereumChain(config.rpcUrl, config.apiKey); + const walletClient = createWalletClient({ + account, + chain: chain.chainInfo, + transport: http(chain.rpcUrl), + }); + const publicClient = createPublicClient({ + chain: chain.chainInfo, + transport: http(chain.rpcUrl), + }); + const contracts: DeployL1Contracts = { + rollupAddress: config.rollupContract, + registryAddress: EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS), + inboxAddress: config.inboxContract, + outboxAddress: EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS), + contractDeploymentEmitterAddress: config.contractDeploymentEmitterContract, + decoderHelperAddress: undefined, + walletClient, + publicClient, + }; + return Promise.resolve(contracts); +} + /** * Helper function that waits for the Ethereum RPC server to respond before deploying L1 contracts. */ -async function waitThenDeploy(rpcUrl: string, hdAccount: HDAccount) { +async function waitThenDeploy(config: AztecNodeConfig, deployFunction: () => Promise) { + const chain = createEthereumChain(config.rpcUrl, config.apiKey); // wait for ETH RPC to respond to a request. const publicClient = createPublicClient({ - chain: foundry, - transport: httpViemTransport(rpcUrl), + chain: chain.chainInfo, + transport: httpViemTransport(chain.rpcUrl), }); const chainID = await retryUntil( async () => { @@ -30,7 +71,7 @@ async function waitThenDeploy(rpcUrl: string, hdAccount: HDAccount) { try { chainId = await publicClient.getChainId(); } catch (err) { - logger.warn(`Failed to connect to Ethereum node at ${rpcUrl}. Retrying...`); + logger.warn(`Failed to connect to Ethereum node at ${chain.rpcUrl}. Retrying...`); } return chainId; }, @@ -40,12 +81,11 @@ async function waitThenDeploy(rpcUrl: string, hdAccount: HDAccount) { ); if (!chainID) { - throw Error(`Ethereum node unresponsive at ${rpcUrl}.`); + throw Error(`Ethereum node unresponsive at ${chain.rpcUrl}.`); } // Deploy L1 contracts - const deployedL1Contracts = await deployL1Contracts(rpcUrl, hdAccount, localAnvil, logger); - return deployedL1Contracts; + return await deployFunction(); } /** Sandbox settings. */ @@ -65,7 +105,9 @@ export async function createSandbox(config: Partial = {}) { const hdAccount = mnemonicToAccount(config.l1Mnemonic ?? MNEMONIC); const privKey = hdAccount.getHdKey().privateKey; - const l1Contracts = await waitThenDeploy(aztecNodeConfig.rpcUrl, hdAccount); + const l1Contracts = await waitThenDeploy(aztecNodeConfig, () => + deployL1Contracts(aztecNodeConfig.rpcUrl, hdAccount, localAnvil, logger), + ); aztecNodeConfig.publisherPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`; aztecNodeConfig.rollupContract = l1Contracts.rollupAddress; aztecNodeConfig.contractDeploymentEmitterContract = l1Contracts.contractDeploymentEmitterAddress; @@ -81,3 +123,31 @@ export async function createSandbox(config: Partial = {}) { return { node, rpcServer, l1Contracts, stop }; } + +/** + * Create and start a new Aztec Node and RPC Server. Designed for interaction with a node network. + * Does not start any HTTP services nor populate any initial accounts. + * @param config - Optional Sandbox settings. + */ +export async function createP2PSandbox() { + const aztecNodeConfig: AztecNodeConfig = { ...getConfigEnvVars() }; + const rpcConfig = getRpcConfigEnvVars(); + const privateKeyAccount = privateKeyToAccount(aztecNodeConfig.publisherPrivateKey); + + const l1Contracts = await waitThenDeploy(aztecNodeConfig, () => + retrieveL1Contracts(aztecNodeConfig, privateKeyAccount), + ); + aztecNodeConfig.rollupContract = l1Contracts.rollupAddress; + aztecNodeConfig.contractDeploymentEmitterContract = l1Contracts.contractDeploymentEmitterAddress; + aztecNodeConfig.inboxContract = l1Contracts.inboxAddress; + + const node = await AztecNodeService.createAndSync(aztecNodeConfig); + const rpcServer = await createAztecRPCServer(node, rpcConfig); + + const stop = async () => { + await rpcServer.stop(); + await node.stop(); + }; + + return { node, rpcServer, l1Contracts, stop }; +} From bb043912cf9cbd985d37290a21937e6a29ce7d19 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sat, 23 Sep 2023 19:33:19 +0000 Subject: [PATCH 03/39] WIP --- circuits/cpp/barretenberg | 1 + .../archiver/src/archiver/archiver.ts | 6 +- yarn-project/archiver/src/archiver/config.ts | 10 +-- yarn-project/archiver/src/index.ts | 8 +-- yarn-project/aztec-node/package.json | 4 ++ .../aztec-node/src/aztec-node/server.ts | 21 +++++- yarn-project/aztec-node/src/bin/index.ts | 68 +++++++++++++++++++ yarn-project/aztec-node/src/index.ts | 2 - yarn-project/aztec-node/tsconfig.json | 2 +- yarn-project/aztec-rpc/package.json | 2 + .../aztec_rpc_http/aztec_rpc_http_server.ts | 17 +++++ .../src/aztec_rpc_server/aztec_rpc_server.ts | 6 +- .../test/aztec_rpc_server.test.ts | 3 +- .../test/aztec_rpc_test_suite.ts | 2 +- yarn-project/aztec-rpc/src/bin/index.ts | 39 +++++++++++ yarn-project/aztec-sandbox/src/bin/index.ts | 6 +- yarn-project/aztec-sandbox/src/routes.ts | 16 +---- yarn-project/aztec-sandbox/src/sandbox.ts | 26 +++---- yarn-project/aztec-sandbox/src/server.ts | 10 +-- .../aztec.js/src/contract/contract.test.ts | 4 +- .../aztec.js/src/utils/cheat_codes.ts | 2 +- yarn-project/cli/package.json | 1 + yarn-project/cli/src/index.ts | 36 ++++++---- yarn-project/cli/tsconfig.json | 3 + yarn-project/end-to-end/package.json | 2 +- .../end-to-end/src/e2e_cheat_codes.test.ts | 2 +- yarn-project/end-to-end/src/e2e_cli.test.ts | 3 +- .../end-to-end/src/e2e_p2p_network.test.ts | 13 ++-- .../src/e2e_sandbox_example.test.ts | 6 +- .../src/fixtures/cross_chain_test_harness.ts | 4 +- yarn-project/end-to-end/src/fixtures/utils.ts | 24 ++++--- .../src/integration_archiver_l1_to_l2.test.ts | 2 +- .../src/integration_l1_publisher.test.ts | 24 +++---- .../src/uniswap_trade_on_l1_from_l2.test.ts | 2 +- .../ethereum/src/deploy_l1_contracts.ts | 37 ++++------ yarn-project/ethereum/src/index.ts | 1 + .../ethereum/src/l1_contract_addresses.ts | 31 +++++++++ yarn-project/p2p/src/bootstrap/bootstrap.ts | 5 +- .../p2p/src/service/libp2p_service.ts | 21 ++++-- yarn-project/sequencer-client/src/config.ts | 6 +- .../src/global_variable_builder/config.ts | 8 +-- .../global_variable_builder/viem-reader.ts | 4 +- .../sequencer-client/src/publisher/config.ts | 4 +- .../src/publisher/viem-tx-sender.ts | 8 +-- yarn-project/types/package.json | 1 + .../src/aztec_node}/rpc/http_rpc_client.ts | 0 .../src/aztec_node}/rpc/http_rpc_server.ts | 0 .../types/src/aztec_node/rpc/index.ts | 2 + yarn-project/types/src/index.ts | 2 +- .../types/src/interfaces/aztec-node.ts | 9 +-- .../types/src/interfaces/node-info.ts | 6 +- yarn-project/types/src/l1_addresses.ts | 21 ------ yarn-project/yarn.lock | 8 +++ 53 files changed, 355 insertions(+), 196 deletions(-) create mode 120000 circuits/cpp/barretenberg create mode 100644 yarn-project/aztec-node/src/bin/index.ts create mode 100644 yarn-project/aztec-rpc/src/bin/index.ts create mode 100644 yarn-project/ethereum/src/l1_contract_addresses.ts rename yarn-project/{aztec-node/src => types/src/aztec_node}/rpc/http_rpc_client.ts (100%) rename yarn-project/{aztec-node/src => types/src/aztec_node}/rpc/http_rpc_server.ts (100%) create mode 100644 yarn-project/types/src/aztec_node/rpc/index.ts delete mode 100644 yarn-project/types/src/l1_addresses.ts diff --git a/circuits/cpp/barretenberg b/circuits/cpp/barretenberg new file mode 120000 index 00000000000..e9b54f1df3e --- /dev/null +++ b/circuits/cpp/barretenberg @@ -0,0 +1 @@ +../../barretenberg \ No newline at end of file diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 6c88251805d..94a0eccf0d0 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -101,9 +101,9 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource const archiverStore = new MemoryArchiverStore(); const archiver = new Archiver( publicClient, - config.rollupContract, - config.inboxContract, - config.contractDeploymentEmitterContract, + config.rollupAddress!, + config.inboxAddress!, + config.contractDeploymentEmitterAddress!, config.searchStartBlock, archiverStore, config.archiverPollingIntervalMS, diff --git a/yarn-project/archiver/src/archiver/config.ts b/yarn-project/archiver/src/archiver/config.ts index 675db4c278a..d20cfe64bc1 100644 --- a/yarn-project/archiver/src/archiver/config.ts +++ b/yarn-project/archiver/src/archiver/config.ts @@ -1,5 +1,5 @@ +import { L1ContractAddresses } from '@aztec/ethereum'; import { EthAddress } from '@aztec/foundation/eth-address'; -import { L1Addresses } from '@aztec/types'; /** * There are 2 polling intervals used in this configuration. The first is the archiver polling interval, archiverPollingIntervalMS. @@ -11,7 +11,7 @@ import { L1Addresses } from '@aztec/types'; /** * The archiver configuration. */ -export interface ArchiverConfig extends L1Addresses { +export interface ArchiverConfig extends L1ContractAddresses { /** * The url of the Ethereum RPC node. */ @@ -58,9 +58,9 @@ export function getConfigEnvVars(): ArchiverConfig { rpcUrl: ETHEREUM_HOST || 'http://127.0.0.1:8545/', archiverPollingIntervalMS: ARCHIVER_POLLING_INTERVAL_MS ? +ARCHIVER_POLLING_INTERVAL_MS : 1_000, viemPollingIntervalMS: ARCHIVER_VIEM_POLLING_INTERVAL_MS ? +ARCHIVER_VIEM_POLLING_INTERVAL_MS : 1_000, - rollupContract: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, - inboxContract: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, - contractDeploymentEmitterContract: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS + rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, + inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, + contractDeploymentEmitterAddress: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS ? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS) : EthAddress.ZERO, searchStartBlock: SEARCH_START_BLOCK ? +SEARCH_START_BLOCK : 0, diff --git a/yarn-project/archiver/src/index.ts b/yarn-project/archiver/src/index.ts index 1ab04d4c58e..c2650e037b4 100644 --- a/yarn-project/archiver/src/index.ts +++ b/yarn-project/archiver/src/index.ts @@ -17,7 +17,7 @@ const log = createDebugLogger('aztec:archiver'); // eslint-disable-next-line require-await async function main() { const config = getConfigEnvVars(); - const { rpcUrl, rollupContract, inboxContract, contractDeploymentEmitterContract, searchStartBlock } = config; + const { rpcUrl, rollupAddress, inboxAddress, contractDeploymentEmitterAddress, searchStartBlock } = config; const publicClient = createPublicClient({ chain: localhost, @@ -28,9 +28,9 @@ async function main() { const archiver = new Archiver( publicClient, - rollupContract, - inboxContract, - contractDeploymentEmitterContract, + rollupAddress!, + inboxAddress!, + contractDeploymentEmitterAddress!, searchStartBlock, archiverStore, ); diff --git a/yarn-project/aztec-node/package.json b/yarn-project/aztec-node/package.json index 8e785e5b058..a63d72ab416 100644 --- a/yarn-project/aztec-node/package.json +++ b/yarn-project/aztec-node/package.json @@ -4,6 +4,7 @@ "main": "dest/index.js", "type": "module", "exports": "./dest/index.js", + "bin": "./dest/bin/index.js", "typedocOptions": { "entryPoints": [ "./src/index.ts" @@ -12,6 +13,7 @@ "tsconfig": "./tsconfig.json" }, "scripts": { + "start": "node --no-warnings ./dest/bin", "build": "yarn clean && tsc -b", "build:dev": "tsc -b --watch", "clean": "rm -rf ./dest .tsbuildinfo", @@ -40,6 +42,8 @@ "@aztec/sequencer-client": "workspace:^", "@aztec/types": "workspace:^", "@aztec/world-state": "workspace:^", + "koa": "^2.14.2", + "koa-router": "^12.0.0", "tslib": "^2.4.0" }, "devDependencies": { diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index fcf509ff6cb..025c6fb1338 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -9,6 +9,7 @@ import { L1_TO_L2_MSG_TREE_HEIGHT, PRIVATE_DATA_TREE_HEIGHT, } from '@aztec/circuits.js'; +import { L1ContractAddresses } from '@aztec/ethereum'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { createDebugLogger } from '@aztec/foundation/log'; import { InMemoryTxPool, P2P, createP2PClient } from '@aztec/p2p'; @@ -57,6 +58,7 @@ export const createMemDown = () => (memdown as any)() as MemDown; */ export class AztecNodeService implements AztecNode { constructor( + protected config: AztecNodeConfig, protected p2pClient: P2P, protected blockSource: L2BlockSource, protected encryptedLogsSource: L2LogsSource, @@ -83,7 +85,7 @@ export class AztecNodeService implements AztecNode { // we identify the P2P transaction protocol by using the rollup contract address. // this may well change in future - config.transactionProtocol = `/aztec/tx/${config.rollupContract.toString()}`; + config.transactionProtocol = `/aztec/tx/${config.rollupAddress!.toString()}`; // create the tx pool and the p2p client, which will need the l2 block source const p2pClient = await createP2PClient(config, new InMemoryTxPool(), archiver); @@ -107,6 +109,7 @@ export class AztecNodeService implements AztecNode { archiver, ); return new AztecNodeService( + config, p2pClient, archiver, archiver, @@ -122,6 +125,22 @@ export class AztecNodeService implements AztecNode { ); } + /** + * Method to return the currently deployed L1 contract addresses. + * @returns - The currently deployed L1 contract addresses. + */ + public getL1ContractAddresses(): Promise { + const l1Contracts: L1ContractAddresses = { + rollupAddress: this.config.rollupAddress, + registryAddress: this.config.registryAddress, + inboxAddress: this.config.inboxAddress, + outboxAddress: this.config.outboxAddress, + contractDeploymentEmitterAddress: this.config.contractDeploymentEmitterAddress, + decoderHelperAddress: this.config.decoderHelperAddress, + }; + return Promise.resolve(l1Contracts); + } + /** * Method to determine if the node is ready to accept transactions. * @returns - Flag indicating the readiness for tx submission. diff --git a/yarn-project/aztec-node/src/bin/index.ts b/yarn-project/aztec-node/src/bin/index.ts new file mode 100644 index 00000000000..ddf361e2b71 --- /dev/null +++ b/yarn-project/aztec-node/src/bin/index.ts @@ -0,0 +1,68 @@ +#!/usr/bin/env -S node --no-warnings +import { createDebugLogger } from '@aztec/foundation/log'; +import { createAztecNodeRpcServer } from '@aztec/types'; + +import http from 'http'; +import Koa from 'koa'; +import Router from 'koa-router'; + +import { AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '../index.js'; + +const { SERVER_PORT = 8080, API_PREFIX = '' } = process.env; + +const logger = createDebugLogger('aztec:node'); + +/** + * Creates the node from provided config + */ +async function createAndDeployAztecNode() { + const aztecNodeConfig: AztecNodeConfig = { ...getConfigEnvVars() }; + + return await AztecNodeService.createAndSync(aztecNodeConfig); +} + +/** + * Creates a router for helper API endpoints of the Aztec RPC Server. + * @param apiPrefix - The prefix to use for all api requests + * @returns - The router for handling status requests. + */ +export function createStatusRouter(apiPrefix: string) { + const router = new Router({ prefix: `${apiPrefix}` }); + router.get('/status', (ctx: Koa.Context) => { + ctx.status = 200; + }); + return router; +} + +/** + * Create and start a new Aztec Node HTTP Server + */ +async function main() { + logger.info(`Setting up Aztec Node...`); + + const aztecNode = await createAndDeployAztecNode(); + + const shutdown = async () => { + logger.info('Shutting down...'); + await aztecNode.stop(); + process.exit(0); + }; + + process.once('SIGINT', shutdown); + process.once('SIGTERM', shutdown); + + const rpcServer = createAztecNodeRpcServer(aztecNode); + const app = rpcServer.getApp(API_PREFIX); + const apiRouter = createStatusRouter(API_PREFIX); + app.use(apiRouter.routes()); + app.use(apiRouter.allowedMethods()); + + const httpServer = http.createServer(app.callback()); + httpServer.listen(+SERVER_PORT); + logger.info(`Aztec Node JSON-RPC Server listening on port ${SERVER_PORT}`); +} + +main().catch(err => { + logger.error(err); + process.exit(1); +}); diff --git a/yarn-project/aztec-node/src/index.ts b/yarn-project/aztec-node/src/index.ts index 853db6bae96..30446306da6 100644 --- a/yarn-project/aztec-node/src/index.ts +++ b/yarn-project/aztec-node/src/index.ts @@ -1,4 +1,2 @@ export * from './aztec-node/config.js'; export * from './aztec-node/server.js'; -export * from './rpc/http_rpc_server.js'; -export * from './rpc/http_rpc_client.js'; diff --git a/yarn-project/aztec-node/tsconfig.json b/yarn-project/aztec-node/tsconfig.json index 5457afa2a41..485500056f2 100644 --- a/yarn-project/aztec-node/tsconfig.json +++ b/yarn-project/aztec-node/tsconfig.json @@ -34,5 +34,5 @@ "path": "../world-state" } ], - "include": ["src"] + "include": ["src", "../types/src/aztec_node/rpc"] } diff --git a/yarn-project/aztec-rpc/package.json b/yarn-project/aztec-rpc/package.json index 9c477cf34f1..d626c45994d 100644 --- a/yarn-project/aztec-rpc/package.json +++ b/yarn-project/aztec-rpc/package.json @@ -37,6 +37,8 @@ "@aztec/key-store": "workspace:^", "@aztec/noir-compiler": "workspace:^", "@aztec/types": "workspace:^", + "koa": "^2.14.2", + "koa-router": "^12.0.0", "lodash.omit": "^4.5.0", "lodash.partition": "^4.6.0", "lodash.times": "^4.3.2", diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts b/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts index 162eb59183d..93f9d3e6d3c 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts @@ -16,6 +16,7 @@ import { TxReceipt, } from '@aztec/types'; +import http from 'http'; import { foundry } from 'viem/chains'; import { EthAddress } from '../index.js'; @@ -50,3 +51,19 @@ export function getHttpRpcServer(aztecRpcServer: AztecRPC): JsonRpcServer { ); return generatedRpcServer; } + +/** + * Creates an http server that forwards calls to the rpc server and starts it on the given port. + * @param aztecRpcServer - RPC server that answers queries to the created HTTP server. + * @param port - Port to listen in. + * @returns A running http server. + */ +export function startHttpRpcServer(aztecRpcServer: AztecRPC, port: string | number): http.Server { + const rpcServer = getHttpRpcServer(aztecRpcServer); + + const app = rpcServer.getApp(); + const httpServer = http.createServer(app.callback()); + httpServer.listen(port); + + return httpServer; +} diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts index fe754f7c652..65e787ead2d 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts @@ -337,10 +337,10 @@ export class AztecRPCServer implements AztecRPC { } public async getNodeInfo(): Promise { - const [version, chainId, rollupAddress] = await Promise.all([ + const [version, chainId, contractAddresses] = await Promise.all([ this.node.getVersion(), this.node.getChainId(), - this.node.getRollupAddress(), + this.node.getL1ContractAddresses(), ]); return { @@ -348,7 +348,7 @@ export class AztecRPCServer implements AztecRPC { compatibleNargoVersion: NoirVersion.tag, chainId, protocolVersion: version, - rollupAddress, + l1ContractAddresses: contractAddresses, }; } diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts index 99adad75081..840a1031849 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts @@ -5,7 +5,7 @@ import { AztecNode, AztecRPC, L2Tx, mockTx } from '@aztec/types'; import { MockProxy, mock } from 'jest-mock-extended'; import { MemoryDB } from '../../database/memory_db.js'; -import { EthAddress, RpcServerConfig } from '../../index.js'; +import { RpcServerConfig } from '../../index.js'; import { AztecRPCServer } from '../aztec_rpc_server.js'; import { aztecRpcTestSuite } from './aztec_rpc_test_suite.js'; @@ -21,7 +21,6 @@ async function createAztecRpcServer(): Promise { node.getBlockNumber.mockResolvedValue(2); node.getVersion.mockResolvedValue(1); node.getChainId.mockResolvedValue(1); - node.getRollupAddress.mockResolvedValue(EthAddress.random()); return new AztecRPCServer(keyStore, node, db, config); } diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_test_suite.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_test_suite.ts index 79f68176cb0..1a1ef438cbb 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_test_suite.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_test_suite.ts @@ -135,7 +135,7 @@ export const aztecRpcTestSuite = (testName: string, aztecRpcSetup: () => Promise const nodeInfo = await rpc.getNodeInfo(); expect(typeof nodeInfo.protocolVersion).toEqual('number'); expect(typeof nodeInfo.chainId).toEqual('number'); - expect(nodeInfo.rollupAddress.toString()).toMatch(/0x[a-fA-F0-9]+/); + expect(nodeInfo.l1ContractAddresses.rollupAddress!.toString()).toMatch(/0x[a-fA-F0-9]+/); }); // Note: Not testing `isGlobalStateSynchronised`, `isAccountStateSynchronised` and `getSyncStatus` as these methods diff --git a/yarn-project/aztec-rpc/src/bin/index.ts b/yarn-project/aztec-rpc/src/bin/index.ts new file mode 100644 index 00000000000..80584d0a8e6 --- /dev/null +++ b/yarn-project/aztec-rpc/src/bin/index.ts @@ -0,0 +1,39 @@ +#!/usr/bin/env -S node --no-warnings +import { createDebugLogger } from '@aztec/foundation/log'; +import { createAztecNodeRpcClient } from '@aztec/types'; + +import { startHttpRpcServer } from '../aztec_rpc_http/index.js'; +import { createAztecRPCServer } from '../aztec_rpc_server/index.js'; +import { getConfigEnvVars } from '../config/index.js'; + +const { SERVER_PORT = 8080, AZTEC_NODE_RPC_URL = '' } = process.env; + +const logger = createDebugLogger('aztec:rpc_server'); + +/** + * Create and start a new Aztec RCP HTTP Server + */ +async function main() { + logger.info(`Setting up Aztec RPC Server...`); + + const rpcConfig = getConfigEnvVars(); + const nodeRpcClient = createAztecNodeRpcClient(AZTEC_NODE_RPC_URL); + const rpcServer = await createAztecRPCServer(nodeRpcClient, rpcConfig); + + const shutdown = async () => { + logger.info('Shutting down...'); + await rpcServer.stop(); + process.exit(0); + }; + + process.once('SIGINT', shutdown); + process.once('SIGTERM', shutdown); + + startHttpRpcServer(rpcServer, SERVER_PORT); + logger.info(`Aztec RPC Server listening on port ${SERVER_PORT}`); +} + +main().catch(err => { + logger.error(err); + process.exit(1); +}); diff --git a/yarn-project/aztec-sandbox/src/bin/index.ts b/yarn-project/aztec-sandbox/src/bin/index.ts index 4a017c9e2bb..6e5dcdd4011 100644 --- a/yarn-project/aztec-sandbox/src/bin/index.ts +++ b/yarn-project/aztec-sandbox/src/bin/index.ts @@ -1,4 +1,5 @@ #!/usr/bin/env -S node --no-warnings +import { startHttpRpcServer } from '@aztec/aztec-rpc'; import { deployInitialSandboxAccounts } from '@aztec/aztec.js'; import { createDebugLogger } from '@aztec/foundation/log'; import { fileURLToPath } from '@aztec/foundation/url'; @@ -9,7 +10,6 @@ import { dirname, resolve } from 'path'; import { setupFileDebugLog } from '../logging.js'; import { createP2PSandbox, createSandbox } from '../sandbox.js'; -import { startHttpRpcServer } from '../server.js'; import { github, splash } from '../splash.js'; const { SERVER_PORT = 8080, P2P_ENABLED = 'false' } = process.env; @@ -56,7 +56,7 @@ async function main() { logger.info(`Setting up Aztec Sandbox as P2P Node`); } - const { l1Contracts, rpcServer, stop, accounts } = await createAndDeploySandbox(p2pSandbox); + const { rpcServer, stop, accounts } = await createAndDeploySandbox(p2pSandbox); const shutdown = async () => { logger.info('Shutting down...'); @@ -67,7 +67,7 @@ async function main() { process.once('SIGINT', shutdown); process.once('SIGTERM', shutdown); - startHttpRpcServer(rpcServer, l1Contracts, SERVER_PORT); + startHttpRpcServer(rpcServer, SERVER_PORT); logger.info(`Aztec Sandbox JSON-RPC Server listening on port ${SERVER_PORT}`); logger.info(`Debug logs will be written to ${logPath}`); const accountStrings = [`Initial Accounts:\n\n`]; diff --git a/yarn-project/aztec-sandbox/src/routes.ts b/yarn-project/aztec-sandbox/src/routes.ts index 43967f3bd82..982fd37677d 100644 --- a/yarn-project/aztec-sandbox/src/routes.ts +++ b/yarn-project/aztec-sandbox/src/routes.ts @@ -1,5 +1,3 @@ -import { DeployL1Contracts } from '@aztec/ethereum'; - import Koa from 'koa'; import Router from 'koa-router'; @@ -8,24 +6,12 @@ import Router from 'koa-router'; * @param aztecNode - An instance of the aztec node. * @param config - The aztec node's configuration variables. */ -export function createApiRouter(l1Contracts: DeployL1Contracts) { +export function createApiRouter() { const router = new Router({ prefix: '/api' }); router.get('/status', (ctx: Koa.Context) => { // TODO: add `status` to Aztec node. ctx.status = 200; }); - router.get('/l1-contract-addresses', (ctx: Koa.Context) => { - ctx.body = { - rollup: l1Contracts.rollupAddress.toString(), - contractDeploymentEmitter: l1Contracts.contractDeploymentEmitterAddress.toString(), - inbox: l1Contracts.inboxAddress.toString(), - outbox: l1Contracts.outboxAddress.toString(), - decoderHelper: l1Contracts.decoderHelperAddress?.toString(), - registry: l1Contracts.registryAddress.toString(), - }; - ctx.status = 200; - }); - return router; } diff --git a/yarn-project/aztec-sandbox/src/sandbox.ts b/yarn-project/aztec-sandbox/src/sandbox.ts index 3de9e127ceb..d7fee7e2b47 100644 --- a/yarn-project/aztec-sandbox/src/sandbox.ts +++ b/yarn-project/aztec-sandbox/src/sandbox.ts @@ -43,12 +43,14 @@ function retrieveL1Contracts(config: AztecNodeConfig, account: Account): Promise transport: http(chain.rpcUrl), }); const contracts: DeployL1Contracts = { - rollupAddress: config.rollupContract, - registryAddress: EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS), - inboxAddress: config.inboxContract, - outboxAddress: EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS), - contractDeploymentEmitterAddress: config.contractDeploymentEmitterContract, - decoderHelperAddress: undefined, + l1ContractAddresses: { + rollupAddress: config.rollupAddress, + registryAddress: EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS), + inboxAddress: config.inboxAddress, + outboxAddress: EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS), + contractDeploymentEmitterAddress: config.contractDeploymentEmitterAddress, + decoderHelperAddress: undefined, + }, walletClient, publicClient, }; @@ -109,9 +111,9 @@ export async function createSandbox(config: Partial = {}) { deployL1Contracts(aztecNodeConfig.rpcUrl, hdAccount, localAnvil, logger), ); aztecNodeConfig.publisherPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`; - aztecNodeConfig.rollupContract = l1Contracts.rollupAddress; - aztecNodeConfig.contractDeploymentEmitterContract = l1Contracts.contractDeploymentEmitterAddress; - aztecNodeConfig.inboxContract = l1Contracts.inboxAddress; + aztecNodeConfig.rollupAddress = l1Contracts.l1ContractAddresses.rollupAddress; + aztecNodeConfig.contractDeploymentEmitterAddress = l1Contracts.l1ContractAddresses.contractDeploymentEmitterAddress; + aztecNodeConfig.inboxAddress = l1Contracts.l1ContractAddresses.inboxAddress; const node = await AztecNodeService.createAndSync(aztecNodeConfig); const rpcServer = await createAztecRPCServer(node, rpcConfig); @@ -137,9 +139,9 @@ export async function createP2PSandbox() { const l1Contracts = await waitThenDeploy(aztecNodeConfig, () => retrieveL1Contracts(aztecNodeConfig, privateKeyAccount), ); - aztecNodeConfig.rollupContract = l1Contracts.rollupAddress; - aztecNodeConfig.contractDeploymentEmitterContract = l1Contracts.contractDeploymentEmitterAddress; - aztecNodeConfig.inboxContract = l1Contracts.inboxAddress; + aztecNodeConfig.rollupAddress = l1Contracts.l1ContractAddresses.rollupAddress; + aztecNodeConfig.contractDeploymentEmitterAddress = l1Contracts.l1ContractAddresses.contractDeploymentEmitterAddress; + aztecNodeConfig.inboxAddress = l1Contracts.l1ContractAddresses.inboxAddress; const node = await AztecNodeService.createAndSync(aztecNodeConfig); const rpcServer = await createAztecRPCServer(node, rpcConfig); diff --git a/yarn-project/aztec-sandbox/src/server.ts b/yarn-project/aztec-sandbox/src/server.ts index e749c4cc79c..0e37b1c91a0 100644 --- a/yarn-project/aztec-sandbox/src/server.ts +++ b/yarn-project/aztec-sandbox/src/server.ts @@ -1,5 +1,4 @@ import { getHttpRpcServer } from '@aztec/aztec-rpc'; -import { DeployL1Contracts } from '@aztec/ethereum'; import { AztecRPC } from '@aztec/types'; import http from 'http'; @@ -9,19 +8,14 @@ import { createApiRouter } from './routes.js'; /** * Creates an http server that forwards calls to the rpc server and starts it on the given port. * @param aztecRpcServer - RPC server that answers queries to the created HTTP server. - * @param deployedL1Contracts - Info on L1 deployed contracts. * @param port - Port to listen in. * @returns A running http server. */ -export function startHttpRpcServer( - aztecRpcServer: AztecRPC, - deployedL1Contracts: DeployL1Contracts, - port: string | number, -): http.Server { +export function startHttpRpcServer(aztecRpcServer: AztecRPC, port: string | number): http.Server { const rpcServer = getHttpRpcServer(aztecRpcServer); const app = rpcServer.getApp(); - const apiRouter = createApiRouter(deployedL1Contracts); + const apiRouter = createApiRouter(); app.use(apiRouter.routes()); app.use(apiRouter.allowedMethods()); diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index 1df16e7de1f..9c2e7c0471a 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -33,7 +33,9 @@ describe('Contract Class', () => { compatibleNargoVersion: 'vx.x.x-aztec.x', protocolVersion: 1, chainId: 2, - rollupAddress: EthAddress.random(), + l1ContractAddresses: { + rollupAddress: EthAddress.random(), + }, }; const defaultAbi: ContractAbi = { diff --git a/yarn-project/aztec.js/src/utils/cheat_codes.ts b/yarn-project/aztec.js/src/utils/cheat_codes.ts index fc3fe96c080..c1488f7c02a 100644 --- a/yarn-project/aztec.js/src/utils/cheat_codes.ts +++ b/yarn-project/aztec.js/src/utils/cheat_codes.ts @@ -257,7 +257,7 @@ export class AztecCheatCodes { * @param to - The timestamp to set the next block to (must be greater than current time) */ public async warp(to: number): Promise { - const rollupContract = (await this.aztecRpc.getNodeInfo()).rollupAddress; + const rollupContract = (await this.aztecRpc.getNodeInfo()).l1ContractAddresses.rollupAddress!; await this.eth.setNextBlockTimestamp(to); // also store this time on the rollup contract (slot 1 tracks `lastBlockTs`). // This is because when the sequencer executes public functions, it uses the timestamp stored in the rollup contract. diff --git a/yarn-project/cli/package.json b/yarn-project/cli/package.json index 8a9dce35fdf..feb0477e29d 100644 --- a/yarn-project/cli/package.json +++ b/yarn-project/cli/package.json @@ -39,6 +39,7 @@ "@aztec/foundation": "workspace:^", "@aztec/noir-compiler": "workspace:^", "@aztec/noir-contracts": "workspace:^", + "@aztec/p2p": "workspace:^", "@aztec/types": "workspace:^", "commander": "^9.0.0", "jszip": "^3.10.1", diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index fe38efd4508..ff351bcd506 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -14,6 +14,7 @@ import { JsonStringify } from '@aztec/foundation/json-rpc'; import { DebugLogger, LogFn } from '@aztec/foundation/log'; import { fileURLToPath } from '@aztec/foundation/url'; import { compileContract, generateNoirInterface, generateTypescriptInterface } from '@aztec/noir-compiler/cli'; +import { createLibP2PPeerId } from '@aztec/p2p'; import { CompleteAddress, ContractData, L2BlockL2Logs, TxHash } from '@aztec/types'; import { Command } from 'commander'; @@ -75,20 +76,19 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { 'test test test test test test test test test test test junk', ) .action(async options => { - const { rollupAddress, registryAddress, inboxAddress, outboxAddress, contractDeploymentEmitterAddress } = - await deployAztecContracts( - options.rpcUrl, - options.apiKey ?? '', - options.privateKey, - options.mnemonic, - debugLogger, - ); + const { l1ContractAddresses } = await deployAztecContracts( + options.rpcUrl, + options.apiKey ?? '', + options.privateKey, + options.mnemonic, + debugLogger, + ); log('\n'); - log(`Rollup Address: ${rollupAddress.toString()}`); - log(`Registry Address: ${registryAddress.toString()}`); - log(`L1 -> L2 Inbox Address: ${inboxAddress.toString()}`); - log(`L2 -> L1 Outbox address: ${outboxAddress.toString()}`); - log(`Contract Deployment Emitter Address: ${contractDeploymentEmitterAddress.toString()}`); + log(`Rollup Address: ${l1ContractAddresses.rollupAddress?.toString()}`); + log(`Registry Address: ${l1ContractAddresses.registryAddress?.toString()}`); + log(`L1 -> L2 Inbox Address: ${l1ContractAddresses.inboxAddress?.toString()}`); + log(`L2 -> L1 Outbox address: ${l1ContractAddresses.outboxAddress?.toString()}`); + log(`Contract Deployment Emitter Address: ${l1ContractAddresses.contractDeploymentEmitterAddress?.toString()}`); log('\n'); }); @@ -118,6 +118,16 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { log(`\nPrivate Key: ${privKey}\nPublic Key: ${publicKey.toString()}\n`); }); + program + .command('generate-p2p-private-key') + .summary('Generates a LibP2P peer private key.') + .description('Generates a private key that can be used for running a node on a LibP2P network.') + .action(async () => { + const peerId = await createLibP2PPeerId(); + const exportedPeerId = Buffer.from(peerId.privateKey!).toString('hex'); + log(`\nPrivate key: ${exportedPeerId}`); + }); + program .command('create-account') .description( diff --git a/yarn-project/cli/tsconfig.json b/yarn-project/cli/tsconfig.json index a654a1611c8..28e130a83a3 100644 --- a/yarn-project/cli/tsconfig.json +++ b/yarn-project/cli/tsconfig.json @@ -21,6 +21,9 @@ { "path": "../noir-contracts" }, + { + "path": "../p2p" + }, { "path": "../types" } diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 01e14a2ecb1..7d3600df156 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -9,7 +9,7 @@ "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src \"!src/web/main.js\" && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", - "test": "DEBUG='aztec:*' NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --runInBand --passWithNoTests --testTimeout=15000", + "test": "DEBUG='aztec:*,libp2p:*' NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --runInBand --passWithNoTests --testTimeout=15000", "test:integration": "concurrently -k -s first -c reset,dim -n test,anvil \"yarn test:integration:run\" \"anvil\"", "test:integration:run": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --config jest.integration.config.json" }, diff --git a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts index f0968945e54..6b776447548 100644 --- a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts +++ b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts @@ -25,7 +25,7 @@ describe('e2e_cheat_codes', () => { walletClient = deployL1ContractsValues.walletClient; publicClient = deployL1ContractsValues.publicClient; - rollupAddress = deployL1ContractsValues.rollupAddress; + rollupAddress = deployL1ContractsValues.l1ContractAddresses.rollupAddress!; }, 100_000); afterAll(async () => { diff --git a/yarn-project/end-to-end/src/e2e_cli.test.ts b/yarn-project/end-to-end/src/e2e_cli.test.ts index 112748fe75b..19d4d44a9d1 100644 --- a/yarn-project/end-to-end/src/e2e_cli.test.ts +++ b/yarn-project/end-to-end/src/e2e_cli.test.ts @@ -17,9 +17,8 @@ let aztecRpcServer: AztecRPC; const testSetup = async () => { const context = await e2eSetup(2); debug(`Environment set up`); - const { deployL1ContractsValues } = context; ({ aztecNode, aztecRpcServer } = context); - http = startHttpRpcServer(aztecRpcServer, deployL1ContractsValues, HTTP_PORT); + http = startHttpRpcServer(aztecRpcServer, HTTP_PORT); debug(`HTTP RPC server started in port ${HTTP_PORT}`); return aztecRpcServer; }; diff --git a/yarn-project/end-to-end/src/e2e_p2p_network.test.ts b/yarn-project/end-to-end/src/e2e_p2p_network.test.ts index f28b101c754..3669dc33831 100644 --- a/yarn-project/end-to-end/src/e2e_p2p_network.test.ts +++ b/yarn-project/end-to-end/src/e2e_p2p_network.test.ts @@ -10,7 +10,7 @@ import { AztecAddress, CompleteAddress, Fr, PublicKey, getContractDeploymentInfo import { Grumpkin } from '@aztec/circuits.js/barretenberg'; import { DebugLogger } from '@aztec/foundation/log'; import { TestContractAbi } from '@aztec/noir-contracts/artifacts'; -import { BootstrapNode, P2PConfig, createLibP2PPeerId, exportLibP2PPeerIdToString } from '@aztec/p2p'; +import { BootstrapNode, P2PConfig, createLibP2PPeerId } from '@aztec/p2p'; import { AztecRPC, TxStatus } from '@aztec/types'; import { setup } from './fixtures/utils.js'; @@ -57,6 +57,11 @@ describe('e2e_p2p_network', () => { const contexts: NodeContext[] = []; for (let i = 0; i < NUM_NODES; i++) { const node = await createNode(i + 1 + BOOT_NODE_TCP_PORT, bootstrapNodeAddress); + await new Promise(resolve => + setTimeout(() => { + resolve(); + }, 100000), + ); const context = await createAztecRpcServerAndSubmitTransactions(node, NUM_TXS_PER_NODE); contexts.push(context); } @@ -90,10 +95,10 @@ describe('e2e_p2p_network', () => { p2pEnabled: true, tcpListenPort: BOOT_NODE_TCP_PORT, tcpListenIp: '0.0.0.0', - announceHostname: '127.0.0.1', + announceHostname: '10.1.0.15', announcePort: BOOT_NODE_TCP_PORT, - peerIdPrivateKey: exportLibP2PPeerIdToString(peerId), - serverMode: true, + peerIdPrivateKey: Buffer.from(peerId.privateKey!).toString('hex'), + serverMode: false, minPeerCount: 10, maxPeerCount: 100, diff --git a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts index 0cf0115d8b8..84f72c805ca 100644 --- a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts +++ b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts @@ -5,8 +5,8 @@ import { computeMessageSecretHash, createAztecRpcClient, createDebugLogger, - getSchnorrAccount, getSandboxAccountsWallets, + getSchnorrAccount, waitForSandbox, } from '@aztec/aztec.js'; import { GrumpkinScalar } from '@aztec/circuits.js'; @@ -33,7 +33,7 @@ describe('e2e_sandbox_example', () => { expect(typeof nodeInfo.protocolVersion).toBe('number'); expect(typeof nodeInfo.chainId).toBe('number'); - expect(typeof nodeInfo.rollupAddress).toBe('object'); + expect(typeof nodeInfo.l1ContractAddresses.rollupAddress).toBe('object'); // For the sandbox quickstart we just want to show them preloaded accounts (since it is a quickstart) // We show creation of accounts in a later test @@ -47,7 +47,7 @@ describe('e2e_sandbox_example', () => { logger(`Loaded alice's account at ${alice.toShortString()}`); logger(`Loaded bob's account at ${bob.toShortString()}`); // docs:end:load_accounts - + // docs:start:Deployment ////////////// DEPLOY OUR TOKEN CONTRACT ////////////// diff --git a/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts index e34244ade3f..ac0e4938aa3 100644 --- a/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts @@ -36,7 +36,7 @@ export class CrossChainTestHarness { const [owner, receiver] = accounts; const outbox = getContract({ - address: deployL1ContractsValues.outboxAddress.toString(), + address: deployL1ContractsValues.l1ContractAddresses.outboxAddress!.toString(), abi: OutboxAbi, publicClient, }); @@ -47,7 +47,7 @@ export class CrossChainTestHarness { wallet, walletClient, publicClient, - deployL1ContractsValues!.registryAddress, + deployL1ContractsValues!.l1ContractAddresses.registryAddress!, owner.address, underlyingERC20Address, ); diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index df49c2dc438..daa05d4c520 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -98,16 +98,19 @@ const setupL1Contracts = async (l1RpcUrl: string, account: HDAccount, logger: De chain: localAnvil, transport: http(l1RpcUrl), }); - return { - rollupAddress: l1Contracts.rollup, - registryAddress: l1Contracts.registry, - inboxAddress: l1Contracts.inbox, - outboxAddress: l1Contracts.outbox, - contractDeploymentEmitterAddress: l1Contracts.contractDeploymentEmitter, - decoderHelperAddress: l1Contracts.decoderHelper, + const contracts: DeployL1Contracts = { + l1ContractAddresses: { + rollupAddress: l1Contracts.rollup, + registryAddress: l1Contracts.registry, + inboxAddress: l1Contracts.inbox, + outboxAddress: l1Contracts.outbox, + contractDeploymentEmitterAddress: l1Contracts.contractDeploymentEmitter, + decoderHelperAddress: l1Contracts.decoderHelper, + }, walletClient, publicClient, }; + return contracts; } return await deployL1Contracts(l1RpcUrl, account, localAnvil, logger); }; @@ -227,9 +230,10 @@ export async function setup( const publisherPrivKey = privKeyRaw === null ? null : Buffer.from(privKeyRaw); config.publisherPrivateKey = `0x${publisherPrivKey!.toString('hex')}`; - config.rollupContract = deployL1ContractsValues.rollupAddress; - config.contractDeploymentEmitterContract = deployL1ContractsValues.contractDeploymentEmitterAddress; - config.inboxContract = deployL1ContractsValues.inboxAddress; + config.rollupAddress = deployL1ContractsValues.l1ContractAddresses.rollupAddress; + config.contractDeploymentEmitterAddress = + deployL1ContractsValues.l1ContractAddresses.contractDeploymentEmitterAddress; + config.inboxAddress = deployL1ContractsValues.l1ContractAddresses.inboxAddress; const aztecNode = await createAztecNode(config, logger); diff --git a/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts b/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts index 771502116e5..ff740dcdd3e 100644 --- a/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts +++ b/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts @@ -52,7 +52,7 @@ describe('archiver integration with l1 to l2 messages', () => { wallet, walletClient, publicClient, - deployL1ContractsValues!.registryAddress, + deployL1ContractsValues!.l1ContractAddresses.registryAddress!, initialBalance, owner, ); diff --git a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts index 2ad33406c21..601dbeffa3a 100644 --- a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts @@ -92,21 +92,17 @@ describe('L1Publisher integration', () => { beforeEach(async () => { deployerAccount = privateKeyToAccount(deployerPK); const { - rollupAddress: rollupAddress_, - inboxAddress: inboxAddress_, - outboxAddress: outboxAddress_, - contractDeploymentEmitterAddress: contractDeploymentEmitterAddress_, - decoderHelperAddress: decoderHelperAddress_, - publicClient: publicClient_, + l1ContractAddresses, walletClient, + publicClient: publicClient_, } = await deployL1Contracts(config.rpcUrl, deployerAccount, localAnvil, logger, true); publicClient = publicClient_; - rollupAddress = getAddress(rollupAddress_.toString()); - inboxAddress = getAddress(inboxAddress_.toString()); - outboxAddress = getAddress(outboxAddress_.toString()); - contractDeploymentEmitterAddress = getAddress(contractDeploymentEmitterAddress_.toString()); - decoderHelperAddress = getAddress(decoderHelperAddress_!.toString()); + rollupAddress = getAddress(l1ContractAddresses.rollupAddress!.toString()); + inboxAddress = getAddress(l1ContractAddresses.inboxAddress!.toString()); + outboxAddress = getAddress(l1ContractAddresses.outboxAddress!.toString()); + contractDeploymentEmitterAddress = getAddress(l1ContractAddresses.contractDeploymentEmitterAddress!.toString()); + decoderHelperAddress = getAddress(l1ContractAddresses.decoderHelperAddress!.toString()); // Set up contract instances rollup = getContract({ @@ -143,9 +139,9 @@ describe('L1Publisher integration', () => { rpcUrl: config.rpcUrl, apiKey: '', requiredConfirmations: 1, - rollupContract: EthAddress.fromString(rollupAddress), - inboxContract: EthAddress.fromString(inboxAddress), - contractDeploymentEmitterContract: EthAddress.fromString(contractDeploymentEmitterAddress), + rollupAddress: EthAddress.fromString(rollupAddress), + inboxAddress: EthAddress.fromString(inboxAddress), + contractDeploymentEmitterAddress: EthAddress.fromString(contractDeploymentEmitterAddress), publisherPrivateKey: sequencerPK, l1BlockPublishRetryIntervalMS: 100, }); diff --git a/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts b/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts index b8482b98f7c..8b27b03fd26 100644 --- a/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts +++ b/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts @@ -111,7 +111,7 @@ describe.skip('uniswap_trade_on_l1_from_l2', () => { await uniswapL2Contract.attach(uniswapPortalAddress); await uniswapPortal.write.initialize( - [deployL1ContractsValues!.registryAddress.toString(), uniswapL2Contract.address.toString()], + [deployL1ContractsValues!.l1ContractAddresses.registryAddress!.toString(), uniswapL2Contract.address.toString()], {} as any, ); diff --git a/yarn-project/ethereum/src/deploy_l1_contracts.ts b/yarn-project/ethereum/src/deploy_l1_contracts.ts index 4a8a7998e03..2cd08850ab8 100644 --- a/yarn-project/ethereum/src/deploy_l1_contracts.ts +++ b/yarn-project/ethereum/src/deploy_l1_contracts.ts @@ -31,6 +31,8 @@ import { } from 'viem'; import { HDAccount, PrivateKeyAccount } from 'viem/accounts'; +import { L1ContractAddresses } from './l1_contract_addresses.js'; + /** * Return type of the deployL1Contract function. */ @@ -43,30 +45,11 @@ export type DeployL1Contracts = { * Public Client Type. */ publicClient: PublicClient; + /** - * Rollup Address. - */ - rollupAddress: EthAddress; - /** - * Registry Address. - */ - registryAddress: EthAddress; - /** - * Inbox Address. - */ - inboxAddress: EthAddress; - /** - * Outbox Address. - */ - outboxAddress: EthAddress; - /** - * Data Emitter Address. - */ - contractDeploymentEmitterAddress: EthAddress; - /** - * Decoder Helper Address. + * The currently deployed l1 contract addresses */ - decoderHelperAddress?: EthAddress; + l1ContractAddresses: L1ContractAddresses; }; /** @@ -141,9 +124,7 @@ export const deployL1Contracts = async ( logger(`Deployed DecoderHelper at ${decoderHelperAddress}`); } - return { - walletClient, - publicClient, + const l1Contracts = { rollupAddress, registryAddress, inboxAddress, @@ -151,6 +132,12 @@ export const deployL1Contracts = async ( contractDeploymentEmitterAddress, decoderHelperAddress, }; + + return { + walletClient, + publicClient, + l1ContractAddresses: l1Contracts, + }; }; /** diff --git a/yarn-project/ethereum/src/index.ts b/yarn-project/ethereum/src/index.ts index 6279349059c..c8edddb8dde 100644 --- a/yarn-project/ethereum/src/index.ts +++ b/yarn-project/ethereum/src/index.ts @@ -5,6 +5,7 @@ import { createTestnetChain } from './testnet.js'; export * from './testnet.js'; export * from './deploy_l1_contracts.js'; +export * from './l1_contract_addresses.js'; /** * Helper function to create an instance of Aztec Chain from an rpc url and api key. diff --git a/yarn-project/ethereum/src/l1_contract_addresses.ts b/yarn-project/ethereum/src/l1_contract_addresses.ts new file mode 100644 index 00000000000..0812300de43 --- /dev/null +++ b/yarn-project/ethereum/src/l1_contract_addresses.ts @@ -0,0 +1,31 @@ +import { EthAddress } from '@aztec/foundation/eth-address'; + +/** + * Provides the directory of current L1 contract addresses + */ +export type L1ContractAddresses = { + /** + * Rollup Address. + */ + rollupAddress?: EthAddress; + /** + * Registry Address. + */ + registryAddress?: EthAddress; + /** + * Inbox Address. + */ + inboxAddress?: EthAddress; + /** + * Outbox Address. + */ + outboxAddress?: EthAddress; + /** + * Data Emitter Address. + */ + contractDeploymentEmitterAddress?: EthAddress; + /** + * Decoder Helper Address. + */ + decoderHelperAddress?: EthAddress; +}; diff --git a/yarn-project/p2p/src/bootstrap/bootstrap.ts b/yarn-project/p2p/src/bootstrap/bootstrap.ts index 5c02976f1e2..d724f69617b 100644 --- a/yarn-project/p2p/src/bootstrap/bootstrap.ts +++ b/yarn-project/p2p/src/bootstrap/bootstrap.ts @@ -5,7 +5,6 @@ import { yamux } from '@chainsafe/libp2p-yamux'; import type { ServiceMap } from '@libp2p/interface-libp2p'; import { kadDHT } from '@libp2p/kad-dht'; import { mplex } from '@libp2p/mplex'; -import { createFromProtobuf } from '@libp2p/peer-id-factory'; import { tcp } from '@libp2p/tcp'; import { Libp2p, Libp2pOptions, ServiceFactoryMap, createLibp2p } from 'libp2p'; import { identifyService } from 'libp2p/identify'; @@ -29,9 +28,7 @@ export class BootstrapNode { public async start(config: P2PConfig) { const { peerIdPrivateKey, tcpListenIp, tcpListenPort, announceHostname, announcePort, minPeerCount, maxPeerCount } = config; - const peerId = peerIdPrivateKey - ? await createFromProtobuf(Buffer.from(peerIdPrivateKey, 'hex')) - : await createLibP2PPeerId(); + const peerId = await createLibP2PPeerId(peerIdPrivateKey); this.logger( `Starting bootstrap node ${peerId} on ${tcpListenIp}:${tcpListenPort} announced at ${announceHostname}:${announcePort}`, ); diff --git a/yarn-project/p2p/src/service/libp2p_service.ts b/yarn-project/p2p/src/service/libp2p_service.ts index ca2e5f4de8a..83cd580e320 100644 --- a/yarn-project/p2p/src/service/libp2p_service.ts +++ b/yarn-project/p2p/src/service/libp2p_service.ts @@ -10,7 +10,7 @@ import { PeerId } from '@libp2p/interface-peer-id'; import { IncomingStreamData } from '@libp2p/interface/stream-handler'; import { DualKadDHT, kadDHT } from '@libp2p/kad-dht'; import { mplex } from '@libp2p/mplex'; -import { createEd25519PeerId, createFromProtobuf, exportToProtobuf } from '@libp2p/peer-id-factory'; +import { createFromJSON, createSecp256k1PeerId, exportToProtobuf } from '@libp2p/peer-id-factory'; import { tcp } from '@libp2p/tcp'; import { pipe } from 'it-pipe'; import { Libp2p, Libp2pOptions, ServiceFactoryMap, createLibp2p } from 'libp2p'; @@ -35,11 +35,19 @@ import { const INITIAL_PEER_REFRESH_INTERVAL = 20000; /** - * Create a libp2p peer ID. + * Create a libp2p peer ID from the private key if provided, otherwise creates a new random ID. + * @param privateKey - Optional peer ID private key as hex string * @returns The peer ID. */ -export async function createLibP2PPeerId() { - return await createEd25519PeerId(); +export async function createLibP2PPeerId(privateKey?: string) { + if (!privateKey) { + return await createSecp256k1PeerId(); + } + const base64 = Buffer.from(privateKey, 'hex').toString('base64'); + return await createFromJSON({ + id: '', + privKey: base64, + }); } /** @@ -141,10 +149,9 @@ export class LibP2PService implements P2PService { serverMode, minPeerCount, maxPeerCount, + peerIdPrivateKey, } = config; - const peerId = config.peerIdPrivateKey - ? await createFromProtobuf(Buffer.from(config.peerIdPrivateKey, 'hex')) - : await createLibP2PPeerId(); + const peerId = await createLibP2PPeerId(peerIdPrivateKey); const opts: Libp2pOptions = { start: false, diff --git a/yarn-project/sequencer-client/src/config.ts b/yarn-project/sequencer-client/src/config.ts index 9060a659c26..1edf3658bec 100644 --- a/yarn-project/sequencer-client/src/config.ts +++ b/yarn-project/sequencer-client/src/config.ts @@ -43,9 +43,9 @@ export function getConfigEnvVars(): SequencerClientConfig { requiredConfirmations: SEQ_REQUIRED_CONFS ? +SEQ_REQUIRED_CONFS : 1, l1BlockPublishRetryIntervalMS: SEQ_PUBLISH_RETRY_INTERVAL_MS ? +SEQ_PUBLISH_RETRY_INTERVAL_MS : 1_000, transactionPollingIntervalMS: SEQ_TX_POLLING_INTERVAL_MS ? +SEQ_TX_POLLING_INTERVAL_MS : 1_000, - rollupContract: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, - inboxContract: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, - contractDeploymentEmitterContract: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS + rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, + inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, + contractDeploymentEmitterAddress: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS ? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS) : EthAddress.ZERO, publisherPrivateKey, diff --git a/yarn-project/sequencer-client/src/global_variable_builder/config.ts b/yarn-project/sequencer-client/src/global_variable_builder/config.ts index 909d3d32b05..8d4682ee5b4 100644 --- a/yarn-project/sequencer-client/src/global_variable_builder/config.ts +++ b/yarn-project/sequencer-client/src/global_variable_builder/config.ts @@ -1,13 +1,9 @@ -import { EthAddress } from '@aztec/circuits.js'; +import { L1ContractAddresses } from '@aztec/ethereum'; /** * Configuration of the L1GlobalReader. */ -export interface GlobalReaderConfig { - /** - * Rollup contract address. - */ - rollupContract: EthAddress; +export interface GlobalReaderConfig extends L1ContractAddresses { /** * The RPC Url of the ethereum host. */ diff --git a/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts b/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts index e351db0c09d..31640460664 100644 --- a/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts +++ b/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts @@ -23,7 +23,7 @@ export class ViemReader implements L1GlobalReader { private publicClient: PublicClient; constructor(config: GlobalReaderConfig) { - const { rpcUrl, apiKey, rollupContract: rollupContractAddress } = config; + const { rpcUrl, apiKey, rollupAddress: rollupContractAddress } = config; const chain = createEthereumChain(rpcUrl, apiKey); @@ -33,7 +33,7 @@ export class ViemReader implements L1GlobalReader { }); this.rollupContract = getContract({ - address: getAddress(rollupContractAddress.toString()), + address: getAddress(rollupContractAddress!.toString()), abi: RollupAbi, publicClient: this.publicClient, }); diff --git a/yarn-project/sequencer-client/src/publisher/config.ts b/yarn-project/sequencer-client/src/publisher/config.ts index 5ec4cfde76c..5cbb92c25f6 100644 --- a/yarn-project/sequencer-client/src/publisher/config.ts +++ b/yarn-project/sequencer-client/src/publisher/config.ts @@ -1,9 +1,9 @@ -import { L1Addresses } from '@aztec/types'; +import { L1ContractAddresses } from '@aztec/ethereum'; /** * The configuration of the rollup transaction publisher. */ -export interface TxSenderConfig extends L1Addresses { +export interface TxSenderConfig extends L1ContractAddresses { /** * The private key to be used by the publisher. */ diff --git a/yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts b/yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts index d9e112e8d0a..49aee747ffd 100644 --- a/yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts +++ b/yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts @@ -45,8 +45,8 @@ export class ViemTxSender implements L1PublisherTxSender { rpcUrl, apiKey, publisherPrivateKey, - rollupContract: rollupContractAddress, - contractDeploymentEmitterContract: contractDeploymentEmitterContractAddress, + rollupAddress: rollupContractAddress, + contractDeploymentEmitterAddress: contractDeploymentEmitterContractAddress, } = config; const chain = createEthereumChain(rpcUrl, apiKey); this.account = privateKeyToAccount(publisherPrivateKey); @@ -62,13 +62,13 @@ export class ViemTxSender implements L1PublisherTxSender { }); this.rollupContract = getContract({ - address: getAddress(rollupContractAddress.toString()), + address: getAddress(rollupContractAddress!.toString()), abi: RollupAbi, publicClient: this.publicClient, walletClient, }); this.contractDeploymentEmitterContract = getContract({ - address: getAddress(contractDeploymentEmitterContractAddress.toString()), + address: getAddress(contractDeploymentEmitterContractAddress!.toString()), abi: ContractDeploymentEmitterAbi, publicClient: this.publicClient, walletClient, diff --git a/yarn-project/types/package.json b/yarn-project/types/package.json index 78977f0c5f4..78fa4e4fda9 100644 --- a/yarn-project/types/package.json +++ b/yarn-project/types/package.json @@ -31,6 +31,7 @@ }, "dependencies": { "@aztec/circuits.js": "workspace:^", + "@aztec/ethereum": "workspace:^", "@aztec/foundation": "workspace:^", "browserify-cipher": "^1.0.1", "lodash.clonedeep": "^4.5.0", diff --git a/yarn-project/aztec-node/src/rpc/http_rpc_client.ts b/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts similarity index 100% rename from yarn-project/aztec-node/src/rpc/http_rpc_client.ts rename to yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts diff --git a/yarn-project/aztec-node/src/rpc/http_rpc_server.ts b/yarn-project/types/src/aztec_node/rpc/http_rpc_server.ts similarity index 100% rename from yarn-project/aztec-node/src/rpc/http_rpc_server.ts rename to yarn-project/types/src/aztec_node/rpc/http_rpc_server.ts diff --git a/yarn-project/types/src/aztec_node/rpc/index.ts b/yarn-project/types/src/aztec_node/rpc/index.ts new file mode 100644 index 00000000000..b182baaccf1 --- /dev/null +++ b/yarn-project/types/src/aztec_node/rpc/index.ts @@ -0,0 +1,2 @@ +export * from './http_rpc_client.js'; +export * from './http_rpc_server.js'; diff --git a/yarn-project/types/src/index.ts b/yarn-project/types/src/index.ts index d064651f5ce..eb19075cb32 100644 --- a/yarn-project/types/src/index.ts +++ b/yarn-project/types/src/index.ts @@ -4,7 +4,6 @@ export * from './contract_database.js'; export * from './contract_data.js'; export * from './function_call.js'; export * from './keys/index.js'; -export * from './l1_addresses.js'; export * from './l1_to_l2_message.js'; export * from './l2_block.js'; export * from './l2_block_context.js'; @@ -22,4 +21,5 @@ export * from './packed_arguments.js'; export * from './interfaces/index.js'; export * from './sibling_path.js'; export * from './auth_witness.js'; +export * from './aztec_node/rpc/index.js'; export * from '@aztec/circuits.js/types'; diff --git a/yarn-project/types/src/interfaces/aztec-node.ts b/yarn-project/types/src/interfaces/aztec-node.ts index ed61b46a11d..a3ebcf30039 100644 --- a/yarn-project/types/src/interfaces/aztec-node.ts +++ b/yarn-project/types/src/interfaces/aztec-node.ts @@ -1,4 +1,5 @@ -import { EthAddress, HistoricBlockData } from '@aztec/circuits.js'; +import { HistoricBlockData } from '@aztec/circuits.js'; +import { L1ContractAddresses } from '@aztec/ethereum'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; @@ -62,10 +63,10 @@ export interface AztecNode extends DataCommitmentProvider, L1ToL2MessageProvider getChainId(): Promise; /** - * Method to fetch the rollup contract address at the base-layer. - * @returns The rollup address. + * Method to fetch the currently deployed l1 contract addresses. + * @returns The deployed contract addresses. */ - getRollupAddress(): Promise; + getL1ContractAddresses(): Promise; /** * Get the extended contract data for this contract. diff --git a/yarn-project/types/src/interfaces/node-info.ts b/yarn-project/types/src/interfaces/node-info.ts index 4037d4917ed..ad9a7e41c5f 100644 --- a/yarn-project/types/src/interfaces/node-info.ts +++ b/yarn-project/types/src/interfaces/node-info.ts @@ -1,4 +1,4 @@ -import { EthAddress } from '@aztec/circuits.js'; +import { L1ContractAddresses } from '@aztec/ethereum'; /** * Provides basic information about the running node. @@ -21,7 +21,7 @@ export type NodeInfo = { */ protocolVersion: number; /** - * The rollup contract address + * The deployed l1 contract addresses */ - rollupAddress: EthAddress; + l1ContractAddresses: L1ContractAddresses; }; diff --git a/yarn-project/types/src/l1_addresses.ts b/yarn-project/types/src/l1_addresses.ts deleted file mode 100644 index 3a9b9b77233..00000000000 --- a/yarn-project/types/src/l1_addresses.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { EthAddress } from '@aztec/foundation/eth-address'; - -/** - * Rollup contract addresses. - */ -export interface L1Addresses { - /** - * Rollup contract address. - */ - rollupContract: EthAddress; - - /** - * Inbox contract address. - */ - inboxContract: EthAddress; - - /** - * ContractDeploymentEmitter contract address. - */ - contractDeploymentEmitterContract: EthAddress; -} diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 1806b4a0e26..7de31f6b4c9 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -134,10 +134,14 @@ __metadata: "@types/memdown": ^3.0.0 "@types/node": ^18.7.23 jest: ^29.5.0 + koa: ^2.14.2 + koa-router: ^12.0.0 ts-jest: ^29.1.0 ts-node: ^10.9.1 tslib: ^2.4.0 typescript: ^5.0.4 + bin: + aztec-node: ./dest/bin/index.js languageName: unknown linkType: soft @@ -160,6 +164,8 @@ __metadata: "@types/node": ^18.7.23 jest: ^29.5.0 jest-mock-extended: ^3.0.3 + koa: ^2.14.2 + koa-router: ^12.0.0 lodash.omit: ^4.5.0 lodash.partition: ^4.6.0 lodash.times: ^4.3.2 @@ -341,6 +347,7 @@ __metadata: "@aztec/foundation": "workspace:^" "@aztec/noir-compiler": "workspace:^" "@aztec/noir-contracts": "workspace:^" + "@aztec/p2p": "workspace:^" "@aztec/types": "workspace:^" "@jest/globals": ^29.5.0 "@rushstack/eslint-patch": ^1.1.4 @@ -730,6 +737,7 @@ __metadata: resolution: "@aztec/types@workspace:types" dependencies: "@aztec/circuits.js": "workspace:^" + "@aztec/ethereum": "workspace:^" "@aztec/foundation": "workspace:^" "@jest/globals": ^29.5.0 "@rushstack/eslint-patch": ^1.1.4 From ed810e72b61526992a752301db21e97b0845b677 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sat, 23 Sep 2023 19:43:13 +0000 Subject: [PATCH 04/39] Fix --- yarn-project/types/tsconfig.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/yarn-project/types/tsconfig.json b/yarn-project/types/tsconfig.json index 82aa8cf4ccf..e7053342b34 100644 --- a/yarn-project/types/tsconfig.json +++ b/yarn-project/types/tsconfig.json @@ -9,6 +9,9 @@ { "path": "../circuits.js" }, + { + "path": "../ethereum" + }, { "path": "../foundation" } From 5e6e8b2c0d3b399f122fb7475d908e0ebd56c903 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sat, 23 Sep 2023 20:08:21 +0000 Subject: [PATCH 05/39] Merge fixes --- yarn-project/aztec-node/src/aztec-node/server.ts | 13 ------------- .../end-to-end/src/integration_l1_publisher.test.ts | 2 +- yarn-project/types/src/interfaces/aztec-node.ts | 6 ------ 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index e2414d0b227..54698df4f12 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -2,7 +2,6 @@ import { Archiver } from '@aztec/archiver'; import { CONTRACT_TREE_HEIGHT, CircuitsWasm, - EthAddress, Fr, GlobalVariables, HistoricBlockData, @@ -192,18 +191,6 @@ export class AztecNodeService implements AztecNode { return Promise.resolve(this.chainId); } - /** - * Method to fetch the rollup contract address at the base-layer. - * @returns The rollup address. - */ - public getRollupAddress(): Promise { - return this.blockSource.getRollupAddress(); - } - - public getRegistryAddress(): Promise { - return this.blockSource.getRegistryAddress(); - } - /** * Get the extended contract data for this contract. * @param contractAddress - The contract data address. diff --git a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts index 3cd0a590568..96525c35f6e 100644 --- a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts @@ -144,7 +144,7 @@ describe('L1Publisher integration', () => { rollupAddress: EthAddress.fromString(rollupAddress), inboxAddress: EthAddress.fromString(inboxAddress), contractDeploymentEmitterAddress: EthAddress.fromString(contractDeploymentEmitterAddress), - registryContract: EthAddress.fromString(registryAddress), + registryAddress: EthAddress.fromString(registryAddress), publisherPrivateKey: sequencerPK, l1BlockPublishRetryIntervalMS: 100, }); diff --git a/yarn-project/types/src/interfaces/aztec-node.ts b/yarn-project/types/src/interfaces/aztec-node.ts index 831401ae07a..a3ebcf30039 100644 --- a/yarn-project/types/src/interfaces/aztec-node.ts +++ b/yarn-project/types/src/interfaces/aztec-node.ts @@ -68,12 +68,6 @@ export interface AztecNode extends DataCommitmentProvider, L1ToL2MessageProvider */ getL1ContractAddresses(): Promise; - /** - * Method to fetch the registry contract address at the base-layer. - * @returns The registry address. - */ - getRegistryAddress(): Promise; - /** * Get the extended contract data for this contract. * @param contractAddress - The contract data address. From 3b9e08eda04bb30ed84c53fa18fce41a366e7283 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sat, 23 Sep 2023 20:29:57 +0000 Subject: [PATCH 06/39] Fixes --- .../test/aztec_rpc_server.test.ts | 5 + .../circuits.js/src/cbind/circuits.gen.ts | 109 +++++------------- 2 files changed, 33 insertions(+), 81 deletions(-) diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts index 840a1031849..4db4ffb1ebf 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts @@ -1,4 +1,5 @@ import { Grumpkin } from '@aztec/circuits.js/barretenberg'; +import { EthAddress } from '@aztec/foundation'; import { TestKeyStore } from '@aztec/key-store'; import { AztecNode, AztecRPC, L2Tx, mockTx } from '@aztec/types'; @@ -21,6 +22,10 @@ async function createAztecRpcServer(): Promise { node.getBlockNumber.mockResolvedValue(2); node.getVersion.mockResolvedValue(1); node.getChainId.mockResolvedValue(1); + const mockedContracts = { + rollupAddress: EthAddress.random(), + }; + node.getL1ContractAddresses.mockResolvedValue(mockedContracts); return new AztecRPCServer(keyStore, node, db, config); } diff --git a/yarn-project/circuits.js/src/cbind/circuits.gen.ts b/yarn-project/circuits.js/src/cbind/circuits.gen.ts index 73a0f908492..5dabbdef88f 100644 --- a/yarn-project/circuits.js/src/cbind/circuits.gen.ts +++ b/yarn-project/circuits.js/src/cbind/circuits.gen.ts @@ -16,7 +16,6 @@ import { CircuitError, CombinedAccumulatedData, CombinedConstantData, - CompleteAddress, ConstantRollupData, ContractDeploymentData, ContractStorageRead, @@ -65,70 +64,6 @@ import { toBuffer, } from './types.js'; -interface MsgpackPoint { - x: Buffer; - y: Buffer; -} - -export function toPoint(o: MsgpackPoint): Point { - if (o.x === undefined) { - throw new Error('Expected x in Point deserialization'); - } - if (o.y === undefined) { - throw new Error('Expected y in Point deserialization'); - } - return new Point(Fr.fromBuffer(o.x), Fr.fromBuffer(o.y)); -} - -export function fromPoint(o: Point): MsgpackPoint { - if (o.x === undefined) { - throw new Error('Expected x in Point serialization'); - } - if (o.y === undefined) { - throw new Error('Expected y in Point serialization'); - } - return { - x: toBuffer(o.x), - y: toBuffer(o.y), - }; -} - -interface MsgpackCompleteAddress { - address: Buffer; - public_key: MsgpackPoint; - partial_address: Buffer; -} - -export function toCompleteAddress(o: MsgpackCompleteAddress): CompleteAddress { - if (o.address === undefined) { - throw new Error('Expected address in CompleteAddress deserialization'); - } - if (o.public_key === undefined) { - throw new Error('Expected public_key in CompleteAddress deserialization'); - } - if (o.partial_address === undefined) { - throw new Error('Expected partial_address in CompleteAddress deserialization'); - } - return new CompleteAddress(Address.fromBuffer(o.address), toPoint(o.public_key), Fr.fromBuffer(o.partial_address)); -} - -export function fromCompleteAddress(o: CompleteAddress): MsgpackCompleteAddress { - if (o.address === undefined) { - throw new Error('Expected address in CompleteAddress serialization'); - } - if (o.publicKey === undefined) { - throw new Error('Expected publicKey in CompleteAddress serialization'); - } - if (o.partialAddress === undefined) { - throw new Error('Expected partialAddress in CompleteAddress serialization'); - } - return { - address: toBuffer(o.address), - public_key: fromPoint(o.publicKey), - partial_address: toBuffer(o.partialAddress), - }; -} - interface MsgpackGlobalVariables { chain_id: Buffer; version: Buffer; @@ -767,6 +702,34 @@ export function fromHistoricBlockData(o: HistoricBlockData): MsgpackHistoricBloc }; } +interface MsgpackPoint { + x: Buffer; + y: Buffer; +} + +export function toPoint(o: MsgpackPoint): Point { + if (o.x === undefined) { + throw new Error('Expected x in Point deserialization'); + } + if (o.y === undefined) { + throw new Error('Expected y in Point deserialization'); + } + return new Point(Fr.fromBuffer(o.x), Fr.fromBuffer(o.y)); +} + +export function fromPoint(o: Point): MsgpackPoint { + if (o.x === undefined) { + throw new Error('Expected x in Point serialization'); + } + if (o.y === undefined) { + throw new Error('Expected y in Point serialization'); + } + return { + x: toBuffer(o.x), + y: toBuffer(o.y), + }; +} + interface MsgpackContractDeploymentData { deployer_public_key: MsgpackPoint; constructor_vk_hash: Buffer; @@ -3125,22 +3088,6 @@ export function fromRootRollupPublicInputs(o: RootRollupPublicInputs): MsgpackRo }; } -export function abisComputeCompleteAddress( - wasm: IWasmModule, - arg0: Point, - arg1: Fr, - arg2: Fr, - arg3: Fr, -): CompleteAddress { - return toCompleteAddress( - callCbind(wasm, 'abis__compute_complete_address', [ - fromPoint(arg0), - toBuffer(arg1), - toBuffer(arg2), - toBuffer(arg3), - ]), - ); -} export function abisComputeCommitmentNonce(wasm: IWasmModule, arg0: Fr, arg1: Fr): Fr { return Fr.fromBuffer(callCbind(wasm, 'abis__compute_commitment_nonce', [toBuffer(arg0), toBuffer(arg1)])); } From 4518654dbebf1af34054a66b4fbc90b6a531fb9a Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sat, 23 Sep 2023 20:44:25 +0000 Subject: [PATCH 07/39] Fix --- .../circuits.js/src/cbind/circuits.gen.ts | 109 +++++++++++++----- 1 file changed, 81 insertions(+), 28 deletions(-) diff --git a/yarn-project/circuits.js/src/cbind/circuits.gen.ts b/yarn-project/circuits.js/src/cbind/circuits.gen.ts index 5dabbdef88f..73a0f908492 100644 --- a/yarn-project/circuits.js/src/cbind/circuits.gen.ts +++ b/yarn-project/circuits.js/src/cbind/circuits.gen.ts @@ -16,6 +16,7 @@ import { CircuitError, CombinedAccumulatedData, CombinedConstantData, + CompleteAddress, ConstantRollupData, ContractDeploymentData, ContractStorageRead, @@ -64,6 +65,70 @@ import { toBuffer, } from './types.js'; +interface MsgpackPoint { + x: Buffer; + y: Buffer; +} + +export function toPoint(o: MsgpackPoint): Point { + if (o.x === undefined) { + throw new Error('Expected x in Point deserialization'); + } + if (o.y === undefined) { + throw new Error('Expected y in Point deserialization'); + } + return new Point(Fr.fromBuffer(o.x), Fr.fromBuffer(o.y)); +} + +export function fromPoint(o: Point): MsgpackPoint { + if (o.x === undefined) { + throw new Error('Expected x in Point serialization'); + } + if (o.y === undefined) { + throw new Error('Expected y in Point serialization'); + } + return { + x: toBuffer(o.x), + y: toBuffer(o.y), + }; +} + +interface MsgpackCompleteAddress { + address: Buffer; + public_key: MsgpackPoint; + partial_address: Buffer; +} + +export function toCompleteAddress(o: MsgpackCompleteAddress): CompleteAddress { + if (o.address === undefined) { + throw new Error('Expected address in CompleteAddress deserialization'); + } + if (o.public_key === undefined) { + throw new Error('Expected public_key in CompleteAddress deserialization'); + } + if (o.partial_address === undefined) { + throw new Error('Expected partial_address in CompleteAddress deserialization'); + } + return new CompleteAddress(Address.fromBuffer(o.address), toPoint(o.public_key), Fr.fromBuffer(o.partial_address)); +} + +export function fromCompleteAddress(o: CompleteAddress): MsgpackCompleteAddress { + if (o.address === undefined) { + throw new Error('Expected address in CompleteAddress serialization'); + } + if (o.publicKey === undefined) { + throw new Error('Expected publicKey in CompleteAddress serialization'); + } + if (o.partialAddress === undefined) { + throw new Error('Expected partialAddress in CompleteAddress serialization'); + } + return { + address: toBuffer(o.address), + public_key: fromPoint(o.publicKey), + partial_address: toBuffer(o.partialAddress), + }; +} + interface MsgpackGlobalVariables { chain_id: Buffer; version: Buffer; @@ -702,34 +767,6 @@ export function fromHistoricBlockData(o: HistoricBlockData): MsgpackHistoricBloc }; } -interface MsgpackPoint { - x: Buffer; - y: Buffer; -} - -export function toPoint(o: MsgpackPoint): Point { - if (o.x === undefined) { - throw new Error('Expected x in Point deserialization'); - } - if (o.y === undefined) { - throw new Error('Expected y in Point deserialization'); - } - return new Point(Fr.fromBuffer(o.x), Fr.fromBuffer(o.y)); -} - -export function fromPoint(o: Point): MsgpackPoint { - if (o.x === undefined) { - throw new Error('Expected x in Point serialization'); - } - if (o.y === undefined) { - throw new Error('Expected y in Point serialization'); - } - return { - x: toBuffer(o.x), - y: toBuffer(o.y), - }; -} - interface MsgpackContractDeploymentData { deployer_public_key: MsgpackPoint; constructor_vk_hash: Buffer; @@ -3088,6 +3125,22 @@ export function fromRootRollupPublicInputs(o: RootRollupPublicInputs): MsgpackRo }; } +export function abisComputeCompleteAddress( + wasm: IWasmModule, + arg0: Point, + arg1: Fr, + arg2: Fr, + arg3: Fr, +): CompleteAddress { + return toCompleteAddress( + callCbind(wasm, 'abis__compute_complete_address', [ + fromPoint(arg0), + toBuffer(arg1), + toBuffer(arg2), + toBuffer(arg3), + ]), + ); +} export function abisComputeCommitmentNonce(wasm: IWasmModule, arg0: Fr, arg1: Fr): Fr { return Fr.fromBuffer(callCbind(wasm, 'abis__compute_commitment_nonce', [toBuffer(arg0), toBuffer(arg1)])); } From 1343d918a4a81826d1c5a5a1df65bfb866c1c28a Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sat, 23 Sep 2023 20:52:53 +0000 Subject: [PATCH 08/39] fix --- .../src/aztec_rpc_server/test/aztec_rpc_server.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts index 4db4ffb1ebf..07a065cb2a6 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts @@ -1,5 +1,5 @@ import { Grumpkin } from '@aztec/circuits.js/barretenberg'; -import { EthAddress } from '@aztec/foundation'; +import { EthAddress } from '@aztec/foundation/eth-address'; import { TestKeyStore } from '@aztec/key-store'; import { AztecNode, AztecRPC, L2Tx, mockTx } from '@aztec/types'; From f2821aa78e1375ca16c6a32089807cf7dfcc9b87 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sat, 23 Sep 2023 21:06:39 +0000 Subject: [PATCH 09/39] Update version --- yarn-project/foundation/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/foundation/package.json b/yarn-project/foundation/package.json index 3e8e058f4be..59e7f903efb 100644 --- a/yarn-project/foundation/package.json +++ b/yarn-project/foundation/package.json @@ -58,7 +58,7 @@ "debug": "^4.3.4", "detect-node": "^2.1.0", "hash.js": "^1.1.7", - "koa": "^2.14.1", + "koa": "^2.14.2", "koa-bodyparser": "^4.4.0", "koa-compress": "^5.1.0", "koa-router": "^12.0.0", From 0223f1696743a086c15ecad47e96b55d7cfc9f75 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sat, 23 Sep 2023 21:11:54 +0000 Subject: [PATCH 10/39] yarn lock --- yarn-project/yarn.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 7de31f6b4c9..aaef528528e 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -484,7 +484,7 @@ __metadata: eslint-plugin-tsdoc: ^0.2.17 hash.js: ^1.1.7 jest: ^29.5.0 - koa: ^2.14.1 + koa: ^2.14.2 koa-bodyparser: ^4.4.0 koa-compress: ^5.1.0 koa-router: ^12.0.0 @@ -13083,7 +13083,7 @@ __metadata: languageName: node linkType: hard -"koa@npm:^2.14.1, koa@npm:^2.14.2": +"koa@npm:^2.14.2": version: 2.14.2 resolution: "koa@npm:2.14.2" dependencies: From a11de0f94c93aea65247b4c1d1de558034c6f81c Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sat, 23 Sep 2023 21:29:04 +0000 Subject: [PATCH 11/39] Fix --- yarn-project/aztec-node/package.json | 1 + yarn-project/aztec-node/tsconfig.json | 3 +++ yarn-project/yarn.lock | 1 + 3 files changed, 5 insertions(+) diff --git a/yarn-project/aztec-node/package.json b/yarn-project/aztec-node/package.json index a63d72ab416..85df499f9ba 100644 --- a/yarn-project/aztec-node/package.json +++ b/yarn-project/aztec-node/package.json @@ -35,6 +35,7 @@ "dependencies": { "@aztec/archiver": "workspace:^", "@aztec/circuits.js": "workspace:^", + "@aztec/ethereum": "workspace:^", "@aztec/foundation": "workspace:^", "@aztec/l1-artifacts": "workspace:^", "@aztec/merkle-tree": "workspace:^", diff --git a/yarn-project/aztec-node/tsconfig.json b/yarn-project/aztec-node/tsconfig.json index 485500056f2..4cac8cc5046 100644 --- a/yarn-project/aztec-node/tsconfig.json +++ b/yarn-project/aztec-node/tsconfig.json @@ -32,6 +32,9 @@ }, { "path": "../world-state" + }, + { + "path": "../ethereum" } ], "include": ["src", "../types/src/aztec_node/rpc"] diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index aaef528528e..d7525884580 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -120,6 +120,7 @@ __metadata: dependencies: "@aztec/archiver": "workspace:^" "@aztec/circuits.js": "workspace:^" + "@aztec/ethereum": "workspace:^" "@aztec/foundation": "workspace:^" "@aztec/l1-artifacts": "workspace:^" "@aztec/merkle-tree": "workspace:^" From 395f24eed4c14040ca6482920fb07fedd415b53c Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sun, 24 Sep 2023 11:55:37 +0000 Subject: [PATCH 12/39] WIP --- yarn-project/aztec-node/tsconfig.json | 6 +-- yarn-project/aztec.js/package.json | 4 ++ yarn-project/aztec.js/webpack.config.js | 6 +++ yarn-project/yarn.lock | 66 ++++++++++++++++++++++++- 4 files changed, 77 insertions(+), 5 deletions(-) diff --git a/yarn-project/aztec-node/tsconfig.json b/yarn-project/aztec-node/tsconfig.json index 4cac8cc5046..2c9a7bdb1de 100644 --- a/yarn-project/aztec-node/tsconfig.json +++ b/yarn-project/aztec-node/tsconfig.json @@ -12,6 +12,9 @@ { "path": "../circuits.js" }, + { + "path": "../ethereum" + }, { "path": "../foundation" }, @@ -32,9 +35,6 @@ }, { "path": "../world-state" - }, - { - "path": "../ethereum" } ], "include": ["src", "../types/src/aztec_node/rpc"] diff --git a/yarn-project/aztec.js/package.json b/yarn-project/aztec.js/package.json index 12d26f8484b..d65c6b00ec1 100644 --- a/yarn-project/aztec.js/package.json +++ b/yarn-project/aztec.js/package.json @@ -54,13 +54,17 @@ "@types/lodash.partition": "^4.6.0", "@types/lodash.zip": "^4.2.7", "@types/node": "^18.7.23", + "assert": "^2.1.0", + "browserify-zlib": "^0.2.0", "buffer": "^6.0.3", "crypto-browserify": "^3.12.0", "jest": "^29.5.0", "jest-mock-extended": "^3.0.3", "process": "^0.11.10", + "querystring-es3": "^0.2.1", "resolve-typescript-plugin": "^2.0.1", "stream-browserify": "^3.0.0", + "stream-http": "^3.2.0", "ts-jest": "^29.1.0", "ts-loader": "^9.4.4", "ts-node": "^10.9.1", diff --git a/yarn-project/aztec.js/webpack.config.js b/yarn-project/aztec.js/webpack.config.js index 67005d8790a..cf722e339c2 100644 --- a/yarn-project/aztec.js/webpack.config.js +++ b/yarn-project/aztec.js/webpack.config.js @@ -62,13 +62,19 @@ export default { fs: false, path: false, url: false, + async_hooks: false, worker_threads: false, + net: false, events: require.resolve('events/'), buffer: require.resolve('buffer/'), util: require.resolve('util/'), stream: require.resolve('stream-browserify'), string_decoder: require.resolve('string_decoder/'), tty: require.resolve('tty-browserify'), + http: require.resolve('stream-http'), + zlib: require.resolve('browserify-zlib'), + assert: require.resolve('assert/'), + querystring: require.resolve('querystring-es3'), }, }, }; diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index d7525884580..17a4e96f238 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -244,6 +244,8 @@ __metadata: "@types/lodash.partition": ^4.6.0 "@types/lodash.zip": ^4.2.7 "@types/node": ^18.7.23 + assert: ^2.1.0 + browserify-zlib: ^0.2.0 buffer: ^6.0.3 crypto-browserify: ^3.12.0 jest: ^29.5.0 @@ -252,8 +254,10 @@ __metadata: lodash.partition: ^4.6.0 lodash.zip: ^4.2.0 process: ^0.11.10 + querystring-es3: ^0.2.1 resolve-typescript-plugin: ^2.0.1 stream-browserify: ^3.0.0 + stream-http: ^3.2.0 ts-jest: ^29.1.0 ts-loader: ^9.4.4 ts-node: ^10.9.1 @@ -6526,6 +6530,19 @@ __metadata: languageName: node linkType: hard +"assert@npm:^2.1.0": + version: 2.1.0 + resolution: "assert@npm:2.1.0" + dependencies: + call-bind: ^1.0.2 + is-nan: ^1.3.2 + object-is: ^1.1.5 + object.assign: ^4.1.4 + util: ^0.12.5 + checksum: 1ed1cabba9abe55f4109b3f7292b4e4f3cf2953aad8dc148c0b3c3bd676675c31b1abb32ef563b7d5a19d1715bf90d1e5f09fad2a4ee655199468902da80f7c2 + languageName: node + linkType: hard + "assertion-error@npm:^1.1.0": version: 1.1.0 resolution: "assertion-error@npm:1.1.0" @@ -7106,6 +7123,15 @@ __metadata: languageName: node linkType: hard +"browserify-zlib@npm:^0.2.0": + version: 0.2.0 + resolution: "browserify-zlib@npm:0.2.0" + dependencies: + pako: ~1.0.5 + checksum: 5cd9d6a665190fedb4a97dfbad8dabc8698d8a507298a03f42c734e96d58ca35d3c7d4085e283440bbca1cd1938cff85031728079bedb3345310c58ab1ec92d6 + languageName: node + linkType: hard + "browserslist@npm:^4.14.5, browserslist@npm:^4.21.10, browserslist@npm:^4.21.9": version: 4.21.10 resolution: "browserslist@npm:4.21.10" @@ -7222,6 +7248,13 @@ __metadata: languageName: node linkType: hard +"builtin-status-codes@npm:^3.0.0": + version: 3.0.0 + resolution: "builtin-status-codes@npm:3.0.0" + checksum: 1119429cf4b0d57bf76b248ad6f529167d343156ebbcc4d4e4ad600484f6bc63002595cbb61b67ad03ce55cd1d3c4711c03bbf198bf24653b8392420482f3773 + languageName: node + linkType: hard + "bundle-name@npm:^3.0.0": version: 3.0.0 resolution: "bundle-name@npm:3.0.0" @@ -11294,6 +11327,16 @@ __metadata: languageName: node linkType: hard +"is-nan@npm:^1.3.2": + version: 1.3.2 + resolution: "is-nan@npm:1.3.2" + dependencies: + call-bind: ^1.0.0 + define-properties: ^1.1.3 + checksum: 5dfadcef6ad12d3029d43643d9800adbba21cf3ce2ec849f734b0e14ee8da4070d82b15fdb35138716d02587c6578225b9a22779cab34888a139cc43e4e3610a + languageName: node + linkType: hard + "is-negative-zero@npm:^2.0.2": version: 2.0.2 resolution: "is-negative-zero@npm:2.0.2" @@ -14997,7 +15040,7 @@ __metadata: languageName: node linkType: hard -"pako@npm:~1.0.2": +"pako@npm:~1.0.2, pako@npm:~1.0.5": version: 1.0.11 resolution: "pako@npm:1.0.11" checksum: 1be2bfa1f807608c7538afa15d6f25baa523c30ec870a3228a89579e474a4d992f4293859524e46d5d87fd30fa17c5edf34dbef0671251d9749820b488660b16 @@ -15803,6 +15846,13 @@ __metadata: languageName: node linkType: hard +"querystring-es3@npm:^0.2.1": + version: 0.2.1 + resolution: "querystring-es3@npm:0.2.1" + checksum: 691e8d6b8b157e7cd49ae8e83fcf86de39ab3ba948c25abaa94fba84c0986c641aa2f597770848c64abce290ed17a39c9df6df737dfa7e87c3b63acc7d225d61 + languageName: node + linkType: hard + "queue-microtask@npm:^1.2.2, queue-microtask@npm:^1.2.3": version: 1.2.3 resolution: "queue-microtask@npm:1.2.3" @@ -17246,6 +17296,18 @@ __metadata: languageName: node linkType: hard +"stream-http@npm:^3.2.0": + version: 3.2.0 + resolution: "stream-http@npm:3.2.0" + dependencies: + builtin-status-codes: ^3.0.0 + inherits: ^2.0.4 + readable-stream: ^3.6.0 + xtend: ^4.0.2 + checksum: c9b78453aeb0c84fcc59555518ac62bacab9fa98e323e7b7666e5f9f58af8f3155e34481078509b02929bd1268427f664d186604cdccee95abc446099b339f83 + languageName: node + linkType: hard + "stream-shift@npm:^1.0.0": version: 1.0.1 resolution: "stream-shift@npm:1.0.1" @@ -19207,7 +19269,7 @@ __metadata: languageName: node linkType: hard -"xtend@npm:^4.0.1": +"xtend@npm:^4.0.1, xtend@npm:^4.0.2": version: 4.0.2 resolution: "xtend@npm:4.0.2" checksum: ac5dfa738b21f6e7f0dd6e65e1b3155036d68104e67e5d5d1bde74892e327d7e5636a076f625599dc394330a731861e87343ff184b0047fef1360a7ec0a5a36a From 6dfee3901303c8ec3907d26c7228e9040aad87ce Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sun, 24 Sep 2023 12:36:47 +0000 Subject: [PATCH 13/39] Fix --- yarn-project/archiver/src/archiver/archiver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 5bd51662d41..1c66150b8b6 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -105,8 +105,8 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource publicClient, config.rollupAddress!, config.inboxAddress!, - config.contractDeploymentEmitterAddress!, config.registryAddress!, + config.contractDeploymentEmitterAddress!, config.searchStartBlock, archiverStore, config.archiverPollingIntervalMS, From 7fbc059eb47b603433a52319b26f25148aa6b1a7 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sun, 24 Sep 2023 12:56:59 +0000 Subject: [PATCH 14/39] Fix --- yarn-project/end-to-end/src/e2e_p2p_network.test.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_p2p_network.test.ts b/yarn-project/end-to-end/src/e2e_p2p_network.test.ts index 3669dc33831..baa70687c27 100644 --- a/yarn-project/end-to-end/src/e2e_p2p_network.test.ts +++ b/yarn-project/end-to-end/src/e2e_p2p_network.test.ts @@ -57,11 +57,6 @@ describe('e2e_p2p_network', () => { const contexts: NodeContext[] = []; for (let i = 0; i < NUM_NODES; i++) { const node = await createNode(i + 1 + BOOT_NODE_TCP_PORT, bootstrapNodeAddress); - await new Promise(resolve => - setTimeout(() => { - resolve(); - }, 100000), - ); const context = await createAztecRpcServerAndSubmitTransactions(node, NUM_TXS_PER_NODE); contexts.push(context); } From 51ab998c75b4204b07d9a8aaf847898fce89deec Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sun, 24 Sep 2023 17:30:56 +0000 Subject: [PATCH 15/39] Serialise node info --- .../archiver/src/archiver/archiver.ts | 8 +- yarn-project/archiver/src/archiver/config.ts | 21 ++-- yarn-project/archiver/src/index.ts | 11 +-- .../aztec-node/src/aztec-node/server.ts | 12 +-- yarn-project/aztec-rpc/package.json | 3 +- .../aztec_rpc_http/aztec_rpc_http_server.ts | 4 +- .../src/aztec_rpc_server/aztec_rpc_server.ts | 8 +- .../test/aztec_rpc_server.test.ts | 5 +- yarn-project/aztec-rpc/src/bin/index.ts | 2 +- yarn-project/aztec-sandbox/src/sandbox.ts | 37 ++++---- yarn-project/aztec.js/src/aztec_rpc_client.ts | 3 +- .../aztec.js/src/contract/contract.test.ts | 18 ++-- yarn-project/cli/src/index.ts | 3 +- yarn-project/end-to-end/src/fixtures/utils.ts | 70 +++++++------- .../src/integration_l1_publisher.test.ts | 15 ++- .../ethereum/src/deploy_l1_contracts.ts | 4 +- .../ethereum/src/l1_contract_addresses.ts | 95 ++++++++++++++----- yarn-project/sequencer-client/src/config.ts | 16 ++-- .../src/global_variable_builder/config.ts | 7 +- .../global_variable_builder/viem-reader.ts | 4 +- .../sequencer-client/src/publisher/config.ts | 7 +- .../src/publisher/viem-tx-sender.ts | 12 +-- .../src/aztec_node/rpc/http_rpc_client.ts | 3 +- .../src/aztec_node/rpc/http_rpc_server.ts | 3 +- .../types/src/interfaces/aztec_rpc.ts | 2 +- yarn-project/types/src/interfaces/index.ts | 2 +- .../types/src/interfaces/node-info.ts | 27 ------ yarn-project/types/src/node-info/index.ts | 1 + yarn-project/types/src/node-info/node-info.ts | 72 ++++++++++++++ 29 files changed, 294 insertions(+), 181 deletions(-) delete mode 100644 yarn-project/types/src/interfaces/node-info.ts create mode 100644 yarn-project/types/src/node-info/index.ts create mode 100644 yarn-project/types/src/node-info/node-info.ts diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 1c66150b8b6..04531d92e48 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -103,10 +103,10 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource const archiverStore = new MemoryArchiverStore(); const archiver = new Archiver( publicClient, - config.rollupAddress!, - config.inboxAddress!, - config.registryAddress!, - config.contractDeploymentEmitterAddress!, + config.l1Contracts.rollupAddress!, + config.l1Contracts.inboxAddress!, + config.l1Contracts.registryAddress!, + config.l1Contracts.contractDeploymentEmitterAddress!, config.searchStartBlock, archiverStore, config.archiverPollingIntervalMS, diff --git a/yarn-project/archiver/src/archiver/config.ts b/yarn-project/archiver/src/archiver/config.ts index 252772dcf45..e4494a4945d 100644 --- a/yarn-project/archiver/src/archiver/config.ts +++ b/yarn-project/archiver/src/archiver/config.ts @@ -11,7 +11,7 @@ import { EthAddress } from '@aztec/foundation/eth-address'; /** * The archiver configuration. */ -export interface ArchiverConfig extends L1ContractAddresses { +export interface ArchiverConfig { /** * The url of the Ethereum RPC node. */ @@ -36,6 +36,11 @@ export interface ArchiverConfig extends L1ContractAddresses { * Eth block from which we start scanning for L2Blocks. */ searchStartBlock: number; + + /** + * The deployed L1 contract addresses + */ + l1Contracts: L1ContractAddresses; } /** @@ -55,17 +60,19 @@ export function getConfigEnvVars(): ArchiverConfig { INBOX_CONTRACT_ADDRESS, REGISTRY_CONTRACT_ADDRESS, } = process.env; + const addresses = new L1ContractAddresses( + ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, + REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO, + INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, + undefined, + CONTRACT_DEPLOYMENT_EMITTER_ADDRESS ? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS) : EthAddress.ZERO, + ); return { rpcUrl: ETHEREUM_HOST || 'http://127.0.0.1:8545/', archiverPollingIntervalMS: ARCHIVER_POLLING_INTERVAL_MS ? +ARCHIVER_POLLING_INTERVAL_MS : 1_000, viemPollingIntervalMS: ARCHIVER_VIEM_POLLING_INTERVAL_MS ? +ARCHIVER_VIEM_POLLING_INTERVAL_MS : 1_000, - rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, - inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, - registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO, - contractDeploymentEmitterAddress: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS - ? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS) - : EthAddress.ZERO, searchStartBlock: SEARCH_START_BLOCK ? +SEARCH_START_BLOCK : 0, apiKey: API_KEY, + l1Contracts: addresses, }; } diff --git a/yarn-project/archiver/src/index.ts b/yarn-project/archiver/src/index.ts index 8771028468f..1edb9b488f5 100644 --- a/yarn-project/archiver/src/index.ts +++ b/yarn-project/archiver/src/index.ts @@ -17,8 +17,7 @@ const log = createDebugLogger('aztec:archiver'); // eslint-disable-next-line require-await async function main() { const config = getConfigEnvVars(); - const { rpcUrl, rollupAddress, inboxAddress, registryAddress, contractDeploymentEmitterAddress, searchStartBlock } = - config; + const { rpcUrl, l1Contracts, searchStartBlock } = config; const publicClient = createPublicClient({ chain: localhost, @@ -29,10 +28,10 @@ async function main() { const archiver = new Archiver( publicClient, - rollupAddress!, - inboxAddress!, - registryAddress!, - contractDeploymentEmitterAddress!, + l1Contracts.rollupAddress!, + l1Contracts.inboxAddress!, + l1Contracts.registryAddress!, + l1Contracts.contractDeploymentEmitterAddress!, searchStartBlock, archiverStore, ); diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 54698df4f12..babb4be9e6f 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -84,7 +84,7 @@ export class AztecNodeService implements AztecNode { // we identify the P2P transaction protocol by using the rollup contract address. // this may well change in future - config.transactionProtocol = `/aztec/tx/${config.rollupAddress!.toString()}`; + config.transactionProtocol = `/aztec/tx/${config.l1Contracts.rollupAddress!.toString()}`; // create the tx pool and the p2p client, which will need the l2 block source const p2pClient = await createP2PClient(config, new InMemoryTxPool(), archiver); @@ -129,15 +129,7 @@ export class AztecNodeService implements AztecNode { * @returns - The currently deployed L1 contract addresses. */ public getL1ContractAddresses(): Promise { - const l1Contracts: L1ContractAddresses = { - rollupAddress: this.config.rollupAddress, - registryAddress: this.config.registryAddress, - inboxAddress: this.config.inboxAddress, - outboxAddress: this.config.outboxAddress, - contractDeploymentEmitterAddress: this.config.contractDeploymentEmitterAddress, - decoderHelperAddress: this.config.decoderHelperAddress, - }; - return Promise.resolve(l1Contracts); + return Promise.resolve(this.config.l1Contracts); } /** diff --git a/yarn-project/aztec-rpc/package.json b/yarn-project/aztec-rpc/package.json index d626c45994d..08d6776d525 100644 --- a/yarn-project/aztec-rpc/package.json +++ b/yarn-project/aztec-rpc/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "type": "module", "exports": "./dest/index.js", + "bin": "./dest/bin/index.js", "typedocOptions": { "entryPoints": [ "./src/index.ts" @@ -17,7 +18,7 @@ "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests", - "start:http": "DEBUG='aztec:*' && node ./dest/aztec_rpc_http/aztec_rpc_http_server.js" + "start": "DEBUG='aztec:*' && node ./dest/bin/index.js" }, "inherits": [ "../package.common.json" diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts b/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts index 93f9d3e6d3c..83fd26a1c27 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts @@ -1,3 +1,4 @@ +import { L1ContractAddresses } from '@aztec/ethereum'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr, GrumpkinScalar, Point } from '@aztec/foundation/fields'; import { JsonRpcServer } from '@aztec/foundation/json-rpc/server'; @@ -9,6 +10,7 @@ import { ExtendedContractData, L2Block, L2BlockL2Logs, + NodeInfo, NotePreimage, Tx, TxExecutionRequest, @@ -45,7 +47,7 @@ export function getHttpRpcServer(aztecRpcServer: AztecRPC): JsonRpcServer { AuthWitness, L2Block, }, - { Tx, TxReceipt, L2BlockL2Logs }, + { Tx, TxReceipt, L2BlockL2Logs, NodeInfo, L1ContractAddresses }, false, ['start', 'stop'], ); diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts index 17fecc1ea6b..830e7283d41 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts @@ -343,13 +343,7 @@ export class AztecRPCServer implements AztecRPC { this.node.getL1ContractAddresses(), ]); - return { - sandboxVersion: this.sandboxVersion, - compatibleNargoVersion: NoirVersion.tag, - chainId, - protocolVersion: version, - l1ContractAddresses: contractAddresses, - }; + return new NodeInfo(this.sandboxVersion, NoirVersion.tag, chainId, version, contractAddresses); } /** diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts index 07a065cb2a6..dbde0945ba8 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts @@ -1,4 +1,5 @@ import { Grumpkin } from '@aztec/circuits.js/barretenberg'; +import { L1ContractAddresses } from '@aztec/ethereum'; import { EthAddress } from '@aztec/foundation/eth-address'; import { TestKeyStore } from '@aztec/key-store'; import { AztecNode, AztecRPC, L2Tx, mockTx } from '@aztec/types'; @@ -22,9 +23,7 @@ async function createAztecRpcServer(): Promise { node.getBlockNumber.mockResolvedValue(2); node.getVersion.mockResolvedValue(1); node.getChainId.mockResolvedValue(1); - const mockedContracts = { - rollupAddress: EthAddress.random(), - }; + const mockedContracts = new L1ContractAddresses(EthAddress.random()); node.getL1ContractAddresses.mockResolvedValue(mockedContracts); return new AztecRPCServer(keyStore, node, db, config); diff --git a/yarn-project/aztec-rpc/src/bin/index.ts b/yarn-project/aztec-rpc/src/bin/index.ts index 80584d0a8e6..ce1baff58b5 100644 --- a/yarn-project/aztec-rpc/src/bin/index.ts +++ b/yarn-project/aztec-rpc/src/bin/index.ts @@ -6,7 +6,7 @@ import { startHttpRpcServer } from '../aztec_rpc_http/index.js'; import { createAztecRPCServer } from '../aztec_rpc_server/index.js'; import { getConfigEnvVars } from '../config/index.js'; -const { SERVER_PORT = 8080, AZTEC_NODE_RPC_URL = '' } = process.env; +const { SERVER_PORT = 8081, AZTEC_NODE_RPC_URL = '' } = process.env; const logger = createDebugLogger('aztec:rpc_server'); diff --git a/yarn-project/aztec-sandbox/src/sandbox.ts b/yarn-project/aztec-sandbox/src/sandbox.ts index 37e0ca068f3..91e3b2d7da3 100644 --- a/yarn-project/aztec-sandbox/src/sandbox.ts +++ b/yarn-project/aztec-sandbox/src/sandbox.ts @@ -1,7 +1,7 @@ #!/usr/bin/env -S node --no-warnings import { AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; import { EthAddress, createAztecRPCServer, getConfigEnvVars as getRpcConfigEnvVars } from '@aztec/aztec-rpc'; -import { DeployL1Contracts, createEthereumChain, deployL1Contracts } from '@aztec/ethereum'; +import { DeployL1Contracts, L1ContractAddresses, createEthereumChain, deployL1Contracts } from '@aztec/ethereum'; import { createDebugLogger } from '@aztec/foundation/log'; import { retryUntil } from '@aztec/foundation/retry'; @@ -42,15 +42,16 @@ function retrieveL1Contracts(config: AztecNodeConfig, account: Account): Promise chain: chain.chainInfo, transport: http(chain.rpcUrl), }); + const l1Contracts = new L1ContractAddresses( + config.l1Contracts.rollupAddress, + EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS), + config.l1Contracts.inboxAddress, + EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS), + config.l1Contracts.contractDeploymentEmitterAddress, + undefined, + ); const contracts: DeployL1Contracts = { - l1ContractAddresses: { - rollupAddress: config.rollupAddress, - registryAddress: EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS), - inboxAddress: config.inboxAddress, - outboxAddress: EthAddress.fromString(OUTBOX_CONTRACT_ADDRESS), - contractDeploymentEmitterAddress: config.contractDeploymentEmitterAddress, - decoderHelperAddress: undefined, - }, + l1ContractAddresses: l1Contracts, walletClient, publicClient, }; @@ -111,10 +112,11 @@ export async function createSandbox(config: Partial = {}) { deployL1Contracts(aztecNodeConfig.rpcUrl, hdAccount, localAnvil, logger), ); aztecNodeConfig.publisherPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`; - aztecNodeConfig.rollupAddress = l1Contracts.l1ContractAddresses.rollupAddress; - aztecNodeConfig.contractDeploymentEmitterAddress = l1Contracts.l1ContractAddresses.contractDeploymentEmitterAddress; - aztecNodeConfig.inboxAddress = l1Contracts.l1ContractAddresses.inboxAddress; - aztecNodeConfig.registryAddress = l1Contracts.l1ContractAddresses.registryAddress; + aztecNodeConfig.l1Contracts.rollupAddress = l1Contracts.l1ContractAddresses.rollupAddress; + aztecNodeConfig.l1Contracts.contractDeploymentEmitterAddress = + l1Contracts.l1ContractAddresses.contractDeploymentEmitterAddress; + aztecNodeConfig.l1Contracts.inboxAddress = l1Contracts.l1ContractAddresses.inboxAddress; + aztecNodeConfig.l1Contracts.registryAddress = l1Contracts.l1ContractAddresses.registryAddress; const node = await AztecNodeService.createAndSync(aztecNodeConfig); const rpcServer = await createAztecRPCServer(node, rpcConfig); @@ -140,10 +142,11 @@ export async function createP2PSandbox() { const l1Contracts = await waitThenDeploy(aztecNodeConfig, () => retrieveL1Contracts(aztecNodeConfig, privateKeyAccount), ); - aztecNodeConfig.rollupAddress = l1Contracts.l1ContractAddresses.rollupAddress; - aztecNodeConfig.contractDeploymentEmitterAddress = l1Contracts.l1ContractAddresses.contractDeploymentEmitterAddress; - aztecNodeConfig.inboxAddress = l1Contracts.l1ContractAddresses.inboxAddress; - aztecNodeConfig.registryAddress = l1Contracts.l1ContractAddresses.registryAddress; + aztecNodeConfig.l1Contracts.rollupAddress = l1Contracts.l1ContractAddresses.rollupAddress; + aztecNodeConfig.l1Contracts.contractDeploymentEmitterAddress = + l1Contracts.l1ContractAddresses.contractDeploymentEmitterAddress; + aztecNodeConfig.l1Contracts.inboxAddress = l1Contracts.l1ContractAddresses.inboxAddress; + aztecNodeConfig.l1Contracts.registryAddress = l1Contracts.l1ContractAddresses.registryAddress; const node = await AztecNodeService.createAndSync(aztecNodeConfig); const rpcServer = await createAztecRPCServer(node, rpcConfig); diff --git a/yarn-project/aztec.js/src/aztec_rpc_client.ts b/yarn-project/aztec.js/src/aztec_rpc_client.ts index fee9e8192e1..274cc98dd84 100644 --- a/yarn-project/aztec.js/src/aztec_rpc_client.ts +++ b/yarn-project/aztec.js/src/aztec_rpc_client.ts @@ -6,6 +6,7 @@ import { ContractData, ExtendedContractData, L2BlockL2Logs, + NodeInfo, NotePreimage, Tx, TxExecutionRequest, @@ -32,7 +33,7 @@ export const createAztecRpcClient = (url: string, fetch = makeFetch([1, 2, 3], t NotePreimage, AuthWitness, }, - { Tx, TxReceipt, L2BlockL2Logs }, + { Tx, TxReceipt, L2BlockL2Logs, NodeInfo }, false, fetch, ); diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index f8543d89003..bcdf3fc5a51 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -1,4 +1,5 @@ import { AztecAddress, CompleteAddress, EthAddress } from '@aztec/circuits.js'; +import { L1ContractAddresses } from '@aztec/ethereum'; import { ABIParameterVisibility, ContractAbi, FunctionType } from '@aztec/foundation/abi'; import { DeployedContract, @@ -28,16 +29,13 @@ describe('Contract Class', () => { const mockTxHash = { type: 'TxHash' } as any as TxHash; const mockTxReceipt = { type: 'TxReceipt' } as any as TxReceipt; const mockViewResultValue = 1; - const mockNodeInfo: NodeInfo = { - sandboxVersion: 'vx.x.x', - compatibleNargoVersion: 'vx.x.x-aztec.x', - protocolVersion: 1, - chainId: 2, - l1ContractAddresses: { - rollupAddress: EthAddress.random(), - registryAddress: EthAddress.random(), - }, - }; + const mockNodeInfo: NodeInfo = new NodeInfo( + 'vx.x.x', + 'vx.x.x-aztec.x', + 1, + 2, + new L1ContractAddresses(EthAddress.random(), EthAddress.random()), + ); const defaultAbi: ContractAbi = { name: 'FooContract', diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index ff351bcd506..ef38a25ef18 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -492,8 +492,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { .action(async options => { const client = await createCompatibleClient(options.rpcUrl, debugLogger); const info = await client.getNodeInfo(); - log(`\nNode Info:\n`); - Object.entries(info).map(([key, value]) => log(`${startCase(key)}: ${value}`)); + log(`\nNode Info:\n`, info.toReadableString()); }); program diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 2f8668d6342..ee52d114346 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -10,7 +10,6 @@ import { Wallet, createAccounts, createAztecRpcClient as createJsonRpcClient, - getL1ContractAddresses, getSandboxAccountsWallets, } from '@aztec/aztec.js'; import { CircuitsWasm, GeneratorIndex } from '@aztec/circuits.js'; @@ -85,33 +84,6 @@ const createRpcServer = async ( }; const setupL1Contracts = async (l1RpcUrl: string, account: HDAccount, logger: DebugLogger) => { - if (SANDBOX_URL) { - logger(`Retrieving contract addresses from ${SANDBOX_URL}`); - const l1Contracts = await getL1ContractAddresses(SANDBOX_URL); - - const walletClient = createWalletClient({ - account, - chain: localAnvil, - transport: http(l1RpcUrl), - }); - const publicClient = createPublicClient({ - chain: localAnvil, - transport: http(l1RpcUrl), - }); - const contracts: DeployL1Contracts = { - l1ContractAddresses: { - rollupAddress: l1Contracts.rollup, - registryAddress: l1Contracts.registry, - inboxAddress: l1Contracts.inbox, - outboxAddress: l1Contracts.outbox, - contractDeploymentEmitterAddress: l1Contracts.contractDeploymentEmitter, - decoderHelperAddress: l1Contracts.decoderHelper, - }, - walletClient, - publicClient, - }; - return contracts; - } return await deployL1Contracts(l1RpcUrl, account, localAnvil, logger); }; @@ -225,16 +197,50 @@ export async function setup( const logger = getLogger(); const hdAccount = mnemonicToAccount(MNEMONIC); + if (SANDBOX_URL) { + // we are setting up against the sandbox, l1 contracts are already deployed + const { aztecRpcServer, accounts, wallets } = await setupAztecRPCServer(numberOfAccounts, undefined, logger); + logger(`Retrieving contract addresses from ${SANDBOX_URL}`); + const l1Contracts = (await aztecRpcServer.getNodeInfo()).l1ContractAddresses; + + const walletClient = createWalletClient({ + account: hdAccount, + chain: localAnvil, + transport: http(config.rpcUrl), + }); + const publicClient = createPublicClient({ + chain: localAnvil, + transport: http(config.rpcUrl), + }); + const deployL1ContractsValues: DeployL1Contracts = { + l1ContractAddresses: l1Contracts, + walletClient, + publicClient, + }; + const cheatCodes = await CheatCodes.create(config.rpcUrl, aztecRpcServer!); + return { + aztecNode: undefined, + aztecRpcServer, + deployL1ContractsValues, + accounts, + config, + wallet: wallets[0], + wallets, + logger, + cheatCodes, + }; + } + const deployL1ContractsValues = await setupL1Contracts(config.rpcUrl, hdAccount, logger); const privKeyRaw = hdAccount.getHdKey().privateKey; const publisherPrivKey = privKeyRaw === null ? null : Buffer.from(privKeyRaw); config.publisherPrivateKey = `0x${publisherPrivKey!.toString('hex')}`; - config.rollupAddress = deployL1ContractsValues.l1ContractAddresses.rollupAddress; - config.registryAddress = deployL1ContractsValues.l1ContractAddresses.registryAddress; - config.contractDeploymentEmitterAddress = + config.l1Contracts.rollupAddress = deployL1ContractsValues.l1ContractAddresses.rollupAddress; + config.l1Contracts.registryAddress = deployL1ContractsValues.l1ContractAddresses.registryAddress; + config.l1Contracts.contractDeploymentEmitterAddress = deployL1ContractsValues.l1ContractAddresses.contractDeploymentEmitterAddress; - config.inboxAddress = deployL1ContractsValues.l1ContractAddresses.inboxAddress; + config.l1Contracts.inboxAddress = deployL1ContractsValues.l1ContractAddresses.inboxAddress; const aztecNode = await createAztecNode(config, logger); diff --git a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts index 96525c35f6e..75406d8f06d 100644 --- a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts @@ -13,7 +13,7 @@ import { range, } from '@aztec/circuits.js'; import { fr, makeNewContractData, makeProof } from '@aztec/circuits.js/factories'; -import { deployL1Contracts } from '@aztec/ethereum'; +import { L1ContractAddresses, deployL1Contracts } from '@aztec/ethereum'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; @@ -137,14 +137,19 @@ describe('L1Publisher integration', () => { l2Proof = Buffer.alloc(0); + const l1Contracts = new L1ContractAddresses( + EthAddress.fromString(rollupAddress), + EthAddress.fromString(registryAddress), + EthAddress.fromString(inboxAddress), + undefined, + EthAddress.fromString(contractDeploymentEmitterAddress), + ); + publisher = getL1Publisher({ rpcUrl: config.rpcUrl, apiKey: '', requiredConfirmations: 1, - rollupAddress: EthAddress.fromString(rollupAddress), - inboxAddress: EthAddress.fromString(inboxAddress), - contractDeploymentEmitterAddress: EthAddress.fromString(contractDeploymentEmitterAddress), - registryAddress: EthAddress.fromString(registryAddress), + l1Contracts, publisherPrivateKey: sequencerPK, l1BlockPublishRetryIntervalMS: 100, }); diff --git a/yarn-project/ethereum/src/deploy_l1_contracts.ts b/yarn-project/ethereum/src/deploy_l1_contracts.ts index 2cd08850ab8..744209d85f4 100644 --- a/yarn-project/ethereum/src/deploy_l1_contracts.ts +++ b/yarn-project/ethereum/src/deploy_l1_contracts.ts @@ -124,14 +124,14 @@ export const deployL1Contracts = async ( logger(`Deployed DecoderHelper at ${decoderHelperAddress}`); } - const l1Contracts = { + const l1Contracts = new L1ContractAddresses( rollupAddress, registryAddress, inboxAddress, outboxAddress, contractDeploymentEmitterAddress, decoderHelperAddress, - }; + ); return { walletClient, diff --git a/yarn-project/ethereum/src/l1_contract_addresses.ts b/yarn-project/ethereum/src/l1_contract_addresses.ts index 0812300de43..814a04ed5e8 100644 --- a/yarn-project/ethereum/src/l1_contract_addresses.ts +++ b/yarn-project/ethereum/src/l1_contract_addresses.ts @@ -3,29 +3,80 @@ import { EthAddress } from '@aztec/foundation/eth-address'; /** * Provides the directory of current L1 contract addresses */ -export type L1ContractAddresses = { - /** - * Rollup Address. - */ - rollupAddress?: EthAddress; - /** - * Registry Address. - */ - registryAddress?: EthAddress; - /** - * Inbox Address. - */ - inboxAddress?: EthAddress; - /** - * Outbox Address. - */ - outboxAddress?: EthAddress; +export class L1ContractAddresses { + constructor( + /** + * Rollup Address. + */ + public rollupAddress?: EthAddress, + /** + * Registry Address. + */ + public registryAddress?: EthAddress, + /** + * Inbox Address. + */ + public inboxAddress?: EthAddress, + /** + * Outbox Address. + */ + public outboxAddress?: EthAddress, + /** + * Data Emitter Address. + */ + public contractDeploymentEmitterAddress?: EthAddress, + /** + * Decoder Helper Address. + */ + public decoderHelperAddress?: EthAddress, + ) {} + /** - * Data Emitter Address. + * Serialize as JSON object. + * @returns The string. */ - contractDeploymentEmitterAddress?: EthAddress; + toJSON() { + const obj: { [key: string]: string } = {}; + if (this.rollupAddress) { + obj.rollupAddress = this.rollupAddress?.toString(); + } + if (this.registryAddress) { + obj.registryAddress = this.registryAddress?.toString(); + } + if (this.inboxAddress) { + obj.inboxAddress = this.inboxAddress?.toString(); + } + if (this.outboxAddress) { + obj.outboxAddress = this.outboxAddress?.toString(); + } + if (this.contractDeploymentEmitterAddress) { + obj.contractDeploymentEmitterAddress = this.contractDeploymentEmitterAddress?.toString(); + } + if (this.decoderHelperAddress) { + obj.decoderHelperAddress = this.decoderHelperAddress?.toString(); + } + return obj; + } + /** - * Decoder Helper Address. + * Deserializes from a JSON. + * @param obj - object to read from + * @returns The deserialized L1ContractAddresses object. */ - decoderHelperAddress?: EthAddress; -}; + static fromJSON(obj: any): L1ContractAddresses { + const fromString = (key: string) => { + if (obj[key]) { + return EthAddress.fromString(obj[key]); + } + return undefined; + }; + return new L1ContractAddresses( + fromString('rollupAddress'), + fromString('registryAddress'), + fromString('inboxAddress'), + fromString('outboxAddress'), + fromString('contractDeploymentEmitterAddress'), + fromString('decoderHelperAddress'), + ); + } +} diff --git a/yarn-project/sequencer-client/src/config.ts b/yarn-project/sequencer-client/src/config.ts index 0e5bb9a1dde..f7e74ce7d72 100644 --- a/yarn-project/sequencer-client/src/config.ts +++ b/yarn-project/sequencer-client/src/config.ts @@ -1,3 +1,4 @@ +import { L1ContractAddresses } from '@aztec/ethereum'; import { EthAddress } from '@aztec/foundation/eth-address'; import { GlobalReaderConfig } from './global_variable_builder/index.js'; @@ -36,6 +37,14 @@ export function getConfigEnvVars(): SequencerClientConfig { : '0000000000000000000000000000000000000000000000000000000000000000' }`; + const addresses = new L1ContractAddresses( + ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, + REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO, + INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, + undefined, + CONTRACT_DEPLOYMENT_EMITTER_ADDRESS ? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS) : EthAddress.ZERO, + ); + return { rpcUrl: ETHEREUM_HOST ? ETHEREUM_HOST : '', chainId: CHAIN_ID ? +CHAIN_ID : 31337, // 31337 is the default chain id for anvil @@ -44,12 +53,7 @@ export function getConfigEnvVars(): SequencerClientConfig { requiredConfirmations: SEQ_REQUIRED_CONFS ? +SEQ_REQUIRED_CONFS : 1, l1BlockPublishRetryIntervalMS: SEQ_PUBLISH_RETRY_INTERVAL_MS ? +SEQ_PUBLISH_RETRY_INTERVAL_MS : 1_000, transactionPollingIntervalMS: SEQ_TX_POLLING_INTERVAL_MS ? +SEQ_TX_POLLING_INTERVAL_MS : 1_000, - rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, - inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, - registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO, - contractDeploymentEmitterAddress: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS - ? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS) - : EthAddress.ZERO, + l1Contracts: addresses, publisherPrivateKey, maxTxsPerBlock: SEQ_MAX_TX_PER_BLOCK ? +SEQ_MAX_TX_PER_BLOCK : 32, minTxsPerBlock: SEQ_MIN_TX_PER_BLOCK ? +SEQ_MIN_TX_PER_BLOCK : 1, diff --git a/yarn-project/sequencer-client/src/global_variable_builder/config.ts b/yarn-project/sequencer-client/src/global_variable_builder/config.ts index 8d4682ee5b4..2884374561a 100644 --- a/yarn-project/sequencer-client/src/global_variable_builder/config.ts +++ b/yarn-project/sequencer-client/src/global_variable_builder/config.ts @@ -3,7 +3,7 @@ import { L1ContractAddresses } from '@aztec/ethereum'; /** * Configuration of the L1GlobalReader. */ -export interface GlobalReaderConfig extends L1ContractAddresses { +export interface GlobalReaderConfig { /** * The RPC Url of the ethereum host. */ @@ -12,4 +12,9 @@ export interface GlobalReaderConfig extends L1ContractAddresses { * The API key of the ethereum host. */ apiKey?: string; + + /** + * The deployed l1 contract addresses + */ + l1Contracts: L1ContractAddresses; } diff --git a/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts b/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts index 31640460664..6dd24c2c4b7 100644 --- a/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts +++ b/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts @@ -23,7 +23,7 @@ export class ViemReader implements L1GlobalReader { private publicClient: PublicClient; constructor(config: GlobalReaderConfig) { - const { rpcUrl, apiKey, rollupAddress: rollupContractAddress } = config; + const { rpcUrl, apiKey, l1Contracts } = config; const chain = createEthereumChain(rpcUrl, apiKey); @@ -33,7 +33,7 @@ export class ViemReader implements L1GlobalReader { }); this.rollupContract = getContract({ - address: getAddress(rollupContractAddress!.toString()), + address: getAddress(l1Contracts.rollupAddress!.toString()), abi: RollupAbi, publicClient: this.publicClient, }); diff --git a/yarn-project/sequencer-client/src/publisher/config.ts b/yarn-project/sequencer-client/src/publisher/config.ts index 5cbb92c25f6..96ad07bd6f1 100644 --- a/yarn-project/sequencer-client/src/publisher/config.ts +++ b/yarn-project/sequencer-client/src/publisher/config.ts @@ -3,7 +3,7 @@ import { L1ContractAddresses } from '@aztec/ethereum'; /** * The configuration of the rollup transaction publisher. */ -export interface TxSenderConfig extends L1ContractAddresses { +export interface TxSenderConfig { /** * The private key to be used by the publisher. */ @@ -23,6 +23,11 @@ export interface TxSenderConfig extends L1ContractAddresses { * The number of confirmations required. */ requiredConfirmations: number; + + /** + * The deployed l1 contract addresses + */ + l1Contracts: L1ContractAddresses; } /** diff --git a/yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts b/yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts index 49aee747ffd..106517c65fe 100644 --- a/yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts +++ b/yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts @@ -41,13 +41,7 @@ export class ViemTxSender implements L1PublisherTxSender { private account: PrivateKeyAccount; constructor(config: TxSenderConfig) { - const { - rpcUrl, - apiKey, - publisherPrivateKey, - rollupAddress: rollupContractAddress, - contractDeploymentEmitterAddress: contractDeploymentEmitterContractAddress, - } = config; + const { rpcUrl, apiKey, publisherPrivateKey, l1Contracts } = config; const chain = createEthereumChain(rpcUrl, apiKey); this.account = privateKeyToAccount(publisherPrivateKey); const walletClient = createWalletClient({ @@ -62,13 +56,13 @@ export class ViemTxSender implements L1PublisherTxSender { }); this.rollupContract = getContract({ - address: getAddress(rollupContractAddress!.toString()), + address: getAddress(l1Contracts.rollupAddress!.toString()), abi: RollupAbi, publicClient: this.publicClient, walletClient, }); this.contractDeploymentEmitterContract = getContract({ - address: getAddress(contractDeploymentEmitterContractAddress!.toString()), + address: getAddress(l1Contracts.contractDeploymentEmitterAddress!.toString()), abi: ContractDeploymentEmitterAbi, publicClient: this.publicClient, walletClient, diff --git a/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts b/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts index c19c787a35d..23c1216475e 100644 --- a/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts +++ b/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts @@ -1,4 +1,5 @@ import { HistoricBlockData } from '@aztec/circuits.js'; +import { L1ContractAddresses } from '@aztec/ethereum'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; @@ -15,7 +16,7 @@ export function createAztecNodeRpcClient(url: string, fetch = defaultFetch): Azt const rpcClient = createJsonRpcClient( url, { AztecAddress, EthAddress, ExtendedContractData, ContractData, Fr, HistoricBlockData, L2Block, L2Tx, TxHash }, - { Tx, L2BlockL2Logs }, + { Tx, L2BlockL2Logs, L1ContractAddresses }, false, fetch, ); diff --git a/yarn-project/types/src/aztec_node/rpc/http_rpc_server.ts b/yarn-project/types/src/aztec_node/rpc/http_rpc_server.ts index e1fb672952b..25b7c2205cf 100644 --- a/yarn-project/types/src/aztec_node/rpc/http_rpc_server.ts +++ b/yarn-project/types/src/aztec_node/rpc/http_rpc_server.ts @@ -1,4 +1,5 @@ import { HistoricBlockData } from '@aztec/circuits.js'; +import { L1ContractAddresses } from '@aztec/ethereum'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; @@ -14,7 +15,7 @@ export function createAztecNodeRpcServer(node: AztecNode) { const rpc = new JsonRpcServer( node, { AztecAddress, EthAddress, ExtendedContractData, ContractData, Fr, HistoricBlockData, L2Block, L2Tx, TxHash }, - { Tx, L2BlockL2Logs }, + { Tx, L2BlockL2Logs, L1ContractAddresses }, false, // disable methods not part of the AztecNode interface [ diff --git a/yarn-project/types/src/interfaces/aztec_rpc.ts b/yarn-project/types/src/interfaces/aztec_rpc.ts index d362e4fc728..9002aa89c0b 100644 --- a/yarn-project/types/src/interfaces/aztec_rpc.ts +++ b/yarn-project/types/src/interfaces/aztec_rpc.ts @@ -12,8 +12,8 @@ import { TxReceipt, } from '@aztec/types'; +import { NodeInfo } from '../node-info/node-info.js'; import { DeployedContract } from './deployed-contract.js'; -import { NodeInfo } from './node-info.js'; import { SyncStatus } from './sync-status.js'; // docs:start:rpc-interface diff --git a/yarn-project/types/src/interfaces/index.ts b/yarn-project/types/src/interfaces/index.ts index d53098ad94c..18df9e9e0ce 100644 --- a/yarn-project/types/src/interfaces/index.ts +++ b/yarn-project/types/src/interfaces/index.ts @@ -5,5 +5,5 @@ export * from './l1_l2_message_provider.js'; export * from './aztec-node.js'; export * from './aztec_rpc.js'; export * from './deployed-contract.js'; -export * from './node-info.js'; +export * from '../node-info/node-info.js'; export * from './sync-status.js'; diff --git a/yarn-project/types/src/interfaces/node-info.ts b/yarn-project/types/src/interfaces/node-info.ts deleted file mode 100644 index ad9a7e41c5f..00000000000 --- a/yarn-project/types/src/interfaces/node-info.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { L1ContractAddresses } from '@aztec/ethereum'; - -/** - * Provides basic information about the running node. - */ -export type NodeInfo = { - /** - * Version as tracked in the aztec-packages repository. - */ - sandboxVersion: string; - /** - * The nargo version compatible with this sandbox version - */ - compatibleNargoVersion: string; - /** - * L1 chain id. - */ - chainId: number; - /** - * Protocol version. - */ - protocolVersion: number; - /** - * The deployed l1 contract addresses - */ - l1ContractAddresses: L1ContractAddresses; -}; diff --git a/yarn-project/types/src/node-info/index.ts b/yarn-project/types/src/node-info/index.ts new file mode 100644 index 00000000000..46da7a96f90 --- /dev/null +++ b/yarn-project/types/src/node-info/index.ts @@ -0,0 +1 @@ +export * from './node-info.js'; diff --git a/yarn-project/types/src/node-info/node-info.ts b/yarn-project/types/src/node-info/node-info.ts new file mode 100644 index 00000000000..b71b8f7374e --- /dev/null +++ b/yarn-project/types/src/node-info/node-info.ts @@ -0,0 +1,72 @@ +import { L1ContractAddresses } from '@aztec/ethereum'; + +/** + * Provides basic information about the running node. + */ +export class NodeInfo { + constructor( + /** + * Version as tracked in the aztec-packages repository. + */ + public sandboxVersion: string, + /** + * The nargo version compatible with this sandbox version + */ + public compatibleNargoVersion: string, + /** + * L1 chain id. + */ + public chainId: number, + /** + * Protocol version. + */ + public protocolVersion: number, + /** + * The deployed l1 contract addresses + */ + public l1ContractAddresses: L1ContractAddresses, + ) {} + + /** + * Converts the Node Info to a readable string. + * @returns A readable string contaiing the node info. + */ + public toReadableString() { + return ` + Sandbox Version: ${this.sandboxVersion}\n + Compatible Nargo Version: ${this.compatibleNargoVersion}\n + Chain Id: ${this.chainId}\n + Protocol Version: ${this.protocolVersion}\n + Rollup Address: ${this.l1ContractAddresses.rollupAddress?.toString()} + `; + } + + /** + * Serialize as JSON object. + * @returns The string. + */ + toJSON() { + return { + sandboxVersion: this.sandboxVersion, + compatibleNargoVersion: this.compatibleNargoVersion, + chainId: this.chainId, + protocolVersion: this.protocolVersion, + l1ContractAddresses: this.l1ContractAddresses.toJSON(), + }; + } + + /** + * Deserializes from a JSON. + * @param obj - String to read from. + * @returns The deserialized NodeInfo object. + */ + static fromJSON(obj: any): NodeInfo { + return new NodeInfo( + obj.sandboxVersion, + obj.compatibleNargoVersion, + obj.chainId, + obj.protocolVersion, + L1ContractAddresses.fromJSON(obj.l1ContractAddresses), + ); + } +} From 236634eb0caa5b3badce33e3d64ab01dd3d5fbdb Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sun, 24 Sep 2023 18:28:45 +0000 Subject: [PATCH 16/39] Fixes --- yarn-project/aztec-rpc/package.json | 1 + yarn-project/aztec-rpc/tsconfig.json | 3 +++ yarn-project/cli/src/index.ts | 1 - yarn-project/yarn.lock | 3 +++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/yarn-project/aztec-rpc/package.json b/yarn-project/aztec-rpc/package.json index 08d6776d525..d2f53e0f4c7 100644 --- a/yarn-project/aztec-rpc/package.json +++ b/yarn-project/aztec-rpc/package.json @@ -34,6 +34,7 @@ "dependencies": { "@aztec/acir-simulator": "workspace:^", "@aztec/circuits.js": "workspace:^", + "@aztec/ethereum": "workspace:^", "@aztec/foundation": "workspace:^", "@aztec/key-store": "workspace:^", "@aztec/noir-compiler": "workspace:^", diff --git a/yarn-project/aztec-rpc/tsconfig.json b/yarn-project/aztec-rpc/tsconfig.json index 8f298d5722d..1190999ce69 100644 --- a/yarn-project/aztec-rpc/tsconfig.json +++ b/yarn-project/aztec-rpc/tsconfig.json @@ -12,6 +12,9 @@ { "path": "../circuits.js" }, + { + "path": "../ethereum" + }, { "path": "../foundation" }, diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index ef38a25ef18..b40857f9796 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -19,7 +19,6 @@ import { CompleteAddress, ContractData, L2BlockL2Logs, TxHash } from '@aztec/typ import { Command } from 'commander'; import { readFileSync } from 'fs'; -import startCase from 'lodash.startcase'; import { dirname, resolve } from 'path'; import { mnemonicToAccount } from 'viem/accounts'; diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 17a4e96f238..3b725697f54 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -152,6 +152,7 @@ __metadata: dependencies: "@aztec/acir-simulator": "workspace:^" "@aztec/circuits.js": "workspace:^" + "@aztec/ethereum": "workspace:^" "@aztec/foundation": "workspace:^" "@aztec/key-store": "workspace:^" "@aztec/noir-compiler": "workspace:^" @@ -176,6 +177,8 @@ __metadata: tslib: ^2.4.0 typescript: ^5.0.4 viem: ^1.2.5 + bin: + aztec-rpc: ./dest/bin/index.js languageName: unknown linkType: soft From ec7ef728b079a29712551acb363bdd6b8930e137 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Sun, 24 Sep 2023 18:30:39 +0000 Subject: [PATCH 17/39] Fixes --- yarn-project/aztec.js/package.json | 1 + yarn-project/aztec.js/tsconfig.json | 3 +++ yarn-project/yarn.lock | 1 + 3 files changed, 5 insertions(+) diff --git a/yarn-project/aztec.js/package.json b/yarn-project/aztec.js/package.json index d65c6b00ec1..b2d29580ad7 100644 --- a/yarn-project/aztec.js/package.json +++ b/yarn-project/aztec.js/package.json @@ -39,6 +39,7 @@ }, "dependencies": { "@aztec/circuits.js": "workspace:^", + "@aztec/ethereum": "workspace:^", "@aztec/foundation": "workspace:^", "@aztec/types": "workspace:^", "lodash.every": "^4.6.0", diff --git a/yarn-project/aztec.js/tsconfig.json b/yarn-project/aztec.js/tsconfig.json index 01c876235ce..7d0bb1110ba 100644 --- a/yarn-project/aztec.js/tsconfig.json +++ b/yarn-project/aztec.js/tsconfig.json @@ -9,6 +9,9 @@ { "path": "../circuits.js" }, + { + "path": "../ethereum" + }, { "path": "../foundation" }, diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 3b725697f54..9a0524457cd 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -238,6 +238,7 @@ __metadata: resolution: "@aztec/aztec.js@workspace:aztec.js" dependencies: "@aztec/circuits.js": "workspace:^" + "@aztec/ethereum": "workspace:^" "@aztec/foundation": "workspace:^" "@aztec/types": "workspace:^" "@jest/globals": ^29.5.0 From f65c0fa7421b2c82f404cc5e5d546c120c7232e3 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 25 Sep 2023 12:45:16 +0000 Subject: [PATCH 18/39] WIP --- yarn-project/aztec-node/Dockerfile | 4 +- yarn-project/aztec-node/src/bin/index.ts | 2 +- yarn-project/aztec-node/terraform/main.tf | 392 ++++++++++++++++++ .../aztec-node/terraform/variables.tf | 23 + yarn-project/aztec-rpc/src/bin/index.ts | 2 +- yarn-project/aztec-sandbox/Dockerfile | 1 - yarn-project/cli/src/index.ts | 3 +- yarn-project/p2p/src/bootstrap/bootstrap.ts | 2 +- 8 files changed, 422 insertions(+), 7 deletions(-) create mode 100644 yarn-project/aztec-node/terraform/main.tf create mode 100644 yarn-project/aztec-node/terraform/variables.tf diff --git a/yarn-project/aztec-node/Dockerfile b/yarn-project/aztec-node/Dockerfile index efb5e939ea5..5608c729449 100644 --- a/yarn-project/aztec-node/Dockerfile +++ b/yarn-project/aztec-node/Dockerfile @@ -10,6 +10,6 @@ RUN yarn cache clean RUN yarn workspaces focus --production > /dev/null FROM node:18-alpine -COPY --from=builder /usr/src/yarn-project/aztec-node /usr/src/yarn-project/aztec-node +COPY --from=builder /usr/src /usr/src WORKDIR /usr/src/yarn-project/aztec-node -ENTRYPOINT ["yarn"] \ No newline at end of file +ENTRYPOINT ["yarn", "start"] \ No newline at end of file diff --git a/yarn-project/aztec-node/src/bin/index.ts b/yarn-project/aztec-node/src/bin/index.ts index ddf361e2b71..6938c9317f6 100644 --- a/yarn-project/aztec-node/src/bin/index.ts +++ b/yarn-project/aztec-node/src/bin/index.ts @@ -8,7 +8,7 @@ import Router from 'koa-router'; import { AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '../index.js'; -const { SERVER_PORT = 8080, API_PREFIX = '' } = process.env; +const { SERVER_PORT = 8081, API_PREFIX = '' } = process.env; const logger = createDebugLogger('aztec:node'); diff --git a/yarn-project/aztec-node/terraform/main.tf b/yarn-project/aztec-node/terraform/main.tf new file mode 100644 index 00000000000..86591f1ff76 --- /dev/null +++ b/yarn-project/aztec-node/terraform/main.tf @@ -0,0 +1,392 @@ +terraform { + backend "s3" { + bucket = "aztec-terraform" + region = "eu-west-2" + } + required_providers { + aws = { + source = "hashicorp/aws" + version = "3.74.2" + } + } +} + +# Define provider and region +provider "aws" { + region = "eu-west-2" +} + +data "terraform_remote_state" "setup_iac" { + backend = "s3" + config = { + bucket = "aztec-terraform" + key = "setup/setup-iac" + region = "eu-west-2" + } +} + +data "terraform_remote_state" "aztec2_iac" { + backend = "s3" + config = { + bucket = "aztec-terraform" + key = "aztec2/iac" + region = "eu-west-2" + } +} + + +resource "aws_cloudwatch_log_group" "aztec_node_log_group" { + name = "/fargate/service/${var.DEPLOY_TAG}/aztec-node" + retention_in_days = 14 +} + +resource "aws_service_discovery_service" "aztec-node" { + name = "${var.DEPLOY_TAG}-aztec-node" + + health_check_custom_config { + failure_threshold = 1 + } + + dns_config { + namespace_id = data.terraform_remote_state.setup_iac.outputs.local_service_discovery_id + + dns_records { + ttl = 60 + type = "A" + } + + dns_records { + ttl = 60 + type = "SRV" + } + + routing_policy = "MULTIVALUE" + } + + # Terraform just fails if this resource changes and you have registered instances. + provisioner "local-exec" { + when = destroy + command = "${path.module}/../servicediscovery-drain.sh ${self.id}" + } +} + +# Define task definition and service. +resource "aws_ecs_task_definition" "aztec-node-1" { + family = "${var.DEPLOY_TAG}-aztec-node" + requires_compatibilities = ["FARGATE"] + network_mode = "awsvpc" + cpu = "2048" + memory = "4096" + execution_role_arn = data.terraform_remote_state.setup_iac.outputs.ecs_task_execution_role_arn + task_role_arn = data.terraform_remote_state.aztec2_iac.outputs.cloudwatch_logging_ecs_role_arn + + container_definitions = < _temp && mv _temp package.json; \ fi diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index b40857f9796..beea7b28db2 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -124,7 +124,8 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { .action(async () => { const peerId = await createLibP2PPeerId(); const exportedPeerId = Buffer.from(peerId.privateKey!).toString('hex'); - log(`\nPrivate key: ${exportedPeerId}`); + log(`Private key: ${exportedPeerId}`); + log(`Peer Id: ${peerId}`); }); program diff --git a/yarn-project/p2p/src/bootstrap/bootstrap.ts b/yarn-project/p2p/src/bootstrap/bootstrap.ts index d724f69617b..e57e9596263 100644 --- a/yarn-project/p2p/src/bootstrap/bootstrap.ts +++ b/yarn-project/p2p/src/bootstrap/bootstrap.ts @@ -38,7 +38,7 @@ export class BootstrapNode { peerId, addresses: { listen: [`/ip4/${tcpListenIp}/tcp/${tcpListenPort}`], - announce: [`/ip4/${announceHostname}/tcp/${announcePort ?? tcpListenPort}`], + announce: announceHostname ? [`/ip4/${announceHostname}/tcp/${announcePort ?? tcpListenPort}`] : [], }, transports: [tcp()], streamMuxers: [yamux(), mplex()], From 657b7807172e7b6d73b7fd9853d21d7dacb26e04 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 25 Sep 2023 15:27:46 +0000 Subject: [PATCH 19/39] WIP --- yarn-project/aztec-node/terraform/main.tf | 2 +- yarn-project/sequencer-client/src/sequencer/sequencer.ts | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/yarn-project/aztec-node/terraform/main.tf b/yarn-project/aztec-node/terraform/main.tf index 86591f1ff76..f616da8e39d 100644 --- a/yarn-project/aztec-node/terraform/main.tf +++ b/yarn-project/aztec-node/terraform/main.tf @@ -123,7 +123,7 @@ resource "aws_ecs_task_definition" "aztec-node-1" { }, { "name": "SEQ_MIN_TX_PER_BLOCK", - "value": "32" + "value": "4" }, { "name": "SEQ_PUBLISHER_PRIVATE_KEY", diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index e51a0d9595b..a04c7568907 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -32,8 +32,6 @@ export class Sequencer { private minTxsPerBLock = 1; private lastPublishedBlock = 0; private state = SequencerState.STOPPED; - private chainId: Fr; - private version: Fr; constructor( private publisher: L1Publisher, @@ -54,8 +52,6 @@ export class Sequencer { if (config.minTxsPerBlock) { this.minTxsPerBLock = config.minTxsPerBlock; } - this.chainId = new Fr(config.chainId); - this.version = new Fr(config.version); } /** From c9f7c27ecd0b0f4f5fa796c498e457d9cb8b09ca Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 25 Sep 2023 15:35:58 +0000 Subject: [PATCH 20/39] Remove old terraform --- iac/main.tf | 247 ----------------------------------------------- iac/variables.tf | 3 - 2 files changed, 250 deletions(-) delete mode 100644 iac/main.tf delete mode 100644 iac/variables.tf diff --git a/iac/main.tf b/iac/main.tf deleted file mode 100644 index 6eb2b99d13d..00000000000 --- a/iac/main.tf +++ /dev/null @@ -1,247 +0,0 @@ -terraform { - backend "s3" { - bucket = "aztec-terraform" - region = "eu-west-2" - } - required_providers { - aws = { - source = "hashicorp/aws" - version = "3.74.2" - } - } -} - -# Define provider and region -provider "aws" { - region = "eu-west-2" -} - -data "terraform_remote_state" "setup_iac" { - backend = "s3" - config = { - bucket = "aztec-terraform" - key = "setup/setup-iac" - region = "eu-west-2" - } -} - -data "terraform_remote_state" "aztec2_iac" { - backend = "s3" - config = { - bucket = "aztec-terraform" - key = "aztec2/iac" - region = "eu-west-2" - } -} - - -resource "aws_cloudwatch_log_group" "aztec_node_log_group" { - name = "/fargate/service/${var.DEPLOY_TAG}/aztec-node" - retention_in_days = 14 -} - -resource "aws_service_discovery_service" "aztec-node" { - name = "${var.DEPLOY_TAG}-aztec-node" - - health_check_custom_config { - failure_threshold = 1 - } - - dns_config { - namespace_id = data.terraform_remote_state.setup_iac.outputs.local_service_discovery_id - - dns_records { - ttl = 60 - type = "A" - } - - dns_records { - ttl = 60 - type = "SRV" - } - - routing_policy = "MULTIVALUE" - } - - # Terraform just fails if this resource changes and you have registered instances. - provisioner "local-exec" { - when = destroy - command = "${path.module}/../servicediscovery-drain.sh ${self.id}" - } -} - -# Define task definition and service. -resource "aws_ecs_task_definition" "aztec-node" { - family = "${var.DEPLOY_TAG}-aztec-node" - requires_compatibilities = ["FARGATE"] - network_mode = "awsvpc" - cpu = "2048" - memory = "4096" - execution_role_arn = data.terraform_remote_state.setup_iac.outputs.ecs_task_execution_role_arn - task_role_arn = data.terraform_remote_state.aztec2_iac.outputs.cloudwatch_logging_ecs_role_arn - - container_definitions = < Date: Mon, 25 Sep 2023 15:43:06 +0000 Subject: [PATCH 21/39] WIP --- yarn-project/aztec-node/tsconfig.json | 2 +- yarn-project/aztec-sandbox/src/bin/index.ts | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/yarn-project/aztec-node/tsconfig.json b/yarn-project/aztec-node/tsconfig.json index 2c9a7bdb1de..47573e6ef0d 100644 --- a/yarn-project/aztec-node/tsconfig.json +++ b/yarn-project/aztec-node/tsconfig.json @@ -37,5 +37,5 @@ "path": "../world-state" } ], - "include": ["src", "../types/src/aztec_node/rpc"] + "include": ["src"] } diff --git a/yarn-project/aztec-sandbox/src/bin/index.ts b/yarn-project/aztec-sandbox/src/bin/index.ts index 6e5dcdd4011..d8358595893 100644 --- a/yarn-project/aztec-sandbox/src/bin/index.ts +++ b/yarn-project/aztec-sandbox/src/bin/index.ts @@ -12,7 +12,7 @@ import { setupFileDebugLog } from '../logging.js'; import { createP2PSandbox, createSandbox } from '../sandbox.js'; import { github, splash } from '../splash.js'; -const { SERVER_PORT = 8080, P2P_ENABLED = 'false' } = process.env; +const { SERVER_PORT = 8080 } = process.env; const logger = createDebugLogger('aztec:sandbox'); @@ -51,12 +51,7 @@ async function main() { logger.info(`Setting up Aztec Sandbox v${version} (nargo ${NoirVersion.tag}), please stand by...`); - const p2pSandbox = P2P_ENABLED === 'true'; - if (p2pSandbox) { - logger.info(`Setting up Aztec Sandbox as P2P Node`); - } - - const { rpcServer, stop, accounts } = await createAndDeploySandbox(p2pSandbox); + const { rpcServer, stop, accounts } = await createAndDeploySandbox(false); const shutdown = async () => { logger.info('Shutting down...'); From 471159bfbbcb13a1f26f3613ed431d929efea59b Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 25 Sep 2023 16:02:01 +0000 Subject: [PATCH 22/39] Cleanup --- yarn-project/aztec-node/terraform/main.tf | 143 +----------------- yarn-project/aztec-sandbox/src/sandbox.ts | 12 +- yarn-project/end-to-end/package.json | 2 +- .../end-to-end/src/e2e_p2p_network.test.ts | 2 +- 4 files changed, 7 insertions(+), 152 deletions(-) diff --git a/yarn-project/aztec-node/terraform/main.tf b/yarn-project/aztec-node/terraform/main.tf index f616da8e39d..c425b64c69a 100644 --- a/yarn-project/aztec-node/terraform/main.tf +++ b/yarn-project/aztec-node/terraform/main.tf @@ -84,7 +84,7 @@ resource "aws_ecs_task_definition" "aztec-node-1" { [ { "name": "${var.DEPLOY_TAG}-aztec-node", - "image": "philwindle/aztec-node:latest", + "image": "aztecprotocol/aztec-node:latest", "essential": true, "memoryReservation": 3776, "portMappings": [ @@ -211,147 +211,6 @@ resource "aws_ecs_service" "aztec-node-1" { task_definition = aws_ecs_task_definition.aztec-node-1.family } -# # Define task definition and service. -# resource "aws_ecs_task_definition" "aztec-node-2" { -# family = "${var.DEPLOY_TAG}-aztec-node" -# requires_compatibilities = ["FARGATE"] -# network_mode = "awsvpc" -# cpu = "2048" -# memory = "4096" -# execution_role_arn = data.terraform_remote_state.setup_iac.outputs.ecs_task_execution_role_arn -# task_role_arn = data.terraform_remote_state.aztec2_iac.outputs.cloudwatch_logging_ecs_role_arn - -# container_definitions = < { p2pEnabled: true, tcpListenPort: BOOT_NODE_TCP_PORT, tcpListenIp: '0.0.0.0', - announceHostname: '10.1.0.15', + announceHostname: '127.0.0.1', announcePort: BOOT_NODE_TCP_PORT, peerIdPrivateKey: Buffer.from(peerId.privateKey!).toString('hex'), serverMode: false, From 1c9da9add2cfb5d89de5923ada6b124a31d8a909 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 10:00:43 +0000 Subject: [PATCH 23/39] Refactor --- .../archiver/src/archiver/archiver.ts | 8 +- yarn-project/archiver/src/archiver/config.ts | 18 ++- yarn-project/archiver/src/index.ts | 8 +- .../aztec-node/src/aztec-node/server.ts | 2 +- yarn-project/aztec-node/terraform/main.tf | 8 +- .../aztec-node/terraform/variables.tf | 5 + .../aztec_rpc_http/aztec_rpc_http_server.ts | 4 +- .../src/aztec_rpc_server/aztec_rpc_server.ts | 9 +- .../test/aztec_rpc_server.test.ts | 9 +- .../test/aztec_rpc_test_suite.ts | 2 +- yarn-project/aztec-sandbox/src/sandbox.ts | 62 +++++++-- yarn-project/aztec.js/src/aztec_rpc_client.ts | 2 +- .../aztec.js/src/contract/contract.test.ts | 22 +++- .../aztec.js/src/utils/cheat_codes.ts | 2 +- yarn-project/cli/package.json | 1 + yarn-project/cli/src/index.ts | 7 +- yarn-project/cli/src/utils.ts | 38 +++++- .../end-to-end/src/e2e_cheat_codes.test.ts | 2 +- yarn-project/end-to-end/src/fixtures/utils.ts | 64 +++++++++- .../src/integration_l1_publisher.test.ts | 28 ++-- yarn-project/ethereum/package.json | 1 - .../ethereum/src/deploy_l1_contracts.ts | 120 +++++++++++++----- .../ethereum/src/l1_contract_addresses.ts | 93 +++----------- yarn-project/sequencer-client/src/config.ts | 19 +-- .../global_variable_builder/viem-reader.ts | 2 +- .../src/publisher/viem-tx-sender.ts | 4 +- .../src/aztec_node/rpc/http_rpc_client.ts | 3 +- .../src/aztec_node/rpc/http_rpc_server.ts | 3 +- yarn-project/types/src/node-info/node-info.ts | 75 +++-------- yarn-project/yarn.lock | 2 +- 30 files changed, 366 insertions(+), 257 deletions(-) diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 04531d92e48..f6f25e59c64 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -103,10 +103,10 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource const archiverStore = new MemoryArchiverStore(); const archiver = new Archiver( publicClient, - config.l1Contracts.rollupAddress!, - config.l1Contracts.inboxAddress!, - config.l1Contracts.registryAddress!, - config.l1Contracts.contractDeploymentEmitterAddress!, + config.l1Contracts.rollupAddress, + config.l1Contracts.inboxAddress, + config.l1Contracts.registryAddress, + config.l1Contracts.contractDeploymentEmitterAddress, config.searchStartBlock, archiverStore, config.archiverPollingIntervalMS, diff --git a/yarn-project/archiver/src/archiver/config.ts b/yarn-project/archiver/src/archiver/config.ts index e4494a4945d..fbfa3a0ac9f 100644 --- a/yarn-project/archiver/src/archiver/config.ts +++ b/yarn-project/archiver/src/archiver/config.ts @@ -60,13 +60,17 @@ export function getConfigEnvVars(): ArchiverConfig { INBOX_CONTRACT_ADDRESS, REGISTRY_CONTRACT_ADDRESS, } = process.env; - const addresses = new L1ContractAddresses( - ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, - REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO, - INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, - undefined, - CONTRACT_DEPLOYMENT_EMITTER_ADDRESS ? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS) : EthAddress.ZERO, - ); + // Populate the relevant addresses for use by the archiver. + const addresses: L1ContractAddresses = { + rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, + registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO, + inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, + outboxAddress: EthAddress.ZERO, + contractDeploymentEmitterAddress: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS + ? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS) + : EthAddress.ZERO, + decoderHelperAddress: EthAddress.ZERO, + }; return { rpcUrl: ETHEREUM_HOST || 'http://127.0.0.1:8545/', archiverPollingIntervalMS: ARCHIVER_POLLING_INTERVAL_MS ? +ARCHIVER_POLLING_INTERVAL_MS : 1_000, diff --git a/yarn-project/archiver/src/index.ts b/yarn-project/archiver/src/index.ts index 1edb9b488f5..b327c5f9bb4 100644 --- a/yarn-project/archiver/src/index.ts +++ b/yarn-project/archiver/src/index.ts @@ -28,10 +28,10 @@ async function main() { const archiver = new Archiver( publicClient, - l1Contracts.rollupAddress!, - l1Contracts.inboxAddress!, - l1Contracts.registryAddress!, - l1Contracts.contractDeploymentEmitterAddress!, + l1Contracts.rollupAddress, + l1Contracts.inboxAddress, + l1Contracts.registryAddress, + l1Contracts.contractDeploymentEmitterAddress, searchStartBlock, archiverStore, ); diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index babb4be9e6f..4bb01c96111 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -84,7 +84,7 @@ export class AztecNodeService implements AztecNode { // we identify the P2P transaction protocol by using the rollup contract address. // this may well change in future - config.transactionProtocol = `/aztec/tx/${config.l1Contracts.rollupAddress!.toString()}`; + config.transactionProtocol = `/aztec/tx/${config.l1Contracts.rollupAddress.toString()}`; // create the tx pool and the p2p client, which will need the l2 block source const p2pClient = await createP2PClient(config, new InMemoryTxPool(), archiver); diff --git a/yarn-project/aztec-node/terraform/main.tf b/yarn-project/aztec-node/terraform/main.tf index c425b64c69a..c2518571d3b 100644 --- a/yarn-project/aztec-node/terraform/main.tf +++ b/yarn-project/aztec-node/terraform/main.tf @@ -153,17 +153,13 @@ resource "aws_ecs_task_definition" "aztec-node-1" { "name": "SEARCH_START_BLOCK", "value": "15918000" }, - { - "name": "P2P_TCP_LISTEN_PORT", - "value": "40401" - }, { "name": "P2P_ENABLED", "value": "false" }, { - "name": "BOOTSTRAP_NODES", - "value": "/ip4/44.201.46.76/tcp/40400/p2p/12D3KooWGBpbC6qQFkaCYphjNeY6sV99o4SnEWyTeBigoVriDn4D" + "name": "CHAIN_ID", + "value": "${var.CHAIN_ID}" } ], "logConfiguration": { diff --git a/yarn-project/aztec-node/terraform/variables.tf b/yarn-project/aztec-node/terraform/variables.tf index ea322d4d64a..c70372f6561 100644 --- a/yarn-project/aztec-node/terraform/variables.tf +++ b/yarn-project/aztec-node/terraform/variables.tf @@ -21,3 +21,8 @@ variable "INBOX_CONTRACT_ADDRESS" { variable "SEQ_PUBLISHER_PRIVATE_KEY" { type = string } + +variable "CHAIN_ID" { + type = string +} + \ No newline at end of file diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts b/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts index 83fd26a1c27..93f9d3e6d3c 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts @@ -1,4 +1,3 @@ -import { L1ContractAddresses } from '@aztec/ethereum'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr, GrumpkinScalar, Point } from '@aztec/foundation/fields'; import { JsonRpcServer } from '@aztec/foundation/json-rpc/server'; @@ -10,7 +9,6 @@ import { ExtendedContractData, L2Block, L2BlockL2Logs, - NodeInfo, NotePreimage, Tx, TxExecutionRequest, @@ -47,7 +45,7 @@ export function getHttpRpcServer(aztecRpcServer: AztecRPC): JsonRpcServer { AuthWitness, L2Block, }, - { Tx, TxReceipt, L2BlockL2Logs, NodeInfo, L1ContractAddresses }, + { Tx, TxReceipt, L2BlockL2Logs }, false, ['start', 'stop'], ); diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts index 830e7283d41..791018ae5f7 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts @@ -343,7 +343,14 @@ export class AztecRPCServer implements AztecRPC { this.node.getL1ContractAddresses(), ]); - return new NodeInfo(this.sandboxVersion, NoirVersion.tag, chainId, version, contractAddresses); + const nodeInfo: NodeInfo = { + sandboxVersion: this.sandboxVersion, + compatibleNargoVersion: NoirVersion.tag, + chainId, + protocolVersion: version, + l1ContractAddresses: contractAddresses, + }; + return nodeInfo; } /** diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts index dbde0945ba8..09aabfd08ed 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_server.test.ts @@ -23,7 +23,14 @@ async function createAztecRpcServer(): Promise { node.getBlockNumber.mockResolvedValue(2); node.getVersion.mockResolvedValue(1); node.getChainId.mockResolvedValue(1); - const mockedContracts = new L1ContractAddresses(EthAddress.random()); + const mockedContracts: L1ContractAddresses = { + rollupAddress: EthAddress.random(), + registryAddress: EthAddress.random(), + inboxAddress: EthAddress.random(), + outboxAddress: EthAddress.random(), + contractDeploymentEmitterAddress: EthAddress.random(), + decoderHelperAddress: EthAddress.random(), + }; node.getL1ContractAddresses.mockResolvedValue(mockedContracts); return new AztecRPCServer(keyStore, node, db, config); diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_test_suite.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_test_suite.ts index f9de03b941e..ce612295dfd 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_test_suite.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/test/aztec_rpc_test_suite.ts @@ -135,7 +135,7 @@ export const aztecRpcTestSuite = (testName: string, aztecRpcSetup: () => Promise const nodeInfo = await rpc.getNodeInfo(); expect(typeof nodeInfo.protocolVersion).toEqual('number'); expect(typeof nodeInfo.chainId).toEqual('number'); - expect(nodeInfo.l1ContractAddresses.rollupAddress!.toString()).toMatch(/0x[a-fA-F0-9]+/); + expect(nodeInfo.l1ContractAddresses.rollupAddress.toString()).toMatch(/0x[a-fA-F0-9]+/); }); // Note: Not testing `isGlobalStateSynchronized`, `isAccountStateSynchronized` and `getSyncStatus` as these methods diff --git a/yarn-project/aztec-sandbox/src/sandbox.ts b/yarn-project/aztec-sandbox/src/sandbox.ts index 270199b30d5..ce41e64b910 100644 --- a/yarn-project/aztec-sandbox/src/sandbox.ts +++ b/yarn-project/aztec-sandbox/src/sandbox.ts @@ -1,9 +1,28 @@ #!/usr/bin/env -S node --no-warnings import { AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; import { createAztecRPCServer, getConfigEnvVars as getRpcConfigEnvVars } from '@aztec/aztec-rpc'; -import { DeployL1Contracts, L1ContractAddresses, createEthereumChain, deployL1Contracts } from '@aztec/ethereum'; +import { + DeployL1Contracts, + L1ContractAddresses, + L1ContractArtifactsForDeployment, + createEthereumChain, + deployL1Contracts, +} from '@aztec/ethereum'; +import { EthAddress } from '@aztec/foundation/eth-address'; import { createDebugLogger } from '@aztec/foundation/log'; import { retryUntil } from '@aztec/foundation/retry'; +import { + ContractDeploymentEmitterAbi, + ContractDeploymentEmitterBytecode, + InboxAbi, + InboxBytecode, + OutboxAbi, + OutboxBytecode, + RegistryAbi, + RegistryBytecode, + RollupAbi, + RollupBytecode, +} from '@aztec/l1-artifacts'; import { Account, @@ -38,14 +57,14 @@ function retrieveL1Contracts(config: AztecNodeConfig, account: Account): Promise chain: chain.chainInfo, transport: http(chain.rpcUrl), }); - const l1Contracts = new L1ContractAddresses( - config.l1Contracts.rollupAddress, - config.l1Contracts.registryAddress, - config.l1Contracts.inboxAddress, - config.l1Contracts.outboxAddress, - config.l1Contracts.contractDeploymentEmitterAddress, - undefined, - ); + const l1Contracts: L1ContractAddresses = { + rollupAddress: config.l1Contracts.rollupAddress, + registryAddress: config.l1Contracts.registryAddress, + inboxAddress: config.l1Contracts.inboxAddress, + outboxAddress: config.l1Contracts.outboxAddress, + contractDeploymentEmitterAddress: config.l1Contracts.contractDeploymentEmitterAddress, + decoderHelperAddress: EthAddress.ZERO, + }; const contracts: DeployL1Contracts = { l1ContractAddresses: l1Contracts, walletClient, @@ -104,8 +123,31 @@ export async function createSandbox(config: Partial = {}) { const hdAccount = mnemonicToAccount(config.l1Mnemonic ?? MNEMONIC); const privKey = hdAccount.getHdKey().privateKey; + const l1Artifacts: L1ContractArtifactsForDeployment = { + contractDeploymentEmitter: { + contractAbi: ContractDeploymentEmitterAbi, + contractBytecode: ContractDeploymentEmitterBytecode, + }, + registry: { + contractAbi: RegistryAbi, + contractBytecode: RegistryBytecode, + }, + inbox: { + contractAbi: InboxAbi, + contractBytecode: InboxBytecode, + }, + outbox: { + contractAbi: OutboxAbi, + contractBytecode: OutboxBytecode, + }, + rollup: { + contractAbi: RollupAbi, + contractBytecode: RollupBytecode, + }, + }; + const l1Contracts = await waitThenDeploy(aztecNodeConfig, () => - deployL1Contracts(aztecNodeConfig.rpcUrl, hdAccount, localAnvil, logger), + deployL1Contracts(aztecNodeConfig.rpcUrl, hdAccount, localAnvil, logger, l1Artifacts), ); aztecNodeConfig.publisherPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`; aztecNodeConfig.l1Contracts.rollupAddress = l1Contracts.l1ContractAddresses.rollupAddress; diff --git a/yarn-project/aztec.js/src/aztec_rpc_client.ts b/yarn-project/aztec.js/src/aztec_rpc_client.ts index 274cc98dd84..707dcaa7f48 100644 --- a/yarn-project/aztec.js/src/aztec_rpc_client.ts +++ b/yarn-project/aztec.js/src/aztec_rpc_client.ts @@ -33,7 +33,7 @@ export const createAztecRpcClient = (url: string, fetch = makeFetch([1, 2, 3], t NotePreimage, AuthWitness, }, - { Tx, TxReceipt, L2BlockL2Logs, NodeInfo }, + { Tx, TxReceipt, L2BlockL2Logs }, false, fetch, ); diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index bcdf3fc5a51..6afe155e32e 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -29,13 +29,21 @@ describe('Contract Class', () => { const mockTxHash = { type: 'TxHash' } as any as TxHash; const mockTxReceipt = { type: 'TxReceipt' } as any as TxReceipt; const mockViewResultValue = 1; - const mockNodeInfo: NodeInfo = new NodeInfo( - 'vx.x.x', - 'vx.x.x-aztec.x', - 1, - 2, - new L1ContractAddresses(EthAddress.random(), EthAddress.random()), - ); + const l1Addresses: L1ContractAddresses = { + rollupAddress: EthAddress.random(), + registryAddress: EthAddress.random(), + inboxAddress: EthAddress.random(), + outboxAddress: EthAddress.random(), + contractDeploymentEmitterAddress: EthAddress.random(), + decoderHelperAddress: EthAddress.random(), + }; + const mockNodeInfo: NodeInfo = { + sandboxVersion: 'vx.x.x', + compatibleNargoVersion: 'vx.x.x-aztec.x', + chainId: 1, + protocolVersion: 2, + l1ContractAddresses: l1Addresses, + }; const defaultAbi: ContractAbi = { name: 'FooContract', diff --git a/yarn-project/aztec.js/src/utils/cheat_codes.ts b/yarn-project/aztec.js/src/utils/cheat_codes.ts index c1488f7c02a..dc0dfee94fb 100644 --- a/yarn-project/aztec.js/src/utils/cheat_codes.ts +++ b/yarn-project/aztec.js/src/utils/cheat_codes.ts @@ -257,7 +257,7 @@ export class AztecCheatCodes { * @param to - The timestamp to set the next block to (must be greater than current time) */ public async warp(to: number): Promise { - const rollupContract = (await this.aztecRpc.getNodeInfo()).l1ContractAddresses.rollupAddress!; + const rollupContract = (await this.aztecRpc.getNodeInfo()).l1ContractAddresses.rollupAddress; await this.eth.setNextBlockTimestamp(to); // also store this time on the rollup contract (slot 1 tracks `lastBlockTs`). // This is because when the sequencer executes public functions, it uses the timestamp stored in the rollup contract. diff --git a/yarn-project/cli/package.json b/yarn-project/cli/package.json index feb0477e29d..234dd698620 100644 --- a/yarn-project/cli/package.json +++ b/yarn-project/cli/package.json @@ -37,6 +37,7 @@ "@aztec/aztec.js": "workspace:^", "@aztec/ethereum": "workspace:^", "@aztec/foundation": "workspace:^", + "@aztec/l1-artifacts": "workspace:^", "@aztec/noir-compiler": "workspace:^", "@aztec/noir-contracts": "workspace:^", "@aztec/p2p": "workspace:^", diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index a7e0c55d1b4..3374e10a99c 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -510,7 +510,12 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { .action(async options => { const client = await createCompatibleClient(options.rpcUrl, debugLogger); const info = await client.getNodeInfo(); - log(`\nNode Info:\n`, info.toReadableString()); + log(`\nNode Info:\n`); + log(`Sandbox Version: ${info.sandboxVersion}\n`); + log(`Compatible Nargo Version: ${info.compatibleNargoVersion}\n`); + log(`Chain Id: ${info.chainId}\n`); + log(`Protocol Version: ${info.protocolVersion}\n`); + log(`Rollup Address: ${info.l1ContractAddresses.rollupAddress.toString()}`); }); program diff --git a/yarn-project/cli/src/utils.ts b/yarn-project/cli/src/utils.ts index aa8dc514ef6..7bb19a4f8db 100644 --- a/yarn-project/cli/src/utils.ts +++ b/yarn-project/cli/src/utils.ts @@ -1,7 +1,19 @@ import { AztecAddress, AztecRPC, Fr } from '@aztec/aztec.js'; -import { createEthereumChain, deployL1Contracts } from '@aztec/ethereum'; +import { L1ContractArtifactsForDeployment, createEthereumChain, deployL1Contracts } from '@aztec/ethereum'; import { ContractAbi } from '@aztec/foundation/abi'; import { DebugLogger, LogFn } from '@aztec/foundation/log'; +import { + ContractDeploymentEmitterAbi, + ContractDeploymentEmitterBytecode, + InboxAbi, + InboxBytecode, + OutboxAbi, + OutboxBytecode, + RegistryAbi, + RegistryBytecode, + RollupAbi, + RollupBytecode, +} from '@aztec/l1-artifacts'; import { InvalidArgumentError } from 'commander'; import fs from 'fs'; @@ -47,7 +59,29 @@ export async function deployAztecContracts( ) { const account = !privateKey ? mnemonicToAccount(mnemonic!) : privateKeyToAccount(`0x${privateKey}`); const chain = createEthereumChain(rpcUrl, apiKey); - return await deployL1Contracts(chain.rpcUrl, account, chain.chainInfo, debugLogger); + const l1Artifacts: L1ContractArtifactsForDeployment = { + contractDeploymentEmitter: { + contractAbi: ContractDeploymentEmitterAbi, + contractBytecode: ContractDeploymentEmitterBytecode, + }, + registry: { + contractAbi: RegistryAbi, + contractBytecode: RegistryBytecode, + }, + inbox: { + contractAbi: InboxAbi, + contractBytecode: InboxBytecode, + }, + outbox: { + contractAbi: OutboxAbi, + contractBytecode: OutboxBytecode, + }, + rollup: { + contractAbi: RollupAbi, + contractBytecode: RollupBytecode, + }, + }; + return await deployL1Contracts(chain.rpcUrl, account, chain.chainInfo, debugLogger, l1Artifacts); } /** diff --git a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts index 6b776447548..17ff6291d8b 100644 --- a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts +++ b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts @@ -25,7 +25,7 @@ describe('e2e_cheat_codes', () => { walletClient = deployL1ContractsValues.walletClient; publicClient = deployL1ContractsValues.publicClient; - rollupAddress = deployL1ContractsValues.l1ContractAddresses.rollupAddress!; + rollupAddress = deployL1ContractsValues.l1ContractAddresses.rollupAddress; }, 100_000); afterAll(async () => { diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index ee52d114346..4284d9a0675 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -14,11 +14,33 @@ import { } from '@aztec/aztec.js'; import { CircuitsWasm, GeneratorIndex } from '@aztec/circuits.js'; import { pedersenPlookupCompressWithHashIndex } from '@aztec/circuits.js/barretenberg'; -import { DeployL1Contracts, deployL1Contract, deployL1Contracts } from '@aztec/ethereum'; +import { + DeployL1Contracts, + L1ContractArtifactsForDeployment, + deployL1Contract, + deployL1Contracts, +} from '@aztec/ethereum'; import { Fr } from '@aztec/foundation/fields'; import { DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { retryUntil } from '@aztec/foundation/retry'; -import { PortalERC20Abi, PortalERC20Bytecode, TokenPortalAbi, TokenPortalBytecode } from '@aztec/l1-artifacts'; +import { + ContractDeploymentEmitterAbi, + ContractDeploymentEmitterBytecode, + DecoderHelperAbi, + DecoderHelperBytecode, + InboxAbi, + InboxBytecode, + OutboxAbi, + OutboxBytecode, + PortalERC20Abi, + PortalERC20Bytecode, + RegistryAbi, + RegistryBytecode, + RollupAbi, + RollupBytecode, + TokenPortalAbi, + TokenPortalBytecode, +} from '@aztec/l1-artifacts'; import { NonNativeTokenContract, TokenBridgeContract, TokenContract } from '@aztec/noir-contracts/types'; import { AztecRPC, L2BlockL2Logs, LogType, TxStatus } from '@aztec/types'; @@ -27,6 +49,7 @@ import { Chain, HDAccount, HttpTransport, + PrivateKeyAccount, PublicClient, WalletClient, createPublicClient, @@ -83,8 +106,41 @@ const createRpcServer = async ( return createAztecRPCServer(aztecNode, rpcConfig, {}, useLogSuffix); }; -const setupL1Contracts = async (l1RpcUrl: string, account: HDAccount, logger: DebugLogger) => { - return await deployL1Contracts(l1RpcUrl, account, localAnvil, logger); +export const setupL1Contracts = async ( + l1RpcUrl: string, + account: HDAccount | PrivateKeyAccount, + logger: DebugLogger, + deployDecoderHelper = false, +) => { + const l1Artifacts: L1ContractArtifactsForDeployment = { + contractDeploymentEmitter: { + contractAbi: ContractDeploymentEmitterAbi, + contractBytecode: ContractDeploymentEmitterBytecode, + }, + registry: { + contractAbi: RegistryAbi, + contractBytecode: RegistryBytecode, + }, + inbox: { + contractAbi: InboxAbi, + contractBytecode: InboxBytecode, + }, + outbox: { + contractAbi: OutboxAbi, + contractBytecode: OutboxBytecode, + }, + rollup: { + contractAbi: RollupAbi, + contractBytecode: RollupBytecode, + }, + }; + if (deployDecoderHelper) { + l1Artifacts.decoderHelper = { + contractAbi: DecoderHelperAbi, + contractBytecode: DecoderHelperBytecode, + }; + } + return await deployL1Contracts(l1RpcUrl, account, localAnvil, logger, l1Artifacts); }; /** diff --git a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts index 75406d8f06d..66e3f894f0d 100644 --- a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts @@ -13,8 +13,6 @@ import { range, } from '@aztec/circuits.js'; import { fr, makeNewContractData, makeProof } from '@aztec/circuits.js/factories'; -import { L1ContractAddresses, deployL1Contracts } from '@aztec/ethereum'; -import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; import { to2Fields } from '@aztec/foundation/serialize'; @@ -49,7 +47,7 @@ import { } from 'viem'; import { PrivateKeyAccount, privateKeyToAccount } from 'viem/accounts'; -import { localAnvil } from './fixtures/fixtures.js'; +import { setupL1Contracts } from './fixtures/utils.js'; // Accounts 4 and 5 of Anvil default startup with mnemonic: 'test test test test test test test test test test test junk' const sequencerPK = '0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a'; @@ -96,15 +94,15 @@ describe('L1Publisher integration', () => { l1ContractAddresses, walletClient, publicClient: publicClient_, - } = await deployL1Contracts(config.rpcUrl, deployerAccount, localAnvil, logger, true); + } = await setupL1Contracts(config.rpcUrl, deployerAccount, logger, true); publicClient = publicClient_; - rollupAddress = getAddress(l1ContractAddresses.rollupAddress!.toString()); - inboxAddress = getAddress(l1ContractAddresses.inboxAddress!.toString()); - outboxAddress = getAddress(l1ContractAddresses.outboxAddress!.toString()); - contractDeploymentEmitterAddress = getAddress(l1ContractAddresses.contractDeploymentEmitterAddress!.toString()); - decoderHelperAddress = getAddress(l1ContractAddresses.decoderHelperAddress!.toString()); - registryAddress = getAddress(l1ContractAddresses.registryAddress!.toString()); + rollupAddress = getAddress(l1ContractAddresses.rollupAddress.toString()); + inboxAddress = getAddress(l1ContractAddresses.inboxAddress.toString()); + outboxAddress = getAddress(l1ContractAddresses.outboxAddress.toString()); + contractDeploymentEmitterAddress = getAddress(l1ContractAddresses.contractDeploymentEmitterAddress.toString()); + decoderHelperAddress = getAddress(l1ContractAddresses.decoderHelperAddress.toString()); + registryAddress = getAddress(l1ContractAddresses.registryAddress.toString()); // Set up contract instances rollup = getContract({ @@ -137,19 +135,11 @@ describe('L1Publisher integration', () => { l2Proof = Buffer.alloc(0); - const l1Contracts = new L1ContractAddresses( - EthAddress.fromString(rollupAddress), - EthAddress.fromString(registryAddress), - EthAddress.fromString(inboxAddress), - undefined, - EthAddress.fromString(contractDeploymentEmitterAddress), - ); - publisher = getL1Publisher({ rpcUrl: config.rpcUrl, apiKey: '', requiredConfirmations: 1, - l1Contracts, + l1Contracts: l1ContractAddresses, publisherPrivateKey: sequencerPK, l1BlockPublishRetryIntervalMS: 100, }); diff --git a/yarn-project/ethereum/package.json b/yarn-project/ethereum/package.json index 90e6f2ee7c1..26fec484fa2 100644 --- a/yarn-project/ethereum/package.json +++ b/yarn-project/ethereum/package.json @@ -25,7 +25,6 @@ ], "dependencies": { "@aztec/foundation": "workspace:^", - "@aztec/l1-artifacts": "workspace:^", "dotenv": "^16.0.3", "tslib": "^2.4.0", "viem": "^1.2.5" diff --git a/yarn-project/ethereum/src/deploy_l1_contracts.ts b/yarn-project/ethereum/src/deploy_l1_contracts.ts index 744209d85f4..49933e2477c 100644 --- a/yarn-project/ethereum/src/deploy_l1_contracts.ts +++ b/yarn-project/ethereum/src/deploy_l1_contracts.ts @@ -1,19 +1,5 @@ import { EthAddress } from '@aztec/foundation/eth-address'; import { DebugLogger } from '@aztec/foundation/log'; -import { - ContractDeploymentEmitterAbi, - ContractDeploymentEmitterBytecode, - DecoderHelperAbi, - DecoderHelperBytecode, - InboxAbi, - InboxBytecode, - OutboxAbi, - OutboxBytecode, - RegistryAbi, - RegistryBytecode, - RollupAbi, - RollupBytecode, -} from '@aztec/l1-artifacts'; import type { Abi, Narrow } from 'abitype'; import { @@ -52,13 +38,57 @@ export type DeployL1Contracts = { l1ContractAddresses: L1ContractAddresses; }; +/** + * Contract artifacts + */ +export interface ContractArtifacts { + /** + * The conttract abi. + */ + contractAbi: Narrow; + /** + * The contract bytecode + */ + contractBytecode: Hex; +} + +/** + * All L1 Contract Artifacts for deployment + */ +export interface L1ContractArtifactsForDeployment { + /** + * Contract deployment emitter artifacts + */ + contractDeploymentEmitter: ContractArtifacts; + /** + * Decoder contract artifacts + */ + decoderHelper?: ContractArtifacts; + /** + * Inbox contract artifacts + */ + inbox: ContractArtifacts; + /** + * Outbox contract artifacts + */ + outbox: ContractArtifacts; + /** + * Registry contract artifacts + */ + registry: ContractArtifacts; + /** + * Rollup contract artifacts + */ + rollup: ContractArtifacts; +} + /** * Deploys the aztec L1 contracts; Rollup, Contract Deployment Emitter & (optionally) Decoder Helper. * @param rpcUrl - URL of the ETH RPC to use for deployment. * @param account - Private Key or HD Account that will deploy the contracts. * @param chain - The chain instance to deploy to. * @param logger - A logger object. - * @param deployDecoderHelper - Boolean, whether to deploy the decoder helper or not. + * @param contractsToDeploy - The set of L1 artifacts to be deployed * @returns A list of ETH addresses of the deployed contracts. */ export const deployL1Contracts = async ( @@ -66,7 +96,7 @@ export const deployL1Contracts = async ( account: HDAccount | PrivateKeyAccount, chain: Chain, logger: DebugLogger, - deployDecoderHelper = false, + contractsToDeploy: L1ContractArtifactsForDeployment, ): Promise => { logger('Deploying contracts...'); @@ -80,28 +110,45 @@ export const deployL1Contracts = async ( transport: http(rpcUrl), }); - const registryAddress = await deployL1Contract(walletClient, publicClient, RegistryAbi, RegistryBytecode); + const registryAddress = await deployL1Contract( + walletClient, + publicClient, + contractsToDeploy.registry.contractAbi, + contractsToDeploy.registry.contractBytecode, + ); logger(`Deployed Registry at ${registryAddress}`); - const inboxAddress = await deployL1Contract(walletClient, publicClient, InboxAbi, InboxBytecode, [ - getAddress(registryAddress.toString()), - ]); + const inboxAddress = await deployL1Contract( + walletClient, + publicClient, + contractsToDeploy.inbox.contractAbi, + contractsToDeploy.inbox.contractBytecode, + [getAddress(registryAddress.toString())], + ); logger(`Deployed Inbox at ${inboxAddress}`); - const outboxAddress = await deployL1Contract(walletClient, publicClient, OutboxAbi, OutboxBytecode, [ - getAddress(registryAddress.toString()), - ]); + const outboxAddress = await deployL1Contract( + walletClient, + publicClient, + contractsToDeploy.outbox.contractAbi, + contractsToDeploy.outbox.contractBytecode, + [getAddress(registryAddress.toString())], + ); logger(`Deployed Outbox at ${outboxAddress}`); - const rollupAddress = await deployL1Contract(walletClient, publicClient, RollupAbi, RollupBytecode, [ - getAddress(registryAddress.toString()), - ]); + const rollupAddress = await deployL1Contract( + walletClient, + publicClient, + contractsToDeploy.rollup.contractAbi, + contractsToDeploy.rollup.contractBytecode, + [getAddress(registryAddress.toString())], + ); logger(`Deployed Rollup at ${rollupAddress}`); // We need to call a function on the registry to set the various contract addresses. const registryContract = getContract({ address: getAddress(registryAddress.toString()), - abi: RegistryAbi, + abi: contractsToDeploy.registry.contractAbi, publicClient, walletClient, }); @@ -113,25 +160,30 @@ export const deployL1Contracts = async ( const contractDeploymentEmitterAddress = await deployL1Contract( walletClient, publicClient, - ContractDeploymentEmitterAbi, - ContractDeploymentEmitterBytecode, + contractsToDeploy.contractDeploymentEmitter.contractAbi, + contractsToDeploy.contractDeploymentEmitter.contractBytecode, ); logger(`Deployed contract deployment emitter at ${contractDeploymentEmitterAddress}`); let decoderHelperAddress: EthAddress | undefined; - if (deployDecoderHelper) { - decoderHelperAddress = await deployL1Contract(walletClient, publicClient, DecoderHelperAbi, DecoderHelperBytecode); + if (contractsToDeploy.decoderHelper) { + decoderHelperAddress = await deployL1Contract( + walletClient, + publicClient, + contractsToDeploy.decoderHelper.contractAbi, + contractsToDeploy.decoderHelper.contractBytecode, + ); logger(`Deployed DecoderHelper at ${decoderHelperAddress}`); } - const l1Contracts = new L1ContractAddresses( + const l1Contracts: L1ContractAddresses = { rollupAddress, registryAddress, inboxAddress, outboxAddress, contractDeploymentEmitterAddress, - decoderHelperAddress, - ); + decoderHelperAddress: decoderHelperAddress ?? EthAddress.ZERO, + }; return { walletClient, diff --git a/yarn-project/ethereum/src/l1_contract_addresses.ts b/yarn-project/ethereum/src/l1_contract_addresses.ts index 814a04ed5e8..a5021698775 100644 --- a/yarn-project/ethereum/src/l1_contract_addresses.ts +++ b/yarn-project/ethereum/src/l1_contract_addresses.ts @@ -3,80 +3,29 @@ import { EthAddress } from '@aztec/foundation/eth-address'; /** * Provides the directory of current L1 contract addresses */ -export class L1ContractAddresses { - constructor( - /** - * Rollup Address. - */ - public rollupAddress?: EthAddress, - /** - * Registry Address. - */ - public registryAddress?: EthAddress, - /** - * Inbox Address. - */ - public inboxAddress?: EthAddress, - /** - * Outbox Address. - */ - public outboxAddress?: EthAddress, - /** - * Data Emitter Address. - */ - public contractDeploymentEmitterAddress?: EthAddress, - /** - * Decoder Helper Address. - */ - public decoderHelperAddress?: EthAddress, - ) {} - +export interface L1ContractAddresses { /** - * Serialize as JSON object. - * @returns The string. + * Rollup Address. */ - toJSON() { - const obj: { [key: string]: string } = {}; - if (this.rollupAddress) { - obj.rollupAddress = this.rollupAddress?.toString(); - } - if (this.registryAddress) { - obj.registryAddress = this.registryAddress?.toString(); - } - if (this.inboxAddress) { - obj.inboxAddress = this.inboxAddress?.toString(); - } - if (this.outboxAddress) { - obj.outboxAddress = this.outboxAddress?.toString(); - } - if (this.contractDeploymentEmitterAddress) { - obj.contractDeploymentEmitterAddress = this.contractDeploymentEmitterAddress?.toString(); - } - if (this.decoderHelperAddress) { - obj.decoderHelperAddress = this.decoderHelperAddress?.toString(); - } - return obj; - } - + rollupAddress: EthAddress; + /** + * Registry Address. + */ + registryAddress: EthAddress; + /** + * Inbox Address. + */ + inboxAddress: EthAddress; + /** + * Outbox Address. + */ + outboxAddress: EthAddress; + /** + * Data Emitter Address. + */ + contractDeploymentEmitterAddress: EthAddress; /** - * Deserializes from a JSON. - * @param obj - object to read from - * @returns The deserialized L1ContractAddresses object. + * Decoder Helper Address. */ - static fromJSON(obj: any): L1ContractAddresses { - const fromString = (key: string) => { - if (obj[key]) { - return EthAddress.fromString(obj[key]); - } - return undefined; - }; - return new L1ContractAddresses( - fromString('rollupAddress'), - fromString('registryAddress'), - fromString('inboxAddress'), - fromString('outboxAddress'), - fromString('contractDeploymentEmitterAddress'), - fromString('decoderHelperAddress'), - ); - } + decoderHelperAddress: EthAddress; } diff --git a/yarn-project/sequencer-client/src/config.ts b/yarn-project/sequencer-client/src/config.ts index f7e74ce7d72..5a75ff6980b 100644 --- a/yarn-project/sequencer-client/src/config.ts +++ b/yarn-project/sequencer-client/src/config.ts @@ -36,14 +36,17 @@ export function getConfigEnvVars(): SequencerClientConfig { ? SEQ_PUBLISHER_PRIVATE_KEY.replace('0x', '') : '0000000000000000000000000000000000000000000000000000000000000000' }`; - - const addresses = new L1ContractAddresses( - ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, - REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO, - INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, - undefined, - CONTRACT_DEPLOYMENT_EMITTER_ADDRESS ? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS) : EthAddress.ZERO, - ); + // Populate the relevant addresses for use by the sequencer + const addresses: L1ContractAddresses = { + rollupAddress: ROLLUP_CONTRACT_ADDRESS ? EthAddress.fromString(ROLLUP_CONTRACT_ADDRESS) : EthAddress.ZERO, + registryAddress: REGISTRY_CONTRACT_ADDRESS ? EthAddress.fromString(REGISTRY_CONTRACT_ADDRESS) : EthAddress.ZERO, + inboxAddress: INBOX_CONTRACT_ADDRESS ? EthAddress.fromString(INBOX_CONTRACT_ADDRESS) : EthAddress.ZERO, + outboxAddress: EthAddress.ZERO, + contractDeploymentEmitterAddress: CONTRACT_DEPLOYMENT_EMITTER_ADDRESS + ? EthAddress.fromString(CONTRACT_DEPLOYMENT_EMITTER_ADDRESS) + : EthAddress.ZERO, + decoderHelperAddress: EthAddress.ZERO, + }; return { rpcUrl: ETHEREUM_HOST ? ETHEREUM_HOST : '', diff --git a/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts b/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts index 6dd24c2c4b7..ae0617d9fb3 100644 --- a/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts +++ b/yarn-project/sequencer-client/src/global_variable_builder/viem-reader.ts @@ -33,7 +33,7 @@ export class ViemReader implements L1GlobalReader { }); this.rollupContract = getContract({ - address: getAddress(l1Contracts.rollupAddress!.toString()), + address: getAddress(l1Contracts.rollupAddress.toString()), abi: RollupAbi, publicClient: this.publicClient, }); diff --git a/yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts b/yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts index 106517c65fe..2e087b723fe 100644 --- a/yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts +++ b/yarn-project/sequencer-client/src/publisher/viem-tx-sender.ts @@ -56,13 +56,13 @@ export class ViemTxSender implements L1PublisherTxSender { }); this.rollupContract = getContract({ - address: getAddress(l1Contracts.rollupAddress!.toString()), + address: getAddress(l1Contracts.rollupAddress.toString()), abi: RollupAbi, publicClient: this.publicClient, walletClient, }); this.contractDeploymentEmitterContract = getContract({ - address: getAddress(l1Contracts.contractDeploymentEmitterAddress!.toString()), + address: getAddress(l1Contracts.contractDeploymentEmitterAddress.toString()), abi: ContractDeploymentEmitterAbi, publicClient: this.publicClient, walletClient, diff --git a/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts b/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts index 23c1216475e..c19c787a35d 100644 --- a/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts +++ b/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts @@ -1,5 +1,4 @@ import { HistoricBlockData } from '@aztec/circuits.js'; -import { L1ContractAddresses } from '@aztec/ethereum'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; @@ -16,7 +15,7 @@ export function createAztecNodeRpcClient(url: string, fetch = defaultFetch): Azt const rpcClient = createJsonRpcClient( url, { AztecAddress, EthAddress, ExtendedContractData, ContractData, Fr, HistoricBlockData, L2Block, L2Tx, TxHash }, - { Tx, L2BlockL2Logs, L1ContractAddresses }, + { Tx, L2BlockL2Logs }, false, fetch, ); diff --git a/yarn-project/types/src/aztec_node/rpc/http_rpc_server.ts b/yarn-project/types/src/aztec_node/rpc/http_rpc_server.ts index 25b7c2205cf..e1fb672952b 100644 --- a/yarn-project/types/src/aztec_node/rpc/http_rpc_server.ts +++ b/yarn-project/types/src/aztec_node/rpc/http_rpc_server.ts @@ -1,5 +1,4 @@ import { HistoricBlockData } from '@aztec/circuits.js'; -import { L1ContractAddresses } from '@aztec/ethereum'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; @@ -15,7 +14,7 @@ export function createAztecNodeRpcServer(node: AztecNode) { const rpc = new JsonRpcServer( node, { AztecAddress, EthAddress, ExtendedContractData, ContractData, Fr, HistoricBlockData, L2Block, L2Tx, TxHash }, - { Tx, L2BlockL2Logs, L1ContractAddresses }, + { Tx, L2BlockL2Logs }, false, // disable methods not part of the AztecNode interface [ diff --git a/yarn-project/types/src/node-info/node-info.ts b/yarn-project/types/src/node-info/node-info.ts index b71b8f7374e..3aaef041da8 100644 --- a/yarn-project/types/src/node-info/node-info.ts +++ b/yarn-project/types/src/node-info/node-info.ts @@ -3,70 +3,25 @@ import { L1ContractAddresses } from '@aztec/ethereum'; /** * Provides basic information about the running node. */ -export class NodeInfo { - constructor( - /** - * Version as tracked in the aztec-packages repository. - */ - public sandboxVersion: string, - /** - * The nargo version compatible with this sandbox version - */ - public compatibleNargoVersion: string, - /** - * L1 chain id. - */ - public chainId: number, - /** - * Protocol version. - */ - public protocolVersion: number, - /** - * The deployed l1 contract addresses - */ - public l1ContractAddresses: L1ContractAddresses, - ) {} - +export interface NodeInfo { /** - * Converts the Node Info to a readable string. - * @returns A readable string contaiing the node info. + * Version as tracked in the aztec-packages repository. */ - public toReadableString() { - return ` - Sandbox Version: ${this.sandboxVersion}\n - Compatible Nargo Version: ${this.compatibleNargoVersion}\n - Chain Id: ${this.chainId}\n - Protocol Version: ${this.protocolVersion}\n - Rollup Address: ${this.l1ContractAddresses.rollupAddress?.toString()} - `; - } - + sandboxVersion: string; /** - * Serialize as JSON object. - * @returns The string. + * The nargo version compatible with this sandbox version */ - toJSON() { - return { - sandboxVersion: this.sandboxVersion, - compatibleNargoVersion: this.compatibleNargoVersion, - chainId: this.chainId, - protocolVersion: this.protocolVersion, - l1ContractAddresses: this.l1ContractAddresses.toJSON(), - }; - } - + compatibleNargoVersion: string; + /** + * L1 chain id. + */ + chainId: number; + /** + * Protocol version. + */ + protocolVersion: number; /** - * Deserializes from a JSON. - * @param obj - String to read from. - * @returns The deserialized NodeInfo object. + * The deployed l1 contract addresses */ - static fromJSON(obj: any): NodeInfo { - return new NodeInfo( - obj.sandboxVersion, - obj.compatibleNargoVersion, - obj.chainId, - obj.protocolVersion, - L1ContractAddresses.fromJSON(obj.l1ContractAddresses), - ); - } + l1ContractAddresses: L1ContractAddresses; } diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 25bee29a45c..7c343bc0d1c 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -354,6 +354,7 @@ __metadata: "@aztec/aztec.js": "workspace:^" "@aztec/ethereum": "workspace:^" "@aztec/foundation": "workspace:^" + "@aztec/l1-artifacts": "workspace:^" "@aztec/noir-compiler": "workspace:^" "@aztec/noir-contracts": "workspace:^" "@aztec/p2p": "workspace:^" @@ -444,7 +445,6 @@ __metadata: resolution: "@aztec/ethereum@workspace:ethereum" dependencies: "@aztec/foundation": "workspace:^" - "@aztec/l1-artifacts": "workspace:^" "@jest/globals": ^29.5.0 "@rushstack/eslint-patch": ^1.1.4 "@types/jest": ^29.5.0 From fa0b43af816f450d68f78cbde3c1035d4af65f68 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 10:08:53 +0000 Subject: [PATCH 24/39] Fixes --- yarn-project/aztec.js/package.json | 1 - yarn-project/aztec.js/src/aztec_rpc_client.ts | 1 - yarn-project/aztec.js/webpack.config.js | 2 +- yarn-project/cli/tsconfig.json | 3 +++ yarn-project/end-to-end/src/integration_l1_publisher.test.ts | 4 ---- yarn-project/ethereum/tsconfig.json | 3 --- 6 files changed, 4 insertions(+), 10 deletions(-) diff --git a/yarn-project/aztec.js/package.json b/yarn-project/aztec.js/package.json index b2d29580ad7..e39cb63e232 100644 --- a/yarn-project/aztec.js/package.json +++ b/yarn-project/aztec.js/package.json @@ -65,7 +65,6 @@ "querystring-es3": "^0.2.1", "resolve-typescript-plugin": "^2.0.1", "stream-browserify": "^3.0.0", - "stream-http": "^3.2.0", "ts-jest": "^29.1.0", "ts-loader": "^9.4.4", "ts-node": "^10.9.1", diff --git a/yarn-project/aztec.js/src/aztec_rpc_client.ts b/yarn-project/aztec.js/src/aztec_rpc_client.ts index 707dcaa7f48..fee9e8192e1 100644 --- a/yarn-project/aztec.js/src/aztec_rpc_client.ts +++ b/yarn-project/aztec.js/src/aztec_rpc_client.ts @@ -6,7 +6,6 @@ import { ContractData, ExtendedContractData, L2BlockL2Logs, - NodeInfo, NotePreimage, Tx, TxExecutionRequest, diff --git a/yarn-project/aztec.js/webpack.config.js b/yarn-project/aztec.js/webpack.config.js index cf722e339c2..a9a1cafc527 100644 --- a/yarn-project/aztec.js/webpack.config.js +++ b/yarn-project/aztec.js/webpack.config.js @@ -71,7 +71,7 @@ export default { stream: require.resolve('stream-browserify'), string_decoder: require.resolve('string_decoder/'), tty: require.resolve('tty-browserify'), - http: require.resolve('stream-http'), + //http: require.resolve('stream-http'), zlib: require.resolve('browserify-zlib'), assert: require.resolve('assert/'), querystring: require.resolve('querystring-es3'), diff --git a/yarn-project/cli/tsconfig.json b/yarn-project/cli/tsconfig.json index 28e130a83a3..42761fac561 100644 --- a/yarn-project/cli/tsconfig.json +++ b/yarn-project/cli/tsconfig.json @@ -15,6 +15,9 @@ { "path": "../foundation" }, + { + "path": "../l1-artifacts" + }, { "path": "../noir-compiler" }, diff --git a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts index 66e3f894f0d..7a70dff9c38 100644 --- a/yarn-project/end-to-end/src/integration_l1_publisher.test.ts +++ b/yarn-project/end-to-end/src/integration_l1_publisher.test.ts @@ -66,8 +66,6 @@ describe('L1Publisher integration', () => { let rollupAddress: Address; let inboxAddress: Address; let outboxAddress: Address; - let registryAddress: Address; - let contractDeploymentEmitterAddress: Address; let decoderHelperAddress: Address; let rollup: GetContractReturnType>; @@ -100,9 +98,7 @@ describe('L1Publisher integration', () => { rollupAddress = getAddress(l1ContractAddresses.rollupAddress.toString()); inboxAddress = getAddress(l1ContractAddresses.inboxAddress.toString()); outboxAddress = getAddress(l1ContractAddresses.outboxAddress.toString()); - contractDeploymentEmitterAddress = getAddress(l1ContractAddresses.contractDeploymentEmitterAddress.toString()); decoderHelperAddress = getAddress(l1ContractAddresses.decoderHelperAddress.toString()); - registryAddress = getAddress(l1ContractAddresses.registryAddress.toString()); // Set up contract instances rollup = getContract({ diff --git a/yarn-project/ethereum/tsconfig.json b/yarn-project/ethereum/tsconfig.json index b12e902b946..e92b3fa2562 100644 --- a/yarn-project/ethereum/tsconfig.json +++ b/yarn-project/ethereum/tsconfig.json @@ -9,9 +9,6 @@ "references": [ { "path": "../foundation" - }, - { - "path": "../l1-artifacts" } ] } From 604276687296f88505738eef25320f8364a4586a Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 10:10:15 +0000 Subject: [PATCH 25/39] Updated lock file --- yarn-project/yarn.lock | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 7c343bc0d1c..f8fadd2f2a0 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -261,7 +261,6 @@ __metadata: querystring-es3: ^0.2.1 resolve-typescript-plugin: ^2.0.1 stream-browserify: ^3.0.0 - stream-http: ^3.2.0 ts-jest: ^29.1.0 ts-loader: ^9.4.4 ts-node: ^10.9.1 @@ -7253,13 +7252,6 @@ __metadata: languageName: node linkType: hard -"builtin-status-codes@npm:^3.0.0": - version: 3.0.0 - resolution: "builtin-status-codes@npm:3.0.0" - checksum: 1119429cf4b0d57bf76b248ad6f529167d343156ebbcc4d4e4ad600484f6bc63002595cbb61b67ad03ce55cd1d3c4711c03bbf198bf24653b8392420482f3773 - languageName: node - linkType: hard - "bundle-name@npm:^3.0.0": version: 3.0.0 resolution: "bundle-name@npm:3.0.0" @@ -17302,18 +17294,6 @@ __metadata: languageName: node linkType: hard -"stream-http@npm:^3.2.0": - version: 3.2.0 - resolution: "stream-http@npm:3.2.0" - dependencies: - builtin-status-codes: ^3.0.0 - inherits: ^2.0.4 - readable-stream: ^3.6.0 - xtend: ^4.0.2 - checksum: c9b78453aeb0c84fcc59555518ac62bacab9fa98e323e7b7666e5f9f58af8f3155e34481078509b02929bd1268427f664d186604cdccee95abc446099b339f83 - languageName: node - linkType: hard - "stream-shift@npm:^1.0.0": version: 1.0.1 resolution: "stream-shift@npm:1.0.1" @@ -19275,7 +19255,7 @@ __metadata: languageName: node linkType: hard -"xtend@npm:^4.0.1, xtend@npm:^4.0.2": +"xtend@npm:^4.0.1": version: 4.0.2 resolution: "xtend@npm:4.0.2" checksum: ac5dfa738b21f6e7f0dd6e65e1b3155036d68104e67e5d5d1bde74892e327d7e5636a076f625599dc394330a731861e87343ff184b0047fef1360a7ec0a5a36a From a0ff7a367c49b9fc129db06c1e7c9af0a8bdfb2e Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 10:29:44 +0000 Subject: [PATCH 26/39] Fix --- yarn-project/aztec.js/webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/aztec.js/webpack.config.js b/yarn-project/aztec.js/webpack.config.js index a9a1cafc527..cf722e339c2 100644 --- a/yarn-project/aztec.js/webpack.config.js +++ b/yarn-project/aztec.js/webpack.config.js @@ -71,7 +71,7 @@ export default { stream: require.resolve('stream-browserify'), string_decoder: require.resolve('string_decoder/'), tty: require.resolve('tty-browserify'), - //http: require.resolve('stream-http'), + http: require.resolve('stream-http'), zlib: require.resolve('browserify-zlib'), assert: require.resolve('assert/'), querystring: require.resolve('querystring-es3'), From f14ead4b444cd691dede02d358870c49204e236a Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 10:42:33 +0000 Subject: [PATCH 27/39] Refactor --- .../rpc => aztec-node/src/aztec-node}/http_rpc_server.ts | 0 yarn-project/aztec-node/src/bin/index.ts | 3 +-- yarn-project/aztec-node/src/index.ts | 1 + yarn-project/aztec.js/package.json | 3 --- yarn-project/aztec.js/webpack.config.js | 6 ------ yarn-project/types/src/aztec_node/rpc/index.ts | 2 +- yarn-project/types/tsconfig.json | 2 +- 7 files changed, 4 insertions(+), 13 deletions(-) rename yarn-project/{types/src/aztec_node/rpc => aztec-node/src/aztec-node}/http_rpc_server.ts (100%) diff --git a/yarn-project/types/src/aztec_node/rpc/http_rpc_server.ts b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts similarity index 100% rename from yarn-project/types/src/aztec_node/rpc/http_rpc_server.ts rename to yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts diff --git a/yarn-project/aztec-node/src/bin/index.ts b/yarn-project/aztec-node/src/bin/index.ts index 6938c9317f6..6ee1ed4cd78 100644 --- a/yarn-project/aztec-node/src/bin/index.ts +++ b/yarn-project/aztec-node/src/bin/index.ts @@ -1,12 +1,11 @@ #!/usr/bin/env -S node --no-warnings import { createDebugLogger } from '@aztec/foundation/log'; -import { createAztecNodeRpcServer } from '@aztec/types'; import http from 'http'; import Koa from 'koa'; import Router from 'koa-router'; -import { AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '../index.js'; +import { AztecNodeConfig, AztecNodeService, getConfigEnvVars, createAztecNodeRpcServer } from '../index.js'; const { SERVER_PORT = 8081, API_PREFIX = '' } = process.env; diff --git a/yarn-project/aztec-node/src/index.ts b/yarn-project/aztec-node/src/index.ts index 30446306da6..0cf8b330148 100644 --- a/yarn-project/aztec-node/src/index.ts +++ b/yarn-project/aztec-node/src/index.ts @@ -1,2 +1,3 @@ export * from './aztec-node/config.js'; export * from './aztec-node/server.js'; +export * from './aztec-node/http_rpc_server.js'; diff --git a/yarn-project/aztec.js/package.json b/yarn-project/aztec.js/package.json index e39cb63e232..cf560b1b957 100644 --- a/yarn-project/aztec.js/package.json +++ b/yarn-project/aztec.js/package.json @@ -55,14 +55,11 @@ "@types/lodash.partition": "^4.6.0", "@types/lodash.zip": "^4.2.7", "@types/node": "^18.7.23", - "assert": "^2.1.0", - "browserify-zlib": "^0.2.0", "buffer": "^6.0.3", "crypto-browserify": "^3.12.0", "jest": "^29.5.0", "jest-mock-extended": "^3.0.3", "process": "^0.11.10", - "querystring-es3": "^0.2.1", "resolve-typescript-plugin": "^2.0.1", "stream-browserify": "^3.0.0", "ts-jest": "^29.1.0", diff --git a/yarn-project/aztec.js/webpack.config.js b/yarn-project/aztec.js/webpack.config.js index cf722e339c2..67005d8790a 100644 --- a/yarn-project/aztec.js/webpack.config.js +++ b/yarn-project/aztec.js/webpack.config.js @@ -62,19 +62,13 @@ export default { fs: false, path: false, url: false, - async_hooks: false, worker_threads: false, - net: false, events: require.resolve('events/'), buffer: require.resolve('buffer/'), util: require.resolve('util/'), stream: require.resolve('stream-browserify'), string_decoder: require.resolve('string_decoder/'), tty: require.resolve('tty-browserify'), - http: require.resolve('stream-http'), - zlib: require.resolve('browserify-zlib'), - assert: require.resolve('assert/'), - querystring: require.resolve('querystring-es3'), }, }, }; diff --git a/yarn-project/types/src/aztec_node/rpc/index.ts b/yarn-project/types/src/aztec_node/rpc/index.ts index b182baaccf1..f9efc92e98c 100644 --- a/yarn-project/types/src/aztec_node/rpc/index.ts +++ b/yarn-project/types/src/aztec_node/rpc/index.ts @@ -1,2 +1,2 @@ export * from './http_rpc_client.js'; -export * from './http_rpc_server.js'; +export * from '../../../../aztec-node/src/aztec-node/http_rpc_server.js'; diff --git a/yarn-project/types/tsconfig.json b/yarn-project/types/tsconfig.json index e7053342b34..200451c1eb3 100644 --- a/yarn-project/types/tsconfig.json +++ b/yarn-project/types/tsconfig.json @@ -16,5 +16,5 @@ "path": "../foundation" } ], - "include": ["src"] + "include": ["src", "../aztec-node/src/aztec-node/http_rpc_server.ts"] } From cd35270df154bb198fade6eb9b4ebe6bc59a1df7 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 10:51:04 +0000 Subject: [PATCH 28/39] Refactoring --- yarn-project/types/src/aztec_node/rpc/index.ts | 1 - yarn-project/types/src/interfaces/aztec_rpc.ts | 2 +- yarn-project/types/src/interfaces/index.ts | 2 +- yarn-project/types/src/{node-info => interfaces}/node-info.ts | 0 yarn-project/types/src/node-info/index.ts | 1 - yarn-project/types/tsconfig.json | 2 +- 6 files changed, 3 insertions(+), 5 deletions(-) rename yarn-project/types/src/{node-info => interfaces}/node-info.ts (100%) delete mode 100644 yarn-project/types/src/node-info/index.ts diff --git a/yarn-project/types/src/aztec_node/rpc/index.ts b/yarn-project/types/src/aztec_node/rpc/index.ts index f9efc92e98c..e8ecf164fef 100644 --- a/yarn-project/types/src/aztec_node/rpc/index.ts +++ b/yarn-project/types/src/aztec_node/rpc/index.ts @@ -1,2 +1 @@ export * from './http_rpc_client.js'; -export * from '../../../../aztec-node/src/aztec-node/http_rpc_server.js'; diff --git a/yarn-project/types/src/interfaces/aztec_rpc.ts b/yarn-project/types/src/interfaces/aztec_rpc.ts index ea78215dc3e..2c487329fac 100644 --- a/yarn-project/types/src/interfaces/aztec_rpc.ts +++ b/yarn-project/types/src/interfaces/aztec_rpc.ts @@ -12,8 +12,8 @@ import { TxReceipt, } from '@aztec/types'; -import { NodeInfo } from '../node-info/node-info.js'; import { DeployedContract } from './deployed-contract.js'; +import { NodeInfo } from './node-info.js'; import { SyncStatus } from './sync-status.js'; // docs:start:rpc-interface diff --git a/yarn-project/types/src/interfaces/index.ts b/yarn-project/types/src/interfaces/index.ts index 18df9e9e0ce..d53098ad94c 100644 --- a/yarn-project/types/src/interfaces/index.ts +++ b/yarn-project/types/src/interfaces/index.ts @@ -5,5 +5,5 @@ export * from './l1_l2_message_provider.js'; export * from './aztec-node.js'; export * from './aztec_rpc.js'; export * from './deployed-contract.js'; -export * from '../node-info/node-info.js'; +export * from './node-info.js'; export * from './sync-status.js'; diff --git a/yarn-project/types/src/node-info/node-info.ts b/yarn-project/types/src/interfaces/node-info.ts similarity index 100% rename from yarn-project/types/src/node-info/node-info.ts rename to yarn-project/types/src/interfaces/node-info.ts diff --git a/yarn-project/types/src/node-info/index.ts b/yarn-project/types/src/node-info/index.ts deleted file mode 100644 index 46da7a96f90..00000000000 --- a/yarn-project/types/src/node-info/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './node-info.js'; diff --git a/yarn-project/types/tsconfig.json b/yarn-project/types/tsconfig.json index 200451c1eb3..e7053342b34 100644 --- a/yarn-project/types/tsconfig.json +++ b/yarn-project/types/tsconfig.json @@ -16,5 +16,5 @@ "path": "../foundation" } ], - "include": ["src", "../aztec-node/src/aztec-node/http_rpc_server.ts"] + "include": ["src"] } From ee4f11db1858a8d8d70585c4c32de45d148fea61 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 10:56:49 +0000 Subject: [PATCH 29/39] Don't default the entrypoint command --- yarn-project/aztec-node/Dockerfile | 3 ++- yarn-project/ethereum/Dockerfile | 2 +- yarn-project/p2p-bootstrap/Dockerfile | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/yarn-project/aztec-node/Dockerfile b/yarn-project/aztec-node/Dockerfile index 5608c729449..f93944094e1 100644 --- a/yarn-project/aztec-node/Dockerfile +++ b/yarn-project/aztec-node/Dockerfile @@ -12,4 +12,5 @@ RUN yarn workspaces focus --production > /dev/null FROM node:18-alpine COPY --from=builder /usr/src /usr/src WORKDIR /usr/src/yarn-project/aztec-node -ENTRYPOINT ["yarn", "start"] \ No newline at end of file +ENTRYPOINT ["yarn"] +CMD [ "start" ] \ No newline at end of file diff --git a/yarn-project/ethereum/Dockerfile b/yarn-project/ethereum/Dockerfile index 206d5034cd6..35123be37db 100644 --- a/yarn-project/ethereum/Dockerfile +++ b/yarn-project/ethereum/Dockerfile @@ -14,4 +14,4 @@ RUN yarn workspaces focus --production > /dev/null FROM node:18-alpine COPY --from=builder /usr/src/ /usr/src/ WORKDIR /usr/src/yarn-project/ethereum -ENTRYPOINT ["yarn", "start"] \ No newline at end of file +ENTRYPOINT ["yarn"] \ No newline at end of file diff --git a/yarn-project/p2p-bootstrap/Dockerfile b/yarn-project/p2p-bootstrap/Dockerfile index da22a6c8198..a2c114481f1 100644 --- a/yarn-project/p2p-bootstrap/Dockerfile +++ b/yarn-project/p2p-bootstrap/Dockerfile @@ -14,4 +14,5 @@ RUN yarn workspaces focus --production > /dev/null FROM node:18-alpine COPY --from=builder /usr/src/ /usr/src/ WORKDIR /usr/src/yarn-project/p2p-bootstrap -ENTRYPOINT ["yarn", "start"] \ No newline at end of file +ENTRYPOINT ["yarn"] +CMD ["start"] \ No newline at end of file From fd346e85f9885bba6fbd1444109f2c1b626fbef8 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 14:24:45 +0000 Subject: [PATCH 30/39] Removed unused code --- yarn-project/aztec-sandbox/src/bin/index.ts | 24 +++++------------ yarn-project/aztec-sandbox/src/sandbox.ts | 30 --------------------- 2 files changed, 7 insertions(+), 47 deletions(-) diff --git a/yarn-project/aztec-sandbox/src/bin/index.ts b/yarn-project/aztec-sandbox/src/bin/index.ts index d8358595893..757eefa4261 100644 --- a/yarn-project/aztec-sandbox/src/bin/index.ts +++ b/yarn-project/aztec-sandbox/src/bin/index.ts @@ -9,7 +9,7 @@ import { readFileSync } from 'fs'; import { dirname, resolve } from 'path'; import { setupFileDebugLog } from '../logging.js'; -import { createP2PSandbox, createSandbox } from '../sandbox.js'; +import { createSandbox } from '../sandbox.js'; import { github, splash } from '../splash.js'; const { SERVER_PORT = 8080 } = process.env; @@ -18,26 +18,16 @@ const logger = createDebugLogger('aztec:sandbox'); /** * Creates the sandbox from provided config and deploys any initial L1 and L2 contracts - * @param isP2PSandbox - Flag indicating if this sandbox is to connect to a P2P network */ -async function createAndDeploySandbox(isP2PSandbox: boolean) { - if (!isP2PSandbox) { - const { l1Contracts, rpcServer, stop } = await createSandbox(); - logger.info('Setting up test accounts...'); - const accounts = await deployInitialSandboxAccounts(rpcServer); - return { - l1Contracts, - rpcServer, - stop, - accounts, - }; - } - const { l1Contracts, rpcServer, stop } = await createP2PSandbox(); +async function createAndDeploySandbox() { + const { l1Contracts, rpcServer, stop } = await createSandbox(); + logger.info('Setting up test accounts...'); + const accounts = await deployInitialSandboxAccounts(rpcServer); return { l1Contracts, rpcServer, stop, - accounts: [], + accounts, }; } @@ -51,7 +41,7 @@ async function main() { logger.info(`Setting up Aztec Sandbox v${version} (nargo ${NoirVersion.tag}), please stand by...`); - const { rpcServer, stop, accounts } = await createAndDeploySandbox(false); + const { rpcServer, stop, accounts } = await createAndDeploySandbox(); const shutdown = async () => { logger.info('Shutting down...'); diff --git a/yarn-project/aztec-sandbox/src/sandbox.ts b/yarn-project/aztec-sandbox/src/sandbox.ts index ce41e64b910..e1316e4137e 100644 --- a/yarn-project/aztec-sandbox/src/sandbox.ts +++ b/yarn-project/aztec-sandbox/src/sandbox.ts @@ -166,33 +166,3 @@ export async function createSandbox(config: Partial = {}) { return { node, rpcServer, l1Contracts, stop }; } - -/** - * Create and start a new Aztec Node and RPC Server. Designed for interaction with a node network. - * Does not start any HTTP services nor populate any initial accounts. - * @param config - Optional Sandbox settings. - */ -export async function createP2PSandbox() { - const aztecNodeConfig: AztecNodeConfig = { ...getConfigEnvVars() }; - const rpcConfig = getRpcConfigEnvVars(); - const privateKeyAccount = privateKeyToAccount(aztecNodeConfig.publisherPrivateKey); - - const l1Contracts = await waitThenDeploy(aztecNodeConfig, () => - retrieveL1Contracts(aztecNodeConfig, privateKeyAccount), - ); - aztecNodeConfig.l1Contracts.rollupAddress = l1Contracts.l1ContractAddresses.rollupAddress; - aztecNodeConfig.l1Contracts.contractDeploymentEmitterAddress = - l1Contracts.l1ContractAddresses.contractDeploymentEmitterAddress; - aztecNodeConfig.l1Contracts.inboxAddress = l1Contracts.l1ContractAddresses.inboxAddress; - aztecNodeConfig.l1Contracts.registryAddress = l1Contracts.l1ContractAddresses.registryAddress; - - const node = await AztecNodeService.createAndSync(aztecNodeConfig); - const rpcServer = await createAztecRPCServer(node, rpcConfig); - - const stop = async () => { - await rpcServer.stop(); - await node.stop(); - }; - - return { node, rpcServer, l1Contracts, stop }; -} From 90e3154f15ba3d4edf16d83cd5230414e5445020 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 14:42:10 +0000 Subject: [PATCH 31/39] Removed unused code --- yarn-project/aztec-sandbox/src/sandbox.ts | 45 +---------------------- 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/yarn-project/aztec-sandbox/src/sandbox.ts b/yarn-project/aztec-sandbox/src/sandbox.ts index e1316e4137e..c3ce6e177f4 100644 --- a/yarn-project/aztec-sandbox/src/sandbox.ts +++ b/yarn-project/aztec-sandbox/src/sandbox.ts @@ -3,12 +3,10 @@ import { AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/azte import { createAztecRPCServer, getConfigEnvVars as getRpcConfigEnvVars } from '@aztec/aztec-rpc'; import { DeployL1Contracts, - L1ContractAddresses, L1ContractArtifactsForDeployment, createEthereumChain, deployL1Contracts, } from '@aztec/ethereum'; -import { EthAddress } from '@aztec/foundation/eth-address'; import { createDebugLogger } from '@aztec/foundation/log'; import { retryUntil } from '@aztec/foundation/retry'; import { @@ -24,17 +22,8 @@ import { RollupBytecode, } from '@aztec/l1-artifacts'; -import { - Account, - Chain, - HDAccount, - HttpTransport, - createPublicClient, - createWalletClient, - http, - http as httpViemTransport, -} from 'viem'; -import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts'; +import { createPublicClient, http as httpViemTransport } from 'viem'; +import { mnemonicToAccount } from 'viem/accounts'; import { foundry } from 'viem/chains'; const { MNEMONIC = 'test test test test test test test test test test test junk' } = process.env; @@ -43,36 +32,6 @@ const logger = createDebugLogger('aztec:sandbox'); const localAnvil = foundry; -/** - * Helper function that retrieves the addresses of configured deployed contracts. - */ -function retrieveL1Contracts(config: AztecNodeConfig, account: Account): Promise { - const chain = createEthereumChain(config.rpcUrl, config.apiKey); - const walletClient = createWalletClient({ - account, - chain: chain.chainInfo, - transport: http(chain.rpcUrl), - }); - const publicClient = createPublicClient({ - chain: chain.chainInfo, - transport: http(chain.rpcUrl), - }); - const l1Contracts: L1ContractAddresses = { - rollupAddress: config.l1Contracts.rollupAddress, - registryAddress: config.l1Contracts.registryAddress, - inboxAddress: config.l1Contracts.inboxAddress, - outboxAddress: config.l1Contracts.outboxAddress, - contractDeploymentEmitterAddress: config.l1Contracts.contractDeploymentEmitterAddress, - decoderHelperAddress: EthAddress.ZERO, - }; - const contracts: DeployL1Contracts = { - l1ContractAddresses: l1Contracts, - walletClient, - publicClient, - }; - return Promise.resolve(contracts); -} - /** * Helper function that waits for the Ethereum RPC server to respond before deploying L1 contracts. */ From 8fce9db51d508946d6528a8dc752e5fe91c5d155 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 14:56:33 +0000 Subject: [PATCH 32/39] Yarn lock file --- yarn-project/yarn.lock | 44 +----------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index f8fadd2f2a0..32328f2dfc4 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -248,8 +248,6 @@ __metadata: "@types/lodash.partition": ^4.6.0 "@types/lodash.zip": ^4.2.7 "@types/node": ^18.7.23 - assert: ^2.1.0 - browserify-zlib: ^0.2.0 buffer: ^6.0.3 crypto-browserify: ^3.12.0 jest: ^29.5.0 @@ -258,7 +256,6 @@ __metadata: lodash.partition: ^4.6.0 lodash.zip: ^4.2.0 process: ^0.11.10 - querystring-es3: ^0.2.1 resolve-typescript-plugin: ^2.0.1 stream-browserify: ^3.0.0 ts-jest: ^29.1.0 @@ -6533,19 +6530,6 @@ __metadata: languageName: node linkType: hard -"assert@npm:^2.1.0": - version: 2.1.0 - resolution: "assert@npm:2.1.0" - dependencies: - call-bind: ^1.0.2 - is-nan: ^1.3.2 - object-is: ^1.1.5 - object.assign: ^4.1.4 - util: ^0.12.5 - checksum: 1ed1cabba9abe55f4109b3f7292b4e4f3cf2953aad8dc148c0b3c3bd676675c31b1abb32ef563b7d5a19d1715bf90d1e5f09fad2a4ee655199468902da80f7c2 - languageName: node - linkType: hard - "assertion-error@npm:^1.1.0": version: 1.1.0 resolution: "assertion-error@npm:1.1.0" @@ -7127,15 +7111,6 @@ __metadata: languageName: node linkType: hard -"browserify-zlib@npm:^0.2.0": - version: 0.2.0 - resolution: "browserify-zlib@npm:0.2.0" - dependencies: - pako: ~1.0.5 - checksum: 5cd9d6a665190fedb4a97dfbad8dabc8698d8a507298a03f42c734e96d58ca35d3c7d4085e283440bbca1cd1938cff85031728079bedb3345310c58ab1ec92d6 - languageName: node - linkType: hard - "browserslist@npm:^4.14.5, browserslist@npm:^4.21.10, browserslist@npm:^4.21.9": version: 4.21.10 resolution: "browserslist@npm:4.21.10" @@ -11324,16 +11299,6 @@ __metadata: languageName: node linkType: hard -"is-nan@npm:^1.3.2": - version: 1.3.2 - resolution: "is-nan@npm:1.3.2" - dependencies: - call-bind: ^1.0.0 - define-properties: ^1.1.3 - checksum: 5dfadcef6ad12d3029d43643d9800adbba21cf3ce2ec849f734b0e14ee8da4070d82b15fdb35138716d02587c6578225b9a22779cab34888a139cc43e4e3610a - languageName: node - linkType: hard - "is-negative-zero@npm:^2.0.2": version: 2.0.2 resolution: "is-negative-zero@npm:2.0.2" @@ -15037,7 +15002,7 @@ __metadata: languageName: node linkType: hard -"pako@npm:~1.0.2, pako@npm:~1.0.5": +"pako@npm:~1.0.2": version: 1.0.11 resolution: "pako@npm:1.0.11" checksum: 1be2bfa1f807608c7538afa15d6f25baa523c30ec870a3228a89579e474a4d992f4293859524e46d5d87fd30fa17c5edf34dbef0671251d9749820b488660b16 @@ -15844,13 +15809,6 @@ __metadata: languageName: node linkType: hard -"querystring-es3@npm:^0.2.1": - version: 0.2.1 - resolution: "querystring-es3@npm:0.2.1" - checksum: 691e8d6b8b157e7cd49ae8e83fcf86de39ab3ba948c25abaa94fba84c0986c641aa2f597770848c64abce290ed17a39c9df6df737dfa7e87c3b63acc7d225d61 - languageName: node - linkType: hard - "queue-microtask@npm:^1.2.2, queue-microtask@npm:^1.2.3": version: 1.2.3 resolution: "queue-microtask@npm:1.2.3" From 72089aed5e78a0c06324fb578b99c96cc35b7d23 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 15:15:51 +0000 Subject: [PATCH 33/39] Merge fix --- yarn-project/end-to-end/src/fixtures/utils.ts | 82 ++++++++++++------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index e86704e3daa..bb61877580c 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -203,6 +203,57 @@ export async function setupAztecRPCServer( }; } +/** + * Function to setup the test against a running sandbox. + * @param account - The account for use in create viem wallets. + * @param config - The aztec Node Configuration + * @param logger - The logger to be used + * @param numberOfAccounts - The number of accounts to create on the sandbox + * @returns RPC Client, viwm wallets, contract addreses etc. + */ +async function setupWithSandbox( + account: Account, + config: AztecNodeConfig, + logger: DebugLogger, + numberOfAccounts: number, +) { + // we are setting up against the sandbox, l1 contracts are already deployed + const { aztecRpcServer, accounts, wallets } = await setupAztecRPCServer(numberOfAccounts, undefined, logger); + logger(`Retrieving contract addresses from ${SANDBOX_URL}`); + const l1Contracts = (await aztecRpcServer.getNodeInfo()).l1ContractAddresses; + + const walletClient = createWalletClient({ + account, + chain: localAnvil, + transport: http(config.rpcUrl), + }); + const publicClient = createPublicClient({ + chain: localAnvil, + transport: http(config.rpcUrl), + }); + const deployL1ContractsValues: DeployL1Contracts = { + l1ContractAddresses: l1Contracts, + walletClient, + publicClient, + }; + const cheatCodes = await CheatCodes.create(config.rpcUrl, aztecRpcServer!); + const teardown = async () => { + if (aztecRpcServer instanceof AztecRPCServer) await aztecRpcServer?.stop(); + }; + return { + aztecNode: undefined, + aztecRpcServer, + deployL1ContractsValues, + accounts, + config, + wallet: wallets[0], + wallets, + logger, + cheatCodes, + teardown, + }; +} + /** * Sets up the environment for the end-to-end tests. * @param numberOfAccounts - The number of new accounts to be created once the RPC server is initiated. @@ -264,36 +315,7 @@ export async function setup( if (SANDBOX_URL) { // we are setting up against the sandbox, l1 contracts are already deployed - const { aztecRpcServer, accounts, wallets } = await setupAztecRPCServer(numberOfAccounts, undefined, logger); - logger(`Retrieving contract addresses from ${SANDBOX_URL}`); - const l1Contracts = (await aztecRpcServer.getNodeInfo()).l1ContractAddresses; - - const walletClient = createWalletClient({ - account: hdAccount, - chain: localAnvil, - transport: http(config.rpcUrl), - }); - const publicClient = createPublicClient({ - chain: localAnvil, - transport: http(config.rpcUrl), - }); - const deployL1ContractsValues: DeployL1Contracts = { - l1ContractAddresses: l1Contracts, - walletClient, - publicClient, - }; - const cheatCodes = await CheatCodes.create(config.rpcUrl, aztecRpcServer!); - return { - aztecNode: undefined, - aztecRpcServer, - deployL1ContractsValues, - accounts, - config, - wallet: wallets[0], - wallets, - logger, - cheatCodes, - }; + return await setupWithSandbox(hdAccount, config, logger, numberOfAccounts); } const deployL1ContractsValues = await setupL1Contracts(config.rpcUrl, hdAccount, logger); From e6445449eb5bcaf1fd96549b09d49c5cae4175ad Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 16:00:56 +0000 Subject: [PATCH 34/39] Cleanup --- yarn-project/end-to-end/src/fixtures/utils.ts | 65 +++++-------------- 1 file changed, 17 insertions(+), 48 deletions(-) diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index bb61877580c..7c04633e80f 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -93,24 +93,6 @@ const createAztecNode = async ( return await AztecNodeService.createAndSync(nodeConfig); }; -const createRpcServer = async ( - rpcConfig: RpcServerConfig, - aztecNode: AztecNodeService | undefined, - logger: DebugLogger, - useLogSuffix?: boolean | string, -): Promise => { - if (SANDBOX_URL) { - logger(`Creating JSON RPC client to remote host ${SANDBOX_URL}`); - const jsonClient = createJsonRpcClient(SANDBOX_URL); - await waitForRPCServer(jsonClient, logger); - logger('JSON RPC client connected to RPC Server'); - return jsonClient; - } else if (!aztecNode) { - throw new Error('Invalid aztec node when creating RPC server'); - } - return createAztecRPCServer(aztecNode, rpcConfig, {}, useLogSuffix); -}; - export const setupL1Contracts = async ( l1RpcUrl: string, account: HDAccount | PrivateKeyAccount, @@ -159,7 +141,7 @@ export const setupL1Contracts = async ( */ export async function setupAztecRPCServer( numberOfAccounts: number, - aztecNode: AztecNodeService | undefined, + aztecNode: AztecNodeService, logger = getLogger(), useLogSuffix = false, ): Promise<{ @@ -181,19 +163,9 @@ export async function setupAztecRPCServer( logger: DebugLogger; }> { const rpcConfig = getRpcConfigEnvVars(); - const rpc = await createRpcServer(rpcConfig, aztecNode, logger, useLogSuffix); - - const createWallets = () => { - if (!SANDBOX_URL) { - logger('RPC server created, deploying new accounts...'); - return createAccounts(rpc, numberOfAccounts); - } else { - logger('RPC server created, constructing wallets from initial sandbox accounts...'); - return getSandboxAccountsWallets(rpc); - } - }; + const rpc = await createAztecRPCServer(aztecNode, rpcConfig, {}, useLogSuffix); - const wallets = await createWallets(); + const wallets = await createAccounts(rpc, numberOfAccounts); return { aztecRpcServer: rpc!, @@ -208,19 +180,18 @@ export async function setupAztecRPCServer( * @param account - The account for use in create viem wallets. * @param config - The aztec Node Configuration * @param logger - The logger to be used - * @param numberOfAccounts - The number of accounts to create on the sandbox * @returns RPC Client, viwm wallets, contract addreses etc. */ -async function setupWithSandbox( - account: Account, - config: AztecNodeConfig, - logger: DebugLogger, - numberOfAccounts: number, -) { +async function setupWithSandbox(account: Account, config: AztecNodeConfig, logger: DebugLogger) { // we are setting up against the sandbox, l1 contracts are already deployed - const { aztecRpcServer, accounts, wallets } = await setupAztecRPCServer(numberOfAccounts, undefined, logger); + logger(`Creating JSON RPC client to remote host ${SANDBOX_URL}`); + const jsonClient = createJsonRpcClient(SANDBOX_URL); + await waitForRPCServer(jsonClient, logger); + logger('JSON RPC client connected to RPC Server'); logger(`Retrieving contract addresses from ${SANDBOX_URL}`); - const l1Contracts = (await aztecRpcServer.getNodeInfo()).l1ContractAddresses; + const l1Contracts = (await jsonClient.getNodeInfo()).l1ContractAddresses; + logger('RPC server created, constructing wallets from initial sandbox accounts...'); + const wallets = await getSandboxAccountsWallets(jsonClient); const walletClient = createWalletClient({ account, @@ -236,15 +207,13 @@ async function setupWithSandbox( walletClient, publicClient, }; - const cheatCodes = await CheatCodes.create(config.rpcUrl, aztecRpcServer!); - const teardown = async () => { - if (aztecRpcServer instanceof AztecRPCServer) await aztecRpcServer?.stop(); - }; + const cheatCodes = await CheatCodes.create(config.rpcUrl, jsonClient!); + const teardown = () => Promise.resolve(); return { aztecNode: undefined, - aztecRpcServer, + aztecRpcServer: jsonClient, deployL1ContractsValues, - accounts, + accounts: await jsonClient!.getRegisteredAccounts(), config, wallet: wallets[0], wallets, @@ -315,7 +284,7 @@ export async function setup( if (SANDBOX_URL) { // we are setting up against the sandbox, l1 contracts are already deployed - return await setupWithSandbox(hdAccount, config, logger, numberOfAccounts); + return await setupWithSandbox(hdAccount, config, logger); } const deployL1ContractsValues = await setupL1Contracts(config.rpcUrl, hdAccount, logger); @@ -331,7 +300,7 @@ export async function setup( const aztecNode = await createAztecNode(config, logger); - const { aztecRpcServer, accounts, wallets } = await setupAztecRPCServer(numberOfAccounts, aztecNode, logger); + const { aztecRpcServer, accounts, wallets } = await setupAztecRPCServer(numberOfAccounts, aztecNode!, logger); const cheatCodes = await CheatCodes.create(config.rpcUrl, aztecRpcServer!); From f3d354fe8f1567a5a357cb194cf755f96956846c Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 16:02:58 +0000 Subject: [PATCH 35/39] Cleanup --- yarn-project/end-to-end/src/fixtures/utils.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 7c04633e80f..9caea63c96a 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -1,10 +1,5 @@ import { AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; -import { - AztecRPCServer, - RpcServerConfig, - createAztecRPCServer, - getConfigEnvVars as getRpcConfigEnvVars, -} from '@aztec/aztec-rpc'; +import { AztecRPCServer, createAztecRPCServer, getConfigEnvVars as getRpcConfigEnvVars } from '@aztec/aztec-rpc'; import { AccountWallet, AztecAddress, From dc531c15c9e3269a3b41d03b97c5aac2f2512a8b Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 16:06:29 +0000 Subject: [PATCH 36/39] Cleanup --- yarn-project/cli/src/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index 3374e10a99c..86a7623b687 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -83,11 +83,11 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { debugLogger, ); log('\n'); - log(`Rollup Address: ${l1ContractAddresses.rollupAddress?.toString()}`); - log(`Registry Address: ${l1ContractAddresses.registryAddress?.toString()}`); - log(`L1 -> L2 Inbox Address: ${l1ContractAddresses.inboxAddress?.toString()}`); - log(`L2 -> L1 Outbox address: ${l1ContractAddresses.outboxAddress?.toString()}`); - log(`Contract Deployment Emitter Address: ${l1ContractAddresses.contractDeploymentEmitterAddress?.toString()}`); + log(`Rollup Address: ${l1ContractAddresses.rollupAddress.toString()}`); + log(`Registry Address: ${l1ContractAddresses.registryAddress.toString()}`); + log(`L1 -> L2 Inbox Address: ${l1ContractAddresses.inboxAddress.toString()}`); + log(`L2 -> L1 Outbox address: ${l1ContractAddresses.outboxAddress.toString()}`); + log(`Contract Deployment Emitter Address: ${l1ContractAddresses.contractDeploymentEmitterAddress.toString()}`); log('\n'); }); From 2a878952498d9eb7c2d9bb5e4b7a43c7adb38799 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 16:10:15 +0000 Subject: [PATCH 37/39] Cleanup --- yarn-project/aztec-sandbox/src/bin/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/aztec-sandbox/src/bin/index.ts b/yarn-project/aztec-sandbox/src/bin/index.ts index 757eefa4261..4537603afe8 100644 --- a/yarn-project/aztec-sandbox/src/bin/index.ts +++ b/yarn-project/aztec-sandbox/src/bin/index.ts @@ -19,7 +19,7 @@ const logger = createDebugLogger('aztec:sandbox'); /** * Creates the sandbox from provided config and deploys any initial L1 and L2 contracts */ -async function createAndDeploySandbox() { +async function createAndInitialiseSandbox() { const { l1Contracts, rpcServer, stop } = await createSandbox(); logger.info('Setting up test accounts...'); const accounts = await deployInitialSandboxAccounts(rpcServer); @@ -41,7 +41,7 @@ async function main() { logger.info(`Setting up Aztec Sandbox v${version} (nargo ${NoirVersion.tag}), please stand by...`); - const { rpcServer, stop, accounts } = await createAndDeploySandbox(); + const { rpcServer, stop, accounts } = await createAndInitialiseSandbox(); const shutdown = async () => { logger.info('Shutting down...'); From ce74c310e30755d56e8cd772d40a9279bd547dcf Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 16:22:30 +0000 Subject: [PATCH 38/39] Cleanup --- yarn-project/cli/package.json | 2 +- yarn-project/cli/src/index.ts | 4 ++-- yarn-project/cli/tsconfig.json | 3 --- yarn-project/yarn.lock | 33 ++++++++++++++++++++++++++++++++- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/yarn-project/cli/package.json b/yarn-project/cli/package.json index 234dd698620..0f680becf60 100644 --- a/yarn-project/cli/package.json +++ b/yarn-project/cli/package.json @@ -40,8 +40,8 @@ "@aztec/l1-artifacts": "workspace:^", "@aztec/noir-compiler": "workspace:^", "@aztec/noir-contracts": "workspace:^", - "@aztec/p2p": "workspace:^", "@aztec/types": "workspace:^", + "@libp2p/peer-id-factory": "^3.0.4", "commander": "^9.0.0", "jszip": "^3.10.1", "lodash.startcase": "^4.4.0", diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index 86a7623b687..6e048412cb7 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -14,9 +14,9 @@ import { JsonStringify } from '@aztec/foundation/json-rpc'; import { DebugLogger, LogFn } from '@aztec/foundation/log'; import { fileURLToPath } from '@aztec/foundation/url'; import { compileContract, generateNoirInterface, generateTypescriptInterface } from '@aztec/noir-compiler/cli'; -import { createLibP2PPeerId } from '@aztec/p2p'; import { CompleteAddress, ContractData, L2BlockL2Logs, TxHash } from '@aztec/types'; +import { createSecp256k1PeerId } from '@libp2p/peer-id-factory'; import { Command } from 'commander'; import { readFileSync } from 'fs'; import { dirname, resolve } from 'path'; @@ -122,7 +122,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { .summary('Generates a LibP2P peer private key.') .description('Generates a private key that can be used for running a node on a LibP2P network.') .action(async () => { - const peerId = await createLibP2PPeerId(); + const peerId = await createSecp256k1PeerId(); const exportedPeerId = Buffer.from(peerId.privateKey!).toString('hex'); log(`Private key: ${exportedPeerId}`); log(`Peer Id: ${peerId}`); diff --git a/yarn-project/cli/tsconfig.json b/yarn-project/cli/tsconfig.json index 42761fac561..7bd5491149a 100644 --- a/yarn-project/cli/tsconfig.json +++ b/yarn-project/cli/tsconfig.json @@ -24,9 +24,6 @@ { "path": "../noir-contracts" }, - { - "path": "../p2p" - }, { "path": "../types" } diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 32328f2dfc4..30f0e303e5e 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -353,9 +353,9 @@ __metadata: "@aztec/l1-artifacts": "workspace:^" "@aztec/noir-compiler": "workspace:^" "@aztec/noir-contracts": "workspace:^" - "@aztec/p2p": "workspace:^" "@aztec/types": "workspace:^" "@jest/globals": ^29.5.0 + "@libp2p/peer-id-factory": ^3.0.4 "@rushstack/eslint-patch": ^1.1.4 "@types/jest": ^29.5.0 "@types/lodash.startcase": ^4.4.7 @@ -2691,6 +2691,22 @@ __metadata: languageName: node linkType: hard +"@libp2p/crypto@npm:^2.0.4": + version: 2.0.4 + resolution: "@libp2p/crypto@npm:2.0.4" + dependencies: + "@libp2p/interface": ^0.1.2 + "@noble/curves": ^1.1.0 + "@noble/hashes": ^1.3.1 + multiformats: ^12.0.1 + node-forge: ^1.1.0 + protons-runtime: ^5.0.0 + uint8arraylist: ^2.4.3 + uint8arrays: ^4.0.6 + checksum: 1e0a0e8006e9ca7caaec16ce94d193063749fc7f62a7b3d0b4469915e2837c380987baa400a9f35ee13c23783f8317f8bc58b8ed647a5b4bf55635a2a909ae97 + languageName: node + linkType: hard + "@libp2p/interface-connection@npm:^5.0.0": version: 5.1.1 resolution: "@libp2p/interface-connection@npm:5.1.1" @@ -3017,6 +3033,21 @@ __metadata: languageName: node linkType: hard +"@libp2p/peer-id-factory@npm:^3.0.4": + version: 3.0.4 + resolution: "@libp2p/peer-id-factory@npm:3.0.4" + dependencies: + "@libp2p/crypto": ^2.0.4 + "@libp2p/interface": ^0.1.2 + "@libp2p/peer-id": ^3.0.2 + multiformats: ^12.0.1 + protons-runtime: ^5.0.0 + uint8arraylist: ^2.4.3 + uint8arrays: ^4.0.6 + checksum: 40c534029bfa8d9b98119ee2c0ce3c0c91bcf7280028e7ba8bfe4da2a90de53014791d75c8d1400877919f748918704276b6e3337c5128975842c0593464fda9 + languageName: node + linkType: hard + "@libp2p/peer-id@npm:^3.0.0, @libp2p/peer-id@npm:^3.0.2": version: 3.0.2 resolution: "@libp2p/peer-id@npm:3.0.2" From 4471ee2c46c68395f80b355f0bb51b8744598fdc Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 26 Sep 2023 16:54:21 +0000 Subject: [PATCH 39/39] Bump ts version in docs --- docs/package.json | 2 +- docs/yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/package.json b/docs/package.json index 59441623353..854f13f07f8 100644 --- a/docs/package.json +++ b/docs/package.json @@ -43,7 +43,7 @@ "nodemon": "^3.0.1", "typedoc": "^0.25.1", "typedoc-plugin-markdown": "^3.16.0", - "typescript": "^4.7.2" + "typescript": "^5.0.4" }, "browserslist": { "production": [ diff --git a/docs/yarn.lock b/docs/yarn.lock index 3057a40b1e8..50055128a74 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -8040,10 +8040,10 @@ typedoc@^0.25.1: minimatch "^9.0.3" shiki "^0.14.1" -typescript@^4.7.2: - version "4.9.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.4.tgz#a2a3d2756c079abda241d75f149df9d561091e78" - integrity sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg== +typescript@^5.0.4: + version "5.2.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78" + integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w== ua-parser-js@^0.7.30: version "0.7.32"