Improve miner log and retry on error, add zx as dep #21

Open
uwiger wants to merge 1 commits from uw-improve-miner-retry into master
6 changed files with 70 additions and 14 deletions

View File

@ -1,6 +1,6 @@
{application,gmhive_client, {application,gmhive_client,
[{description,"Gajumaru Hive Client"}, [{description,"Gajumaru Hive Client"},
{vsn,"0.10.0"}, {vsn,"0.10.1"},
{registered,[]}, {registered,[]},
{applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise, {applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise,
gmconfig,gmhive_protocol,gmhive_worker]}, gmconfig,gmhive_protocol,gmhive_worker]},

View File

@ -3,7 +3,10 @@
{minimum_otp_vsn, "27.1"}. {minimum_otp_vsn, "27.1"}.
{erl_opts, [debug_info]}. {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"}]}. {post_hooks, [{compile, "make schema"}]}.
@ -16,12 +19,13 @@
{gmconfig, {git, "https://git.qpq.swiss/QPQ-AG/gmconfig.git", {gmconfig, {git, "https://git.qpq.swiss/QPQ-AG/gmconfig.git",
{ref, "38620ff9e2"}}}, {ref, "38620ff9e2"}}},
{gproc, "1.0.0"}, {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, [ {relx, [
{release, { gmhive_client, "0.1.0" }, {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 ]}, {gmhive_protocol, load}, gmserialization, gproc, gmconfig, gmhive_client ]},
{dev_mode, true}, {dev_mode, true},
{sys_config, "./config/sys.config"}, {sys_config, "./config/sys.config"},
@ -36,5 +40,5 @@
{dialyzer, [ {warnings, [unknown]} {dialyzer, [ {warnings, [unknown]}
, {plt_apps, all_deps} , {plt_apps, all_deps}
, {base_plt_apps, [erts, kernel, stdlib, inets]} , {base_plt_apps, [erts, kernel, stdlib, inets, zx]}
]}. ]}.

View File

@ -38,7 +38,12 @@
{<<"gproc">>,{pkg,<<"gproc">>,<<"1.0.0">>},0}, {<<"gproc">>,{pkg,<<"gproc">>,<<"1.0.0">>},0},
{<<"setup">>, {<<"setup">>,
{git,"https://github.com/uwiger/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}]}. 0}]}.
[ [
{pkg_hash,[ {pkg_hash,[

View File

@ -46,6 +46,7 @@ stop(_State) ->
set_things_up() -> set_things_up() ->
maybe_add_logger_handler(), maybe_add_logger_handler(),
clean_up_log_directories(),
gmhc_counters:initialize(), gmhc_counters:initialize(),
gmhc_config:load_config(), gmhc_config:load_config(),
logger:set_module_level([gmhw_pow_cuckoo], notice), logger:set_module_level([gmhw_pow_cuckoo], notice),
@ -61,6 +62,36 @@ set_things_up() ->
end, end,
ok. 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() -> maybe_add_logger_handler() ->
case is_headless() orelse application:get_env(gmhive_client, tty_logger, false) of case is_headless() orelse application:get_env(gmhive_client, tty_logger, false) of
true -> true ->

View File

@ -41,6 +41,7 @@
, candidate :: map() | 'undefined' , candidate :: map() | 'undefined'
, nonces = 1 :: pos_integer() , nonces = 1 :: pos_integer()
, workers = [] :: [worker()] , workers = [] :: [worker()]
, check_timer :: 'undefined' | reference()
}). }).
-define(CONNECTED(S), map_size(S#st.connected) > 0). -define(CONNECTED(S), map_size(S#st.connected) > 0).
@ -80,6 +81,7 @@ init([]) ->
N + Acc N + Acc
end, 0, IdleWorkers), end, 0, IdleWorkers),
process_flag(trap_exit, true), process_flag(trap_exit, true),
gproc_ps:subscribe(l, gmhw_miner_return),
{ok, #st{workers = IdleWorkers, nonces = TotalNonces}}. {ok, #st{workers = IdleWorkers, nonces = TotalNonces}}.
handle_call(total_nonces, _From, #st{nonces = Nonces} = S) -> 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, gmhc_events:publish(error, ?ERR_EVT(#{error => worker_error,
data => Reason})), data => Reason})),
Ws1 = incr_worker_error(W, Workers), Ws1 = incr_worker_error(W, Workers),
erlang:start_timer(100, self(), check_workers), S1 = start_check_timer(S#st{workers = Ws1}),
{noreply, S#st{workers = Ws1}}; {noreply, S1};
false -> false ->
%% ?LOG_DEBUG("EXIT apparently not from worker?? (~p)", [Pid]), %% ?LOG_DEBUG("EXIT apparently not from worker?? (~p)", [Pid]),
{noreply, S} {noreply, S}
end; end;
handle_info({timeout, _, check_workers}, #st{workers = Workers} = S) -> 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) -> S2 = lists:foldl(fun(W, Sx) ->
maybe_restart_worker(W, Sx) maybe_restart_worker(W, Sx)
end, S1, Workers), end, S1, Workers),
{noreply, S2}; {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) -> handle_info(Msg, St) ->
?LOG_DEBUG("Unknown msg: ~p", [Msg]), ?LOG_DEBUG("Unknown msg: ~p", [Msg]),
{noreply, St}. {noreply, St}.
@ -180,6 +190,12 @@ terminate(_Reason, _St) ->
code_change(_FromVsn, S, _Extra) -> code_change(_FromVsn, S, _Extra) ->
{ok, S}. {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) -> report_solutions(Solutions, W, #st{} = S) when ?CONNECTED(S) ->
#{via := Via, seq := Seq} = W#worker.cand, #{via := Via, seq := Seq} = W#worker.cand,
Nonces = all_nonces(W), 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, gmhc_events:publish(error, ?ERR_EVT(#{error => worker_error,
data => Result})), data => Result})),
Ws = incr_worker_error(W, S#st.workers), Ws = incr_worker_error(W, S#st.workers),
S#st{workers = Ws} start_check_timer(S#st{workers = Ws})
end; end;
handle_worker_result(Error, W, S) -> handle_worker_result(Error, W, S) ->
?LOG_DEBUG("Got worker error from ~p: ~p", [W#worker.index, Error]), ?LOG_DEBUG("Got worker error from ~p: ~p", [W#worker.index, Error]),

View File

@ -2,16 +2,16 @@
{type,app}. {type,app}.
{modules,[]}. {modules,[]}.
{prefix,"gmhc"}. {prefix,"gmhc"}.
{author,"Ulf Wiger, QPQ AG"}.
{desc,"Gajumaru Hive Client"}. {desc,"Gajumaru Hive Client"}.
{package_id,{"uwiger","gmhive_client",{0,10,0}}}. {author,"Ulf Wiger, QPQ AG"}.
{deps,[{"uwiger","gmhive_protocol",{0,3,1}}, {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","gmhive_worker",{0,5,1}},
{"uwiger","gmcuckoo",{1,2,4}}, {"uwiger","gmcuckoo",{1,2,4}},
{"otpr","eblake2",{1,0,1}}, {"otpr","eblake2",{1,0,1}},
{"otpr","base58",{0,1,1}}, {"otpr","base58",{0,1,1}},
{"otpr","gmserialization",{0,1,3}}, {"otpr","gmserialization",{0,1,3}},
{"uwiger","setup",{2,2,4}},
{"uwiger","gproc",{1,0,1}}, {"uwiger","gproc",{1,0,1}},
{"uwiger","gmconfig",{0,1,2}}, {"uwiger","gmconfig",{0,1,2}},
{"uwiger","enoise",{1,3,0}}]}. {"uwiger","enoise",{1,3,0}}]}.