From e78e674d8f6730890ca5c7814db4f813fd7ecb6c Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Sun, 30 Nov 2025 21:30:38 +0100 Subject: [PATCH] Improve miner log and retry on error, add zx as dep --- ebin/gmhive_client.app | 2 +- rebar.config | 12 ++++++++---- rebar.lock | 7 ++++++- src/gmhc_app.erl | 31 +++++++++++++++++++++++++++++++ src/gmhc_server.erl | 24 ++++++++++++++++++++---- zomp.meta | 8 ++++---- 6 files changed, 70 insertions(+), 14 deletions(-) diff --git a/ebin/gmhive_client.app b/ebin/gmhive_client.app index 3314520..c97996a 100644 --- a/ebin/gmhive_client.app +++ b/ebin/gmhive_client.app @@ -1,6 +1,6 @@ {application,gmhive_client, [{description,"Gajumaru Hive Client"}, - {vsn,"0.10.0"}, + {vsn,"0.10.1"}, {registered,[]}, {applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise, gmconfig,gmhive_protocol,gmhive_worker]}, diff --git a/rebar.config b/rebar.config index 0e2aa69..9dde3e3 100644 --- a/rebar.config +++ b/rebar.config @@ -3,7 +3,10 @@ {minimum_otp_vsn, "27.1"}. {erl_opts, [debug_info]}. -{plugins, [rebar3_hex]}. +{plugins, [ rebar3_hex + , {zx_rebar_plugin, {git, "https://git.qpq.swiss/QPQ-AG/zx_rebar_plugin", + {branch, "master"}}} + ]}. {post_hooks, [{compile, "make schema"}]}. @@ -16,12 +19,13 @@ {gmconfig, {git, "https://git.qpq.swiss/QPQ-AG/gmconfig.git", {ref, "38620ff9e2"}}}, {gproc, "1.0.0"}, - {setup, {git, "https://github.com/uwiger/setup", {ref, "d9b0b51"}}} + {setup, {git, "https://github.com/uwiger/setup", {ref, "0430661"}}}, + {zx, {zx, "https://gitlab.com/zxq9/zx.git", {ref, "2a0437f4"}, "0.14.0"}} ]}. {relx, [ {release, { gmhive_client, "0.1.0" }, - [sasl, enacl, enoise, gmhive_worker, + [sasl, enacl, enoise, gmhive_worker, {zx, load}, {gmhive_protocol, load}, gmserialization, gproc, gmconfig, gmhive_client ]}, {dev_mode, true}, {sys_config, "./config/sys.config"}, @@ -36,5 +40,5 @@ {dialyzer, [ {warnings, [unknown]} , {plt_apps, all_deps} - , {base_plt_apps, [erts, kernel, stdlib, inets]} + , {base_plt_apps, [erts, kernel, stdlib, inets, zx]} ]}. diff --git a/rebar.lock b/rebar.lock index 50980b1..56f1326 100644 --- a/rebar.lock +++ b/rebar.lock @@ -38,7 +38,12 @@ {<<"gproc">>,{pkg,<<"gproc">>,<<"1.0.0">>},0}, {<<"setup">>, {git,"https://github.com/uwiger/setup", - {ref,"d9b0b51505ff75c459f1ab62bd907ca5e3a32291"}}, + {ref,"0430661811269d007285f817467cbab7c4c31e96"}}, + 0}, + {<<"zx">>, + {zx,"https://gitlab.com/zxq9/zx.git", + {ref,"2a0437f416f94596e4e3b403603dbd028727742d"}, + "0.14.0"}, 0}]}. [ {pkg_hash,[ diff --git a/src/gmhc_app.erl b/src/gmhc_app.erl index ba914d7..e1d2694 100644 --- a/src/gmhc_app.erl +++ b/src/gmhc_app.erl @@ -46,6 +46,7 @@ stop(_State) -> set_things_up() -> maybe_add_logger_handler(), + clean_up_log_directories(), gmhc_counters:initialize(), gmhc_config:load_config(), logger:set_module_level([gmhw_pow_cuckoo], notice), @@ -61,6 +62,36 @@ set_things_up() -> end, ok. +clean_up_log_directories() -> + case setup_zomp:is_zomp_context() of + true -> + %% This is a temporary measure to remove old auto-created log sub-directories + LogDir = setup:log_dir(), + SubDirs = filelib:wildcard(LogDir ++ "/*/"), + [delete_if_empty(D) || D <- SubDirs]; + false -> + ok + end. + +delete_if_empty(Dir) -> + case filelib:wildcard(Dir ++ "/*") of + [] -> + Res = file:del_dir(Dir), + Res == ok; + Fs -> + case [filelib:is_regular(F) || F <- Fs] of + [] -> + case [F || F <- Fs, delete_if_empty(F) == false] of + [] -> + delete_if_empty(Dir); + [_|_] -> + false + end; + [_|_] -> + false + end + end. + maybe_add_logger_handler() -> case is_headless() orelse application:get_env(gmhive_client, tty_logger, false) of true -> diff --git a/src/gmhc_server.erl b/src/gmhc_server.erl index 8a6444c..787cb48 100644 --- a/src/gmhc_server.erl +++ b/src/gmhc_server.erl @@ -41,6 +41,7 @@ , candidate :: map() | 'undefined' , nonces = 1 :: pos_integer() , workers = [] :: [worker()] + , check_timer :: 'undefined' | reference() }). -define(CONNECTED(S), map_size(S#st.connected) > 0). @@ -80,6 +81,7 @@ init([]) -> N + Acc end, 0, IdleWorkers), process_flag(trap_exit, true), + gproc_ps:subscribe(l, gmhw_miner_return), {ok, #st{workers = IdleWorkers, nonces = TotalNonces}}. handle_call(total_nonces, _From, #st{nonces = Nonces} = S) -> @@ -158,18 +160,26 @@ handle_info({'EXIT', Pid, Reason}, #st{ workers = Workers gmhc_events:publish(error, ?ERR_EVT(#{error => worker_error, data => Reason})), Ws1 = incr_worker_error(W, Workers), - erlang:start_timer(100, self(), check_workers), - {noreply, S#st{workers = Ws1}}; + S1 = start_check_timer(S#st{workers = Ws1}), + {noreply, S1}; false -> %% ?LOG_DEBUG("EXIT apparently not from worker?? (~p)", [Pid]), {noreply, S} end; handle_info({timeout, _, check_workers}, #st{workers = Workers} = S) -> - S1 = maybe_request_nonces(S), + S1 = maybe_request_nonces(S#st{check_timer = undefined}), S2 = lists:foldl(fun(W, Sx) -> maybe_restart_worker(W, Sx) end, S1, Workers), {noreply, S2}; +handle_info({gproc_ps_event, gmhw_miner_return, Data}, S) -> + case Data of + #{info := #{result := {invalid_output, _}} = Info} -> + ?LOG_NOTICE("Bad miner return: ~p", [Info]); + _ -> + ok + end, + {noreply, S}; handle_info(Msg, St) -> ?LOG_DEBUG("Unknown msg: ~p", [Msg]), {noreply, St}. @@ -180,6 +190,12 @@ terminate(_Reason, _St) -> code_change(_FromVsn, S, _Extra) -> {ok, S}. +start_check_timer(#st{check_timer = undefined} = S) -> + TRef = erlang:start_timer(100, self(), check_workers), + S#st{check_timer = TRef}; +start_check_timer(S) -> + S. + report_solutions(Solutions, W, #st{} = S) when ?CONNECTED(S) -> #{via := Via, seq := Seq} = W#worker.cand, Nonces = all_nonces(W), @@ -268,7 +284,7 @@ handle_worker_result({worker_result, Result}, W, S) -> gmhc_events:publish(error, ?ERR_EVT(#{error => worker_error, data => Result})), Ws = incr_worker_error(W, S#st.workers), - S#st{workers = Ws} + start_check_timer(S#st{workers = Ws}) end; handle_worker_result(Error, W, S) -> ?LOG_DEBUG("Got worker error from ~p: ~p", [W#worker.index, Error]), diff --git a/zomp.meta b/zomp.meta index b3392e8..8197658 100644 --- a/zomp.meta +++ b/zomp.meta @@ -2,16 +2,16 @@ {type,app}. {modules,[]}. {prefix,"gmhc"}. -{author,"Ulf Wiger, QPQ AG"}. {desc,"Gajumaru Hive Client"}. -{package_id,{"uwiger","gmhive_client",{0,10,0}}}. -{deps,[{"uwiger","gmhive_protocol",{0,3,1}}, +{author,"Ulf Wiger, QPQ AG"}. +{package_id,{"uwiger","gmhive_client",{0,10,1}}}. +{deps,[{"uwiger","setup",{3,0,0}}, + {"uwiger","gmhive_protocol",{0,3,1}}, {"uwiger","gmhive_worker",{0,5,1}}, {"uwiger","gmcuckoo",{1,2,4}}, {"otpr","eblake2",{1,0,1}}, {"otpr","base58",{0,1,1}}, {"otpr","gmserialization",{0,1,3}}, - {"uwiger","setup",{2,2,4}}, {"uwiger","gproc",{1,0,1}}, {"uwiger","gmconfig",{0,1,2}}, {"uwiger","enoise",{1,3,0}}]}.