From 2a33d06bd68dc66d24502122a003c6aec58a5aaa Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Thu, 25 Sep 2025 23:25:00 +0200 Subject: [PATCH] Report no_solution for all relevant nonces with repeats --- ebin/gmhive_client.app | 2 +- src/gmhc_app.erl | 2 +- src/gmhc_config.erl | 2 +- src/gmhc_config_schema.erl | 2 +- src/gmhc_connector.erl | 2 +- src/gmhc_connectors_sup.erl | 2 +- src/gmhc_counters.erl | 2 +- src/gmhc_eureka.erl | 2 +- src/gmhc_events.erl | 2 +- src/gmhc_handler.erl | 52 ++++++++++++++++++++++++++----------- src/gmhc_server.erl | 30 +++++++++++++-------- src/gmhc_sup.erl | 2 +- src/gmhc_workers.erl | 2 +- src/gmhive_client.erl | 2 +- zomp.meta | 2 +- 15 files changed, 69 insertions(+), 39 deletions(-) diff --git a/ebin/gmhive_client.app b/ebin/gmhive_client.app index ca863fe..162e967 100644 --- a/ebin/gmhive_client.app +++ b/ebin/gmhive_client.app @@ -1,6 +1,6 @@ {application,gmhive_client, [{description,"Gajumaru Hive Client"}, - {vsn,"0.6.0"}, + {vsn,"0.6.1"}, {registered,[]}, {applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise, gmconfig,gmhive_protocol,gmhive_worker]}, diff --git a/src/gmhc_app.erl b/src/gmhc_app.erl index 7aaae11..5dc520b 100644 --- a/src/gmhc_app.erl +++ b/src/gmhc_app.erl @@ -1,6 +1,6 @@ %% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*- -module(gmhc_app). --vsn("0.6.0"). +-vsn("0.6.1"). -behaviour(application). diff --git a/src/gmhc_config.erl b/src/gmhc_config.erl index b9ff45b..abe45ae 100644 --- a/src/gmhc_config.erl +++ b/src/gmhc_config.erl @@ -1,5 +1,5 @@ -module(gmhc_config). --vsn("0.6.0"). +-vsn("0.6.1"). -export([ load_config/0 , get_config/1 diff --git a/src/gmhc_config_schema.erl b/src/gmhc_config_schema.erl index 5f953ac..f4d8883 100644 --- a/src/gmhc_config_schema.erl +++ b/src/gmhc_config_schema.erl @@ -1,5 +1,5 @@ -module(gmhc_config_schema). --vsn("0.6.0"). +-vsn("0.6.1"). -export([ schema/0 , to_json/0 ]). diff --git a/src/gmhc_connector.erl b/src/gmhc_connector.erl index 8350f67..c59f2cc 100644 --- a/src/gmhc_connector.erl +++ b/src/gmhc_connector.erl @@ -1,5 +1,5 @@ -module(gmhc_connector). --vsn("0.6.0"). +-vsn("0.6.1"). -behaviour(gen_server). diff --git a/src/gmhc_connectors_sup.erl b/src/gmhc_connectors_sup.erl index f1dd906..b94b8a9 100644 --- a/src/gmhc_connectors_sup.erl +++ b/src/gmhc_connectors_sup.erl @@ -1,5 +1,5 @@ -module(gmhc_connectors_sup). --vsn("0.6.0"). +-vsn("0.6.1"). -behavior(supervisor). -export([ start_link/0 diff --git a/src/gmhc_counters.erl b/src/gmhc_counters.erl index 03741ff..d7210ba 100644 --- a/src/gmhc_counters.erl +++ b/src/gmhc_counters.erl @@ -1,5 +1,5 @@ -module(gmhc_counters). --vsn("0.6.0"). +-vsn("0.6.1"). -export([ initialize/0 ]). diff --git a/src/gmhc_eureka.erl b/src/gmhc_eureka.erl index 828ce4b..14b9e05 100644 --- a/src/gmhc_eureka.erl +++ b/src/gmhc_eureka.erl @@ -1,5 +1,5 @@ -module(gmhc_eureka). --vsn("0.6.0"). +-vsn("0.6.1"). -export([get_pool_address/0]). diff --git a/src/gmhc_events.erl b/src/gmhc_events.erl index 03da211..ffbd6da 100644 --- a/src/gmhc_events.erl +++ b/src/gmhc_events.erl @@ -1,5 +1,5 @@ -module(gmhc_events). --vsn("0.6.0"). +-vsn("0.6.1"). -export([subscribe/1, ensure_subscribed/1, diff --git a/src/gmhc_handler.erl b/src/gmhc_handler.erl index 0f8cc85..de44e68 100644 --- a/src/gmhc_handler.erl +++ b/src/gmhc_handler.erl @@ -1,5 +1,5 @@ -module(gmhc_handler). --vsn("0.6.0"). +-vsn("0.6.1"). -behavior(gen_server). -export([ start_link/0 @@ -12,6 +12,7 @@ ]). -export([ call/1 + , async_call/1 , notify/1 , pool_connected/2 , from_pool/1 ]). @@ -38,6 +39,13 @@ call(Req) -> {error, Reason} end. +async_call(Req) -> + try gen_server:call(?MODULE, {async_call, Req}, ?CALL_TIMEOUT) + catch + exit:Reason -> + {error, Reason} + end. + notify(Msg) -> gen_server:cast(?MODULE, {notify, Msg}). @@ -56,6 +64,8 @@ init([]) -> handle_call({call, Req}, _From, #st{} = S) -> {reply, call_connector(Req), S}; +handle_call({async_call, Req}, _From, #st{} = S) -> + {reply, call_connector(Req, false), S}; handle_call(_Req, _From, S) -> {reply, {error, unknown_method}, S}. @@ -119,27 +129,39 @@ maybe_publish(_) -> maybe_via(#{via := Via}, Info) -> Info#{via => Via}. -call_connector(Req0) -> +call_connector(Req) -> + call_connector(Req, true). + +call_connector(Req0, Wait) -> {ViaId, Req} = maps:take(via, Req0), case gmhc_connector:whereis_id(ViaId) of undefined -> {error, no_connection}; Pid when is_pid(Pid) -> Id = erlang:unique_integer(), - MRef = erlang:monitor(process, Pid), + MRef = case Wait of + true -> erlang:monitor(process, Pid); + false -> none + end, 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)}} + case Wait of + true -> + 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; + false -> + ok end end. diff --git a/src/gmhc_server.erl b/src/gmhc_server.erl index dd16f1d..a3856ed 100644 --- a/src/gmhc_server.erl +++ b/src/gmhc_server.erl @@ -1,5 +1,5 @@ -module(gmhc_server). --vsn("0.6.0"). +-vsn("0.6.1"). -behaviour(gen_server). @@ -184,6 +184,9 @@ code_change(_FromVsn, S, _Extra) -> report_solutions(Solutions, W, #st{} = S) when ?CONNECTED(S) -> #{via := Via, seq := Seq} = W#worker.cand, + Nonces = all_nonces(W), + [report_no_solution_(Via, Seq, N) + || N <- Nonces, not lists:keymember(N, 1, Solutions)], gmhc_handler:call( #{via => Via, solutions => #{ seq => Seq @@ -191,18 +194,23 @@ report_solutions(Solutions, W, #st{} = S) when ?CONNECTED(S) -> , evidence => Evd } || {Nonce, Evd} <- Solutions] }}). -%% report_solution(Nonce, Solution, W, #st{connected = true}) -> -%% #{seq := Seq} = W#worker.cand, -%% gmhc_handler:call(#{solution => #{ seq => Seq -%% , nonce => Nonce -%% , evidence => Solution }}). - -report_no_solution(Nonce, W, #st{} = S) when ?CONNECTED(S) -> +report_no_solution(_Nonce, W, #st{} = S) when ?CONNECTED(S) -> #{via := Via, seq := Seq} = W#worker.cand, + Nonces = all_nonces(W), %% ?LOG_DEBUG("report no_solution Seq = ~p, Nonce = ~p", [Seq, Nonce]), - gmhc_handler:call(#{via => Via, - no_solution => #{ seq => Seq - , nonce => Nonce}}). + [report_no_solution_(Via, Seq, Nonce1) || Nonce1 <- Nonces], + ok. + +report_no_solution_(Via, Seq, Nonce) -> + gmhc_handler:async_call(#{via => Via, + no_solution => #{ seq => Seq + , nonce => Nonce}}). + +all_nonces(#worker{nonce = Nonce, config = Config}) -> + case gmhw_pow_cuckoo:repeats(Config) of + 1 -> [Nonce]; + Rs -> lists:seq(Nonce, Nonce + Rs - 1) + end. maybe_request_nonces(#st{ candidate = #{via := Via, seq := Seq, nonces := Nonces} , nonces = N} = S) when ?CONNECTED(S) -> diff --git a/src/gmhc_sup.erl b/src/gmhc_sup.erl index 9027677..7504a16 100644 --- a/src/gmhc_sup.erl +++ b/src/gmhc_sup.erl @@ -1,6 +1,6 @@ %% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*- -module(gmhc_sup). --vsn("0.6.0"). +-vsn("0.6.1"). -behaviour(supervisor). diff --git a/src/gmhc_workers.erl b/src/gmhc_workers.erl index bf25c4d..3b026ee 100644 --- a/src/gmhc_workers.erl +++ b/src/gmhc_workers.erl @@ -8,7 +8,7 @@ %%%------------------------------------------------------------------- -module(gmhc_workers). --vsn("0.6.0"). +-vsn("0.6.1"). -export([ get_worker_configs/0 diff --git a/src/gmhive_client.erl b/src/gmhive_client.erl index 2b10d70..7779d26 100644 --- a/src/gmhive_client.erl +++ b/src/gmhive_client.erl @@ -1,5 +1,5 @@ -module(gmhive_client). --vsn("0.6.0"). +-vsn("0.6.1"). -export([ connect/1 , disconnect/1 diff --git a/zomp.meta b/zomp.meta index 805ecab..579f80f 100644 --- a/zomp.meta +++ b/zomp.meta @@ -4,7 +4,7 @@ {prefix,"gmhc"}. {author,"Ulf Wiger, QPQ AG"}. {desc,"Gajumaru Hive Client"}. -{package_id,{"uwiger","gmhive_client",{0,6,0}}}. +{package_id,{"uwiger","gmhive_client",{0,6,1}}}. {deps,[{"uwiger","gmhive_worker",{0,5,1}}, {"uwiger","gmcuckoo",{1,2,4}}, {"otpr","eblake2",{1,0,1}},