diff --git a/.circleci/config.yml b/.circleci/config.yml index 2707d25fbf0..a8bbcce8be4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -454,7 +454,44 @@ jobs: echo "export DOCKER_BUILDKIT=" > $BASH_ENV force_deploy_build aztec-sandbox false arm64 - aztec-sandbox-ecr-manifest: + pxe-base: + machine: + image: ubuntu-2204:2023.07.2 + resource_class: large + steps: + - *checkout + - *setup_env + - run: + name: "Build and test" + command: force_deploy_build pxe-base false + + pxe-x86_64: + machine: + image: ubuntu-2204:2023.07.2 + resource_class: large + steps: + - *checkout + - *setup_env + - run: + name: "Build and test" + command: force_deploy_build pxe false x86_64 + + pxe-arm64: + machine: + image: ubuntu-2204:2023.07.2 + resource_class: arm.large + steps: + - *checkout + - *setup_env + - run: + name: "Build and test" + # We need to force not to use docker buildkit because for some reason on arm only, it ends up making a call + # out to eu-west2 despite the image being locally tagged, resulting in unauthorised 401. Weird docker bug? + command: | + echo "export DOCKER_BUILDKIT=" > $BASH_ENV + force_deploy_build pxe false arm64 + + ecr-manifest: machine: image: ubuntu-2204:2023.07.2 resource_class: large @@ -463,7 +500,9 @@ jobs: - *setup_env - run: name: "Create ECR manifest" - command: create_ecr_manifest aztec-sandbox-base aztec-sandbox x86_64,arm64 + command: | + create_ecr_manifest aztec-sandbox-base aztec-sandbox x86_64,arm64 + create_ecr_manifest pxe-base pxe x86_64,arm64 boxes-blank-react: machine: @@ -993,7 +1032,7 @@ jobs: name: "yarn-project" command: yarn-project/deploy_npm.sh - deploy-dockerhub: + deploy-dockerhub-sandbox: machine: image: ubuntu-2204:2023.07.2 resource_class: medium @@ -1008,6 +1047,21 @@ jobs: deploy_dockerhub aztec-sandbox arm64 create_dockerhub_manifest aztec-sandbox x86_64,arm64 + deploy-dockerhub-pxe: + machine: + image: ubuntu-2204:2023.07.2 + resource_class: medium + steps: + - *checkout + - *setup_env + - run: + name: "deploy-pxe" + working_directory: pxe + command: | + deploy_dockerhub pxe x86_64 + deploy_dockerhub pxe arm64 + create_dockerhub_manifest pxe x86_64,arm64 + deploy-end: docker: - image: cimg/base:2023.09 @@ -1201,6 +1255,7 @@ workflows: - end-to-end: *yarn_project - aztec-sandbox-base: *yarn_project + - pxe-base: *yarn_project - canary: *yarn_project - build-docs: *yarn_project @@ -1213,10 +1268,21 @@ workflows: - aztec-sandbox-base <<: *defaults - - aztec-sandbox-ecr-manifest: + - pxe-x86_64: + requires: + - pxe-base + <<: *defaults + - pxe-arm64: + requires: + - pxe-base + <<: *defaults + + - ecr-manifest: requires: - aztec-sandbox-x86_64 - aztec-sandbox-arm64 + - pxe-x86_64 + - pxe-arm64 <<: *defaults - boxes-blank-react: @@ -1237,7 +1303,7 @@ workflows: - e2e-join: requires: - end-to-end - - aztec-sandbox-ecr-manifest + - ecr-manifest - canary <<: *defaults @@ -1322,7 +1388,11 @@ workflows: <<: *defaults # Deployment and Canary tests - - deploy-dockerhub: + - deploy-dockerhub-sandbox: + requires: + - e2e-end + <<: *deploy_defaults + - deploy-dockerhub-pxe: requires: - e2e-end <<: *deploy_defaults @@ -1333,7 +1403,8 @@ workflows: - deploy-end: requires: - - deploy-dockerhub + - deploy-dockerhub-sandbox + - deploy-dockerhub-pxe - deploy-npm <<: *deploy_defaults diff --git a/build_manifest.yml b/build_manifest.yml index bdb1f1361e9..e62123a6888 100644 --- a/build_manifest.yml +++ b/build_manifest.yml @@ -120,6 +120,20 @@ aztec-sandbox: dependencies: - aztec-sandbox-base +pxe-base: + buildDir: yarn-project + projectDir: yarn-project/pxe + dockerfile: Dockerfile + dependencies: + - yarn-project + +pxe: + buildDir: yarn-project + projectDir: yarn-project/pxe + dockerfile: Dockerfile.final + dependencies: + - pxe-base + boxes-blank-react: buildDir: yarn-project projectDir: yarn-project/boxes/blank-react diff --git a/docs/docs/dev_docs/cli/main.md b/docs/docs/dev_docs/cli/main.md index 4836fad27a3..8f6d0a584ce 100644 --- a/docs/docs/dev_docs/cli/main.md +++ b/docs/docs/dev_docs/cli/main.md @@ -36,7 +36,7 @@ Once installed it is invoked via: ## I have the Sandbox running, now what? -Lets first establish that we are able to communicate with the Sandbox. Most commands will require the url to the Sandbox, which defaults in the CLI to `http://localhost:8080`. You can override this as an option with each command or by setting `PXE_HOST` environment variable. +Lets first establish that we are able to communicate with the Sandbox. Most commands will require the url to the Sandbox, which defaults in the CLI to `http://localhost:8080`. You can override this as an option with each command or by setting `PXE_URL` environment variable. To test communication with the Sandbox, let's run the command: diff --git a/docs/docs/dev_docs/getting_started/sandbox.md b/docs/docs/dev_docs/getting_started/sandbox.md index 7c15428d9c0..3cc74267891 100644 --- a/docs/docs/dev_docs/getting_started/sandbox.md +++ b/docs/docs/dev_docs/getting_started/sandbox.md @@ -36,7 +36,11 @@ It will download and execute a script invoking docker compose with 2 containers: - Anvil - Aztec Sandbox -2 ports will need to be opened on your system in order for you to interact with the sandbox. The first port is for Anvil, it defaults to 8545 and can be overridden by specifying a value in the environment variable `SANDBOX_ANVIL_PORT`. The second is the sandbox RPC host port. It defaults to value 8080 but can be overridden with environment variable `SANDBOX_RPC_PORT`. +3 ports will need to be opened on your system in order for you to interact with the sandbox. +The first port is for Anvil, it defaults to 8545 and can be overridden by specifying a value in the environment variable `SANDBOX_ANVIL_PORT`. +The second one is sandbox Aztec Node port, it defaults to 8079 and can be overridden by specifying a value in the environment variable `SANDBOX_AZTEC_NODE_PORT`. +The third is the sandbox PXE port. +It defaults to value 8080 but can be overridden with environment variable `SANDBOX_PXE_PORT`. Within a few seconds the Sandbox should be up and running! diff --git a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts index cd740d9c44f..51205c979af 100644 --- a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts +++ b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts @@ -3,7 +3,18 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { JsonRpcServer } from '@aztec/foundation/json-rpc/server'; -import { AztecNode, ContractData, ExtendedContractData, L2Block, L2BlockL2Logs, L2Tx, Tx, TxHash } from '@aztec/types'; +import { + AztecNode, + ContractData, + ExtendedContractData, + L1ToL2MessageAndIndex, + L2Block, + L2BlockL2Logs, + L2Tx, + SiblingPath, + Tx, + TxHash, +} from '@aztec/types'; /** * Wrap an AztecNode instance with a JSON RPC HTTP server. @@ -13,11 +24,23 @@ import { AztecNode, ContractData, ExtendedContractData, L2Block, L2BlockL2Logs, export function createAztecNodeRpcServer(node: AztecNode) { const rpc = new JsonRpcServer( node, - { AztecAddress, EthAddress, ExtendedContractData, ContractData, Fr, HistoricBlockData, L2Block, L2Tx, TxHash }, + { + AztecAddress, + EthAddress, + ExtendedContractData, + ContractData, + Fr, + HistoricBlockData, + L2Block, + L2Tx, + TxHash, + SiblingPath, + L1ToL2MessageAndIndex, + }, { Tx, L2BlockL2Logs }, false, // disable methods not part of the AztecNode interface - ['start', 'stop', 'getDataTreePath', 'getL1ToL2MessageAndIndex', 'getL1ToL2MessagesTreePath'], + ['start', 'stop'], ); return rpc; } diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 9daf4cdd23e..9b7c610fda7 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -299,7 +299,7 @@ export class AztecNodeService implements AztecNode { // todo: #697 - make this one lookup. const index = (await this.findLeafIndex(MerkleTreeId.L1_TO_L2_MESSAGES_TREE, messageKey.toBuffer()))!; const message = await this.l1ToL2MessageSource.getConfirmedL1ToL2Message(messageKey); - return Promise.resolve({ message, index }); + return Promise.resolve(new L1ToL2MessageAndIndex(index, message)); } /** diff --git a/yarn-project/aztec-node/src/bin/index.ts b/yarn-project/aztec-node/src/bin/index.ts index 41ec5382c82..fee7f7808dc 100644 --- a/yarn-project/aztec-node/src/bin/index.ts +++ b/yarn-project/aztec-node/src/bin/index.ts @@ -7,7 +7,7 @@ import Router from 'koa-router'; import { AztecNodeConfig, AztecNodeService, createAztecNodeRpcServer, getConfigEnvVars } from '../index.js'; -const { SERVER_PORT = 8081, API_PREFIX = '' } = process.env; +const { AZTEC_NODE_PORT = 8081, API_PREFIX = '' } = process.env; const logger = createDebugLogger('aztec:node'); @@ -57,8 +57,8 @@ async function main() { 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}`); + httpServer.listen(+AZTEC_NODE_PORT); + logger.info(`Aztec Node JSON-RPC Server listening on port ${AZTEC_NODE_PORT}`); } main().catch(err => { diff --git a/yarn-project/aztec-node/terraform/main.tf b/yarn-project/aztec-node/terraform/main.tf index c2518571d3b..38fff0a2d9e 100644 --- a/yarn-project/aztec-node/terraform/main.tf +++ b/yarn-project/aztec-node/terraform/main.tf @@ -98,7 +98,7 @@ resource "aws_ecs_task_definition" "aztec-node-1" { "value": "production" }, { - "name": "SERVER_PORT", + "name": "AZTEC_NODE_PORT", "value": "80" }, { diff --git a/yarn-project/aztec-sandbox/Dockerfile b/yarn-project/aztec-sandbox/Dockerfile index 3f3a2e6cb3d..3b669677b80 100644 --- a/yarn-project/aztec-sandbox/Dockerfile +++ b/yarn-project/aztec-sandbox/Dockerfile @@ -22,4 +22,4 @@ COPY --from=builder /usr/src/ /usr/src/ WORKDIR /usr/src/yarn-project/aztec-sandbox ENTRYPOINT ["yarn"] CMD [ "start" ] -EXPOSE 8080 +EXPOSE 8079 8080 diff --git a/yarn-project/aztec-sandbox/Dockerfile.final b/yarn-project/aztec-sandbox/Dockerfile.final index a9cc84909f1..5ef50e268e4 100644 --- a/yarn-project/aztec-sandbox/Dockerfile.final +++ b/yarn-project/aztec-sandbox/Dockerfile.final @@ -7,4 +7,4 @@ WORKDIR /usr/src/yarn-project/aztec-sandbox ENTRYPOINT ["yarn"] CMD [ "start" ] -EXPOSE 8080 \ No newline at end of file +EXPOSE 8079 8080 \ No newline at end of file diff --git a/yarn-project/aztec-sandbox/docker-compose.yml b/yarn-project/aztec-sandbox/docker-compose.yml index 935d0da224e..da0939bd062 100644 --- a/yarn-project/aztec-sandbox/docker-compose.yml +++ b/yarn-project/aztec-sandbox/docker-compose.yml @@ -9,7 +9,8 @@ services: aztec: image: 'aztecprotocol/aztec-sandbox:${SANDBOX_VERSION:-latest}' ports: - - '${SANDBOX_RPC_PORT:-8080}:8080' + - '${SANDBOX_AZTEC_NODE_PORT:-8079}:8079' + - '${SANDBOX_PXE_PORT:-8080}:8080' environment: DEBUG: # Loaded from the user shell if explicitly set HOST_WORKDIR: '${PWD}' # Loaded from the user shell to show log files absolute path in host @@ -19,7 +20,7 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS: 50 + PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 volumes: - ./log:/usr/src/yarn-project/aztec-sandbox/log:rw diff --git a/yarn-project/aztec-sandbox/src/bin/index.ts b/yarn-project/aztec-sandbox/src/bin/index.ts index 44387c6b36a..184ca5ad707 100644 --- a/yarn-project/aztec-sandbox/src/bin/index.ts +++ b/yarn-project/aztec-sandbox/src/bin/index.ts @@ -1,18 +1,20 @@ #!/usr/bin/env -S node --no-warnings +import { createAztecNodeRpcServer } from '@aztec/aztec-node'; import { deployInitialSandboxAccounts } from '@aztec/aztec.js'; import { createDebugLogger } from '@aztec/foundation/log'; import { fileURLToPath } from '@aztec/foundation/url'; import NoirVersion from '@aztec/noir-compiler/noir-version'; -import { startPXEHttpServer } from '@aztec/pxe'; +import { createPXERpcServer } from '@aztec/pxe'; import { readFileSync } from 'fs'; import { dirname, resolve } from 'path'; import { setupFileDebugLog } from '../logging.js'; import { createSandbox } from '../sandbox.js'; +import { startHttpRpcServer } from '../server.js'; import { github, splash } from '../splash.js'; -const { SERVER_PORT = 8080 } = process.env; +const { AZTEC_NODE_PORT = 8079, PXE_PORT = 8080 } = process.env; const logger = createDebugLogger('aztec:sandbox'); @@ -20,12 +22,13 @@ const logger = createDebugLogger('aztec:sandbox'); * Creates the sandbox from provided config and deploys any initial L1 and L2 contracts */ async function createAndInitialiseSandbox() { - const { l1Contracts, pxe, stop } = await createSandbox(); + const { l1Contracts, node, pxe, stop } = await createSandbox(); logger.info('Setting up test accounts...'); const accounts = await deployInitialSandboxAccounts(pxe); return { l1Contracts, pxe, + node, stop, accounts, }; @@ -41,7 +44,7 @@ async function main() { logger.info(`Setting up Aztec Sandbox v${version} (nargo ${NoirVersion.tag}), please stand by...`); - const { pxe, stop, accounts } = await createAndInitialiseSandbox(); + const { pxe, node, stop, accounts } = await createAndInitialiseSandbox(); const shutdown = async () => { logger.info('Shutting down...'); @@ -52,8 +55,10 @@ async function main() { process.once('SIGINT', shutdown); process.once('SIGTERM', shutdown); - startPXEHttpServer(pxe, SERVER_PORT); - logger.info(`Aztec Sandbox JSON-RPC Server listening on port ${SERVER_PORT}`); + startHttpRpcServer(node, createAztecNodeRpcServer, AZTEC_NODE_PORT); + logger.info(`Aztec Node JSON-RPC Server listening on port ${AZTEC_NODE_PORT}`); + startHttpRpcServer(pxe, createPXERpcServer, PXE_PORT); + logger.info(`PXE JSON-RPC Server listening on port ${PXE_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 deleted file mode 100644 index 0b6c67f22be..00000000000 --- a/yarn-project/aztec-sandbox/src/routes.ts +++ /dev/null @@ -1,17 +0,0 @@ -import Koa from 'koa'; -import Router from 'koa-router'; - -/** - * Creates a router for helper API endpoints of the Private eXecution Environment (PXE). - * @param aztecNode - An instance of the aztec node. - * @param config - The aztec node's configuration variables. - */ -export function createApiRouter() { - const router = new Router({ prefix: '/api' }); - router.get('/status', (ctx: Koa.Context) => { - // TODO: add `status` to Aztec node. - ctx.status = 200; - }); - - return router; -} diff --git a/yarn-project/aztec-sandbox/src/server.ts b/yarn-project/aztec-sandbox/src/server.ts index 4affe2f2b21..f8cc66f2198 100644 --- a/yarn-project/aztec-sandbox/src/server.ts +++ b/yarn-project/aztec-sandbox/src/server.ts @@ -1,23 +1,22 @@ -import { createPXERpcServer } from '@aztec/pxe'; -import { PXE } from '@aztec/types'; +import { JsonRpcServer } from '@aztec/foundation/json-rpc/server'; import http from 'http'; -import { createApiRouter } from './routes.js'; - /** - * Creates an http server that forwards calls to the PXE and starts it on the given port. - * @param pxe - PXE that answers queries to the created HTTP server. + * Creates an http server that forwards calls to the underlying instance and starts it on the given port. + * @param instance - Instance to wrap in a JSON-RPC server. + * @param jsonRpcFactoryFunc - Function that wraps the instance in a JSON-RPC server. * @param port - Port to listen in. * @returns A running http server. */ -export function startHttpRpcServer(pxe: PXE, port: string | number): http.Server { - const rpcServer = createPXERpcServer(pxe); +export function startHttpRpcServer( + instance: T, + jsonRpcFactoryFunc: (instance: T) => JsonRpcServer, + port: string | number, +): http.Server { + const rpcServer = jsonRpcFactoryFunc(instance); const app = rpcServer.getApp(); - const apiRouter = createApiRouter(); - app.use(apiRouter.routes()); - app.use(apiRouter.allowedMethods()); const httpServer = http.createServer(app.callback()); httpServer.listen(port); diff --git a/yarn-project/aztec.js/src/sandbox/index.ts b/yarn-project/aztec.js/src/sandbox/index.ts index e94cbca275c..73623f82798 100644 --- a/yarn-project/aztec.js/src/sandbox/index.ts +++ b/yarn-project/aztec.js/src/sandbox/index.ts @@ -18,7 +18,7 @@ export const INITIAL_SANDBOX_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO]; export const INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI = SchnorrAccountContractAbi; -export const { SANDBOX_URL = 'http://localhost:8080' } = process.env; +export const { PXE_URL = 'http://localhost:8080' } = process.env; /** * Gets a collection of wallets for the Aztec accounts that are initially stored in the sandbox. @@ -73,7 +73,7 @@ export async function deployInitialSandboxAccounts(pxe: PXE) { * @param pxe - The pxe client connected to the sandbox. */ export async function waitForSandbox(pxe?: PXE) { - pxe = pxe ?? createPXEClient(SANDBOX_URL); + pxe = pxe ?? createPXEClient(PXE_URL); while (true) { try { await pxe.getNodeInfo(); diff --git a/yarn-project/boxes/blank-react/docker-compose.yml b/yarn-project/boxes/blank-react/docker-compose.yml index 2417ca77775..37a653c0fdc 100644 --- a/yarn-project/boxes/blank-react/docker-compose.yml +++ b/yarn-project/boxes/blank-react/docker-compose.yml @@ -9,7 +9,8 @@ services: aztec: image: 'aztecprotocol/aztec-sandbox:${SANDBOX_VERSION:-latest}' ports: - - '${SANDBOX_RPC_PORT:-8080}:8080' + - '${SANDBOX_AZTEC_NODE_PORT:-8079}:8079' + - '${SANDBOX_PXE_PORT:-8080}:8080' environment: DEBUG: # Loaded from the user shell if explicitly set HOST_WORKDIR: '${PWD}' # Loaded from the user shell to show log files absolute path in host @@ -19,7 +20,7 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS: 50 + PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 volumes: - ./log:/usr/src/yarn-project/aztec-sandbox/log:rw @@ -31,4 +32,4 @@ services: environment: ETHEREUM_HOST: http://ethereum:8545 CHAIN_ID: 31337 - SANDBOX_URL: http://aztec:8080 \ No newline at end of file + PXE_URL: http://aztec:8080 \ No newline at end of file diff --git a/yarn-project/boxes/blank-react/src/app/home.tsx b/yarn-project/boxes/blank-react/src/app/home.tsx index f6d7186fcb1..b1535b94d4f 100644 --- a/yarn-project/boxes/blank-react/src/app/home.tsx +++ b/yarn-project/boxes/blank-react/src/app/home.tsx @@ -1,7 +1,7 @@ import { Loader } from '@aztec/aztec-ui'; import { CompleteAddress } from '@aztec/aztec.js'; import { useEffect, useRef, useState } from 'react'; -import { SANDBOX_URL } from '../config.js'; +import { PXE_URL } from '../config.js'; import { WalletDropdown } from './components/wallet_dropdown.js'; import { Contract } from './contract.js'; import styles from './home.module.scss'; @@ -73,7 +73,7 @@ export function Home() { <> {`Failed to load accounts. Error: ${selectWalletError}`}
- {`Make sure the Aztec Sandbox is running at: ${SANDBOX_URL}`} + {`Make sure PXE from Aztec Sandbox is running at: ${PXE_URL}`} )} {!selectWalletError && !selectedWallet && `No accounts.`} diff --git a/yarn-project/boxes/blank-react/src/config.ts b/yarn-project/boxes/blank-react/src/config.ts index bf8bbb85b3b..b2405997b7d 100644 --- a/yarn-project/boxes/blank-react/src/config.ts +++ b/yarn-project/boxes/blank-react/src/config.ts @@ -6,7 +6,7 @@ import { BlankContractAbi } from './artifacts/blank.js'; export const contractAbi: ContractAbi = BlankContractAbi; -export const SANDBOX_URL: string = process.env.SANDBOX_URL || 'http://localhost:8080'; -export const pxe: PXE = createPXEClient(SANDBOX_URL); +export const PXE_URL: string = process.env.PXE_URL || 'http://localhost:8080'; +export const pxe: PXE = createPXEClient(PXE_URL); export const CONTRACT_ADDRESS_PARAM_NAMES = ['address']; diff --git a/yarn-project/boxes/blank-react/src/tests/blank.contract.test.ts b/yarn-project/boxes/blank-react/src/tests/blank.contract.test.ts index 7f1eed6e2c8..035deced39c 100644 --- a/yarn-project/boxes/blank-react/src/tests/blank.contract.test.ts +++ b/yarn-project/boxes/blank-react/src/tests/blank.contract.test.ts @@ -19,8 +19,8 @@ const logger = createDebugLogger('aztec:http-pxe-client'); // assumes sandbox is running locally, which this script does not trigger // as well as anvil. anvil can be started with yarn test:integration const setupSandbox = async () => { - const { SANDBOX_URL = 'http://localhost:8080' } = process.env; - const pxe = createPXEClient(SANDBOX_URL); + const { PXE_URL = 'http://localhost:8080' } = process.env; + const pxe = createPXEClient(PXE_URL); await waitForSandbox(pxe); return pxe; diff --git a/yarn-project/boxes/blank/docker-compose.yml b/yarn-project/boxes/blank/docker-compose.yml index 923aed602d3..2d8d5c5dc18 100644 --- a/yarn-project/boxes/blank/docker-compose.yml +++ b/yarn-project/boxes/blank/docker-compose.yml @@ -9,7 +9,8 @@ services: aztec: image: 'aztecprotocol/aztec-sandbox:${SANDBOX_VERSION:-latest}' ports: - - '${SANDBOX_RPC_PORT:-8080}:8080' + - '${SANDBOX_AZTEC_NODE_PORT:-8079}:8079' + - '${SANDBOX_PXE_PORT:-8080}:8080' environment: DEBUG: # Loaded from the user shell if explicitly set HOST_WORKDIR: '${PWD}' # Loaded from the user shell to show log files absolute path in host @@ -19,7 +20,7 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS: 50 + PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 volumes: - ./log:/usr/src/yarn-project/aztec-sandbox/log:rw @@ -31,4 +32,4 @@ services: environment: ETHEREUM_HOST: http://ethereum:8545 CHAIN_ID: 31337 - SANDBOX_URL: http://aztec:8080 \ No newline at end of file + PXE_URL: http://aztec:8080 \ No newline at end of file diff --git a/yarn-project/boxes/blank/src/index.ts b/yarn-project/boxes/blank/src/index.ts index 6d35b8190fc..a273bcabf70 100644 --- a/yarn-project/boxes/blank/src/index.ts +++ b/yarn-project/boxes/blank/src/index.ts @@ -15,8 +15,8 @@ import { FieldsOf } from '@aztec/foundation/types'; import { BlankContractAbi } from './artifacts/blank.js'; export const contractAbi: ContractAbi = BlankContractAbi; -export const SANDBOX_URL: string = process.env.SANDBOX_URL || 'http://localhost:8080'; -export const pxe: PXE = createPXEClient(SANDBOX_URL); +export const PXE_URL: string = process.env.PXE_URL || 'http://localhost:8080'; +export const pxe: PXE = createPXEClient(PXE_URL); let contractAddress: string = ''; diff --git a/yarn-project/boxes/blank/src/tests/blank.contract.test.ts b/yarn-project/boxes/blank/src/tests/blank.contract.test.ts index 883ef265369..ac9cff71b87 100644 --- a/yarn-project/boxes/blank/src/tests/blank.contract.test.ts +++ b/yarn-project/boxes/blank/src/tests/blank.contract.test.ts @@ -18,8 +18,8 @@ const logger = createDebugLogger('aztec:blank-box-test'); // assumes sandbox is running locally, which this script does not trigger // as well as anvil. anvil can be started with yarn test:integration const setupSandbox = async () => { - const { SANDBOX_URL = 'http://localhost:8080' } = process.env; - const pxe = createPXEClient(SANDBOX_URL); + const { PXE_URL = 'http://localhost:8080' } = process.env; + const pxe = createPXEClient(PXE_URL); await waitForSandbox(pxe); return pxe; }; diff --git a/yarn-project/boxes/private-token/docker-compose.yml b/yarn-project/boxes/private-token/docker-compose.yml index 997eed0992b..9ad3d4e954c 100644 --- a/yarn-project/boxes/private-token/docker-compose.yml +++ b/yarn-project/boxes/private-token/docker-compose.yml @@ -9,7 +9,8 @@ services: aztec: image: 'aztecprotocol/aztec-sandbox:${SANDBOX_VERSION:-latest}' ports: - - '${SANDBOX_RPC_PORT:-8080}:8080' + - '${SANDBOX_AZTEC_NODE_PORT:-8079}:8079' + - '${SANDBOX_PXE_PORT:-8080}:8080' environment: DEBUG: # Loaded from the user shell if explicitly set HOST_WORKDIR: '${PWD}' # Loaded from the user shell to show log files absolute path in host @@ -19,7 +20,7 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS: 50 + PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 volumes: - ./log:/usr/src/yarn-project/aztec-sandbox/log:rw @@ -31,4 +32,4 @@ services: environment: ETHEREUM_HOST: http://ethereum:8545 CHAIN_ID: 31337 - SANDBOX_URL: http://aztec:8080 \ No newline at end of file + PXE_URL: http://aztec:8080 \ No newline at end of file diff --git a/yarn-project/boxes/private-token/src/app/home.tsx b/yarn-project/boxes/private-token/src/app/home.tsx index 64e73a44d12..8475b2afe55 100644 --- a/yarn-project/boxes/private-token/src/app/home.tsx +++ b/yarn-project/boxes/private-token/src/app/home.tsx @@ -1,4 +1,4 @@ -import { SANDBOX_URL } from '../config.js'; +import { PXE_URL } from '../config.js'; import { WalletDropdown } from './components/wallet_dropdown.js'; import { Contract } from './contract.js'; import styles from './home.module.scss'; @@ -73,7 +73,7 @@ export function Home() { <> {`Failed to load accounts. Error: ${selectWalletError}`}
- {`Make sure the Aztec Sandbox is running at: ${SANDBOX_URL}`} + {`Make sure PXE from Aztec Sandbox is running at: ${PXE_URL}`} )} {!selectWalletError && !selectedWallet && `No accounts.`} diff --git a/yarn-project/boxes/private-token/src/config.ts b/yarn-project/boxes/private-token/src/config.ts index 074f5eea5fa..14449eac122 100644 --- a/yarn-project/boxes/private-token/src/config.ts +++ b/yarn-project/boxes/private-token/src/config.ts @@ -6,8 +6,8 @@ import { ContractAbi } from '@aztec/foundation/abi'; export const contractAbi: ContractAbi = PrivateTokenContractAbi; -export const SANDBOX_URL: string = process.env.SANDBOX_URL || 'http://localhost:8080'; -export const pxe: PXE = createPXEClient(SANDBOX_URL); +export const PXE_URL: string = process.env.PXE_URL || 'http://localhost:8080'; +export const pxe: PXE = createPXEClient(PXE_URL); export const CONTRACT_ADDRESS_PARAM_NAMES = ['owner', 'contract_address', 'recipient']; export const FILTERED_FUNCTION_NAMES = ['compute_note_hash_and_nullifier']; diff --git a/yarn-project/boxes/private-token/src/tests/privatetoken.sandbox.test.ts b/yarn-project/boxes/private-token/src/tests/privatetoken.sandbox.test.ts index bfbe139e133..367e0fb60f4 100644 --- a/yarn-project/boxes/private-token/src/tests/privatetoken.sandbox.test.ts +++ b/yarn-project/boxes/private-token/src/tests/privatetoken.sandbox.test.ts @@ -23,8 +23,8 @@ const MINT_AMOUNT = 11n; // assumes sandbox is running locally, which this script does not trigger // as well as anvil. anvil can be started with yarn test:integration const setupSandbox = async () => { - const { SANDBOX_URL = 'http://localhost:8080' } = process.env; - const pxe = createPXEClient(SANDBOX_URL); + const { PXE_URL = 'http://localhost:8080' } = process.env; + const pxe = createPXEClient(PXE_URL); await waitForSandbox(pxe); return pxe; }; diff --git a/yarn-project/canary/scripts/docker-compose-browser.yml b/yarn-project/canary/scripts/docker-compose-browser.yml index e7db3336acc..bb8c3b1ecc5 100644 --- a/yarn-project/canary/scripts/docker-compose-browser.yml +++ b/yarn-project/canary/scripts/docker-compose-browser.yml @@ -22,7 +22,7 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS: 50 + PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0} ports: @@ -33,5 +33,5 @@ services: environment: ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 - SANDBOX_URL: http://sandbox:8080 + PXE_URL: http://sandbox:8080 command: ['./scripts/start_e2e_ci_browser.sh', './src/aztec_js_browser.test.ts'] diff --git a/yarn-project/canary/scripts/docker-compose-e2e-sandbox.yml b/yarn-project/canary/scripts/docker-compose-e2e-sandbox.yml index 7f3d8162382..9fcde2a195a 100644 --- a/yarn-project/canary/scripts/docker-compose-e2e-sandbox.yml +++ b/yarn-project/canary/scripts/docker-compose-e2e-sandbox.yml @@ -22,7 +22,7 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS: 50 + PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0} ports: @@ -33,6 +33,6 @@ services: environment: ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 - SANDBOX_URL: http://sandbox:8080 + PXE_URL: http://sandbox:8080 SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0} command: ${TEST:-./src/e2e_deploy_contract.test.ts} diff --git a/yarn-project/canary/scripts/docker-compose.yml b/yarn-project/canary/scripts/docker-compose.yml index ccba483c3ac..9dba10f56cd 100644 --- a/yarn-project/canary/scripts/docker-compose.yml +++ b/yarn-project/canary/scripts/docker-compose.yml @@ -22,7 +22,7 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS: 50 + PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0} ports: @@ -33,5 +33,5 @@ services: environment: ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 - SANDBOX_URL: http://sandbox:8080 + PXE_URL: http://sandbox:8080 command: ${TEST:-./src/uniswap_trade_on_l1_from_l2.test.ts} diff --git a/yarn-project/canary/src/cli.test.ts b/yarn-project/canary/src/cli.test.ts index a7fef24cc07..ef5e9184789 100644 --- a/yarn-project/canary/src/cli.test.ts +++ b/yarn-project/canary/src/cli.test.ts @@ -1,14 +1,14 @@ import { createDebugLogger, createPXEClient, makeFetch, waitForSandbox } from '@aztec/aztec.js'; import { cliTestSuite } from '@aztec/end-to-end'; -const { SANDBOX_URL = 'http://localhost:8080' } = process.env; +const { PXE_URL = 'http://localhost:8080' } = process.env; const debug = createDebugLogger('aztec:canary_cli'); const setupRPC = async () => { - const pxe = createPXEClient(SANDBOX_URL, makeFetch([1, 2, 3, 4, 5], true)); + const pxe = createPXEClient(PXE_URL, makeFetch([1, 2, 3, 4, 5], true)); await waitForSandbox(pxe); return pxe; }; -cliTestSuite('CLI Canary', setupRPC, () => Promise.resolve(), debug, SANDBOX_URL); +cliTestSuite('CLI Canary', setupRPC, () => Promise.resolve(), debug, PXE_URL); diff --git a/yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts b/yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts index 58fcb9d6797..b028577511c 100644 --- a/yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts +++ b/yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts @@ -36,7 +36,7 @@ import { deployAndInitializeTokenAndBridgeContracts, deployL1Contract, hashPaylo const logger = createDebugLogger('aztec:canary'); -const { SANDBOX_URL = 'http://localhost:8080', ETHEREUM_HOST = 'http://localhost:8545' } = process.env; +const { PXE_URL = 'http://localhost:8080', ETHEREUM_HOST = 'http://localhost:8545' } = process.env; export const MNEMONIC = 'test test test test test test test test test test test junk'; @@ -45,7 +45,7 @@ const DAI_ADDRESS = EthAddress.fromString('0x6B175474E89094C44Da98b954EedeAC4952 const EXPECTED_FORKED_BLOCK = 17514288; -const pxeRpcUrl = SANDBOX_URL; +const pxeRpcUrl = PXE_URL; const ethRpcUrl = ETHEREUM_HOST; const hdAccount = mnemonicToAccount(MNEMONIC); diff --git a/yarn-project/canary/tsconfig.json b/yarn-project/canary/tsconfig.json index 837b3f136a5..d02659b19cd 100644 --- a/yarn-project/canary/tsconfig.json +++ b/yarn-project/canary/tsconfig.json @@ -20,10 +20,10 @@ }, "references": [ { - "path": "../circuits.js" + "path": "../aztec.js" }, { - "path": "../aztec.js" + "path": "../circuits.js" }, { "path": "../cli" diff --git a/yarn-project/cli/README.md b/yarn-project/cli/README.md index ae1d8fd4812..fffc25a7a4b 100644 --- a/yarn-project/cli/README.md +++ b/yarn-project/cli/README.md @@ -43,14 +43,14 @@ These options are: - `PRIVATE_KEY` -> `-k, --private-key` for all commands that require a private key. - `PUBLIC_KEY` -> `-k, --public-key` for all commands that require a public key. -- `PXE_HOST` -> `-u, --rpc-url` for commands that require a PXE +- `PXE_URL` -> `-u, --rpc-url` for commands that require a PXE - `API_KEY` -> `a, --api-key` for `deploy-l1-contracts`. - `ETHEREUM_RPC_HOST` -> `-u, --rpc-url` for `deploy-l1-contracts`. So if for example you are running your Private eXecution Environment (PXE) remotely you can do: ```shell -export PXE_HOST=http://external.site/rpc:8080 +export PXE_URL=http://external.site/rpc:8080 aztec-cli deploy my_contract.json ``` diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index e0e190af6bf..ded8ca5fcf0 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -61,7 +61,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { program.name('aztec-cli').description('CLI for interacting with Aztec.').version(version); const pxeOption = new Option('-u, --rpc-url ', 'URL of the PXE') - .env('PXE_HOST') + .env('PXE_URL') .default('http://localhost:8080') .makeOptionMandatory(true); diff --git a/yarn-project/end-to-end/scripts/docker-compose-e2e-sandbox-browser.yml b/yarn-project/end-to-end/scripts/docker-compose-e2e-sandbox-browser.yml index 7436b41d6fb..2663326eb1c 100644 --- a/yarn-project/end-to-end/scripts/docker-compose-e2e-sandbox-browser.yml +++ b/yarn-project/end-to-end/scripts/docker-compose-e2e-sandbox-browser.yml @@ -22,7 +22,7 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS: 50 + PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0} ports: @@ -35,7 +35,7 @@ services: DEBUG: ${DEBUG:-'aztec:*'} ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 - SANDBOX_URL: http://sandbox:8080 + PXE_URL: http://sandbox:8080 SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0} entrypoint: ['./scripts/start_e2e_ci_browser.sh', './src/e2e_aztec_js_browser.test.ts'] volumes: diff --git a/yarn-project/end-to-end/scripts/docker-compose-e2e-sandbox.yml b/yarn-project/end-to-end/scripts/docker-compose-e2e-sandbox.yml index e59bb5c062f..2cc503da61c 100644 --- a/yarn-project/end-to-end/scripts/docker-compose-e2e-sandbox.yml +++ b/yarn-project/end-to-end/scripts/docker-compose-e2e-sandbox.yml @@ -22,7 +22,7 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS: 50 + PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0} ports: @@ -35,7 +35,7 @@ services: DEBUG: ${DEBUG:-'aztec:*'} ETHEREUM_HOST: http://fork:8545 CHAIN_ID: 31337 - SANDBOX_URL: http://sandbox:8080 + PXE_URL: http://sandbox:8080 SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0} command: ${TEST:-./src/e2e_deploy_contract.test.ts} volumes: diff --git a/yarn-project/end-to-end/scripts/docker-compose.yml b/yarn-project/end-to-end/scripts/docker-compose.yml index 69db7b71b14..eaea6050e00 100644 --- a/yarn-project/end-to-end/scripts/docker-compose.yml +++ b/yarn-project/end-to-end/scripts/docker-compose.yml @@ -23,7 +23,7 @@ services: P2P_BLOCK_CHECK_INTERVAL_MS: 50 SEQ_TX_POLLING_INTERVAL_MS: 50 WS_BLOCK_CHECK_INTERVAL_MS: 50 - PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS: 50 + PXE_BLOCK_POLLING_INTERVAL_MS: 50 ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500 SEARCH_START_BLOCK: ${FORK_BLOCK_NUMBER:-0} command: ${TEST:-./src/e2e_deploy_contract.test.ts} diff --git a/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts index 7a29bfba76a..ee792e59f25 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_publish_rollup.test.ts @@ -3,6 +3,7 @@ import { AztecNodeService } from '@aztec/aztec-node'; import { AztecAddress } from '@aztec/aztec.js'; import { sleep } from '@aztec/foundation/sleep'; import { TokenContract } from '@aztec/noir-contracts/types'; +import { SequencerClient } from '@aztec/sequencer-client'; import times from 'lodash.times'; @@ -15,13 +16,18 @@ describe('benchmarks/publish_rollup', () => { let token: TokenContract; let owner: AztecAddress; let recipient: AztecAddress; + let sequencer: SequencerClient; beforeEach(async () => { context = await setup(2, { maxTxsPerBlock: 1024 }); + + if (!(context.aztecNode instanceof AztecNodeService)) throw new Error('Aztec node is not a service'); + sequencer = context.aztecNode!.getSequencer()!; + [owner, recipient] = context.accounts.map(a => a.address); token = await TokenContract.deploy(context.wallet, owner).send().deployed(); await token.methods.mint_public(owner, 10000n).send().wait(); - await context.aztecNode?.getSequencer()!.stop(); + await sequencer.stop(); }, 60_000); it.each(ROLLUP_SIZES)( @@ -39,7 +45,7 @@ describe('benchmarks/publish_rollup', () => { await sleep(100); // Restart sequencer to process all txs together - context.aztecNode?.getSequencer()!.restart(); + sequencer.restart(); // Wait for the last tx to be processed and finish the current node await sentTxs[sentTxs.length - 1].wait({ timeout: 600_00 }); await context.teardown(); diff --git a/yarn-project/end-to-end/src/canary/browser.ts b/yarn-project/end-to-end/src/canary/browser.ts index c2b7a642cd0..737901dc0d7 100644 --- a/yarn-project/end-to-end/src/canary/browser.ts +++ b/yarn-project/end-to-end/src/canary/browser.ts @@ -25,9 +25,9 @@ const __dirname = dirname(__filename); const PORT = 3000; -const { SANDBOX_URL } = process.env; +const { PXE_URL } = process.env; -const conditionalDescribe = () => (SANDBOX_URL ? describe : describe.skip); +const conditionalDescribe = () => (PXE_URL ? describe : describe.skip); const privKey = AztecJs.GrumpkinScalar.random(); export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugLogger) => @@ -46,7 +46,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL beforeAll(async () => { server = setup(); - testClient = AztecJs.createPXEClient(SANDBOX_URL!); + testClient = AztecJs.createPXEClient(PXE_URL!); await AztecJs.waitForSandbox(testClient); app = new Koa(); @@ -100,7 +100,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL console.log(`Created Account: ${addressString}`); return addressString; }, - SANDBOX_URL, + PXE_URL, privKey.toString(), ); const accounts = await testClient.getRegisteredAccounts(); @@ -123,7 +123,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL const balance = await contract.methods.balance_of_private(owner).view({ from: owner }); return balance; }, - SANDBOX_URL, + PXE_URL, (await getTokenAddress()).toString(), TokenContractAbi, ); @@ -144,7 +144,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL console.log(`Transferred ${transferAmount} tokens to new Account`); return await contract.methods.balance_of_private(receiver).view({ from: receiver }); }, - SANDBOX_URL, + PXE_URL, (await getTokenAddress()).toString(), transferAmount, TokenContractAbi, @@ -196,7 +196,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL return receipt.txHash.toString(); }, - SANDBOX_URL, + PXE_URL, privKey.toString(), initialBalance, TokenContractAbi, diff --git a/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts b/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts index a063df29739..f68b2d11af1 100644 --- a/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts +++ b/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts @@ -6,7 +6,7 @@ import stringArgv from 'string-argv'; const debug = createDebugLogger('aztec:e2e_cli'); -const { SANDBOX_URL = 'http://localhost:8080' } = process.env; +const { PXE_URL = 'http://localhost:8080' } = process.env; describe('CLI docs sandbox', () => { let cli: ReturnType; @@ -64,7 +64,7 @@ Rollup Address: 0x0dcd1bf9a1b36ce34237eeafef220932846bcd82 const run = (cmd: string, addRpcUrl = true) => { const args = stringArgv(cmd, 'node', 'dest/bin/index.js'); if (addRpcUrl) { - args.push('--rpc-url', SANDBOX_URL); + args.push('--rpc-url', PXE_URL); } return cli.parseAsync(args); }; diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index e3f8391ff52..d470d060595 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -1,24 +1,21 @@ -import { AztecNodeService } from '@aztec/aztec-node'; import { AztecAddress, NotePreimage, Wallet, computeMessageSecretHash } from '@aztec/aztec.js'; import { DebugLogger } from '@aztec/foundation/log'; import { retryUntil } from '@aztec/foundation/retry'; import { toBigInt } from '@aztec/foundation/serialize'; import { ChildContract, TokenContract } from '@aztec/noir-contracts/types'; import { EthAddress, Fr, PXEService } from '@aztec/pxe'; -import { CompleteAddress, PXE, TxStatus } from '@aztec/types'; +import { AztecNode, CompleteAddress, PXE, TxStatus } from '@aztec/types'; import { jest } from '@jest/globals'; import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup, setupPXEService } from './fixtures/utils.js'; -const { SANDBOX_URL = '' } = process.env; - const TIMEOUT = 60_000; describe('e2e_2_pxes', () => { jest.setTimeout(TIMEOUT); - let aztecNode: AztecNodeService | undefined; + let aztecNode: AztecNode | undefined; let pxeA: PXE; let pxeB: PXE; let walletA: Wallet; @@ -29,10 +26,6 @@ describe('e2e_2_pxes', () => { let teardownA: () => Promise; beforeEach(async () => { - // this test can't be run against the sandbox as it requires 2 PXEs - if (SANDBOX_URL) { - throw new Error(`Test can't be run against the sandbox as 2 PXEs are required`); - } let accounts: CompleteAddress[] = []; ({ aztecNode, diff --git a/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts b/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts index bb4a246251e..aa88cdbbe18 100644 --- a/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts +++ b/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts @@ -20,7 +20,7 @@ const pageLogger = createDebugLogger('aztec:canary_aztec.js:web:page'); * 3) start anvil: `anvil`, * 4) open new terminal and optionally set the more verbose debug level: `DEBUG=aztec:*`, * 5) go to the sandbox dir `yarn-project/aztec-sandbox` and run `yarn start`, - * 6) open new terminal and export the sandbox URL: `export SANDBOX_URL='http://localhost:8080'`, + * 6) open new terminal and export the URL of PXE from Sandbox: `export PXE_URL='http://localhost:8080'`, * 7) go to `yarn-project/end-to-end` and run the test: `yarn test aztec_js_browser` * * NOTE: If you see aztec-sandbox logs spammed with unexpected logs there is probably a chrome process with a webpage 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 37e4a3c1cda..1f24698ce1e 100644 --- a/yarn-project/end-to-end/src/e2e_cli.test.ts +++ b/yarn-project/end-to-end/src/e2e_cli.test.ts @@ -1,7 +1,6 @@ -import { AztecNodeService } from '@aztec/aztec-node'; import { startHttpRpcServer } from '@aztec/aztec-sandbox'; import { PXE, createDebugLogger } from '@aztec/aztec.js'; -import { PXEService } from '@aztec/pxe'; +import { createPXERpcServer } from '@aztec/pxe'; import { cliTestSuite } from './canary/cli.js'; import { setup as e2eSetup } from './fixtures/utils.js'; @@ -11,22 +10,21 @@ const RPC_URL = `http://localhost:${HTTP_PORT}`; const debug = createDebugLogger('aztec:e2e_cli'); let http: ReturnType; -let aztecNode: AztecNodeService | undefined; let pxe: PXE; +let teardown: () => Promise; const testSetup = async () => { const context = await e2eSetup(2); debug(`Environment set up`); - ({ aztecNode, pxe } = context); - http = startHttpRpcServer(pxe, HTTP_PORT); + ({ pxe, teardown } = context); + http = startHttpRpcServer(pxe, createPXERpcServer, HTTP_PORT); debug(`HTTP RPC server started in port ${HTTP_PORT}`); return pxe; }; const testCleanup = async () => { http.close(); - await aztecNode?.stop(); - await (pxe as PXEService).stop(); + await teardown(); }; cliTestSuite('E2E CLI Test', testSetup, testCleanup, createDebugLogger('aztec:e2e_cli'), RPC_URL); diff --git a/yarn-project/end-to-end/src/e2e_multi_transfer.test.ts b/yarn-project/end-to-end/src/e2e_multi_transfer.test.ts index 65c593fbfc0..81aa130aba0 100644 --- a/yarn-project/end-to-end/src/e2e_multi_transfer.test.ts +++ b/yarn-project/end-to-end/src/e2e_multi_transfer.test.ts @@ -1,8 +1,7 @@ -import { AztecNodeService } from '@aztec/aztec-node'; import { AztecAddress, Contract, Wallet } from '@aztec/aztec.js'; import { DebugLogger } from '@aztec/foundation/log'; import { MultiTransferContract, PrivateTokenAirdropContract } from '@aztec/noir-contracts/types'; -import { CompleteAddress } from '@aztec/types'; +import { AztecNode, CompleteAddress } from '@aztec/types'; import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js'; @@ -14,7 +13,7 @@ import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/u describe('multi-transfer payments', () => { const numberOfAccounts = 12; - let aztecNode: AztecNodeService | undefined; + let aztecNode: AztecNode | undefined; let wallet: Wallet; let logger: DebugLogger; let teardown: () => Promise; diff --git a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts index 61a50b53866..9b705481b78 100644 --- a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts +++ b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts @@ -1,4 +1,3 @@ -import { AztecNodeService } from '@aztec/aztec-node'; import { AztecAddress, NotePreimage, @@ -10,12 +9,12 @@ import { import { Fr, GrumpkinScalar } from '@aztec/circuits.js'; import { DebugLogger } from '@aztec/foundation/log'; import { TokenContract } from '@aztec/noir-contracts/types'; -import { PXE, TxStatus } from '@aztec/types'; +import { AztecNode, PXE, TxStatus } from '@aztec/types'; import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js'; describe('e2e_multiple_accounts_1_enc_key', () => { - let aztecNode: AztecNodeService | undefined; + let aztecNode: AztecNode | undefined; let pxe: PXE; const wallets: Wallet[] = []; const accounts: AztecAddress[] = []; diff --git a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts index 6f4da87a779..9a40f277243 100644 --- a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts +++ b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts @@ -1,13 +1,12 @@ -import { AztecNodeService } from '@aztec/aztec-node'; import { AztecAddress, SignerlessWallet, Wallet } from '@aztec/aztec.js'; import { DebugLogger } from '@aztec/foundation/log'; import { PokeableTokenContract } from '@aztec/noir-contracts/types'; -import { CompleteAddress, PXE, TxStatus } from '@aztec/types'; +import { AztecNode, CompleteAddress, PXE, TxStatus } from '@aztec/types'; import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js'; describe('e2e_non_contract_account', () => { - let aztecNode: AztecNodeService | undefined; + let aztecNode: AztecNode | undefined; let pxe: PXE; let wallet: Wallet; let sender: AztecAddress; diff --git a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts b/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts index 81070e19577..abe745c4688 100644 --- a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts @@ -1,13 +1,12 @@ -import { AztecNodeService } from '@aztec/aztec-node'; import { AztecAddress, Fr, Wallet } from '@aztec/aztec.js'; import { DebugLogger } from '@aztec/foundation/log'; import { PendingCommitmentsContract } from '@aztec/noir-contracts/types'; -import { CompleteAddress, TxStatus } from '@aztec/types'; +import { AztecNode, CompleteAddress, TxStatus } from '@aztec/types'; import { setup } from './fixtures/utils.js'; describe('e2e_pending_commitments_contract', () => { - let aztecNode: AztecNodeService | undefined; + let aztecNode: AztecNode | undefined; let wallet: Wallet; let logger: DebugLogger; let owner: AztecAddress; diff --git a/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts index 3d13f15fa02..1cc13f97e78 100644 --- a/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts @@ -1,13 +1,12 @@ -import { AztecNodeService } from '@aztec/aztec-node'; import { AztecAddress, Wallet } from '@aztec/aztec.js'; import { DebugLogger } from '@aztec/foundation/log'; import { PrivateTokenContract } from '@aztec/noir-contracts/types'; -import { CompleteAddress, TxStatus } from '@aztec/types'; +import { AztecNode, CompleteAddress, TxStatus } from '@aztec/types'; import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js'; describe('e2e_private_token_contract', () => { - let aztecNode: AztecNodeService | undefined; + let aztecNode: AztecNode | undefined; let wallet: Wallet; let logger: DebugLogger; let owner: AztecAddress; 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 3de8d16843f..86efb877d6d 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 @@ -15,7 +15,7 @@ import { TokenContract } from '@aztec/noir-contracts/types'; import { format } from 'util'; -const { SANDBOX_URL = 'http://localhost:8080' } = process.env; +const { PXE_URL = 'http://localhost:8080' } = process.env; // docs:end:imports describe('e2e_sandbox_example', () => { @@ -25,7 +25,7 @@ describe('e2e_sandbox_example', () => { const logger = createDebugLogger('token'); // We create PXE client connected to the sandbox URL - const pxe = createPXEClient(SANDBOX_URL); + const pxe = createPXEClient(PXE_URL); // Wait for sandbox to be ready await waitForSandbox(pxe); @@ -149,7 +149,7 @@ describe('e2e_sandbox_example', () => { it('can create accounts on the sandbox', async () => { const logger = createDebugLogger('token'); // We create PXE client connected to the sandbox URL - const pxe = createPXEClient(SANDBOX_URL); + const pxe = createPXEClient(PXE_URL); // Wait for sandbox to be ready await waitForSandbox(pxe); 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 aa46c47521a..08972e4d551 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 @@ -8,7 +8,7 @@ import { DebugLogger } from '@aztec/foundation/log'; import { OutboxAbi } from '@aztec/l1-artifacts'; import { TokenBridgeContract, TokenContract } from '@aztec/noir-contracts/types'; import { PXEService } from '@aztec/pxe'; -import { NotePreimage, PXE, TxStatus } from '@aztec/types'; +import { AztecNode, NotePreimage, PXE, TxStatus } from '@aztec/types'; import { Chain, HttpTransport, PublicClient, getContract } from 'viem'; @@ -20,7 +20,7 @@ import { deployAndInitializeTokenAndBridgeContracts } from './utils.js'; */ export class CrossChainTestHarness { static async new( - aztecNode: AztecNodeService | undefined, + aztecNode: AztecNode | undefined, pxeService: PXE, deployL1ContractsValues: DeployL1Contracts, accounts: CompleteAddress[], @@ -89,7 +89,7 @@ export class CrossChainTestHarness { } constructor( /** AztecNode. */ - public aztecNode: AztecNodeService | undefined, + public aztecNode: AztecNode | undefined, /** Private eXecution Environment (PXE). */ public pxeService: PXE, /** CheatCodes. */ @@ -351,7 +351,7 @@ export class CrossChainTestHarness { } async stop() { - await this.aztecNode?.stop(); + if (this.aztecNode instanceof AztecNodeService) await this.aztecNode?.stop(); if (this.pxeService instanceof PXEService) { await this.pxeService?.stop(); } diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 596d50ed8a2..9dcdcecb427 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -8,7 +8,7 @@ import { EthCheatCodes, Wallet, createAccounts, - createPXEClient as createJsonRpcClient, + createPXEClient, getSandboxAccountsWallets, } from '@aztec/aztec.js'; import { CircuitsWasm, GeneratorIndex } from '@aztec/circuits.js'; @@ -42,7 +42,15 @@ import { } from '@aztec/l1-artifacts'; import { NonNativeTokenContract, TokenBridgeContract, TokenContract } from '@aztec/noir-contracts/types'; import { PXEService, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; -import { L2BlockL2Logs, LogType, PXE, TxStatus, UnencryptedL2Log } from '@aztec/types'; +import { + AztecNode, + L2BlockL2Logs, + LogType, + PXE, + TxStatus, + UnencryptedL2Log, + createAztecNodeRpcClient, +} from '@aztec/types'; import * as path from 'path'; import { @@ -63,7 +71,16 @@ import { mnemonicToAccount } from 'viem/accounts'; import { MNEMONIC, localAnvil } from './fixtures.js'; import { isMetricsLoggingRequested, setupMetricsLogger } from './logging.js'; -const { SANDBOX_URL = '' } = process.env; +const { PXE_URL = '', AZTEC_NODE_URL = '' } = process.env; + +const getAztecNodeUrl = () => { + if (AZTEC_NODE_URL) return AZTEC_NODE_URL; + + // If AZTEC_NODE_URL is not set, we assume that the PXE is running on the same host as the Aztec Node and use the default port + const url = new URL(PXE_URL); + url.port = '8079'; + return url.toString(); +}; export const waitForPXE = async (pxe: PXE, logger: DebugLogger) => { await retryUntil(async () => { @@ -78,18 +95,6 @@ export const waitForPXE = async (pxe: PXE, logger: DebugLogger) => { }, 'RPC Get Node Info'); }; -const createAztecNode = async ( - nodeConfig: AztecNodeConfig, - logger: DebugLogger, -): Promise => { - if (SANDBOX_URL) { - logger(`Not creating Aztec Node as we are running against a sandbox at ${SANDBOX_URL}`); - return undefined; - } - logger('Creating and synching an aztec node...'); - return await AztecNodeService.createAndSync(nodeConfig); -}; - export const setupL1Contracts = async ( l1RpcUrl: string, account: HDAccount | PrivateKeyAccount, @@ -138,7 +143,7 @@ export const setupL1Contracts = async ( */ export async function setupPXEService( numberOfAccounts: number, - aztecNode: AztecNodeService, + aztecNode: AztecNode, logger = getLogger(), useLogSuffix = false, ): Promise<{ @@ -177,18 +182,21 @@ export async function setupPXEService( * @param account - The account for use in create viem wallets. * @param config - The aztec Node Configuration * @param logger - The logger to be used - * @returns Private eXecution Environment (PXE) client, viem wallets, contract addreses etc. + * @returns Private eXecution Environment (PXE) client, viem wallets, contract addresses etc. */ async function setupWithSandbox(account: Account, config: AztecNodeConfig, logger: DebugLogger) { // we are setting up against the sandbox, l1 contracts are already deployed - logger(`Creating JSON RPC client to remote host ${SANDBOX_URL}`); - const jsonClient = createJsonRpcClient(SANDBOX_URL); - await waitForPXE(jsonClient, logger); + const aztecNodeUrl = getAztecNodeUrl(); + logger(`Creating Aztec Node client to remote host ${aztecNodeUrl}`); + const aztecNode = createAztecNodeRpcClient(aztecNodeUrl); + logger(`Creating PXE client to remote host ${PXE_URL}`); + const pxeClient = createPXEClient(PXE_URL); + await waitForPXE(pxeClient, logger); logger('JSON RPC client connected to PXE'); - logger(`Retrieving contract addresses from ${SANDBOX_URL}`); - const l1Contracts = (await jsonClient.getNodeInfo()).l1ContractAddresses; + logger(`Retrieving contract addresses from ${PXE_URL}`); + const l1Contracts = (await pxeClient.getNodeInfo()).l1ContractAddresses; logger('PXE created, constructing wallets from initial sandbox accounts...'); - const wallets = await getSandboxAccountsWallets(jsonClient); + const wallets = await getSandboxAccountsWallets(pxeClient); const walletClient = createWalletClient({ account, @@ -204,13 +212,13 @@ async function setupWithSandbox(account: Account, config: AztecNodeConfig, logge walletClient, publicClient, }; - const cheatCodes = await CheatCodes.create(config.rpcUrl, jsonClient!); + const cheatCodes = await CheatCodes.create(config.rpcUrl, pxeClient!); const teardown = () => Promise.resolve(); return { - aztecNode: undefined, - pxe: jsonClient, + aztecNode, + pxe: pxeClient, deployL1ContractsValues, - accounts: await jsonClient!.getRegisteredAccounts(), + accounts: await pxeClient!.getRegisteredAccounts(), config, wallet: wallets[0], wallets, @@ -225,8 +233,8 @@ type SetupOptions = { /** State load */ stateLoad?: string } & Partial { - await aztecNode?.stop(); + if (aztecNode instanceof AztecNodeService) await aztecNode?.stop(); if (pxe instanceof PXEService) await pxe?.stop(); }; @@ -511,7 +520,7 @@ export function delay(ms: number): Promise { * @param numEncryptedLogs - The number of expected logs. */ export const expectsNumOfEncryptedLogsInTheLastBlockToBe = async ( - aztecNode: AztecNodeService | undefined, + aztecNode: AztecNode | undefined, numEncryptedLogs: number, ) => { if (!aztecNode) { diff --git a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts index 5c1bfdebed5..d5adfd24890 100644 --- a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts +++ b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts @@ -16,7 +16,7 @@ import { import { toBigIntBE } from '@aztec/foundation/bigint-buffer'; import { TestContract, TokenContract } from '@aztec/noir-contracts/types'; -const { SANDBOX_URL = 'http://localhost:8080', ETHEREUM_HOST = 'http://localhost:8545' } = process.env; +const { PXE_URL = 'http://localhost:8080', ETHEREUM_HOST = 'http://localhost:8545' } = process.env; describe('guides/dapp/testing', () => { describe('on in-proc sandbox', () => { @@ -61,7 +61,7 @@ describe('guides/dapp/testing', () => { describe('on local sandbox', () => { beforeAll(async () => { - const pxe = createPXEClient(SANDBOX_URL); + const pxe = createPXEClient(PXE_URL); await waitForSandbox(pxe); }); @@ -73,7 +73,7 @@ describe('guides/dapp/testing', () => { let token: TokenContract; beforeEach(async () => { - pxe = createPXEClient(SANDBOX_URL); + pxe = createPXEClient(PXE_URL); owner = await createAccount(pxe); recipient = await createAccount(pxe); token = await TokenContract.deploy(owner, owner.getCompleteAddress()).send().deployed(); @@ -106,7 +106,7 @@ describe('guides/dapp/testing', () => { beforeEach(async () => { // docs:start:use-existing-wallets - pxe = createPXEClient(SANDBOX_URL); + pxe = createPXEClient(PXE_URL); [owner, recipient] = await getSandboxAccountsWallets(pxe); token = await TokenContract.deploy(owner, owner.getCompleteAddress()).send().deployed(); // docs:end:use-existing-wallets @@ -136,7 +136,7 @@ describe('guides/dapp/testing', () => { let cheats: CheatCodes; beforeAll(async () => { - pxe = createPXEClient(SANDBOX_URL); + pxe = createPXEClient(PXE_URL); owner = await createAccount(pxe); testContract = await TestContract.deploy(owner).send().deployed(); cheats = await CheatCodes.create(ETHEREUM_HOST, pxe); @@ -161,7 +161,7 @@ describe('guides/dapp/testing', () => { let ownerSlot: Fr; beforeAll(async () => { - pxe = createPXEClient(SANDBOX_URL); + pxe = createPXEClient(PXE_URL); owner = await createAccount(pxe); recipient = await createAccount(pxe); testContract = await TestContract.deploy(owner).send().deployed(); diff --git a/yarn-project/end-to-end/src/guides/up_quick_start.test.ts b/yarn-project/end-to-end/src/guides/up_quick_start.test.ts index 15d135e2459..82b227054a6 100644 --- a/yarn-project/end-to-end/src/guides/up_quick_start.test.ts +++ b/yarn-project/end-to-end/src/guides/up_quick_start.test.ts @@ -7,7 +7,7 @@ describe('guides/up_quick_start', () => { it('works', async () => { await waitForSandbox(); execSync( - `DEBUG="aztec:*" PXE_HOST=\${SANDBOX_URL:-http://localhost:8080} PATH=$PATH:../node_modules/.bin ./src/guides/up_quick_start.sh`, + `DEBUG="aztec:*" PXE_URL=\${PXE_URL:-http://localhost:8080} PATH=$PATH:../node_modules/.bin ./src/guides/up_quick_start.sh`, { shell: '/bin/bash', stdio: 'inherit', diff --git a/yarn-project/end-to-end/src/pxe_sandbox.test.ts b/yarn-project/end-to-end/src/pxe_sandbox.test.ts index cfdee86086e..c39f0edfd14 100644 --- a/yarn-project/end-to-end/src/pxe_sandbox.test.ts +++ b/yarn-project/end-to-end/src/pxe_sandbox.test.ts @@ -1,10 +1,10 @@ import { createPXEClient, waitForSandbox } from '@aztec/aztec.js'; import { pxeTestSuite } from '@aztec/pxe'; -const { SANDBOX_URL = 'http://localhost:8080' } = process.env; +const { PXE_URL = 'http://localhost:8080' } = process.env; const setup = async () => { - const pxe = createPXEClient(SANDBOX_URL); + const pxe = createPXEClient(PXE_URL); await waitForSandbox(pxe); return pxe; }; diff --git a/yarn-project/end-to-end/src/sample-dapp/connect.mjs b/yarn-project/end-to-end/src/sample-dapp/connect.mjs index 0785fb1ca3a..6486f7447a1 100644 --- a/yarn-project/end-to-end/src/sample-dapp/connect.mjs +++ b/yarn-project/end-to-end/src/sample-dapp/connect.mjs @@ -1,10 +1,10 @@ // docs:start:all import { createPXEClient } from '@aztec/aztec.js'; -const { SANDBOX_URL = 'http://localhost:8080' } = process.env; +const { PXE_URL = 'http://localhost:8080' } = process.env; async function main() { - const pxe = createPXEClient(SANDBOX_URL); + const pxe = createPXEClient(PXE_URL); const { chainId } = await pxe.getNodeInfo(); console.log(`Connected to chain ${chainId}`); } diff --git a/yarn-project/end-to-end/src/sample-dapp/deploy.mjs b/yarn-project/end-to-end/src/sample-dapp/deploy.mjs index 866c14889cd..bebf5e72399 100644 --- a/yarn-project/end-to-end/src/sample-dapp/deploy.mjs +++ b/yarn-project/end-to-end/src/sample-dapp/deploy.mjs @@ -5,10 +5,10 @@ import { writeFileSync } from 'fs'; import { fileURLToPath } from 'url'; // docs:start:dapp-deploy -const { SANDBOX_URL = 'http://localhost:8080' } = process.env; +const { PXE_URL = 'http://localhost:8080' } = process.env; async function main() { - const pxe = createPXEClient(SANDBOX_URL); + const pxe = createPXEClient(PXE_URL); const [owner] = await getSandboxAccountsWallets(pxe); const token = await Contract.deploy(pxe, TokenContractAbi, [owner.getCompleteAddress()]).send().deployed(); diff --git a/yarn-project/end-to-end/src/sample-dapp/index.mjs b/yarn-project/end-to-end/src/sample-dapp/index.mjs index db69c2b26af..449eedace47 100644 --- a/yarn-project/end-to-end/src/sample-dapp/index.mjs +++ b/yarn-project/end-to-end/src/sample-dapp/index.mjs @@ -10,7 +10,7 @@ import { fileURLToPath } from '@aztec/foundation/url'; import { getToken } from './contracts.mjs'; -const { SANDBOX_URL = 'http://localhost:8080' } = process.env; +const { PXE_URL = 'http://localhost:8080' } = process.env; async function showAccounts(pxe) { // docs:start:showAccounts @@ -105,7 +105,7 @@ async function mintPublicFunds(pxe) { } async function main() { - const pxe = createPXEClient(SANDBOX_URL); + const pxe = createPXEClient(PXE_URL); const { chainId } = await pxe.getNodeInfo(); console.log(`Connected to chain ${chainId}`); 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 407e223239e..4e090f1a0d3 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 @@ -1,4 +1,3 @@ -import { AztecNodeService } from '@aztec/aztec-node'; import { AccountWallet, AztecAddress } from '@aztec/aztec.js'; import { Fr, FunctionSelector } from '@aztec/circuits.js'; import { deployL1Contract } from '@aztec/ethereum'; @@ -6,7 +5,7 @@ import { EthAddress } from '@aztec/foundation/eth-address'; import { DebugLogger } from '@aztec/foundation/log'; import { UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts'; import { UniswapContract } from '@aztec/noir-contracts/types'; -import { PXE, TxStatus } from '@aztec/types'; +import { AztecNode, PXE, TxStatus } from '@aztec/types'; import { getContract, parseEther } from 'viem'; @@ -31,7 +30,7 @@ describe('uniswap_trade_on_l1_from_l2', () => { const WETH9_ADDRESS: EthAddress = EthAddress.fromString('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'); const DAI_ADDRESS: EthAddress = EthAddress.fromString('0x6B175474E89094C44Da98b954EedeAC495271d0F'); - let aztecNode: AztecNodeService | undefined; + let aztecNode: AztecNode | undefined; let pxe: PXE; let logger: DebugLogger; let teardown: () => Promise; diff --git a/yarn-project/pxe/Dockerfile b/yarn-project/pxe/Dockerfile new file mode 100644 index 00000000000..49503a0d0d3 --- /dev/null +++ b/yarn-project/pxe/Dockerfile @@ -0,0 +1,20 @@ +FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project AS builder + +ARG COMMIT_TAG="" + +# Update pxe version if COMMIT_TAG has been used +WORKDIR /usr/src/yarn-project/pxe +RUN if [[ -n "${COMMIT_TAG}" ]]; then \ + jq --arg v ${COMMIT_TAG} '.version = $v' package.json > _temp && mv _temp package.json; \ + fi + +# Productionify. See comment in yarn-project-base/Dockerfile. +RUN yarn cache clean && yarn workspaces focus --production + +# Create final, minimal size image. +FROM node:18-alpine +COPY --from=builder /usr/src/ /usr/src/ +WORKDIR /usr/src/yarn-project/pxe +ENTRYPOINT ["yarn"] +CMD [ "start" ] +EXPOSE 8081 diff --git a/yarn-project/pxe/Dockerfile.final b/yarn-project/pxe/Dockerfile.final new file mode 100644 index 00000000000..5f2ac5b817e --- /dev/null +++ b/yarn-project/pxe/Dockerfile.final @@ -0,0 +1,10 @@ +FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/pxe-base AS builder + +FROM node:18-alpine + +COPY --from=builder /usr/src/ /usr/src/ +WORKDIR /usr/src/yarn-project/pxe + +ENTRYPOINT ["yarn"] +CMD [ "start" ] +EXPOSE 8081 diff --git a/yarn-project/pxe/src/bin/index.ts b/yarn-project/pxe/src/bin/index.ts index 2cfb5794c51..012742ca34d 100644 --- a/yarn-project/pxe/src/bin/index.ts +++ b/yarn-project/pxe/src/bin/index.ts @@ -6,7 +6,7 @@ import { getPXEServiceConfig } from '../config/index.js'; import { startPXEHttpServer } from '../pxe_http/index.js'; import { createPXEService } from '../pxe_service/index.js'; -const { SERVER_PORT = 8080, AZTEC_NODE_RPC_URL = '' } = process.env; +const { PXE_PORT = 8081, AZTEC_NODE_URL = 'http://localhost:8079' } = process.env; const logger = createDebugLogger('aztec:pxe_service'); @@ -17,7 +17,7 @@ async function main() { logger.info(`Setting up PXE...`); const pxeConfig = getPXEServiceConfig(); - const nodeRpcClient = createAztecNodeRpcClient(AZTEC_NODE_RPC_URL); + const nodeRpcClient = createAztecNodeRpcClient(AZTEC_NODE_URL); const pxeService = await createPXEService(nodeRpcClient, pxeConfig); const shutdown = async () => { @@ -29,8 +29,8 @@ async function main() { process.once('SIGINT', shutdown); process.once('SIGTERM', shutdown); - startPXEHttpServer(pxeService, SERVER_PORT); - logger.info(`PXE listening on port ${SERVER_PORT}`); + startPXEHttpServer(pxeService, PXE_PORT); + logger.info(`PXE listening on port ${PXE_PORT}`); } main().catch(err => { diff --git a/yarn-project/pxe/src/config/index.ts b/yarn-project/pxe/src/config/index.ts index 81dab01b2ab..cf07799dab6 100644 --- a/yarn-project/pxe/src/config/index.ts +++ b/yarn-project/pxe/src/config/index.ts @@ -16,10 +16,10 @@ export interface PXEServiceConfig { * Creates an instance of PXEServiceConfig out of environment variables using sensible defaults for integration testing if not set. */ export function getPXEServiceConfig(): PXEServiceConfig { - const { PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS } = process.env; + const { PXE_BLOCK_POLLING_INTERVAL_MS } = process.env; return { - l2BlockPollingIntervalMS: PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS ? +PXE_SERVICE_BLOCK_POLLING_INTERVAL_MS : 1000, + l2BlockPollingIntervalMS: PXE_BLOCK_POLLING_INTERVAL_MS ? +PXE_BLOCK_POLLING_INTERVAL_MS : 1000, }; } diff --git a/yarn-project/types/package.json b/yarn-project/types/package.json index 78fa4e4fda9..ff64626d7ac 100644 --- a/yarn-project/types/package.json +++ b/yarn-project/types/package.json @@ -35,6 +35,7 @@ "@aztec/foundation": "workspace:^", "browserify-cipher": "^1.0.1", "lodash.clonedeep": "^4.5.0", + "lodash.isequal": "^4.5.0", "lodash.times": "^4.3.2", "tslib": "^2.5.0" }, @@ -43,6 +44,7 @@ "@rushstack/eslint-patch": "^1.1.4", "@types/jest": "^29.5.0", "@types/lodash.clonedeep": "^4.5.7", + "@types/lodash.isequal": "^4.5.6", "@types/lodash.times": "^4.3.7", "@types/node": "^18.7.23", "jest": "^29.5.0", diff --git a/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts b/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts index c19c787a35d..96cdfb6676e 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 @@ -3,7 +3,18 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { createJsonRpcClient, defaultFetch } from '@aztec/foundation/json-rpc/client'; -import { AztecNode, ContractData, ExtendedContractData, L2Block, L2BlockL2Logs, L2Tx, Tx, TxHash } from '@aztec/types'; +import { + AztecNode, + ContractData, + ExtendedContractData, + L1ToL2MessageAndIndex, + L2Block, + L2BlockL2Logs, + L2Tx, + SiblingPath, + Tx, + TxHash, +} from '@aztec/types'; /** * Creates a JSON-RPC client to remotely talk to an AztecNode. @@ -14,7 +25,19 @@ import { AztecNode, ContractData, ExtendedContractData, L2Block, L2BlockL2Logs, export function createAztecNodeRpcClient(url: string, fetch = defaultFetch): AztecNode { const rpcClient = createJsonRpcClient( url, - { AztecAddress, EthAddress, ExtendedContractData, ContractData, Fr, HistoricBlockData, L2Block, L2Tx, TxHash }, + { + AztecAddress, + EthAddress, + ExtendedContractData, + ContractData, + Fr, + HistoricBlockData, + L2Block, + L2Tx, + TxHash, + SiblingPath, + L1ToL2MessageAndIndex, + }, { Tx, L2BlockL2Logs }, false, fetch, diff --git a/yarn-project/types/src/l1_to_l2_message.test.ts b/yarn-project/types/src/l1_to_l2_message.test.ts index 842d0b5428f..35dc7e83e05 100644 --- a/yarn-project/types/src/l1_to_l2_message.test.ts +++ b/yarn-project/types/src/l1_to_l2_message.test.ts @@ -1,4 +1,4 @@ -import { L1ToL2Message } from './l1_to_l2_message.js'; +import { L1ToL2Message, L1ToL2MessageAndIndex } from './l1_to_l2_message.js'; describe('L1 to L2 message', () => { it('can encode an L1 to L2 message to buffer and back', () => { @@ -7,4 +7,26 @@ describe('L1 to L2 message', () => { const recovered = L1ToL2Message.fromBuffer(buffer); expect(recovered).toEqual(msg); }); + + it('can encode an L1ToL2MessageAndIndex to buffer and back', () => { + const index = BigInt(Math.floor(Math.random() * 1000)); // Generate a random BigInt + const msg = L1ToL2Message.random(); + const l1ToL2MsgAndIndex = new L1ToL2MessageAndIndex(index, msg); + + const buffer = l1ToL2MsgAndIndex.toBuffer(); + const recovered = L1ToL2MessageAndIndex.fromBuffer(buffer); + + expect(recovered).toEqual(l1ToL2MsgAndIndex); + }); + + it('can encode an L1ToL2MessageAndIndex to string and back', () => { + const index = BigInt(Math.floor(Math.random() * 1000)); // Generate a random BigInt + const msg = L1ToL2Message.random(); + const l1ToL2MsgAndIndex = new L1ToL2MessageAndIndex(index, msg); + + const stringData = l1ToL2MsgAndIndex.toString(); + const recovered = L1ToL2MessageAndIndex.fromString(stringData); + + expect(recovered).toEqual(l1ToL2MsgAndIndex); + }); }); diff --git a/yarn-project/types/src/l1_to_l2_message.ts b/yarn-project/types/src/l1_to_l2_message.ts index 03493c09d29..d56652fd6ae 100644 --- a/yarn-project/types/src/l1_to_l2_message.ts +++ b/yarn-project/types/src/l1_to_l2_message.ts @@ -1,5 +1,6 @@ import { BufferReader, serializeToBuffer } from '@aztec/circuits.js/utils'; import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { toBigIntBE, toBufferBE } from '@aztec/foundation/bigint-buffer'; import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; @@ -32,16 +33,34 @@ export interface L1ToL2MessageSource { /** * L1AndL2Message and Index (in the merkle tree) as one type */ -export type L1ToL2MessageAndIndex = { - /** - * The message. - */ - message: L1ToL2Message; - /** - * the index in the L1 to L2 Message tree. - */ - index: bigint; -}; +export class L1ToL2MessageAndIndex { + constructor( + /** the index in the L1 to L2 Message tree. */ + public readonly index: bigint, + /** The message. */ + public readonly message: L1ToL2Message, + ) {} + + toBuffer(): Buffer { + return Buffer.concat([toBufferBE(this.index, 32), this.message.toBuffer()]); + } + + toString(): string { + return this.toBuffer().toString('hex'); + } + + static fromString(data: string): L1ToL2MessageAndIndex { + const buffer = Buffer.from(data, 'hex'); + return L1ToL2MessageAndIndex.fromBuffer(buffer); + } + + static fromBuffer(buffer: Buffer | BufferReader) { + const reader = BufferReader.asReader(buffer); + const index = toBigIntBE(reader.readBytes(32)); + const message = L1ToL2Message.fromBuffer(reader); + return new L1ToL2MessageAndIndex(index, message); + } +} /** * The format of an L1 to L2 Message. diff --git a/yarn-project/types/src/l2_block.ts b/yarn-project/types/src/l2_block.ts index 8024940bb9c..b4f9ee005fc 100644 --- a/yarn-project/types/src/l2_block.ts +++ b/yarn-project/types/src/l2_block.ts @@ -558,9 +558,7 @@ export class L2Block { const logFieldName = logType === LogType.ENCRYPTED ? 'newEncryptedLogs' : 'newUnencryptedLogs'; if (this[logFieldName]) { - if (this[logFieldName] === logs) { - // Comparing objects only by references is enough in this case since this should occur only when exactly - // the same object is passed in and not a copy. + if (this[logFieldName]?.equals(logs)) { L2Block.logger(`${logFieldName} logs already attached`); return; } diff --git a/yarn-project/types/src/logs/l2_block_l2_logs.ts b/yarn-project/types/src/logs/l2_block_l2_logs.ts index 808062964ee..5668fab26d4 100644 --- a/yarn-project/types/src/logs/l2_block_l2_logs.ts +++ b/yarn-project/types/src/logs/l2_block_l2_logs.ts @@ -1,5 +1,7 @@ import { BufferReader, serializeBufferToVector } from '@aztec/foundation/serialize'; +import isEqual from 'lodash.isequal'; + import { TxL2Logs } from './tx_l2_logs.js'; /** @@ -102,6 +104,15 @@ export class L2BlockL2Logs { }; } + /** + * Checks if two L2BlockL2Logs objects are equal. + * @param other - Another L2BlockL2Logs object to compare with. + * @returns True if the two objects are equal, false otherwise. + */ + public equals(other: L2BlockL2Logs): boolean { + return isEqual(this, other); + } + /** * Convert a plain JSON object to a L2BlockL2Logs class object. * @param obj - A plain L2BlockL2Logs JSON object. diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 67da62167c3..aacf1b24f7f 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -762,12 +762,14 @@ __metadata: "@rushstack/eslint-patch": ^1.1.4 "@types/jest": ^29.5.0 "@types/lodash.clonedeep": ^4.5.7 + "@types/lodash.isequal": ^4.5.6 "@types/lodash.times": ^4.3.7 "@types/node": ^18.7.23 browserify-cipher: ^1.0.1 jest: ^29.5.0 jest-mock-extended: ^3.0.3 lodash.clonedeep: ^4.5.0 + lodash.isequal: ^4.5.0 lodash.times: ^4.3.2 ts-jest: ^29.1.0 ts-node: ^10.9.1 @@ -4609,6 +4611,15 @@ __metadata: languageName: node linkType: hard +"@types/lodash.isequal@npm:^4.5.6": + version: 4.5.6 + resolution: "@types/lodash.isequal@npm:4.5.6" + dependencies: + "@types/lodash": "*" + checksum: 0f065989408a9e0584e6c27495be2cd4602e62650f55266aa195812582444463c0c8570c674ae84f947c11748f49ab43fd5b482fa120e08eeee4c23b162edc38 + languageName: node + linkType: hard + "@types/lodash.mapvalues@npm:^4.6.7": version: 4.6.7 resolution: "@types/lodash.mapvalues@npm:4.6.7" @@ -13558,7 +13569,7 @@ __metadata: languageName: node linkType: hard -"lodash.isequal@npm:4.5.0": +"lodash.isequal@npm:4.5.0, lodash.isequal@npm:^4.5.0": version: 4.5.0 resolution: "lodash.isequal@npm:4.5.0" checksum: da27515dc5230eb1140ba65ff8de3613649620e8656b19a6270afe4866b7bd461d9ba2ac8a48dcc57f7adac4ee80e1de9f965d89d4d81a0ad52bb3eec2609644