From b5e78ad44304944d47e6fd8a6cba110be1277052 Mon Sep 17 00:00:00 2001 From: zichang zhong Date: Fri, 20 Dec 2024 18:25:38 +0800 Subject: [PATCH] Fix: catch error when post_partial_solution This uncaught error causes ar_mining_server to be terminated. b64fast.encode > ar_serialize.poa_to_json_struct > ar_serialize.solution_to_json_struct > ar_http_iface_client,post_partial_solution --- apps/arweave/src/ar_http_iface_client.erl | 34 +++++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/apps/arweave/src/ar_http_iface_client.erl b/apps/arweave/src/ar_http_iface_client.erl index 2d5888265..78c73ab31 100644 --- a/apps/arweave/src/ar_http_iface_client.erl +++ b/apps/arweave/src/ar_http_iface_client.erl @@ -686,20 +686,30 @@ get_jobs(Peer, PrevOutput) -> "/jobs/" ++ binary_to_list(ar_util:encode(PrevOutput))), handle_get_jobs_response(ar_http:req(Req)). +serialize_solution(Solution) -> + Json = ar_serialize:solution_to_json_struct(Solution), + {ok, ar_serialize:jsonify(Json)}. + +serialize_solution_ify(Solution) -> + case is_binary(Solution) of + true -> + {ok, Solution}; + false -> + serialize_solution(Solution) + end. + %% @doc Post the partial solution to the pool or coordinated mining exit peer. post_partial_solution(Peer, Solution) -> - Payload = - case is_binary(Solution) of - true -> - Solution; - false -> - ar_serialize:jsonify(ar_serialize:solution_to_json_struct(Solution)) - end, - Req = build_cm_or_pool_request(post, Peer, "/partial_solution", Payload), - handle_post_partial_solution_response(ar_http:req(Req#{ - timeout => 20 * 1000, - connect_timeout => 5 * 1000 - })). + case catch serialize_solution_ify(Solution) of + {ok, Payload} -> + Req = build_cm_or_pool_request(post, Peer, "/partial_solution", Payload), + handle_post_partial_solution_response(ar_http:req(Req#{ + timeout => 20 * 1000, + connect_timeout => 5 * 1000 + })); + {'EXIT', Reason, _ } -> {error, Reason}; + _ -> {error, failed_to_serialize_partial_solution} + end. get_pool_cm_jobs(Peer, Jobs) -> JSON = ar_serialize:jsonify(ar_serialize:pool_cm_jobs_to_json_struct(Jobs)),