From 326caff7946ed0981cf1716a42d111a38ab9211a Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 10 Jan 2025 09:34:34 +0000 Subject: [PATCH 1/4] cleanup --- .../aztec/src/cli/aztec_start_action.ts | 2 +- .../json-rpc/server/safe_json_rpc_server.ts | 37 +++++++++++-------- yarn-project/txe/src/index.ts | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/yarn-project/aztec/src/cli/aztec_start_action.ts b/yarn-project/aztec/src/cli/aztec_start_action.ts index c45892eccc1..7e8e81b142e 100644 --- a/yarn-project/aztec/src/cli/aztec_start_action.ts +++ b/yarn-project/aztec/src/cli/aztec_start_action.ts @@ -102,7 +102,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg installSignalHandlers(debugLogger.info, signalHandlers); if (Object.entries(services).length > 0) { - const rpcServer = createNamespacedSafeJsonRpcServer(services, false, debugLogger); + const rpcServer = createNamespacedSafeJsonRpcServer(services, { http200OnError: false, log: debugLogger }); const { port } = await startHttpRpcServer(rpcServer, { port: options.port }); debugLogger.info(`Aztec Server listening on port ${port}`); } diff --git a/yarn-project/foundation/src/json-rpc/server/safe_json_rpc_server.ts b/yarn-project/foundation/src/json-rpc/server/safe_json_rpc_server.ts index 8d680cada32..796e8482a63 100644 --- a/yarn-project/foundation/src/json-rpc/server/safe_json_rpc_server.ts +++ b/yarn-project/foundation/src/json-rpc/server/safe_json_rpc_server.ts @@ -60,6 +60,12 @@ export class SafeJsonRpcServer { const message = err.issues.map(e => `${e.message} (${e.path.join('.')})`).join('. ') || 'Validation error'; ctx.status = 400; ctx.body = { jsonrpc: '2.0', id: null, error: { code: -32701, message } }; + } else if (this.http200OnError) { + ctx.body = { + jsonrpc: '2.0', + id: null, + error: { code: err.code || -32600, data: err.data, message: err.message }, + }; } else { ctx.status = 500; ctx.body = { jsonrpc: '2.0', id: null, error: { code: -32600, message: err.message ?? 'Internal error' } }; @@ -111,16 +117,8 @@ export class SafeJsonRpcServer { ctx.body = { jsonrpc, id, error: { code: -32601, message: `Method not found: ${method}` } }; } else { ctx.status = 200; - try { - const result = await this.proxy.call(method, params); - ctx.body = { jsonrpc, id, result }; - } catch (err: any) { - if (this.http200OnError) { - ctx.body = { jsonrpc, id, error: { code: err.code || -32600, data: err.data, message: err.message } }; - } else { - throw err; - } - } + const result = await this.proxy.call(method, params); + ctx.body = { jsonrpc, id, result }; } }); @@ -265,6 +263,12 @@ function makeAggregateHealthcheck(namedHandlers: NamespacedApiHandlers, log?: Lo }; } +type SafeJsonRpcServerOptions = { + http200OnError: boolean; + healthCheck?: StatusCheckFn; + log?: Logger; +}; + /** * Creates a single SafeJsonRpcServer from multiple handlers. * @param servers - List of handlers to be combined. @@ -272,9 +276,12 @@ function makeAggregateHealthcheck(namedHandlers: NamespacedApiHandlers, log?: Lo */ export function createNamespacedSafeJsonRpcServer( handlers: NamespacedApiHandlers, - http200OnError = false, - log = createLogger('json-rpc:server'), + options: Omit = { + http200OnError: false, + log: createLogger('json-rpc:server'), + }, ): SafeJsonRpcServer { + const { http200OnError, log } = options; const proxy = new NamespacedSafeJsonProxy(handlers); const healthCheck = makeAggregateHealthcheck(handlers, log); return new SafeJsonRpcServer(proxy, http200OnError, healthCheck, log); @@ -283,11 +290,11 @@ export function createNamespacedSafeJsonRpcServer( export function createSafeJsonRpcServer( handler: T, schema: ApiSchemaFor, - http200OnError = false, - healthCheck?: StatusCheckFn, + options: SafeJsonRpcServerOptions = { http200OnError: false }, ) { + const { http200OnError, log, healthCheck } = options; const proxy = new SafeJsonProxy(handler, schema); - return new SafeJsonRpcServer(proxy, http200OnError, healthCheck); + return new SafeJsonRpcServer(proxy, http200OnError, healthCheck, log); } /** diff --git a/yarn-project/txe/src/index.ts b/yarn-project/txe/src/index.ts index 1fab653ae0a..a2d48d610b7 100644 --- a/yarn-project/txe/src/index.ts +++ b/yarn-project/txe/src/index.ts @@ -120,5 +120,5 @@ const TXEDispatcherApiSchema: ApiSchemaFor = { * @returns A TXE RPC server. */ export function createTXERpcServer(logger: Logger) { - return createSafeJsonRpcServer(new TXEDispatcher(logger), TXEDispatcherApiSchema, true); + return createSafeJsonRpcServer(new TXEDispatcher(logger), TXEDispatcherApiSchema, { http200OnError: true }); } From 0154973aaaef260130318fa3d2c97b50b16f21df Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 10 Jan 2025 10:02:51 +0000 Subject: [PATCH 2/4] fix --- yarn-project/bot/src/rpc.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/yarn-project/bot/src/rpc.ts b/yarn-project/bot/src/rpc.ts index cca9df44e9c..db21442eaec 100644 --- a/yarn-project/bot/src/rpc.ts +++ b/yarn-project/bot/src/rpc.ts @@ -9,7 +9,10 @@ import { type BotRunner } from './runner.js'; * @returns An JSON-RPC HTTP server */ export function createBotRunnerRpcServer(botRunner: BotRunner) { - createSafeJsonRpcServer(botRunner, BotRunnerApiSchema, false, botRunner.isHealthy.bind(botRunner)); + createSafeJsonRpcServer(botRunner, BotRunnerApiSchema, { + http200OnError: false, + healthCheck: botRunner.isHealthy.bind(botRunner), + }); } export function getBotRunnerApiHandler(botRunner: BotRunner): ApiHandler { From 4359441a75a927179d3bdab7c8c613cce7e2fb2f Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 10 Jan 2025 10:38:52 +0000 Subject: [PATCH 3/4] fixed docs --- .../contracts/easy_private_voting_contract/src/main.nr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr b/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr index c7f51654c76..d293a2c0171 100644 --- a/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr @@ -1,8 +1,10 @@ +// docs:start:declaration mod test; use dep::aztec::macros::aztec; #[aztec] contract EasyPrivateVoting { + // docs:end:declaration // docs:start:imports use dep::aztec::{ keys::getters::get_public_keys, From 78b0afcb80fbf3995575718114c3578c3462654d Mon Sep 17 00:00:00 2001 From: thunkar Date: Fri, 10 Jan 2025 10:39:20 +0000 Subject: [PATCH 4/4] fix --- .../smart_contracts/writing_contracts/index.mdx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/index.mdx b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/index.mdx index a85da746eba..3f8bfb9cefe 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/index.mdx +++ b/docs/docs/guides/developer_guides/smart_contracts/writing_contracts/index.mdx @@ -13,13 +13,6 @@ To write a contract: ```rust #include_code declaration /noir-projects/noir-contracts/contracts/easy_private_voting_contract/src/main.nr raw - - // Imports - - // Storage - - // Functions -} ``` 2. Define imports in your contract block