From dd83d520c9925f00de155bddf0cf95852c971995 Mon Sep 17 00:00:00 2001 From: ludamad Date: Mon, 11 Nov 2024 16:49:46 +0700 Subject: [PATCH] chore: Revert "chore: Validate RPC inputs" (#9875) Reverts AztecProtocol/aztec-packages#9672 as it broke some e2e tests and boxes --- yarn-project/.earthlyignore | 1 - yarn-project/.gitignore | 1 - yarn-project/archiver/src/factory.ts | 6 +- .../archiver/src/rpc/archiver_client.ts | 29 + .../archiver/src/rpc/archiver_server.ts | 35 ++ yarn-project/archiver/src/rpc/index.ts | 13 +- .../src/aztec-node/http_rpc_server.ts | 61 +- .../aztec-node/src/aztec-node/server.ts | 6 +- .../aztec.js/src/contract/batch_call.ts | 5 +- .../fee_juice_payment_method_with_claim.ts | 7 +- .../src/fee/private_fee_payment_method.ts | 4 +- .../src/fee/public_fee_payment_method.ts | 4 +- .../aztec.js/src/rpc_clients/pxe_client.ts | 95 ++- yarn-project/aztec.js/src/utils/abi_types.ts | 2 +- yarn-project/aztec.js/src/utils/authwit.ts | 2 +- .../aztec.js/src/utils/cheat_codes.ts | 3 +- yarn-project/aztec.js/src/utils/pxe.ts | 3 +- .../aztec.js/src/wallet/base_wallet.ts | 23 +- yarn-project/aztec/src/cli/cli.ts | 48 +- .../aztec/src/cli/cmds/start_archiver.ts | 25 +- yarn-project/aztec/src/cli/cmds/start_bot.ts | 20 +- yarn-project/aztec/src/cli/cmds/start_node.ts | 27 +- .../src/cli/cmds/start_proof_verifier.ts | 10 +- .../aztec/src/cli/cmds/start_prover_agent.ts | 38 +- .../aztec/src/cli/cmds/start_prover_node.ts | 23 +- yarn-project/aztec/src/cli/cmds/start_pxe.ts | 20 +- yarn-project/aztec/src/cli/cmds/start_txe.ts | 23 +- yarn-project/aztec/src/cli/util.ts | 5 + .../bb-prover/src/avm_proving.test.ts | 3 +- .../src/prover/bb_private_kernel_prover.ts | 5 +- yarn-project/bot/package.json | 3 +- yarn-project/bot/src/config.ts | 40 +- yarn-project/bot/src/index.ts | 3 +- yarn-project/bot/src/interface.ts | 23 - yarn-project/bot/src/rpc.ts | 13 +- yarn-project/bot/src/runner.ts | 5 +- yarn-project/circuit-types/package.json | 12 +- yarn-project/circuit-types/package.local.json | 12 - .../scripts/copy-test-artifacts.sh | 16 - .../circuit-types/src/auth_witness.ts | 13 - .../src/aztec_node/rpc/aztec_node_client.ts | 64 ++ .../circuit-types/src/aztec_node/rpc/index.ts | 1 + yarn-project/circuit-types/src/body.ts | 13 - yarn-project/circuit-types/src/index.ts | 1 + .../src/interfaces/archiver.test.ts | 352 ----------- .../circuit-types/src/interfaces/archiver.ts | 72 --- .../src/interfaces/aztec-node.test.ts | 526 ---------------- .../src/interfaces/aztec-node.ts | 184 +----- .../circuit-types/src/interfaces/configs.ts | 27 - .../circuit-types/src/interfaces/index.ts | 12 +- .../src/interfaces/l2_block_number.ts | 8 +- .../src/interfaces/nullifier_tree.ts | 25 +- .../src/interfaces/private_kernel_prover.ts | 17 +- .../src/interfaces/prover-agent.test.ts | 57 -- .../src/interfaces/prover-agent.ts | 20 - .../src/interfaces/prover-client.ts | 17 +- .../src/interfaces/prover-coordination.ts | 20 +- .../src/interfaces/prover-node.test.ts | 70 --- .../src/interfaces/prover-node.ts | 16 +- .../src/interfaces/proving-job-source.test.ts | 90 --- .../src/interfaces/proving-job-source.ts | 48 -- .../src/interfaces/proving-job.ts | 265 ++++----- .../circuit-types/src/interfaces/pxe.test.ts | 560 ------------------ .../circuit-types/src/interfaces/pxe.ts | 202 ++----- .../circuit-types/src/interfaces/service.ts | 25 - .../src/interfaces/sync-status.ts | 9 - yarn-project/circuit-types/src/l2_block.ts | 20 - .../circuit-types/src/l2_block_source.ts | 44 +- .../src/logs/encrypted_l2_log.ts | 9 - .../src/logs/encrypted_l2_note_log.ts | 13 +- .../circuit-types/src/logs/event_metadata.ts | 36 +- .../src/logs/extended_unencrypted_l2_log.ts | 23 - .../src/logs/function_l2_logs.test.ts | 4 +- .../src/logs/function_l2_logs.ts | 29 +- .../src/logs/get_logs_response.ts | 42 +- .../src/logs/l1_payload/payload.ts | 11 +- .../src/logs/l2_block_l2_logs.test.ts | 24 +- .../src/logs/l2_block_l2_logs.ts | 45 +- .../circuit-types/src/logs/log_filter.ts | 15 +- yarn-project/circuit-types/src/logs/log_id.ts | 29 - .../circuit-types/src/logs/tx_l2_logs.test.ts | 6 +- .../circuit-types/src/logs/tx_l2_logs.ts | 22 +- .../src/logs/unencrypted_l2_log.ts | 9 - yarn-project/circuit-types/src/mocks.ts | 7 +- .../circuit-types/src/notes/extended_note.ts | 36 -- .../src/notes/incoming_notes_filter.ts | 17 +- .../circuit-types/src/notes/note_status.ts | 2 +- .../src/notes/outgoing_notes_filter.ts | 12 +- .../circuit-types/src/packed_values.test.ts | 11 - .../circuit-types/src/packed_values.ts | 15 - .../src/private_execution_result.test.ts | 6 - .../src/private_execution_result.ts | 139 ----- .../prover_coordination/epoch_proof_quote.ts | 8 - .../epoch_proof_quote_payload.ts | 10 - .../circuit-types/src/public_data_witness.ts | 21 - .../src/public_execution_request.ts | 22 - .../src/sibling_path/sibling_path.ts | 48 +- .../circuit-types/src/simulation_error.ts | 42 +- yarn-project/circuit-types/src/stats/stats.ts | 15 - .../src/tx/public_simulation_output.ts | 53 +- .../circuit-types/src/tx/simulated_tx.test.ts | 4 +- .../circuit-types/src/tx/simulated_tx.ts | 52 +- yarn-project/circuit-types/src/tx/tx.ts | 56 +- yarn-project/circuit-types/src/tx/tx_hash.ts | 13 +- .../circuit-types/src/tx/tx_receipt.ts | 76 +-- yarn-project/circuit-types/src/tx_effect.ts | 13 +- .../src/tx_execution_request.test.ts | 12 - .../circuit-types/src/tx_execution_request.ts | 27 - yarn-project/circuits.js/package.json | 4 +- .../src/contract/artifact_hash.test.ts | 2 +- .../circuits.js/src/contract/artifact_hash.ts | 18 +- .../src/contract/interfaces/contract_class.ts | 118 +--- .../interfaces/contract_data_source.ts | 3 - .../contract/interfaces/contract_instance.ts | 25 +- .../src/contract/interfaces/node-info.ts | 46 +- .../interfaces/protocol_contract_addresses.ts | 17 - .../circuits.js/src/keys/derivation.ts | 8 +- .../circuits.js/src/structs/avm/avm.ts | 27 +- .../circuits.js/src/structs/call_context.ts | 23 - .../src/structs/client_ivc_proof.ts | 10 - .../src/structs/complete_address.test.ts | 4 +- .../src/structs/complete_address.ts | 13 +- .../src/structs/content_commitment.ts | 25 - yarn-project/circuits.js/src/structs/gas.ts | 15 - .../circuits.js/src/structs/gas_fees.ts | 11 - .../circuits.js/src/structs/gas_settings.ts | 14 - .../src/structs/global_variables.ts | 17 - .../circuits.js/src/structs/header.ts | 24 - .../kernel/combined_accumulated_data.ts | 9 - .../structs/kernel/combined_constant_data.ts | 16 - .../kernel/kernel_circuit_public_inputs.ts | 11 - .../private_kernel_circuit_public_inputs.ts | 9 - .../kernel/private_kernel_empty_inputs.ts | 11 - ...ivate_kernel_tail_circuit_public_inputs.ts | 27 - .../src/structs/parity/base_parity_inputs.ts | 11 - .../src/structs/parity/root_parity_input.ts | 11 - .../src/structs/parity/root_parity_inputs.ts | 11 - .../src/structs/partial_state_reference.ts | 23 - .../structs/private_circuit_public_inputs.ts | 9 - .../src/structs/public_data_write.ts | 13 +- .../src/structs/recursive_proof.ts | 11 - .../rollup/append_only_tree_snapshot.ts | 15 - .../base_or_merge_rollup_public_inputs.ts | 27 +- .../src/structs/rollup/block_merge_rollup.ts | 11 - ...block_root_or_block_merge_public_inputs.ts | 11 - .../src/structs/rollup/block_root_rollup.ts | 11 - .../rollup/empty_block_root_rollup_inputs.ts | 11 - .../src/structs/rollup/merge_rollup.ts | 11 - .../rollup/private_base_rollup_inputs.ts | 11 - .../rollup/public_base_rollup_inputs.ts | 11 - .../src/structs/rollup/root_rollup.ts | 21 - .../src/structs/rollup/tube_inputs.ts | 11 - ...ed_key_validation_request_and_generator.ts | 2 +- .../src/structs/state_reference.ts | 14 - .../circuits.js/src/structs/tagging_secret.ts | 4 +- .../src/structs/trees/nullifier_leaf.ts | 31 +- .../src/structs/trees/public_data_leaf.ts | 25 - .../src/structs/tx_context.test.ts | 6 - .../circuits.js/src/structs/tx_context.ts | 21 - .../src/structs/verification_key.ts | 25 - .../src/structs/vk_witness_data.ts | 6 +- .../circuits.js/src/tests/factories.ts | 10 +- .../circuits.js/src/types/public_keys.ts | 25 +- yarn-project/circuits.js/tsconfig.json | 3 - yarn-project/cli/src/utils/inspect.ts | 4 +- .../src/composed/e2e_sandbox_example.test.ts | 6 +- .../end-to-end/src/devnet/e2e_smoke.test.ts | 7 +- .../src/e2e_deploy_contract/legacy.test.ts | 2 +- .../end-to-end/src/e2e_event_logs.test.ts | 40 +- .../end-to-end/src/e2e_fees/failures.test.ts | 4 +- .../end-to-end/src/e2e_synching.test.ts | 4 +- .../private_transfer_recursion.test.ts | 11 +- .../transfer_private.test.ts | 8 +- .../end-to-end/src/sample-dapp/index.mjs | 2 +- .../src/shared/cross_chain_test_harness.ts | 7 +- yarn-project/ethereum/package.json | 3 +- .../ethereum/src/l1_contract_addresses.ts | 24 +- yarn-project/foundation/package.json | 4 +- yarn-project/foundation/src/abi/abi.ts | 439 +++++++------- .../foundation/src/abi/encoder.test.ts | 11 +- yarn-project/foundation/src/abi/encoder.ts | 2 - .../foundation/src/abi/event_selector.ts | 7 - .../foundation/src/aztec-address/index.ts | 82 +-- .../foundation/src/buffer/buffer32.ts | 5 - yarn-project/foundation/src/fields/fields.ts | 5 +- .../foundation/src/fields/point.test.ts | 8 - .../src/json-rpc/class_converter.ts | 213 +++++++ .../foundation/src/json-rpc/client/fetch.ts | 81 --- .../foundation/src/json-rpc/client/index.ts | 2 +- .../json-rpc/client/json_rpc_client.test.ts | 39 ++ .../src/json-rpc/client/json_rpc_client.ts | 151 +++++ .../json-rpc/client/safe_json_rpc_client.ts | 9 +- .../foundation/src/json-rpc/convert.test.ts | 119 ++-- .../foundation/src/json-rpc/convert.ts | 172 +++++- .../src/json-rpc/fixtures/test_state.ts | 35 +- yarn-project/foundation/src/json-rpc/index.ts | 7 + .../foundation/src/json-rpc/server/index.ts | 2 + .../src/json-rpc/server/json_proxy.ts | 68 +++ .../json-rpc/server/json_rpc_server.test.ts | 52 ++ .../src/json-rpc/server/json_rpc_server.ts | 337 +++++++++++ .../server/safe_json_rpc_server.test.ts | 4 +- .../json-rpc/server/safe_json_rpc_server.ts | 119 +--- .../foundation/src/json-rpc/test/index.ts | 1 - .../src/json-rpc/test/integration.test.ts | 62 +- .../src/json-rpc/test/integration.ts | 24 - yarn-project/foundation/src/schemas/api.ts | 27 +- yarn-project/foundation/src/schemas/index.ts | 2 - .../foundation/src/schemas/parse.test.ts | 62 -- yarn-project/foundation/src/schemas/parse.ts | 23 - .../foundation/src/schemas/schemas.test.ts | 36 -- .../foundation/src/schemas/schemas.ts | 99 +--- yarn-project/foundation/src/schemas/types.ts | 3 - yarn-project/foundation/src/schemas/utils.ts | 85 --- yarn-project/foundation/src/string/index.ts | 12 - yarn-project/foundation/src/types/index.ts | 3 - .../src/avm_integration.test.ts | 3 +- .../src/build_protocol_contract_tree.ts | 2 +- .../src/protocol_contract_data.ts | 4 +- .../src/protocol_contract_tree.ts | 2 +- .../src/scripts/generate_data.ts | 8 +- .../agent-queue-rpc-integration.test.ts | 11 +- .../prover-agent/memory-proving-queue.test.ts | 15 +- .../src/prover-agent/memory-proving-queue.ts | 20 +- .../src/prover-agent/prover-agent.ts | 45 +- .../prover-client/src/prover-agent/rpc.ts | 129 +++- .../prover-client/src/tx-prover/tx-prover.ts | 2 +- yarn-project/prover-node/src/http.ts | 18 +- yarn-project/prover-node/src/prover-node.ts | 11 +- ...ild_private_kernel_reset_private_inputs.ts | 4 +- .../kernel_prover/test/test_circuit_prover.ts | 7 +- .../pxe/src/pxe_http/pxe_http_server.ts | 89 ++- .../pxe/src/pxe_service/pxe_service.ts | 41 +- .../src/pxe_service/test/pxe_test_suite.ts | 2 +- .../src/tx_validator/gas_validator.test.ts | 4 +- .../src/tx_validator/gas_validator.ts | 2 +- .../simulator/src/acvm/oracle/oracle.ts | 2 +- .../simulator/src/acvm/oracle/typed_oracle.ts | 2 +- .../src/avm/avm_execution_environment.test.ts | 4 +- .../simulator/src/avm/avm_memory_types.ts | 5 - .../simulator/src/avm/avm_simulator.test.ts | 16 +- .../simulator/src/avm/journal/journal.test.ts | 8 +- .../simulator/src/avm/journal/journal.ts | 30 +- .../src/avm/journal/nullifiers.test.ts | 21 +- .../simulator/src/avm/journal/nullifiers.ts | 14 +- .../src/avm/journal/public_storage.test.ts | 15 +- .../src/avm/journal/public_storage.ts | 10 +- .../src/avm/opcodes/accrued_substate.test.ts | 8 +- .../src/avm/opcodes/accrued_substate.ts | 2 +- .../src/avm/opcodes/contract.test.ts | 8 +- .../simulator/src/avm/opcodes/contract.ts | 2 +- .../src/avm/opcodes/external_calls.ts | 2 +- .../src/client/private_execution.test.ts | 17 +- .../simulator/src/client/view_data_oracle.ts | 2 +- .../src/public/dual_side_effect_trace.ts | 29 +- .../enqueued_call_side_effect_trace.test.ts | 89 ++- .../public/enqueued_call_side_effect_trace.ts | 55 +- .../simulator/src/public/public_processor.ts | 3 +- .../src/public/side_effect_trace.test.ts | 64 +- .../simulator/src/public/side_effect_trace.ts | 39 +- .../src/public/side_effect_trace_interface.ts | 33 +- yarn-project/txe/package.json | 3 +- yarn-project/txe/src/bin/index.ts | 26 +- yarn-project/txe/src/index.ts | 35 +- yarn-project/txe/src/oracle/txe_oracle.ts | 16 +- .../txe/src/txe_service/txe_service.ts | 43 +- yarn-project/txe/src/util/encoding.ts | 24 +- .../types/src/abi/contract_artifact.ts | 5 +- yarn-project/yarn.lock | 7 - 268 files changed, 3007 insertions(+), 5990 deletions(-) create mode 100644 yarn-project/archiver/src/rpc/archiver_client.ts create mode 100644 yarn-project/archiver/src/rpc/archiver_server.ts delete mode 100644 yarn-project/bot/src/interface.ts delete mode 100644 yarn-project/circuit-types/package.local.json delete mode 100755 yarn-project/circuit-types/scripts/copy-test-artifacts.sh create mode 100644 yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts create mode 100644 yarn-project/circuit-types/src/aztec_node/rpc/index.ts delete mode 100644 yarn-project/circuit-types/src/interfaces/archiver.test.ts delete mode 100644 yarn-project/circuit-types/src/interfaces/archiver.ts delete mode 100644 yarn-project/circuit-types/src/interfaces/aztec-node.test.ts delete mode 100644 yarn-project/circuit-types/src/interfaces/prover-agent.test.ts delete mode 100644 yarn-project/circuit-types/src/interfaces/prover-agent.ts delete mode 100644 yarn-project/circuit-types/src/interfaces/prover-node.test.ts delete mode 100644 yarn-project/circuit-types/src/interfaces/proving-job-source.test.ts delete mode 100644 yarn-project/circuit-types/src/interfaces/proving-job-source.ts delete mode 100644 yarn-project/circuit-types/src/interfaces/pxe.test.ts delete mode 100644 yarn-project/circuit-types/src/interfaces/service.ts delete mode 100644 yarn-project/circuit-types/src/packed_values.test.ts delete mode 100644 yarn-project/circuit-types/src/tx_execution_request.test.ts create mode 100644 yarn-project/foundation/src/json-rpc/class_converter.ts delete mode 100644 yarn-project/foundation/src/json-rpc/client/fetch.ts create mode 100644 yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts create mode 100644 yarn-project/foundation/src/json-rpc/client/json_rpc_client.ts create mode 100644 yarn-project/foundation/src/json-rpc/server/json_proxy.ts create mode 100644 yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts create mode 100644 yarn-project/foundation/src/json-rpc/server/json_rpc_server.ts delete mode 100644 yarn-project/foundation/src/json-rpc/test/index.ts delete mode 100644 yarn-project/foundation/src/json-rpc/test/integration.ts delete mode 100644 yarn-project/foundation/src/schemas/parse.test.ts delete mode 100644 yarn-project/foundation/src/schemas/schemas.test.ts delete mode 100644 yarn-project/foundation/src/schemas/types.ts delete mode 100644 yarn-project/foundation/src/schemas/utils.ts diff --git a/yarn-project/.earthlyignore b/yarn-project/.earthlyignore index 0fc5487b6b8..bd9d331e9a6 100644 --- a/yarn-project/.earthlyignore +++ b/yarn-project/.earthlyignore @@ -44,7 +44,6 @@ aztec-faucet/data* aztec-node/data* aztec/log circuits.js/fixtures/*.json -circuit-types/src/test/artifacts docs/dist end-to-end/addresses.json end-to-end/log diff --git a/yarn-project/.gitignore b/yarn-project/.gitignore index 5969baa4dc3..a6182305e1e 100644 --- a/yarn-project/.gitignore +++ b/yarn-project/.gitignore @@ -17,7 +17,6 @@ aztec-faucet/data* aztec-node/data* aztec/log circuits.js/fixtures/*.json -circuit-types/src/test/artifacts docs/dist end-to-end/addresses.json end-to-end/flame_graph diff --git a/yarn-project/archiver/src/factory.ts b/yarn-project/archiver/src/factory.ts index ac5b2786757..b7f5d8d8ab8 100644 --- a/yarn-project/archiver/src/factory.ts +++ b/yarn-project/archiver/src/factory.ts @@ -1,7 +1,5 @@ -import { type ArchiverApi, type Service } from '@aztec/circuit-types'; import { type ContractClassPublic } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; -import { type Maybe } from '@aztec/foundation/types'; import { createStore } from '@aztec/kv-store/utils'; import { getCanonicalProtocolContract, protocolContractNames } from '@aztec/protocol-contracts'; import { type TelemetryClient } from '@aztec/telemetry-client'; @@ -10,13 +8,13 @@ import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import { Archiver } from './archiver/archiver.js'; import { type ArchiverConfig } from './archiver/config.js'; import { KVArchiverDataStore } from './archiver/index.js'; -import { createArchiverClient } from './rpc/index.js'; +import { createArchiverClient } from './rpc/archiver_client.js'; export async function createArchiver( config: ArchiverConfig, telemetry: TelemetryClient = new NoopTelemetryClient(), opts: { blockUntilSync: boolean } = { blockUntilSync: true }, -): Promise> { +) { if (!config.archiverUrl) { const store = await createStore('archiver', config, createDebugLogger('aztec:archiver:lmdb')); const archiverStore = new KVArchiverDataStore(store, config.maxLogs); diff --git a/yarn-project/archiver/src/rpc/archiver_client.ts b/yarn-project/archiver/src/rpc/archiver_client.ts new file mode 100644 index 00000000000..562b89148c2 --- /dev/null +++ b/yarn-project/archiver/src/rpc/archiver_client.ts @@ -0,0 +1,29 @@ +import { + EncryptedNoteL2BlockL2Logs, + ExtendedUnencryptedL2Log, + L2Block, + NullifierMembershipWitness, + TxReceipt, + UnencryptedL2BlockL2Logs, +} from '@aztec/circuit-types'; +import { EthAddress, Fr } from '@aztec/circuits.js'; +import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client'; + +import { type ArchiveSource } from '../archiver/archiver.js'; + +export const createArchiverClient = (url: string, fetch = makeFetch([1, 2, 3], true)): ArchiveSource => + createJsonRpcClient( + url, + { + EthAddress, + ExtendedUnencryptedL2Log, + Fr, + L2Block, + EncryptedNoteL2BlockL2Logs, + UnencryptedL2BlockL2Logs, + }, + { TxReceipt, NullifierMembershipWitness }, + false, + 'archiver', + fetch, + ) as ArchiveSource; diff --git a/yarn-project/archiver/src/rpc/archiver_server.ts b/yarn-project/archiver/src/rpc/archiver_server.ts new file mode 100644 index 00000000000..be18f647e79 --- /dev/null +++ b/yarn-project/archiver/src/rpc/archiver_server.ts @@ -0,0 +1,35 @@ +import { + EncryptedNoteL2BlockL2Logs, + ExtendedUnencryptedL2Log, + L2Block, + NullifierMembershipWitness, + TxEffect, + TxReceipt, + UnencryptedL2BlockL2Logs, +} from '@aztec/circuit-types'; +import { EthAddress, Fr } from '@aztec/circuits.js'; +import { JsonRpcServer } from '@aztec/foundation/json-rpc/server'; + +import { type Archiver } from '../archiver/archiver.js'; + +/** + * Wrap an Archiver instance with a JSON RPC HTTP server. + * @param archiverService - The Archiver instance + * @returns An JSON-RPC HTTP server + */ +export function createArchiverRpcServer(archiverService: Archiver): JsonRpcServer { + return new JsonRpcServer( + archiverService, + { + EthAddress, + ExtendedUnencryptedL2Log, + Fr, + L2Block, + EncryptedNoteL2BlockL2Logs, + UnencryptedL2BlockL2Logs, + TxEffect, + }, + { TxReceipt, NullifierMembershipWitness }, + ['start', 'stop'], + ); +} diff --git a/yarn-project/archiver/src/rpc/index.ts b/yarn-project/archiver/src/rpc/index.ts index 5845eacb4b8..726d9120af8 100644 --- a/yarn-project/archiver/src/rpc/index.ts +++ b/yarn-project/archiver/src/rpc/index.ts @@ -1,11 +1,2 @@ -import { type ArchiverApi, ArchiverApiSchema } from '@aztec/circuit-types'; -import { createSafeJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client'; -import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server'; - -export function createArchiverClient(url: string, fetch = makeFetch([1, 2, 3], true)): ArchiverApi { - return createSafeJsonRpcClient(url, ArchiverApiSchema, false, 'archiver', fetch); -} - -export function createArchiverRpcServer(handler: ArchiverApi) { - return createSafeJsonRpcServer(handler, ArchiverApiSchema); -} +export * from './archiver_client.js'; +export * from './archiver_server.js'; 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 3ceaf4c6c69..00553b4d004 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 @@ -1,5 +1,28 @@ -import { type AztecNode, AztecNodeApiSchema } from '@aztec/circuit-types'; -import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server'; +import { + type AztecNode, + EncryptedL2NoteLog, + EncryptedNoteL2BlockL2Logs, + EpochProofQuote, + ExtendedUnencryptedL2Log, + L2Block, + LogId, + NullifierMembershipWitness, + PublicDataWitness, + PublicSimulationOutput, + SiblingPath, + Tx, + TxEffect, + TxHash, + TxReceipt, + UnencryptedL2BlockL2Logs, +} from '@aztec/circuit-types'; +import { FunctionSelector, Header, PublicKeys } from '@aztec/circuits.js'; +import { NoteSelector } from '@aztec/foundation/abi'; +import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { Buffer32 } from '@aztec/foundation/buffer'; +import { EthAddress } from '@aztec/foundation/eth-address'; +import { Fr } from '@aztec/foundation/fields'; +import { JsonRpcServer } from '@aztec/foundation/json-rpc/server'; /** * Wrap an AztecNode instance with a JSON RPC HTTP server. @@ -7,5 +30,37 @@ import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server'; * @returns An JSON-RPC HTTP server */ export function createAztecNodeRpcServer(node: AztecNode) { - return createSafeJsonRpcServer(node, AztecNodeApiSchema); + const rpc = new JsonRpcServer( + node, + { + AztecAddress, + EthAddress, + ExtendedUnencryptedL2Log, + Fr, + FunctionSelector, + Header, + L2Block, + TxEffect, + LogId, + TxHash, + Buffer32, + PublicDataWitness, + PublicKeys, + SiblingPath, + }, + { + EncryptedNoteL2BlockL2Logs, + EncryptedL2NoteLog, + NoteSelector, + NullifierMembershipWitness, + PublicSimulationOutput, + Tx, + TxReceipt, + UnencryptedL2BlockL2Logs, + EpochProofQuote, + }, + // disable methods not part of the AztecNode interface + ['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 0f8e30f584d..2340fd6f2d4 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -21,7 +21,6 @@ import { PublicDataWitness, PublicSimulationOutput, type SequencerConfig, - type Service, SiblingPath, type Tx, type TxEffect, @@ -31,7 +30,6 @@ import { TxStatus, type TxValidator, type WorldStateSynchronizer, - tryStop, } from '@aztec/circuit-types'; import { type ARCHIVE_HEIGHT, @@ -91,7 +89,7 @@ export class AztecNodeService implements AztecNode { constructor( protected config: AztecNodeConfig, protected readonly p2pClient: P2P, - protected readonly blockSource: L2BlockSource & Partial, + protected readonly blockSource: L2BlockSource, protected readonly encryptedLogsSource: L2LogsSource, protected readonly unencryptedLogsSource: L2LogsSource, protected readonly contractDataSource: ContractDataSource, @@ -375,7 +373,7 @@ export class AztecNodeService implements AztecNode { await this.sequencer?.stop(); await this.p2pClient.stop(); await this.worldStateSynchronizer.stop(); - await tryStop(this.blockSource); + await this.blockSource.stop(); await this.telemetry.stop(); this.log.info(`Stopped`); } diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index 31f6ce37df1..89cc0beb8ae 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -70,10 +70,7 @@ export class BatchCall extends BaseContractInteraction { const unconstrainedCalls = unconstrained.map(async indexedCall => { const call = indexedCall[0]; - return [ - await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.from), - indexedCall[1], - ] as const; + return [await this.wallet.simulateUnconstrained(call.name, call.args, call.to, options?.from), indexedCall[1]]; }); const [unconstrainedResults, simulatedTx] = await Promise.all([ diff --git a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts index f69f515388e..2c3fa87bb59 100644 --- a/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts +++ b/yarn-project/aztec.js/src/fee/fee_juice_payment_method_with_claim.ts @@ -32,12 +32,7 @@ export class FeeJuicePaymentMethodWithClaim extends FeeJuicePaymentMethod { name: 'claim', selector, isStatic: false, - args: [ - this.sender.toField(), - this.claim.claimAmount, - this.claim.claimSecret, - new Fr(this.claim.messageLeafIndex), - ], + args: [this.sender, this.claim.claimAmount, this.claim.claimSecret, new Fr(this.claim.messageLeafIndex)], returnTypes: [], type: FunctionType.PRIVATE, }, diff --git a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts index e505901da36..0578179ef1c 100644 --- a/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/private_fee_payment_method.ts @@ -65,7 +65,7 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod { caller: this.paymentContract, action: { name: 'setup_refund', - args: [this.feeRecipient.toField(), this.wallet.getAddress().toField(), maxFee, nonce], + args: [this.feeRecipient, this.wallet.getAddress(), maxFee, nonce], selector: FunctionSelector.fromSignature('setup_refund((Field),(Field),Field,Field)'), type: FunctionType.PRIVATE, isStatic: false, @@ -81,7 +81,7 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod { selector: FunctionSelector.fromSignature('fee_entrypoint_private(Field,(Field),Field)'), type: FunctionType.PRIVATE, isStatic: false, - args: [maxFee, this.asset.toField(), nonce], + args: [maxFee, this.asset, nonce], returnTypes: [], }, ]; diff --git a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts index 13842e36131..dae20d5fe8a 100644 --- a/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts +++ b/yarn-project/aztec.js/src/fee/public_fee_payment_method.ts @@ -54,7 +54,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod { caller: this.paymentContract, action: { name: 'transfer_public', - args: [this.wallet.getAddress().toField(), this.paymentContract.toField(), maxFee, nonce], + args: [this.wallet.getAddress(), this.paymentContract, maxFee, nonce], selector: FunctionSelector.fromSignature('transfer_public((Field),(Field),Field,Field)'), type: FunctionType.PUBLIC, isStatic: false, @@ -71,7 +71,7 @@ export class PublicFeePaymentMethod implements FeePaymentMethod { selector: FunctionSelector.fromSignature('fee_entrypoint_public(Field,(Field),Field)'), type: FunctionType.PRIVATE, isStatic: false, - args: [maxFee, this.asset.toField(), nonce], + args: [maxFee, this.asset, nonce], returnTypes: [], }, ]); diff --git a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts index b95c3802fff..0e7a81a0714 100644 --- a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts +++ b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts @@ -1,5 +1,45 @@ -import { type PXE, PXESchema } from '@aztec/circuit-types'; -import { createSafeJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client'; +import { + AuthWitness, + CountedNoteLog, + CountedPublicExecutionRequest, + EncryptedL2Log, + EncryptedL2NoteLog, + EncryptedNoteL2BlockL2Logs, + EventMetadata, + ExtendedNote, + ExtendedUnencryptedL2Log, + L2Block, + LogId, + Note, + NullifierMembershipWitness, + type PXE, + PrivateExecutionResult, + SiblingPath, + Tx, + TxEffect, + TxExecutionRequest, + TxHash, + TxProvingResult, + TxReceipt, + TxSimulationResult, + UnencryptedL2BlockL2Logs, + UnencryptedL2Log, + UniqueNote, +} from '@aztec/circuit-types'; +import { + AztecAddress, + CompleteAddress, + EthAddress, + Fr, + FunctionSelector, + GrumpkinScalar, + Point, + PrivateCircuitPublicInputs, + PublicKeys, +} from '@aztec/circuits.js'; +import { EventSelector, NoteSelector } from '@aztec/foundation/abi'; +import { Buffer32 } from '@aztec/foundation/buffer'; +import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client'; /** * Creates a JSON-RPC client to remotely talk to PXE. @@ -7,6 +47,51 @@ import { createSafeJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/c * @param fetch - The fetch implementation to use. * @returns A JSON-RPC client of PXE. */ -export function createPXEClient(url: string, fetch = makeFetch([1, 2, 3], false)): PXE { - return createSafeJsonRpcClient(url, PXESchema, false, 'pxe', fetch); -} +export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false)): PXE => + createJsonRpcClient( + url, + { + AuthWitness, + AztecAddress, + CompleteAddress, + FunctionSelector, + EthAddress, + EventSelector, + ExtendedNote, + UniqueNote, + ExtendedUnencryptedL2Log, + Fr, + GrumpkinScalar, + L2Block, + TxEffect, + LogId, + Note, + Point, + PublicKeys, + TxExecutionRequest, + TxHash, + Buffer32, + SiblingPath, + }, + { + EncryptedNoteL2BlockL2Logs, + EncryptedL2NoteLog, + EncryptedL2Log, + EventMetadata, + UnencryptedL2Log, + NoteSelector, + NullifierMembershipWitness, + TxSimulationResult, + TxProvingResult, + PrivateCircuitPublicInputs, + PrivateExecutionResult, + CountedPublicExecutionRequest, + CountedNoteLog, + Tx, + TxReceipt, + UnencryptedL2BlockL2Logs, + }, + false, + 'pxe', + fetch, + ) as PXE; diff --git a/yarn-project/aztec.js/src/utils/abi_types.ts b/yarn-project/aztec.js/src/utils/abi_types.ts index 96f43ac5de3..304c109899b 100644 --- a/yarn-project/aztec.js/src/utils/abi_types.ts +++ b/yarn-project/aztec.js/src/utils/abi_types.ts @@ -13,7 +13,7 @@ export type FieldLike = Fr | Buffer | bigint | number | { /** Converts to field export type EthAddressLike = { /** Wrapped address */ address: FieldLike } | EthAddress; /** Any type that can be converted into an AztecAddress Aztec.nr struct. */ -export type AztecAddressLike = { /** Wrapped address */ address: FieldLike } | AztecAddress | Fr; +export type AztecAddressLike = { /** Wrapped address */ address: FieldLike } | AztecAddress; /** Any type that can be converted into a FunctionSelector Aztec.nr struct. */ export type FunctionSelectorLike = FieldLike | FunctionSelector; diff --git a/yarn-project/aztec.js/src/utils/authwit.ts b/yarn-project/aztec.js/src/utils/authwit.ts index 51c62370891..d59ef37e3d0 100644 --- a/yarn-project/aztec.js/src/utils/authwit.ts +++ b/yarn-project/aztec.js/src/utils/authwit.ts @@ -57,7 +57,7 @@ export const computeAuthWitMessageHash = (intent: IntentInnerHash | IntentAction if ('caller' in intent) { const action = intent.action instanceof ContractFunctionInteraction ? intent.action.request() : intent.action; return computeOuterAuthWitHash( - action.to, + action.to.toField(), chainId, version, computeInnerAuthWitHashFromAction(intent.caller, action), diff --git a/yarn-project/aztec.js/src/utils/cheat_codes.ts b/yarn-project/aztec.js/src/utils/cheat_codes.ts index f35ae53c25f..7bbc95044cc 100644 --- a/yarn-project/aztec.js/src/utils/cheat_codes.ts +++ b/yarn-project/aztec.js/src/utils/cheat_codes.ts @@ -444,8 +444,7 @@ export class AztecCheatCodes { * @returns The storage slot of the value in the map */ public computeSlotInMap(mapSlot: Fr | bigint, key: Fr | bigint | AztecAddress): Fr { - const keyFr = typeof key === 'bigint' ? new Fr(key) : key.toField(); - return deriveStorageSlotInMap(mapSlot, keyFr); + return deriveStorageSlotInMap(mapSlot, new Fr(key)); } /** diff --git a/yarn-project/aztec.js/src/utils/pxe.ts b/yarn-project/aztec.js/src/utils/pxe.ts index 57d79ce15ae..700a003d217 100644 --- a/yarn-project/aztec.js/src/utils/pxe.ts +++ b/yarn-project/aztec.js/src/utils/pxe.ts @@ -5,9 +5,8 @@ import { retryUntil } from '@aztec/foundation/retry'; export const waitForPXE = async (pxe: PXE, logger?: DebugLogger) => { await retryUntil(async () => { try { - logger?.verbose('Attempting to contact PXE...'); + logger?.debug('Attempting to contact PXE...'); await pxe.getNodeInfo(); - logger?.verbose('Contacted PXE'); return true; } catch (error) { logger?.verbose('Failed to contact PXE'); diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 9e5156f01d2..bc896799004 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -1,6 +1,6 @@ import { type AuthWitness, - type EventMetadataDefinition, + type EventType, type ExtendedNote, type GetUnencryptedLogsResponse, type IncomingNotesFilter, @@ -33,7 +33,7 @@ import { type PartialAddress, type Point, } from '@aztec/circuits.js'; -import type { AbiDecoded, ContractArtifact } from '@aztec/foundation/abi'; +import type { AbiType, ContractArtifact, EventSelector } from '@aztec/foundation/abi'; import { type Wallet } from '../account/wallet.js'; import { type ExecutionRequestInit } from '../entrypoint/entrypoint.js'; @@ -152,7 +152,7 @@ export abstract class BaseWallet implements Wallet { args: any[], to: AztecAddress, from?: AztecAddress | undefined, - ): Promise { + ): Promise { return this.pxe.simulateUnconstrained(functionName, args, to, from); } getUnencryptedLogs(filter: LogFilter): Promise { @@ -197,8 +197,16 @@ export abstract class BaseWallet implements Wallet { getPXEInfo(): Promise { return this.pxe.getPXEInfo(); } - getEncryptedEvents( - event: EventMetadataDefinition, + getEvents( + type: EventType, + event: { + /** The event selector */ + eventSelector: EventSelector; + /** The event's abi type */ + abiType: AbiType; + /** The field names */ + fieldNames: string[]; + }, from: number, limit: number, vpks: Point[] = [ @@ -206,10 +214,7 @@ export abstract class BaseWallet implements Wallet { this.getCompleteAddress().publicKeys.masterOutgoingViewingPublicKey, ], ): Promise { - return this.pxe.getEncryptedEvents(event, from, limit, vpks); - } - getUnencryptedEvents(event: EventMetadataDefinition, from: number, limit: number): Promise { - return this.pxe.getUnencryptedEvents(event, from, limit); + return this.pxe.getEvents(type, event, from, limit, vpks); } public getL1ToL2MembershipWitness( contractAddress: AztecAddress, diff --git a/yarn-project/aztec/src/cli/cli.ts b/yarn-project/aztec/src/cli/cli.ts index 57650fede28..24251b0165e 100644 --- a/yarn-project/aztec/src/cli/cli.ts +++ b/yarn-project/aztec/src/cli/cli.ts @@ -1,13 +1,11 @@ import { deployInitialTestAccounts } from '@aztec/accounts/testing'; -import { AztecNodeApiSchema, PXESchema } from '@aztec/circuit-types'; -import { - type NamespacedApiHandlers, - createNamespacedSafeJsonRpcServer, - startHttpRpcServer, -} from '@aztec/foundation/json-rpc/server'; +import { createAztecNodeRpcServer } from '@aztec/aztec-node'; +import { type ServerList, createNamespacedJsonRpcServer, createStatusRouter } from '@aztec/foundation/json-rpc/server'; import { type DebugLogger, type LogFn } from '@aztec/foundation/log'; +import { createPXERpcServer } from '@aztec/pxe'; import { Command } from 'commander'; +import http from 'http'; import { setupConsoleJsonLog } from '../logging.js'; import { createSandbox } from '../sandbox.js'; @@ -46,7 +44,7 @@ export function injectAztecCommands(program: Command, userLog: LogFn, debugLogge // list of 'stop' functions to call when process ends const signalHandlers: Array<() => Promise> = []; - const services: NamespacedApiHandlers = {}; + let services: ServerList = []; if (options.sandbox) { const sandboxOptions = extractNamespacedOptions(options, 'sandbox'); @@ -71,37 +69,38 @@ export function injectAztecCommands(program: Command, userLog: LogFn, debugLogge } // Start Node and PXE JSON-RPC server + const nodeServer = createAztecNodeRpcServer(node); + const pxeServer = createPXERpcServer(pxe); signalHandlers.push(stop); - services.node = [node, AztecNodeApiSchema]; - services.pxe = [pxe, PXESchema]; + services = [{ node: nodeServer }, { pxe: pxeServer }]; } else { if (options.node) { const { startNode } = await import('./cmds/start_node.js'); - await startNode(options, signalHandlers, services, userLog); + services = await startNode(options, signalHandlers, userLog); } else if (options.proofVerifier) { const { startProofVerifier } = await import('./cmds/start_proof_verifier.js'); - await startProofVerifier(options, signalHandlers, userLog); + services = await startProofVerifier(options, signalHandlers, userLog); } else if (options.bot) { const { startBot } = await import('./cmds/start_bot.js'); - await startBot(options, signalHandlers, services, userLog); + services = await startBot(options, signalHandlers, userLog); } else if (options.proverNode) { const { startProverNode } = await import('./cmds/start_prover_node.js'); - await startProverNode(options, signalHandlers, services, userLog); + services = await startProverNode(options, signalHandlers, userLog); } else if (options.pxe) { const { startPXE } = await import('./cmds/start_pxe.js'); - await startPXE(options, signalHandlers, services, userLog); + services = await startPXE(options, signalHandlers, userLog); } else if (options.archiver) { const { startArchiver } = await import('./cmds/start_archiver.js'); - await startArchiver(options, signalHandlers, services); + services = await startArchiver(options, signalHandlers); } else if (options.p2pBootstrap) { const { startP2PBootstrap } = await import('./cmds/start_p2p_bootstrap.js'); await startP2PBootstrap(options, userLog, debugLogger); } else if (options.prover) { const { startProverAgent } = await import('./cmds/start_prover_agent.js'); - await startProverAgent(options, signalHandlers, services, userLog); + services = await startProverAgent(options, signalHandlers, userLog); } else if (options.txe) { const { startTXE } = await import('./cmds/start_txe.js'); - await startTXE(options, debugLogger); + startTXE(options, debugLogger); } else if (options.sequencer) { userLog(`Cannot run a standalone sequencer without a node`); process.exit(1); @@ -113,10 +112,17 @@ export function injectAztecCommands(program: Command, userLog: LogFn, debugLogge installSignalHandlers(debugLogger.info, signalHandlers); - if (Object.entries(services).length > 0) { - const rpcServer = createNamespacedSafeJsonRpcServer(services, debugLogger); - const { port } = await startHttpRpcServer(rpcServer, { port: options.port }); - debugLogger.info(`Aztec Server listening on port ${port}`); + if (services.length) { + const rpcServer = createNamespacedJsonRpcServer(services, debugLogger); + + const app = rpcServer.getApp(options.apiPrefix); + // add status route + const statusRouter = createStatusRouter(() => rpcServer.isHealthy(), options.apiPrefix); + app.use(statusRouter.routes()).use(statusRouter.allowedMethods()); + + const httpServer = http.createServer(app.callback()); + httpServer.listen(options.port); + debugLogger.info(`Aztec Server listening on port ${options.port}`); } }); diff --git a/yarn-project/aztec/src/cli/cmds/start_archiver.ts b/yarn-project/aztec/src/cli/cmds/start_archiver.ts index cdee55cc214..d9e0c092aa7 100644 --- a/yarn-project/aztec/src/cli/cmds/start_archiver.ts +++ b/yarn-project/aztec/src/cli/cmds/start_archiver.ts @@ -1,7 +1,12 @@ -import { Archiver, type ArchiverConfig, KVArchiverDataStore, archiverConfigMappings } from '@aztec/archiver'; +import { + Archiver, + type ArchiverConfig, + KVArchiverDataStore, + archiverConfigMappings, + createArchiverRpcServer, +} from '@aztec/archiver'; import { createDebugLogger } from '@aztec/aztec.js'; -import { ArchiverApiSchema } from '@aztec/circuit-types'; -import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server'; +import { type ServerList } from '@aztec/foundation/json-rpc/server'; import { createStore } from '@aztec/kv-store/utils'; import { createAndStartTelemetryClient, @@ -10,12 +15,9 @@ import { import { extractRelevantOptions } from '../util.js'; -/** Starts a standalone archiver. */ -export async function startArchiver( - options: any, - signalHandlers: (() => Promise)[], - services: NamespacedApiHandlers, -) { +export const startArchiver = async (options: any, signalHandlers: (() => Promise)[]) => { + const services: ServerList = []; + // Start a standalone archiver. const archiverConfig = extractRelevantOptions(options, archiverConfigMappings, 'archiver'); const storeLog = createDebugLogger('aztec:archiver:lmdb'); @@ -24,7 +26,8 @@ export async function startArchiver( const telemetry = await createAndStartTelemetryClient(getTelemetryClientConfig()); const archiver = await Archiver.createAndSync(archiverConfig, archiverStore, telemetry, true); - services.archiver = [archiver, ArchiverApiSchema]; + const archiverServer = createArchiverRpcServer(archiver); + services.push({ archiver: archiverServer }); signalHandlers.push(archiver.stop); return services; -} +}; diff --git a/yarn-project/aztec/src/cli/cmds/start_bot.ts b/yarn-project/aztec/src/cli/cmds/start_bot.ts index 1d3e110db33..cf61ed0aa95 100644 --- a/yarn-project/aztec/src/cli/cmds/start_bot.ts +++ b/yarn-project/aztec/src/cli/cmds/start_bot.ts @@ -1,6 +1,6 @@ -import { type BotConfig, BotRunner, botConfigMappings, getBotRunnerApiHandler } from '@aztec/bot'; +import { type BotConfig, BotRunner, botConfigMappings, createBotRunnerRpcServer } from '@aztec/bot'; import { type AztecNode, type PXE } from '@aztec/circuit-types'; -import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server'; +import { type ServerList } from '@aztec/foundation/json-rpc/server'; import { type LogFn } from '@aztec/foundation/log'; import { extractRelevantOptions } from '../util.js'; @@ -8,9 +8,11 @@ import { extractRelevantOptions } from '../util.js'; export async function startBot( options: any, signalHandlers: (() => Promise)[], - services: NamespacedApiHandlers, userLog: LogFn, -) { +): Promise { + // Services that will be started in a single multi-rpc server + const services: ServerList = []; + const { proverNode, archiver, sequencer, p2pBootstrap, txe, prover } = options; if (proverNode || archiver || sequencer || p2pBootstrap || txe || prover) { userLog( @@ -22,25 +24,27 @@ export async function startBot( let pxe: PXE | undefined; if (options.pxe) { const { addPXE } = await import('./start_pxe.js'); - pxe = await addPXE(options, signalHandlers, services, userLog); + pxe = await addPXE(options, services, signalHandlers, userLog); } - await addBot(options, signalHandlers, services, { pxe }); + await addBot(options, services, signalHandlers, { pxe }); + return services; } export function addBot( options: any, + services: ServerList, signalHandlers: (() => Promise)[], - services: NamespacedApiHandlers, deps: { pxe?: PXE; node?: AztecNode } = {}, ) { const config = extractRelevantOptions(options, botConfigMappings, 'bot'); const botRunner = new BotRunner(config, deps); + const botServer = createBotRunnerRpcServer(botRunner); if (!config.noStart) { void botRunner.start(); // Do not block since bot setup takes time } - services.bot = getBotRunnerApiHandler(botRunner); + services.push({ bot: botServer }); signalHandlers.push(botRunner.stop); return Promise.resolve(); } diff --git a/yarn-project/aztec/src/cli/cmds/start_node.ts b/yarn-project/aztec/src/cli/cmds/start_node.ts index 939776c345b..ad0cb056257 100644 --- a/yarn-project/aztec/src/cli/cmds/start_node.ts +++ b/yarn-project/aztec/src/cli/cmds/start_node.ts @@ -1,7 +1,7 @@ -import { aztecNodeConfigMappings } from '@aztec/aztec-node'; -import { AztecNodeApiSchema, type PXE } from '@aztec/circuit-types'; +import { aztecNodeConfigMappings, createAztecNodeRpcServer } from '@aztec/aztec-node'; +import { type PXE } from '@aztec/circuit-types'; import { NULL_KEY } from '@aztec/ethereum'; -import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server'; +import { type ServerList } from '@aztec/foundation/json-rpc/server'; import { type LogFn } from '@aztec/foundation/log'; import { type TelemetryClientConfig, @@ -14,12 +14,14 @@ import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts'; import { createAztecNode, deployContractsToL1 } from '../../sandbox.js'; import { extractNamespacedOptions, extractRelevantOptions } from '../util.js'; -export async function startNode( +export const startNode = async ( options: any, signalHandlers: (() => Promise)[], - services: NamespacedApiHandlers, userLog: LogFn, -) { +): Promise => { + // Services that will be started in a single multi-rpc server + const services: ServerList = []; + // options specifically namespaced with --node.