From 9b02d53af11b8f14d5972c619293c33c0eaf8004 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Fri, 8 Sep 2023 09:34:04 +0000 Subject: [PATCH 01/22] 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 16bc8821c570..7d77f0832cf1 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 000000000000..6eb2b99d13d6 --- /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 b64dcd6b3061..0ffc47a8c8e4 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/22] 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 f9ac88c3964f..69a0aaa78964 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 8d25be5a2007..3de9e127ceb9 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/22] 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 000000000000..e9b54f1df3e4 --- /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 6c88251805d5..94a0eccf0d01 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 675db4c278aa..d20cfe64bc1c 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 1ab04d4c58e6..c2650e037b44 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 8e785e5b058b..a63d72ab4166 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 fcf509ff6cb2..025c6fb13385 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 000000000000..ddf361e2b71f --- /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 853db6bae96f..30446306da6c 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 5457afa2a418..485500056f23 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 9c477cf34f17..d626c45994d2 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 162eb59183d9..93f9d3e6d3cb 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 fe754f7c6521..65e787ead2d9 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 99adad75081f..840a10318494 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 79f68176cb02..1a1ef438cbb6 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 000000000000..80584d0a8e62 --- /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 4a017c9e2bbb..6e5dcdd4011b 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 43967f3bd82f..982fd37677d8 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 3de9e127ceb9..d7fee7e2b476 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 e749c4cc79c4..0e37b1c91a05 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 1df16e7de1f8..9c2e7c0471a4 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 fc3fe96c080e..c1488f7c02ae 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 8a9dce35fdf6..feb0477e29d6 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 fe38efd45081..ff351bcd5061 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 a654a1611c83..28e130a83a3f 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 01e14a2ecb11..7d3600df1561 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 f0968945e548..6b7764475485 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 112748fe75b0..19d4d44a9d13 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 f28b101c754c..3669dc33831e 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 0cf0115d8b8d..84f72c805ca7 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 e34244ade3f5..ac0e4938aa32 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 df49c2dc438b..daa05d4c5208 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 771502116e59..ff740dcdd3ee 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 2ad33406c216..601dbeffa3aa 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 b8482b98f7cc..8b27b03fd262 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 4a8a7998e03a..2cd08850ab86 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 6279349059c9..c8edddb8ddee 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 000000000000..0812300de43e --- /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 5c02976f1e24..d724f69617bb 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 ca2e5f4de8ad..83cd580e3205 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 9060a659c269..1edf3658bec7 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 909d3d32b057..8d4682ee5b46 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 e351db0c09de..316404606648 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 5ec4cfde76cc..5cbb92c25f65 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 d9e112e8d0ae..49aee747ffd8 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 78977f0c5f47..78fa4e4fda9d 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 000000000000..b182baaccf18 --- /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 d064651f5cee..eb19075cb320 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 ed61b46a11df..a3ebcf30039b 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 4037d4917ed8..ad9a7e41c5fd 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 3a9b9b772335..000000000000 --- 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 1806b4a0e26e..7de31f6b4c95 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/22] 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 82aa8cf4ccf5..e7053342b34b 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/22] 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 e2414d0b2271..54698df4f128 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 3cd0a590568a..96525c35f6e9 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 831401ae07a6..a3ebcf30039b 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/22] 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 840a10318494..4db4ffb1ebf4 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 73a0f908492d..5dabbdef88f6 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/22] 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 5dabbdef88f6..73a0f908492d 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/22] 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 4db4ffb1ebf4..07a065cb2a66 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/22] 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 3e8e058f4be7..59e7f903efb4 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/22] 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 7de31f6b4c95..aaef528528ec 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/22] 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 a63d72ab4166..85df499f9baf 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 485500056f23..4cac8cc5046b 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 aaef528528ec..d7525884580b 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/22] 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 4cac8cc5046b..2c9a7bdb1dee 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 12d26f8484b6..d65c6b00ec11 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 67005d8790a4..cf722e339c23 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 d7525884580b..17a4e96f238e 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/22] 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 5bd51662d412..1c66150b8b6c 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/22] 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 3669dc33831e..baa70687c277 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/22] 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 1c66150b8b6c..04531d92e489 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 252772dcf455..e4494a4945de 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 8771028468f5..1edb9b488f55 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 54698df4f128..babb4be9e6f1 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 d626c45994d2..08d6776d5252 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 93f9d3e6d3cb..83fd26a1c278 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 17fecc1ea6b2..830e7283d41f 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 07a065cb2a66..dbde0945ba89 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 80584d0a8e62..ce1baff58b5e 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 37e0ca068f3e..91e3b2d7da3d 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 fee9e8192e14..274cc98dd847 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 f8543d890038..bcdf3fc5a51b 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 ff351bcd5061..ef38a25ef182 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 2f8668d6342e..ee52d1143467 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 96525c35f6e9..75406d8f06de 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 2cd08850ab86..744209d85f49 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 0812300de43e..814a04ed5e8c 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 0e5bb9a1dde2..f7e74ce7d72d 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 8d4682ee5b46..2884374561a9 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 316404606648..6dd24c2c4b7a 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 5cbb92c25f65..96ad07bd6f15 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 49aee747ffd8..106517c65fe7 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 c19c787a35de..23c1216475ee 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 e1fb672952be..25b7c2205cf3 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 d362e4fc7289..9002aa89c0b3 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 d53098ad94ca..18df9e9e0ce5 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 ad9a7e41c5fd..000000000000 --- 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 000000000000..46da7a96f90e --- /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 000000000000..b71b8f7374e5 --- /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/22] 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 08d6776d5252..d2f53e0f4c79 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 8f298d5722d7..1190999ce69d 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 ef38a25ef182..b40857f9796f 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 17a4e96f238e..3b725697f543 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/22] 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 d65c6b00ec11..b2d29580ad74 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 01c876235ce3..7d0bb1110ba9 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 3b725697f543..9a0524457cd3 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/22] 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 efb5e939ea53..5608c729449b 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 ddf361e2b71f..6938c9317f65 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 000000000000..86591f1ff765 --- /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 b40857f9796f..beea7b28db27 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 d724f69617bb..e57e95962634 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/22] 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 86591f1ff765..f616da8e39dc 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 e51a0d9595bc..a04c75689071 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/22] 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 6eb2b99d13d6..000000000000 --- 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/22] 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 2c9a7bdb1dee..47573e6ef0d6 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 6e5dcdd4011b..d83585958931 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/22] 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 f616da8e39dc..c425b64c69ae 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,