10 Commits

Author SHA1 Message Date
Ulf Wiger e31a8dd2f1 Update gmhive_worker dep 2025-08-27 16:31:23 +02:00
Ulf Wiger 2ea84ee4b2 Add app.src.script for version mgmt 2025-08-27 12:49:16 +02:00
Ulf Wiger 8d99f55377 Update gmhive_worker and gmcuckoo deps, miner returns in debug 2025-08-27 12:48:33 +02:00
uwiger 6939ae2fd1 Merge pull request 'Add missing demonitor() calls' (#11) from uw-demonitor into master
Reviewed-on: #11
Reviewed-by: Craig Everett <craigeverett@qpq.swiss>
Reviewed-by: Jarvis Carroll <jarviscarrol@qpq.swiss>
2025-08-27 19:28:49 +09:00
Ulf Wiger 196a2d9949 Reset worker errors, retry failed workers 2025-08-21 22:46:54 +02:00
Ulf Wiger d61f103945 update gmhive_worker dep, bump patch vsn 2025-08-21 16:46:11 +02:00
Ulf Wiger 0a76bada43 bump zx patch vsn 2025-08-20 20:44:55 +02:00
Ulf Wiger 36a11575d2 Add missing demonitor() calls 2025-08-20 20:43:22 +02:00
uwiger 5bc0fc5ff8 Merge pull request 'uw-handle-empty-nonces' (#8) from uw-handle-empty-nonces into master
Reviewed-on: #8
Reviewed-by: Jarvis Carroll <jarviscarrol@qpq.swiss>
2025-08-21 03:42:37 +09:00
Ulf Wiger c61ce6df1a Handle empty nonces (zx vsn 0.4.5) 2025-06-16 22:29:00 +02:00
19 changed files with 69 additions and 20 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{application,gmhive_client,
[{description,"Gajumaru Hive Client"},
{vsn,"0.4.4"},
{vsn,"0.5.1"},
{registered,[]},
{applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise,
gmconfig,gmhive_protocol,gmhive_worker]},
+1 -1
View File
@@ -10,7 +10,7 @@
{gmhive_protocol,
{git, "https://git.qpq.swiss/QPQ-AG/gmhive_protocol.git",
{ref, "818ce33"}}},
{gmhive_worker, {git, "https://git.qpq.swiss/QPQ-AG/gmhive_worker", {ref, "255ef59"}}},
{gmhive_worker, {git, "https://git.qpq.swiss/QPQ-AG/gmhive_worker", {ref, "cabd104114"}}},
{gmconfig, {git, "https://git.qpq.swiss/QPQ-AG/gmconfig.git",
{ref, "38620ff9e2"}}},
{gproc, "1.0.0"},
+2 -2
View File
@@ -21,7 +21,7 @@
0},
{<<"gmcuckoo">>,
{git,"https://git.qpq.swiss/QPQ-AG/gmcuckoo.git",
{ref,"106e1cd2e4ff81286f6bc7d7c85f83bc20e14b82"}},
{ref,"256e14e7c88043132245be902ff9756070d285b4"}},
1},
{<<"gmhive_protocol">>,
{git,"https://git.qpq.swiss/QPQ-AG/gmhive_protocol.git",
@@ -29,7 +29,7 @@
0},
{<<"gmhive_worker">>,
{git,"https://git.qpq.swiss/QPQ-AG/gmhive_worker",
{ref,"255ef59ccd7f795d2d25f2d0ebcf24e3251b6f36"}},
{ref,"cabd104114691edb925aacd7e04d431d47bac420"}},
0},
{<<"gmserialization">>,
{git,"https://git.qpq.swiss/QPQ-AG/gmserialization.git",
+1
View File
@@ -1,5 +1,6 @@
%% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*-
-module(gmhc_app).
-vsn("0.4.8").
-behaviour(application).
+1
View File
@@ -1,4 +1,5 @@
-module(gmhc_config).
-vsn("0.4.8").
-export([ load_config/0
, get_config/1
+1
View File
@@ -1,4 +1,5 @@
-module(gmhc_config_schema).
-vsn("0.4.8").
-export([ schema/0
, to_json/0 ]).
+1
View File
@@ -1,4 +1,5 @@
-module(gmhc_connector).
-vsn("0.4.8").
-behaviour(gen_server).
+1
View File
@@ -1,4 +1,5 @@
-module(gmhc_connectors_sup).
-vsn("0.4.8").
-behavior(supervisor).
-export([ start_link/0
+1
View File
@@ -1,4 +1,5 @@
-module(gmhc_counters).
-vsn("0.4.8").
-export([ initialize/0 ]).
+1
View File
@@ -1,4 +1,5 @@
-module(gmhc_eureka).
-vsn("0.4.8").
-export([get_pool_address/0]).
+2
View File
@@ -1,4 +1,5 @@
-module(gmhc_events).
-vsn("0.4.8").
-export([subscribe/1,
ensure_subscribed/1,
@@ -67,6 +68,7 @@ debug() ->
subscribe(result),
subscribe(error),
subscribe(disconnected),
gmhive_worker:subscribe_returns(),
loop()
end).
+4
View File
@@ -1,4 +1,5 @@
-module(gmhc_handler).
-vsn("0.4.8").
-behavior(gen_server).
-export([ start_link/0
@@ -129,12 +130,15 @@ call_connector(Req0) ->
gmhc_connector:send(ViaId, #{call => Req#{ id => Id }}),
receive
{from_pool, #{reply := #{ id := Id, result := Result }}} ->
erlang:demonitor(MRef),
Result;
{from_pool, #{error := #{ id := Id } = Error}} ->
erlang:demonitor(MRef),
{error, maps:remove(id, Error)};
{'DOWN', MRef, _, _, _} ->
{error, no_connection}
after 5000 ->
erlang:demonitor(MRef),
{error, {timeout, process_info(self(), messages)}}
end
end.
+31 -12
View File
@@ -1,4 +1,5 @@
-module(gmhc_server).
-vsn("0.4.8").
-behaviour(gen_server).
@@ -44,7 +45,7 @@
-define(CONNECTED(S), map_size(S#st.connected) > 0).
-define(MAX_ERRORS, 5).
-define(MAX_ERRORS, 50).
connected(Id, Type) ->
gen_server:call(?MODULE, {connected, Id, Type}).
@@ -107,17 +108,20 @@ handle_cast({from_pool, #{via := Connector,
%% We could check whether we have already received the candidate ...
%% For now, stop all workers, restart with new candidate
try
% Most of the time we don't want to stop the worker. If we do, though, then
% we need to do it more carefully than this, or memory usage will triple.
% Workers1 = stop_workers(Workers),
{Workers2, Cand1} = assign_nonces(Workers, Cand),
#st{candidate = Cand2} = S1 = maybe_request_nonces(S#st{candidate = Cand1}),
NewWorkers = [spawn_worker(W, Cand2) || W <- Workers2],
{noreply, S1#st{workers = NewWorkers}}
%% Most of the time we don't want to stop the worker. If we do, though, then
%% we need to do it more carefully than this, or memory usage will triple.
%% Workers1 = stop_workers(Workers),
%%
%% Nonces may be [], in which case we need to request new nonces first.
#st{candidate = Cand1} = S1 = maybe_request_nonces(S#st{candidate = Cand}),
{Workers2, Cand2} = assign_nonces(Workers, Cand1),
#st{candidate = Cand3} = S2 = maybe_request_nonces(S1#st{candidate = Cand2}),
NewWorkers = [spawn_worker(W, Cand3) || W <- Workers2],
{noreply, S2#st{workers = NewWorkers}}
catch
Cat:Err:St ->
?LOG_ERROR("CAUGHT ~p:~p / ~p", [Cat, Err, St]),
{noreply, S}
{noreply, S}
end;
handle_cast({disconnected, Id}, #st{connected = Conn} = S) ->
?LOG_DEBUG("disconnected: ~p", [Id]),
@@ -151,11 +155,23 @@ 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}};
false ->
%% ?LOG_DEBUG("EXIT apparently not from worker?? (~p)", [Pid]),
{noreply, S}
end;
handle_info({timeout, _, check_workers}, #st{workers = Workers} = S) ->
case [W || #worker{cand = undefined} = W <- Workers] of
[] ->
{noreply, S};
Idle ->
S1 = maybe_request_nonces(S),
S2 = lists:foldl(fun(W, Sx) ->
maybe_restart_worker(W, Sx)
end, S1, Idle),
{noreply, S2}
end;
handle_info(Msg, St) ->
?LOG_DEBUG("Unknown msg: ~p", [Msg]),
{noreply, St}.
@@ -223,14 +239,14 @@ handle_worker_result({worker_result, Result}, W, S) ->
case Result of
{solutions, Solutions} ->
{Cont, S1} = report_solutions_(Solutions, W, S),
maybe_continue(Cont, W, S1);
maybe_continue(Cont, reset_errors(W), S1);
{solution, Nonce, Solution} ->
%% report_solution(Nonce, Solution, W, S),
{Cont, S1} = report_solutions_([{Nonce, Solution}], W, S),
maybe_continue(Cont, W, S1);
maybe_continue(Cont, reset_errors(W), S1);
{no_solution, Nonce} ->
report_no_solution(Nonce, W, S),
maybe_restart_worker(W, S);
maybe_restart_worker(reset_errors(W), S);
{error, S} ->
?LOG_DEBUG("Worker ~p reported error as normal", [W#worker.index]),
gmhc_events:publish(error, ?ERR_EVT(#{error => worker_error,
@@ -258,6 +274,9 @@ report_solutions_(Solutions, W, S) ->
{error, S}
end.
reset_errors(#worker{} = W) ->
W#worker{errors = 0}.
reset_worker(#worker{index = I} = W, Ws) ->
W1 = reset_worker_(W),
lists:keyreplace(I, #worker.index, Ws, W1).
+1
View File
@@ -1,5 +1,6 @@
%% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*-
-module(gmhc_sup).
-vsn("0.4.8").
-behaviour(supervisor).
+1
View File
@@ -8,6 +8,7 @@
%%%-------------------------------------------------------------------
-module(gmhc_workers).
-vsn("0.4.8").
-export([
get_worker_configs/0
+1 -1
View File
@@ -1,7 +1,7 @@
%% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*-
{application, gmhive_client,
[{description, "Gajumaru Hive Client"},
{vsn, "0.1.0"},
{vsn, "zomp"},
{registered, []},
{applications,
[
+14
View File
@@ -0,0 +1,14 @@
%% -*- erlang-mode; erlang-indent-level: 4; indent-tabs-mode: nil -*-
[{application, Name, Opts}] = CONFIG.
case lists:keyfind(vsn, 1, Opts) of
{vsn, "zomp"} ->
ZompMetaF = filename:join(filename:dirname(filename:dirname(SCRIPT)), "zomp.meta"),
{ok, ZMeta} = file:consult(ZompMetaF),
{_, {_, _, {Vmaj,Vmin,Vpatch}}} = lists:keyfind(package_id, 1, ZMeta),
VsnStr = unicode:characters_to_list(io_lib:fwrite("~w.~w.~w", [Vmaj, Vmin, Vpatch])),
Opts1 = lists:keyreplace(vsn, 1, Opts, {vsn, VsnStr}),
[{application, Name, Opts1}];
_ ->
CONFIG
end.
+1
View File
@@ -1,4 +1,5 @@
-module(gmhive_client).
-vsn("0.4.8").
-export([ connect/1
, disconnect/1
+3 -3
View File
@@ -4,9 +4,9 @@
{prefix,"gmhc"}.
{desc,"Gajumaru Hive Client"}.
{author,"Ulf Wiger, QPQ AG"}.
{package_id,{"uwiger","gmhive_client",{0,4,4}}}.
{deps,[{"uwiger","gmcuckoo",{1,2,3}},
{"uwiger","gmhive_worker",{0,3,0}},
{package_id,{"uwiger","gmhive_client",{0,5,1}}}.
{deps,[{"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}},