Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(ci): node health-check + contract address env vars #3578

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion l1-contracts/scripts/ci_deploy_contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ docker run \
./scripts/deploy_contracts.sh

# Write the contract addresses as terraform variables
for KEY in ROLLUP_CONTRACT_ADDRESS REGISTRY_CONTRACT_ADDRESS INBOX_CONTRACT_ADDRESS OUTBOX_CONTRACT_ADDRESS; do
for KEY in ROLLUP_CONTRACT_ADDRESS REGISTRY_CONTRACT_ADDRESS INBOX_CONTRACT_ADDRESS OUTBOX_CONTRACT_ADDRESS CONTRACT_DEPLOYMENT_EMITTER_ADDRESS; do
VALUE=$(jq -r .$KEY ./serve/contract_addresses.json)
export TF_VAR_$KEY=$VALUE
done
Expand Down
18 changes: 0 additions & 18 deletions yarn-project/aztec-node/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import { createDebugLogger } from '@aztec/foundation/log';

import http from 'http';
import Koa from 'koa';
import Router from 'koa-router';

import { AztecNodeConfig, AztecNodeService, createAztecNodeRpcServer, getConfigEnvVars } from '../index.js';

Expand All @@ -20,19 +18,6 @@ async function createAndDeployAztecNode() {
return await AztecNodeService.createAndSync(aztecNodeConfig);
}

/**
* Creates a router for helper API endpoints of the Private eXecution Environment (PXE).
* @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
*/
Expand All @@ -52,9 +37,6 @@ async function main() {

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(+AZTEC_NODE_PORT);
Expand Down
5 changes: 4 additions & 1 deletion yarn-project/aztec-node/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ resource "aws_service_discovery_service" "aztec-node" {

# Define task definitions for each node.
resource "aws_ecs_task_definition" "aztec-node" {
# for_each = var.node_keys
count = local.node_count
family = "${var.DEPLOY_TAG}-aztec-node-${count.index + 1}"
requires_compatibilities = ["FARGATE"]
Expand Down Expand Up @@ -188,6 +187,10 @@ resource "aws_ecs_task_definition" "aztec-node" {
"name": "INBOX_CONTRACT_ADDRESS",
"value": "${data.terraform_remote_state.l1_contracts.outputs.inbox_contract_address}"
},
{
"name": "OUTBOX_CONTRACT_ADDRESS",
"value": "${data.terraform_remote_state.l1_contracts.outputs.outbox_contract_address}"
},
{
"name": "REGISTRY_CONTRACT_ADDRESS",
"value": "${data.terraform_remote_state.l1_contracts.outputs.registry_contract_address}"
Expand Down
15 changes: 14 additions & 1 deletion yarn-project/aztec-sandbox/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { createAztecNodeRpcServer, getConfigEnvVars as getNodeConfigEnvVars } fr
import { AccountManager, createAztecNodeClient, deployInitialSandboxAccounts } from '@aztec/aztec.js';
import { NULL_KEY } from '@aztec/ethereum';
import { init } from '@aztec/foundation/crypto';
import { createStatusRouter } from '@aztec/foundation/json-rpc/server';
import { createDebugLogger } from '@aztec/foundation/log';
import { fileURLToPath } from '@aztec/foundation/url';
import { NoirCommit } from '@aztec/noir-compiler/versions';
import { BootstrapNode, getP2PConfigEnvVars } from '@aztec/p2p';
import { GrumpkinScalar, PXEService, createPXERpcServer } from '@aztec/pxe';

import { readFileSync } from 'fs';
import http from 'http';
import { dirname, resolve } from 'path';
import { mnemonicToAccount } from 'viem/accounts';

Expand Down Expand Up @@ -143,8 +145,19 @@ async function main() {
const node = await createAztecNode(nodeConfig);
installSignalHandlers(node.stop);

const port = process.env.AZTEC_NODE_PORT || 8080; // Use standard 8080 when no PXE is running
const nodeRpcServer = createAztecNodeRpcServer(node);
const app = nodeRpcServer.getApp();

// Add a /status endpoint
const statusRouter = createStatusRouter();
app.use(statusRouter.routes());
app.use(statusRouter.allowedMethods());

// Start Node JSON-RPC server
startHttpRpcServer(node, createAztecNodeRpcServer, 8080); // Use standard 8080 when no PXE is running
const httpServer = http.createServer(app.callback());
httpServer.listen(port);

logStrings.push(`Aztec Node v${version} (noir ${NoirCommit}) is now ready for use in port ${AZTEC_NODE_PORT}!`);
} else if (mode === SandboxMode.PXE) {
// Code path for starting PXE only
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/json-rpc/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { JsonRpcServer } from './json_rpc_server.js';
export { JsonRpcServer, createStatusRouter } from './json_rpc_server.js';
export { JsonProxy } from './json_proxy.js';
13 changes: 13 additions & 0 deletions yarn-project/foundation/src/json-rpc/server/json_rpc_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,16 @@ export class JsonRpcServer {
httpServer.listen(port);
}
}

/**
* Creates a router for handling a plain status request that will return 200 status when running.
* @param apiPrefix - The prefix to use for all api requests
* @returns - The router for handling status requests.
*/
export function createStatusRouter(apiPrefix = '') {
const router = new Router({ prefix: `${apiPrefix}` });
router.get('/status', (ctx: Koa.Context) => {
ctx.status = 200;
});
return router;
}
3 changes: 1 addition & 2 deletions yarn-project/pxe/src/pxe_http/pxe_http_server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FunctionSelector } from '@aztec/circuits.js';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr, GrumpkinScalar, Point } from '@aztec/foundation/fields';
import { JsonRpcServer } from '@aztec/foundation/json-rpc/server';
import {
Expand All @@ -24,8 +25,6 @@ import {
import http from 'http';
import { foundry } from 'viem/chains';

import { EthAddress } from '../index.js';

export const localAnvil = foundry;

/**
Expand Down