5 Commits

Author SHA1 Message Date
Ulf Wiger 07b658d509 Configurable progress reporting 2025-09-23 16:44:46 +02:00
uwiger 8a68244c90 Merge pull request 'Update gmhive_worker and gmcuckoo deps, miner returns in debug' (#12) from uw-miner-returns into master
Reviewed-on: #12
2025-09-23 21:46:32 +09:00
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
19 changed files with 150 additions and 36 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{application,gmhive_client, {application,gmhive_client,
[{description,"Gajumaru Hive Client"}, [{description,"Gajumaru Hive Client"},
{vsn,"0.4.8"}, {vsn,"0.6.0"},
{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]},
+1 -1
View File
@@ -10,7 +10,7 @@
{gmhive_protocol, {gmhive_protocol,
{git, "https://git.qpq.swiss/QPQ-AG/gmhive_protocol.git", {git, "https://git.qpq.swiss/QPQ-AG/gmhive_protocol.git",
{ref, "818ce33"}}}, {ref, "818ce33"}}},
{gmhive_worker, {git, "https://git.qpq.swiss/QPQ-AG/gmhive_worker", {ref, "fac460714f"}}}, {gmhive_worker, {git, "https://git.qpq.swiss/QPQ-AG/gmhive_worker", {ref, "cabd104114"}}},
{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"},
+2 -2
View File
@@ -21,7 +21,7 @@
0}, 0},
{<<"gmcuckoo">>, {<<"gmcuckoo">>,
{git,"https://git.qpq.swiss/QPQ-AG/gmcuckoo.git", {git,"https://git.qpq.swiss/QPQ-AG/gmcuckoo.git",
{ref,"106e1cd2e4ff81286f6bc7d7c85f83bc20e14b82"}}, {ref,"256e14e7c88043132245be902ff9756070d285b4"}},
1}, 1},
{<<"gmhive_protocol">>, {<<"gmhive_protocol">>,
{git,"https://git.qpq.swiss/QPQ-AG/gmhive_protocol.git", {git,"https://git.qpq.swiss/QPQ-AG/gmhive_protocol.git",
@@ -29,7 +29,7 @@
0}, 0},
{<<"gmhive_worker">>, {<<"gmhive_worker">>,
{git,"https://git.qpq.swiss/QPQ-AG/gmhive_worker", {git,"https://git.qpq.swiss/QPQ-AG/gmhive_worker",
{ref,"fac460714fc228eb0b723a3f292a44aec77f094a"}}, {ref,"cabd104114691edb925aacd7e04d431d47bac420"}},
0}, 0},
{<<"gmserialization">>, {<<"gmserialization">>,
{git,"https://git.qpq.swiss/QPQ-AG/gmserialization.git", {git,"https://git.qpq.swiss/QPQ-AG/gmserialization.git",
+10 -1
View File
@@ -1,6 +1,6 @@
%% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*- %% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*-
-module(gmhc_app). -module(gmhc_app).
-vsn("0.4.8"). -vsn("0.6.0").
-behaviour(application). -behaviour(application).
@@ -49,4 +49,13 @@ set_things_up() ->
gmhc_config:load_config(), gmhc_config:load_config(),
logger:set_module_level([gmhw_pow_cuckoo], notice), logger:set_module_level([gmhw_pow_cuckoo], notice),
?LOG_DEBUG("Config: ~p", [gmconfig:user_config()]), ?LOG_DEBUG("Config: ~p", [gmconfig:user_config()]),
case gmhc_config:get_config([<<"report">>]) of
<<"debug">> ->
?LOG_NOTICE("Starting debug reporter", []),
gmhc_events:debug();
<<"progress">> ->
?LOG_NOTICE("Starting progress reporter", []),
gmhc_events:progress();
_ -> ok
end,
ok. ok.
+1 -1
View File
@@ -1,5 +1,5 @@
-module(gmhc_config). -module(gmhc_config).
-vsn("0.4.8"). -vsn("0.6.0").
-export([ load_config/0 -export([ load_config/0
, get_config/1 , get_config/1
+4 -1
View File
@@ -1,5 +1,5 @@
-module(gmhc_config_schema). -module(gmhc_config_schema).
-vsn("0.4.8"). -vsn("0.6.0").
-export([ schema/0 -export([ schema/0
, to_json/0 ]). , to_json/0 ]).
@@ -39,6 +39,9 @@ schema() ->
, pool => pool() , pool => pool()
, pool_admin => pool_admin() , pool_admin => pool_admin()
, workers => workers() , workers => workers()
, report => str(#{ enum => [<<"debug">>, <<"progress">>, <<"silent">>]
, default => <<"silent">>
, description => <<"Progress reporting">> })
}). }).
pool() -> pool() ->
+1 -1
View File
@@ -1,5 +1,5 @@
-module(gmhc_connector). -module(gmhc_connector).
-vsn("0.4.8"). -vsn("0.6.0").
-behaviour(gen_server). -behaviour(gen_server).
+1 -1
View File
@@ -1,5 +1,5 @@
-module(gmhc_connectors_sup). -module(gmhc_connectors_sup).
-vsn("0.4.8"). -vsn("0.6.0").
-behavior(supervisor). -behavior(supervisor).
-export([ start_link/0 -export([ start_link/0
+1 -1
View File
@@ -1,5 +1,5 @@
-module(gmhc_counters). -module(gmhc_counters).
-vsn("0.4.8"). -vsn("0.6.0").
-export([ initialize/0 ]). -export([ initialize/0 ]).
+1 -1
View File
@@ -1,5 +1,5 @@
-module(gmhc_eureka). -module(gmhc_eureka).
-vsn("0.4.8"). -vsn("0.6.0").
-export([get_pool_address/0]). -export([get_pool_address/0]).
+104 -16
View File
@@ -1,5 +1,5 @@
-module(gmhc_events). -module(gmhc_events).
-vsn("0.4.8"). -vsn("0.6.0").
-export([subscribe/1, -export([subscribe/1,
ensure_subscribed/1, ensure_subscribed/1,
@@ -7,7 +7,17 @@
ensure_unsubscribed/1, ensure_unsubscribed/1,
publish/2]). publish/2]).
-export([debug/0]). -export([debug/0,
progress/0,
stop/0]).
-export([rpt_debug/2,
rpt_progress/2]).
%% internal
-export([init_reporter/2]).
-include_lib("kernel/include/logger.hrl").
-export_type([event/0]). -export_type([event/0]).
@@ -60,22 +70,100 @@ ensure_unsubscribed(Event) ->
debug() -> debug() ->
ok = application:ensure_started(gproc), ok = application:ensure_started(gproc),
spawn(fun() -> spawn_reporter(fun() ->
subscribe(pool_notification), sub(),
subscribe({pool_notification, new_generation}), gmhive_worker:subscribe_returns(),
subscribe(connected), loop(fun rpt_debug/2, false)
subscribe(puzzle), end).
subscribe(result),
subscribe(error),
subscribe(disconnected),
loop()
end).
loop() -> progress() ->
ok = application:ensure_started(gproc),
spawn_reporter(fun() ->
sub(),
loop(fun rpt_progress/2, true)
end).
spawn_reporter(F) ->
Parent = self(),
proc_lib:start_link(?MODULE, init_reporter, [F, Parent]).
init_reporter(F, Parent) ->
try_register_reporter(),
proc_lib:init_ack(Parent, self()),
F().
stop() ->
case whereis(gmhc_reporter) of
undefined ->
not_running;
Pid ->
exit(Pid, kill)
end.
sub() ->
subscribe(pool_notification),
subscribe({pool_notification, new_generation}),
subscribe(connected),
subscribe(puzzle),
subscribe(result),
subscribe(error),
subscribe(disconnected).
loop(F, Ts) ->
receive receive
stop -> ok; stop -> ok;
{gproc_ps_event, E, Data} -> {gproc_ps_event, E, Data} ->
io:fwrite("EVENT ~p: ~p~n", [E, Data]), maybe_print(F(E, Data), Ts),
loop() loop(F, Ts)
end. end.
try_register_reporter() ->
try register(gmhc_reporter, self())
catch
error:_ ->
?LOG_ERROR("Reporter already running. Try gmhc_events:stop().", []),
error(already_running)
end.
maybe_print([], _) ->
ok;
maybe_print(String, Ts) when is_boolean(Ts) ->
TSstr = [[ts(), " "] || Ts],
io:put_chars([TSstr, String, "\n"]).
ts() ->
calendar:system_time_to_rfc3339(erlang:system_time(millisecond),
[{unit, millisecond}, {offset, "Z"}]).
rpt_debug(E, Data) ->
io_lib:fwrite("EVENT ~p: ~p", [E, Data]).
rpt_progress(puzzle, #{info := {_Data, _Target, Nonce, _Config}}) ->
w("Trying nonce: ~p", [Nonce]);
rpt_progress(result, #{info := Info}) ->
case Info of
{error, no_solution} ->
[];
{ok, Cycles} ->
w("Found! Reporting ~w cycles to leader.", [length(Cycles)]);
Other ->
w("Unexpected 'result': ~tp", [Other])
end;
rpt_progress(pool_notification, #{info := #{msg := Msg}}) ->
case Msg of
#{solution_accepted := #{seq := Seq}} ->
w("The hive has produced a solution! Sequence: ~w", [Seq]);
#{new_generation := _} -> [];
#{candidate := _} -> [];
Other ->
w("Unexpected 'pool_notification': ~tp", [Other])
end;
rpt_progress(connected, _) ->
w("Connected!", []);
rpt_progress(disconnected, _) ->
w("Disconnected!", []);
rpt_progress(_, _) ->
[].
w(Fmt, Args) ->
io_lib:fwrite(Fmt, Args).
+1 -1
View File
@@ -1,5 +1,5 @@
-module(gmhc_handler). -module(gmhc_handler).
-vsn("0.4.8"). -vsn("0.6.0").
-behavior(gen_server). -behavior(gen_server).
-export([ start_link/0 -export([ start_link/0
+1 -1
View File
@@ -1,5 +1,5 @@
-module(gmhc_server). -module(gmhc_server).
-vsn("0.4.8"). -vsn("0.6.0").
-behaviour(gen_server). -behaviour(gen_server).
+1 -1
View File
@@ -1,6 +1,6 @@
%% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*- %% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*-
-module(gmhc_sup). -module(gmhc_sup).
-vsn("0.4.8"). -vsn("0.6.0").
-behaviour(supervisor). -behaviour(supervisor).
+1 -1
View File
@@ -8,7 +8,7 @@
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module(gmhc_workers). -module(gmhc_workers).
-vsn("0.4.8"). -vsn("0.6.0").
-export([ -export([
get_worker_configs/0 get_worker_configs/0
+1 -1
View File
@@ -1,7 +1,7 @@
%% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*- %% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*-
{application, gmhive_client, {application, gmhive_client,
[{description, "Gajumaru Hive Client"}, [{description, "Gajumaru Hive Client"},
{vsn, "0.1.0"}, {vsn, "zomp"},
{registered, []}, {registered, []},
{applications, {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 -1
View File
@@ -1,5 +1,5 @@
-module(gmhive_client). -module(gmhive_client).
-vsn("0.4.8"). -vsn("0.6.0").
-export([ connect/1 -export([ connect/1
, disconnect/1 , disconnect/1
+3 -3
View File
@@ -4,9 +4,9 @@
{prefix,"gmhc"}. {prefix,"gmhc"}.
{author,"Ulf Wiger, QPQ AG"}. {author,"Ulf Wiger, QPQ AG"}.
{desc,"Gajumaru Hive Client"}. {desc,"Gajumaru Hive Client"}.
{package_id,{"uwiger","gmhive_client",{0,4,8}}}. {package_id,{"uwiger","gmhive_client",{0,6,0}}}.
{deps,[{"uwiger","gmhive_worker",{0,4,0}}, {deps,[{"uwiger","gmhive_worker",{0,5,1}},
{"uwiger","gmcuckoo",{1,2,3}}, {"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}},