Zompify, remove deps hut, enacl

This commit is contained in:
Ulf Wiger
2025-04-24 16:37:26 +02:00
parent dcf0dd80e1
commit 4e87116c5f
8 changed files with 742 additions and 26 deletions
+1 -4
View File
@@ -5,10 +5,7 @@
{applications,
[kernel,
stdlib,
enacl,
hut,
aecuckoo,
aecuckooprebuilt
gmcuckoo
]},
{env,[]},
{modules, []},
+1 -1
View File
@@ -14,5 +14,5 @@
-spec hash(hashable()) -> hash().
hash(Bin) ->
enacl:generichash(?HASH_BYTES_SIZE, Bin).
eblake2:blake2b(?HASH_BYTES_SIZE, Bin).
+33 -15
View File
@@ -59,7 +59,7 @@
]).
-endif.
-include_lib("hut/include/hut.hrl").
-include_lib("kernel/include/logger.hrl").
-include("gmminer.hrl").
-type hashable() :: gmminer_blake2b_256:hashable().
@@ -213,7 +213,7 @@ generate_from_hash(Hash, Target, Nonce, Config, Instance) ->
{ok, {nonce(), solution()}} | {ok, solutions()} | {error, no_solution} | {error, {runtime, term()}}.
generate_from_hash(Hash, Target, Nonce, Config, Instance, KeepGoing) ->
Hash64 = base64:encode_to_string(Hash),
?log(debug, "Generating solution for data hash ~p and nonce ~p with target ~p.",
?LOG_DEBUG("Generating solution for data hash ~p and nonce ~p with target ~p.",
[Hash, Nonce, Target]),
case generate_int(Hash64, Nonce, Target, Config, Instance, KeepGoing) of
{ok, Nonce1, Soln} ->
@@ -221,7 +221,7 @@ generate_from_hash(Hash, Target, Nonce, Config, Instance, KeepGoing) ->
{ok, _} = Ok ->
Ok;
{error, no_value} ->
?log(debug, "No cuckoo solution found", []),
?LOG_DEBUG("No cuckoo solution found", []),
{error, no_solution};
{error, Rsn} ->
%% Exec failed (segfault, not found, etc.): let miner decide
@@ -291,7 +291,7 @@ generate_int(Hash, Nonce, Target, MinerBinDir, MinerBin, MinerExtraArgs,
#config{repeats = Repeats0, edge_bits = EdgeBits}, KeepGoing) ->
Repeats = integer_to_list(Repeats0),
Args = ["-h", Hash, "-n", integer_to_list(Nonce), "-r", Repeats | string:tokens(MinerExtraArgs, " ")],
?log(info, "Executing cmd '~s ~s'", [MinerBin, lists:concat(lists:join(" ", Args))]),
?LOG_INFO("Executing cmd '~s ~s'", [MinerBin, lists:concat(lists:join(" ", Args))]),
Old = process_flag(trap_exit, true),
try exec_run(MinerBin, MinerBinDir, Args) of
{ok, Port, OsPid} ->
@@ -327,8 +327,26 @@ is_miner_instance_addressation_enabled(#config{instances = Instances}) ->
exec_bin_dir(#config{exec_group = ExecGroup}) ->
case ExecGroup of
<<"aecuckoo">> -> aecuckoo:bin_dir();
<<"aecuckooprebuilt">> -> code:priv_dir(aecuckooprebuilt)
<<"aecuckoo">> -> gmcuckoo:bin_dir();
<<"gmcuckoo">> -> gmcuckoo:bin_dir();
<<"aecuckooprebuilt">> -> filename:join(priv_dir(gmcuckoo), "cuda");
<<"cuda">> -> filename:join(priv_dir(gmcuckoo), "cuda")
end.
priv_dir(App) ->
case is_pid(whereis(zx_daemon)) of
false ->
code:priv_dir(App);
true ->
%% Running in Zomp context - priv_dir/1 won't work
#{deps := Deps} = zx_daemon:meta(),
case lists:keyfind(atom_to_list(App), 2, Deps) of
false ->
code:priv_dir(App);
PId ->
Lib = zx_lib:ppath(lib, PId),
filename:join(Lib, "priv")
end
end.
-define(POW_TOO_BIG(Nonce), {error, {nonce_too_big, Nonce}}).
@@ -370,7 +388,7 @@ verify_proof_(Header, Solution, EdgeBits) ->
end
catch
throw:{error, Rsn} ->
?log(info, "Proof verification failed for ~p: ~p", [Solution, Rsn]),
?LOG_INFO("Proof verification failed for ~p: ~p", [Solution, Rsn]),
false
end.
@@ -537,7 +555,7 @@ parse_generation_result(["Solution" ++ NonceValuesStr | Rest],
Soln = [list_to_integer(string:trim(V, both, [$\r]), 16) || V <- SolStrs],
case {length(Soln), test_target(Soln, Target, EdgeBits)} of
{?SOLUTION_SIZE, true} ->
?log(debug, "Solution found, KeepGoing = ~p", [KeepGoing]),
?LOG_DEBUG("Solution found, KeepGoing = ~p", [KeepGoing]),
case KeepGoing of
true -> ok;
false ->
@@ -545,7 +563,7 @@ parse_generation_result(["Solution" ++ NonceValuesStr | Rest],
end,
case parse_nonce_str(NonceStr) of
{ok, Nonce} ->
?log(debug, "Solution found: ~p", [Soln]),
?LOG_DEBUG("Solution found: ~p", [Soln]),
case KeepGoing of
true ->
Sols = State#state.solutions,
@@ -555,17 +573,17 @@ parse_generation_result(["Solution" ++ NonceValuesStr | Rest],
{ok, Nonce, Soln}
end;
Err = {error, _} ->
?log(debug, "Bad nonce: ~p", [Err]),
?LOG_DEBUG("Bad nonce: ~p", [Err]),
Err
end;
{N, _} when N /= ?SOLUTION_SIZE ->
?log(debug, "Solution has wrong length (~p) should be ~p", [N, ?SOLUTION_SIZE]),
?LOG_DEBUG("Solution has wrong length (~p) should be ~p", [N, ?SOLUTION_SIZE]),
%% No nonce in solution, old miner exec?
stop_execution(OsPid),
{error, bad_miner};
{_, false} ->
%% failed to meet target: go on, we may find another solution
?log(debug, "Failed to meet target (~p)", [Target]),
?LOG_DEBUG("Failed to meet target (~p)", [Target]),
parse_generation_result(Rest, State)
end;
parse_generation_result([_Msg | T], State) ->
@@ -583,7 +601,7 @@ parse_nonce_str(S) ->
%%------------------------------------------------------------------------------
stop_execution(OsPid) ->
exec_kill(OsPid),
?log(debug, "Mining OS process ~p stopped", [OsPid]),
?LOG_DEBUG("Mining OS process ~p stopped", [OsPid]),
ok.
%%------------------------------------------------------------------------------
@@ -615,10 +633,10 @@ exec_run(Cmd, Dir, Args) ->
Port = erlang:open_port(PortName, PortSettings),
case erlang:port_info(Port, os_pid) of
{os_pid, OsPid} ->
?log(debug, "External mining process started with OS pid ~p", [OsPid]),
?LOG_DEBUG("External mining process started with OS pid ~p", [OsPid]),
{ok, Port, OsPid};
undefined ->
?log(warning, "External mining process finished before ~p could acquire the OS pid", [?MODULE]),
?LOG_WARNING("External mining process finished before ~p could acquire the OS pid", [?MODULE]),
{ok, Port, undefined}
end
catch