Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 968f9d92f2 | |||
| 34f3c93aaa | |||
| c37ee1c3af | |||
| 408bd9fc18 | |||
| 2a33d06bd6 | |||
| 8cb2c76614 |
@@ -0,0 +1,10 @@
|
||||
|
||||
BUILD="_build/default/lib/gmhive_client"
|
||||
SCHEMA_OUT=$(BUILD)/priv/gmhc_schema.json
|
||||
|
||||
schema:
|
||||
ERL_LIBS=_build/default/lib \
|
||||
erl -run gmhc_config_schema export $(SCHEMA_OUT) -run init stop
|
||||
scripts/update_readme_json.sh README.md $(SCHEMA_OUT)
|
||||
|
||||
|
||||
@@ -155,6 +155,16 @@ server. (For `"testnet"` this will be `"test.gajumining.com"`.)
|
||||
"pattern": "^ak_[1-9A-HJ-NP-Za-km-z]*$",
|
||||
"type": "string"
|
||||
},
|
||||
"report": {
|
||||
"default": "silent",
|
||||
"description": "Progress reporting",
|
||||
"enum": [
|
||||
"debug",
|
||||
"progress",
|
||||
"silent"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"default": "worker",
|
||||
"description": "monitor mode can be used to see if a pool is alive",
|
||||
@@ -174,7 +184,7 @@ server. (For `"testnet"` this will be `"test.gajumining.com"`.)
|
||||
"properties": {
|
||||
"executable": {
|
||||
"default": "mean29-generic",
|
||||
"description": "Executable binary of the worker. Can be a fully qualified path, but the software may apply default logic to locate a plain basename.",
|
||||
"description": "Executable binary of the worker. Can be a fully qualified path, \nbut the software may apply default logic to locate a plain basename.",
|
||||
"type": "string"
|
||||
},
|
||||
"extra_args": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{application,gmhive_client,
|
||||
[{description,"Gajumaru Hive Client"},
|
||||
{vsn,"0.6.0"},
|
||||
{vsn,"0.6.3"},
|
||||
{registered,[]},
|
||||
{applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise,
|
||||
gmconfig,gmhive_protocol,gmhive_worker]},
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
{erl_opts, [debug_info]}.
|
||||
{plugins, [rebar3_hex]}.
|
||||
|
||||
{post_hooks, [{compile, "make schema"}]}.
|
||||
|
||||
{deps, [
|
||||
{enoise, {git, "https://git.qpq.swiss/QPQ-AG/enoise.git", {ref, "029292817e"}}},
|
||||
{gmhive_protocol,
|
||||
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
README="$1"
|
||||
SCHEMA="$2"
|
||||
|
||||
if [[ ! -f "$README" || ! -f "$SCHEMA" ]]; then
|
||||
echo "Usage: $0 README.md schema.json"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tmpfile=$(mktemp)
|
||||
|
||||
awk -v schema_file="$SCHEMA" '
|
||||
BEGIN {
|
||||
in_json_block = 0
|
||||
in_schema_section = 0
|
||||
}
|
||||
|
||||
/^##[[:space:]]+JSON[[:space:]]+Schema/ {
|
||||
in_schema_section = 1
|
||||
print
|
||||
next
|
||||
}
|
||||
|
||||
/^##[[:space:]]+/ && in_schema_section {
|
||||
# Another section starts, end the schema section
|
||||
in_schema_section = 0
|
||||
}
|
||||
|
||||
in_schema_section && /^```json/ {
|
||||
print "```json"
|
||||
while ((getline line < schema_file) > 0) print line
|
||||
close(schema_file)
|
||||
in_json_block = 1
|
||||
next
|
||||
}
|
||||
|
||||
in_json_block && /^```$/ {
|
||||
print "```"
|
||||
in_json_block = 0
|
||||
next
|
||||
}
|
||||
|
||||
!(in_schema_section && in_json_block) {
|
||||
print
|
||||
}
|
||||
' "$README" > "$tmpfile"
|
||||
|
||||
mv "$tmpfile" "$README"
|
||||
echo "✅ Updated JSON schema block in $README"
|
||||
+15
-1
@@ -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).
|
||||
|
||||
@@ -45,6 +45,7 @@ stop(_State) ->
|
||||
ok.
|
||||
|
||||
set_things_up() ->
|
||||
maybe_add_logger_handler(),
|
||||
gmhc_counters:initialize(),
|
||||
gmhc_config:load_config(),
|
||||
logger:set_module_level([gmhw_pow_cuckoo], notice),
|
||||
@@ -59,3 +60,16 @@ set_things_up() ->
|
||||
_ -> ok
|
||||
end,
|
||||
ok.
|
||||
|
||||
maybe_add_logger_handler() ->
|
||||
case is_headless() orelse application:get_env(gmhive_client, tty_logger, false) of
|
||||
true ->
|
||||
Level = application:get_env(gmhive_client, tty_logger_level, error),
|
||||
io:fwrite("Adding logger handler: ~p~n", [Level]),
|
||||
logger:add_handler(gmhc_tty, logger_std_h, #{level => Level});
|
||||
false ->
|
||||
ok
|
||||
end.
|
||||
|
||||
is_headless() ->
|
||||
undefined == application:get_key(gajumine, vsn).
|
||||
|
||||
+13
-1
@@ -1,5 +1,5 @@
|
||||
-module(gmhc_config).
|
||||
-vsn("0.6.0").
|
||||
-vsn("0.6.1").
|
||||
|
||||
-export([ load_config/0
|
||||
, get_config/1
|
||||
@@ -14,8 +14,20 @@ load_config() ->
|
||||
gmconfig:apply_os_env(),
|
||||
gmconfig:process_plain_args(),
|
||||
check_application_env(),
|
||||
check_final_config(),
|
||||
ok.
|
||||
|
||||
check_final_config() ->
|
||||
ExtraPubkeys = get_config([<<"extra_pubkeys">>]),
|
||||
AllKeys = [get_config([<<"pubkey">>]) | ExtraPubkeys],
|
||||
case AllKeys -- lists:usort(AllKeys) of
|
||||
[] ->
|
||||
ok;
|
||||
Duplicates ->
|
||||
?LOG_ERROR("Duplicate account ids found: ~p", [Duplicates]),
|
||||
error({duplicate_account_ids, Duplicates})
|
||||
end.
|
||||
|
||||
instrument_gmconfig() ->
|
||||
gmconfig:set_gmconfig_env(gmconfig_env()).
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
-module(gmhc_config_schema).
|
||||
-vsn("0.6.0").
|
||||
-vsn("0.6.1").
|
||||
|
||||
-export([ schema/0
|
||||
, to_json/0 ]).
|
||||
, to_json/0
|
||||
, export/1 ]).
|
||||
|
||||
-import(gmconfig_schema_helpers,
|
||||
[ str/1
|
||||
@@ -22,6 +23,17 @@
|
||||
to_json() ->
|
||||
json:encode(schema()).
|
||||
|
||||
export(ToFile) ->
|
||||
case file:open(ToFile, [write]) of
|
||||
{ok, Fd} ->
|
||||
try ok = io:put_chars(Fd, json:format(schema(), #{indent => 4}))
|
||||
after
|
||||
file:close(Fd)
|
||||
end;
|
||||
{error, _} = Error ->
|
||||
Error
|
||||
end.
|
||||
|
||||
schema() ->
|
||||
obj(schema_init(),
|
||||
#{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-module(gmhc_connector).
|
||||
-vsn("0.6.0").
|
||||
-vsn("0.6.1").
|
||||
|
||||
-behaviour(gen_server).
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-module(gmhc_connectors_sup).
|
||||
-vsn("0.6.0").
|
||||
-vsn("0.6.1").
|
||||
-behavior(supervisor).
|
||||
|
||||
-export([ start_link/0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-module(gmhc_counters).
|
||||
-vsn("0.6.0").
|
||||
-vsn("0.6.1").
|
||||
|
||||
-export([ initialize/0 ]).
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
-module(gmhc_eureka).
|
||||
-vsn("0.6.0").
|
||||
-vsn("0.6.1").
|
||||
|
||||
-export([get_pool_address/0]).
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
-module(gmhc_events).
|
||||
-vsn("0.6.0").
|
||||
-vsn("0.6.1").
|
||||
|
||||
-export([subscribe/1,
|
||||
ensure_subscribed/1,
|
||||
|
||||
+37
-15
@@ -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.
|
||||
|
||||
|
||||
+19
-11
@@ -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) ->
|
||||
|
||||
+1
-1
@@ -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).
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(gmhc_workers).
|
||||
-vsn("0.6.0").
|
||||
-vsn("0.6.1").
|
||||
|
||||
-export([
|
||||
get_worker_configs/0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-module(gmhive_client).
|
||||
-vsn("0.6.0").
|
||||
-vsn("0.6.1").
|
||||
|
||||
-export([ connect/1
|
||||
, disconnect/1
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
{type,app}.
|
||||
{modules,[]}.
|
||||
{prefix,"gmhc"}.
|
||||
{author,"Ulf Wiger, QPQ AG"}.
|
||||
{desc,"Gajumaru Hive Client"}.
|
||||
{package_id,{"uwiger","gmhive_client",{0,6,0}}}.
|
||||
{author,"Ulf Wiger, QPQ AG"}.
|
||||
{package_id,{"uwiger","gmhive_client",{0,6,3}}}.
|
||||
{deps,[{"uwiger","gmhive_worker",{0,5,1}},
|
||||
{"uwiger","gmcuckoo",{1,2,4}},
|
||||
{"otpr","eblake2",{1,0,1}},
|
||||
|
||||
@@ -38,5 +38,12 @@ rm "$IGNORE_TEMP"
|
||||
cp "$PWD/zomp.meta" "$DST/"
|
||||
cp "$PWD/Emakefile" "$DST/"
|
||||
|
||||
# copy generated schema
|
||||
SCHEMA="$SRC/priv/gmhc_schema.json"
|
||||
if [ -e "$SCHEMA" ]; then
|
||||
mkdir -p "$DST/priv"
|
||||
cp -a "$SCHEMA" "$DST/priv/$(basename "$SCHEMA")"
|
||||
fi
|
||||
|
||||
# Clean up beam files just in case
|
||||
[ -d "$DST/ebin" ] && find "$DST/ebin" -name '*.beam' -exec rm -f {} + || true
|
||||
|
||||
Reference in New Issue
Block a user