From 7eff5c5f089080c9bbcec4838fa1fdd033e3722a Mon Sep 17 00:00:00 2001 From: spypsy Date: Tue, 20 Feb 2024 14:53:16 +0000 Subject: [PATCH 1/4] fix: p2p-bootstrap ECS command + /status route --- yarn-project/aztec/src/cli/cli.ts | 10 +++++++--- yarn-project/p2p-bootstrap/terraform/main.tf | 1 - 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/yarn-project/aztec/src/cli/cli.ts b/yarn-project/aztec/src/cli/cli.ts index b4620842cbd..a6ad675c617 100644 --- a/yarn-project/aztec/src/cli/cli.ts +++ b/yarn-project/aztec/src/cli/cli.ts @@ -1,5 +1,5 @@ import { fileURLToPath } from '@aztec/aztec.js'; -import { ServerList, createNamespacedJsonRpcServer } from '@aztec/foundation/json-rpc/server'; +import { ServerList, createNamespacedJsonRpcServer, createStatusRouter } from '@aztec/foundation/json-rpc/server'; import { DebugLogger, LogFn } from '@aztec/foundation/log'; import { Command } from 'commander'; @@ -10,7 +10,7 @@ import { dirname, resolve } from 'path'; import { cliTexts } from './texts.js'; import { installSignalHandlers } from './util.js'; -const { AZTEC_PORT = '8080' } = process.env; +const { AZTEC_PORT = '8080', API_PREFIX = '' } = process.env; /** * Returns commander program that defines the 'aztec' command line interface. @@ -59,7 +59,11 @@ export function getProgram(userLog: LogFn, debugLogger: DebugLogger): Command { if (services.length) { const rpcServer = createNamespacedJsonRpcServer(services, debugLogger); - const app = rpcServer.getApp(); + const app = rpcServer.getApp(API_PREFIX); + // add status route + const statusRouter = createStatusRouter(API_PREFIX); + app.use(statusRouter.routes()).use(statusRouter.allowedMethods()); + const httpServer = http.createServer(app.callback()); httpServer.listen(options.port); userLog(`Aztec Server listening on port ${options.port}`); diff --git a/yarn-project/p2p-bootstrap/terraform/main.tf b/yarn-project/p2p-bootstrap/terraform/main.tf index 57070dcfa76..1d3b8cdffaa 100644 --- a/yarn-project/p2p-bootstrap/terraform/main.tf +++ b/yarn-project/p2p-bootstrap/terraform/main.tf @@ -108,7 +108,6 @@ resource "aws_ecs_task_definition" "p2p-bootstrap" { "image": "${var.DOCKERHUB_ACCOUNT}/aztec:${var.DEPLOY_TAG}", "command": ["start", "--p2p-bootstrap"], "essential": true, - "command": ["start"], "memoryReservation": 3776, "portMappings": [ { From 1efcbb94caf7757def49e12cb75b7633227b7170 Mon Sep 17 00:00:00 2001 From: spypsy Date: Tue, 20 Feb 2024 16:28:43 +0000 Subject: [PATCH 2/4] fix l1 contract option derivation --- yarn-project/aztec-node/terraform/main.tf | 16 ++++----- yarn-project/aztec/src/cli/util.ts | 44 ++++++++++------------- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/yarn-project/aztec-node/terraform/main.tf b/yarn-project/aztec-node/terraform/main.tf index 531d7c0535a..87e349ee077 100644 --- a/yarn-project/aztec-node/terraform/main.tf +++ b/yarn-project/aztec-node/terraform/main.tf @@ -154,7 +154,7 @@ resource "aws_ecs_task_definition" "aztec-node" { [ { "name": "${var.DEPLOY_TAG}-aztec-node-${count.index + 1}", - "image": "${var.DOCKERHUB_ACCOUNT}/aztec:${var.DEPLOY_TAG}", + "image": "278380418400.dkr.ecr.us-east-2.amazonaws.com/aztec:cache-e2fd516b5f6f5de3c642ebf83f4bd0370f2ace1f", "command": ["start", "--node", "--archiver", "--sequencer"], "essential": true, "memoryReservation": 3776, @@ -167,10 +167,6 @@ resource "aws_ecs_task_definition" "aztec-node" { } ], "environment": [ - { - "name": "MODE", - "value": "node" - }, { "name": "NODE_ENV", "value": "production" @@ -221,23 +217,23 @@ resource "aws_ecs_task_definition" "aztec-node" { }, { "name": "CONTRACT_DEPLOYMENT_EMITTER_ADDRESS", - "value": "${data.terraform_remote_state.l1_contracts.outputs.contract_deployment_emitter_address}" + "value": "0x925957af6173b0517627dc338fccac58c7a73b3a" }, { "name": "ROLLUP_CONTRACT_ADDRESS", - "value": "${data.terraform_remote_state.l1_contracts.outputs.rollup_contract_address}" + "value": "0xa1b823cd37878be071e80684f8af49f719f9ad70" }, { "name": "INBOX_CONTRACT_ADDRESS", - "value": "${data.terraform_remote_state.l1_contracts.outputs.inbox_contract_address}" + "value": "0x3ac9d23ac5b8ee0126baf3fac8def4885e6c7999" }, { "name": "OUTBOX_CONTRACT_ADDRESS", - "value": "${data.terraform_remote_state.l1_contracts.outputs.outbox_contract_address}" + "value": "0x03c6f7f5c15dcef8273884784fd43fe76184992c" }, { "name": "REGISTRY_CONTRACT_ADDRESS", - "value": "${data.terraform_remote_state.l1_contracts.outputs.registry_contract_address}" + "value": "0xad463e0cb8ec1031998ff1f2335f6445a3e71d20" }, { "name": "API_KEY", diff --git a/yarn-project/aztec/src/cli/util.ts b/yarn-project/aztec/src/cli/util.ts index 75f8c84d237..3a2734525f7 100644 --- a/yarn-project/aztec/src/cli/util.ts +++ b/yarn-project/aztec/src/cli/util.ts @@ -7,6 +7,8 @@ import { LogFn } from '@aztec/foundation/log'; import { P2PConfig } from '@aztec/p2p'; import { GrumpkinScalar, PXEService, PXEServiceConfig } from '@aztec/pxe'; +const l1ContractsNames = ['rollupAddress', 'inboxAddress', 'outboxAddress', 'contractDeploymentEmitterAddress']; + /** * Checks if the object has l1Contracts property * @param obj - The object to check @@ -25,7 +27,7 @@ function hasL1Contracts(obj: any): obj is { * @returns true if all contract addresses are not zero */ const checkContractAddresses = (contracts: L1ContractAddresses) => { - return ['rollupAddress', 'inboxAddress', 'outboxAddress', 'contractDeploymentEmitterAddress'].every(cn => { + return l1ContractsNames.every(cn => { const key = cn as keyof L1ContractAddresses; return contracts[key] && contracts[key] !== EthAddress.ZERO; }); @@ -69,39 +71,31 @@ export const mergeEnvVarsAndCliOptions = { + const key = cn as keyof L1ContractAddresses; + if (cliOptions[key]) { + return { ...acc, [key]: cliOptions[key] ? EthAddress.fromString(cliOptions[key]) : envVars.l1Contracts[key] }; + } + return acc; + }, {} as L1ContractAddresses); + + if (hasL1Contracts(envVars) && contractsRequired && !checkContractAddresses(l1Contracts)) { + throw new Error('Deployed L1 contract addresses are required to start the service'); + } + merged = { ...merged, - l1Contracts: { - ...(envVars.l1Contracts && { ...envVars.l1Contracts }), - ...cliOptionsContracts, - }, + l1Contracts, } as T; } + console.log('merged', merged); + return merged; }; From 937c4910a1195081a3b3ed7bdf42d45a3430e416 Mon Sep 17 00:00:00 2001 From: spypsy Date: Tue, 20 Feb 2024 16:55:13 +0000 Subject: [PATCH 3/4] fix check & log --- yarn-project/aztec/src/cli/cmds/start_node.ts | 2 +- yarn-project/aztec/src/cli/util.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/yarn-project/aztec/src/cli/cmds/start_node.ts b/yarn-project/aztec/src/cli/cmds/start_node.ts index 7a4a0d3623b..04e066a39ab 100644 --- a/yarn-project/aztec/src/cli/cmds/start_node.ts +++ b/yarn-project/aztec/src/cli/cmds/start_node.ts @@ -36,7 +36,7 @@ export const startNode = async ( nodeConfig.archiverUrl = archiverUrl; } else { const archiverCliOptions = parseModuleOptions(options.archiver); - nodeConfig = mergeEnvVarsAndCliOptions(aztecNodeConfigEnvVars, archiverCliOptions); + nodeConfig = mergeEnvVarsAndCliOptions(aztecNodeConfigEnvVars, archiverCliOptions, true); } // Deploy contracts if needed diff --git a/yarn-project/aztec/src/cli/util.ts b/yarn-project/aztec/src/cli/util.ts index 3a2734525f7..3f3556c87b8 100644 --- a/yarn-project/aztec/src/cli/util.ts +++ b/yarn-project/aztec/src/cli/util.ts @@ -3,7 +3,7 @@ import { AztecNodeConfig } from '@aztec/aztec-node'; import { AccountManager } from '@aztec/aztec.js'; import { L1ContractAddresses } from '@aztec/ethereum'; import { EthAddress } from '@aztec/foundation/eth-address'; -import { LogFn } from '@aztec/foundation/log'; +import { LogFn, createConsoleLogger } from '@aztec/foundation/log'; import { P2PConfig } from '@aztec/p2p'; import { GrumpkinScalar, PXEService, PXEServiceConfig } from '@aztec/pxe'; @@ -67,6 +67,7 @@ export const mergeEnvVarsAndCliOptions = , contractsRequired = false, + userLog = createConsoleLogger(), ) => { if (contractsRequired && !cliOptions.rollupAddress) { throw new Error('Rollup contract address is required to start the service'); @@ -79,12 +80,14 @@ export const mergeEnvVarsAndCliOptions = { const key = cn as keyof L1ContractAddresses; if (cliOptions[key]) { - return { ...acc, [key]: cliOptions[key] ? EthAddress.fromString(cliOptions[key]) : envVars.l1Contracts[key] }; + return { ...acc, [key]: EthAddress.fromString(cliOptions[key]) }; + } else { + return { ...acc, [key]: envVars.l1Contracts[key] }; } - return acc; }, {} as L1ContractAddresses); if (hasL1Contracts(envVars) && contractsRequired && !checkContractAddresses(l1Contracts)) { + userLog('Deployed L1 contract addresses are required to start the service'); throw new Error('Deployed L1 contract addresses are required to start the service'); } @@ -94,8 +97,6 @@ export const mergeEnvVarsAndCliOptions = Date: Tue, 20 Feb 2024 16:57:36 +0000 Subject: [PATCH 4/4] undo tf changes --- yarn-project/aztec-node/terraform/main.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yarn-project/aztec-node/terraform/main.tf b/yarn-project/aztec-node/terraform/main.tf index 87e349ee077..9d1f74dbd90 100644 --- a/yarn-project/aztec-node/terraform/main.tf +++ b/yarn-project/aztec-node/terraform/main.tf @@ -154,7 +154,7 @@ resource "aws_ecs_task_definition" "aztec-node" { [ { "name": "${var.DEPLOY_TAG}-aztec-node-${count.index + 1}", - "image": "278380418400.dkr.ecr.us-east-2.amazonaws.com/aztec:cache-e2fd516b5f6f5de3c642ebf83f4bd0370f2ace1f", + "image": "${var.DOCKERHUB_ACCOUNT}/aztec:${var.DEPLOY_TAG}", "command": ["start", "--node", "--archiver", "--sequencer"], "essential": true, "memoryReservation": 3776, @@ -217,23 +217,23 @@ resource "aws_ecs_task_definition" "aztec-node" { }, { "name": "CONTRACT_DEPLOYMENT_EMITTER_ADDRESS", - "value": "0x925957af6173b0517627dc338fccac58c7a73b3a" + "value": "${data.terraform_remote_state.l1_contracts.outputs.contract_deployment_emitter_address}" }, { "name": "ROLLUP_CONTRACT_ADDRESS", - "value": "0xa1b823cd37878be071e80684f8af49f719f9ad70" + "value": "${data.terraform_remote_state.l1_contracts.outputs.rollup_contract_address}" }, { "name": "INBOX_CONTRACT_ADDRESS", - "value": "0x3ac9d23ac5b8ee0126baf3fac8def4885e6c7999" + "value": "${data.terraform_remote_state.l1_contracts.outputs.inbox_contract_address}" }, { "name": "OUTBOX_CONTRACT_ADDRESS", - "value": "0x03c6f7f5c15dcef8273884784fd43fe76184992c" + "value": "${data.terraform_remote_state.l1_contracts.outputs.outbox_contract_address}" }, { "name": "REGISTRY_CONTRACT_ADDRESS", - "value": "0xad463e0cb8ec1031998ff1f2335f6445a3e71d20" + "value": "${data.terraform_remote_state.l1_contracts.outputs.registry_contract_address}" }, { "name": "API_KEY",