Replace direct lager logging with hut
This ensure we can configure the logging backend in the umbrella project where aeminer is used.
This commit is contained in:
parent
0a82f0fd90
commit
b13515f0af
@ -1,9 +1,5 @@
|
|||||||
|
|
||||||
{erl_opts, [{parse_transform, lager_transform}, {lager_extra_sinks, [aeminer]}]}.
|
|
||||||
|
|
||||||
{deps, [
|
{deps, [
|
||||||
{lager, {git, "https://github.com/erlang-lager/lager.git",
|
{hut, "1.3.0"},
|
||||||
{ref, "69b4ada"}}}, % tag: 3.6.7
|
|
||||||
|
|
||||||
%% Cuckoo prebuilt CUDA binaries.
|
%% Cuckoo prebuilt CUDA binaries.
|
||||||
{aecuckooprebuilt,
|
{aecuckooprebuilt,
|
||||||
@ -23,7 +19,7 @@
|
|||||||
{ref, "4f0a0c64132f837ee47cfaf99cddafabfe4fd7f1"}}}
|
{ref, "4f0a0c64132f837ee47cfaf99cddafabfe4fd7f1"}}}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{profiles, [{test, [{deps, [{meck, "0.8.12"}]}]}]}.
|
{profiles, [{test, [{deps, [{meck, "0.8.13"}]}]}]}.
|
||||||
|
|
||||||
{dialyzer, [{warnings, [unknown]},
|
{dialyzer, [{warnings, [unknown]},
|
||||||
{plt_apps, all_deps},
|
{plt_apps, all_deps},
|
||||||
|
@ -12,12 +12,8 @@
|
|||||||
{git,"https://github.com/aeternity/enacl.git",
|
{git,"https://github.com/aeternity/enacl.git",
|
||||||
{ref,"26180f42c0b3a450905d2efd8bc7fd5fd9cece75"}},
|
{ref,"26180f42c0b3a450905d2efd8bc7fd5fd9cece75"}},
|
||||||
0},
|
0},
|
||||||
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1},
|
{<<"hut">>,{pkg,<<"hut">>,<<"1.3.0">>},0}]}.
|
||||||
{<<"lager">>,
|
|
||||||
{git,"https://github.com/erlang-lager/lager.git",
|
|
||||||
{ref,"69b4ada2341b8ab2cf5c8e464ac936e5e4a9f62b"}},
|
|
||||||
0}]}.
|
|
||||||
[
|
[
|
||||||
{pkg_hash,[
|
{pkg_hash,[
|
||||||
{<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>}]}
|
{<<"hut">>, <<"71F2F054E657C03F959CF1ACC43F436EA87580696528CA2A55C8AFB1B06C85E7">>}]}
|
||||||
].
|
].
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
{applications,
|
{applications,
|
||||||
[kernel,
|
[kernel,
|
||||||
stdlib,
|
stdlib,
|
||||||
lager,
|
|
||||||
enacl,
|
enacl,
|
||||||
|
hut,
|
||||||
aecuckoo,
|
aecuckoo,
|
||||||
aecuckooprebuilt
|
aecuckooprebuilt
|
||||||
]},
|
]},
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
]).
|
]).
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
|
-include_lib("hut/include/hut.hrl").
|
||||||
-include("aeminer.hrl").
|
-include("aeminer.hrl").
|
||||||
|
|
||||||
-type hashable() :: aeminer_blake2b_256:hashable().
|
-type hashable() :: aeminer_blake2b_256:hashable().
|
||||||
@ -118,11 +119,6 @@
|
|||||||
(is_integer(EdgeBits) and (EdgeBits > 0)) and
|
(is_integer(EdgeBits) and (EdgeBits > 0)) and
|
||||||
(is_list(Instances) or (Instances =:= undefined))).
|
(is_list(Instances) or (Instances =:= undefined))).
|
||||||
|
|
||||||
-define(debug(F, A), aeminer:debug(F, A)).
|
|
||||||
-define(info(F, A), aeminer:info(F, A)).
|
|
||||||
-define(warning(F, A), aeminer:warning(F, A)).
|
|
||||||
-define(error(F, A), aeminer:error(F, A)).
|
|
||||||
|
|
||||||
%%%=============================================================================
|
%%%=============================================================================
|
||||||
%%% API
|
%%% API
|
||||||
%%%=============================================================================
|
%%%=============================================================================
|
||||||
@ -190,13 +186,13 @@ generate(Data, Target, Nonce, Config, Instance) when
|
|||||||
{ok, {nonce(), solution()}} | {error, no_solution} | {error, {runtime, term()}}.
|
{ok, {nonce(), solution()}} | {error, no_solution} | {error, {runtime, term()}}.
|
||||||
generate_from_hash(Hash, Target, Nonce, Config, Instance) ->
|
generate_from_hash(Hash, Target, Nonce, Config, Instance) ->
|
||||||
Hash64 = base64:encode_to_string(Hash),
|
Hash64 = base64:encode_to_string(Hash),
|
||||||
?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]),
|
[Hash, Nonce, Target]),
|
||||||
case generate_int(Hash64, Nonce, Target, Config, Instance) of
|
case generate_int(Hash64, Nonce, Target, Config, Instance) of
|
||||||
{ok, Nonce1, Soln} ->
|
{ok, Nonce1, Soln} ->
|
||||||
{ok, {Nonce1, Soln}};
|
{ok, {Nonce1, Soln}};
|
||||||
{error, no_value} ->
|
{error, no_value} ->
|
||||||
?debug("No cuckoo solution found", []),
|
?log(debug, "No cuckoo solution found", []),
|
||||||
{error, no_solution};
|
{error, no_solution};
|
||||||
{error, Rsn} ->
|
{error, Rsn} ->
|
||||||
%% Exec failed (segfault, not found, etc.): let miner decide
|
%% Exec failed (segfault, not found, etc.): let miner decide
|
||||||
@ -266,7 +262,7 @@ generate_int(Hash, Nonce, Target, MinerBinDir, MinerBin, MinerExtraArgs,
|
|||||||
#config{repeats = Repeats0, edge_bits = EdgeBits}) ->
|
#config{repeats = Repeats0, edge_bits = EdgeBits}) ->
|
||||||
Repeats = integer_to_list(Repeats0),
|
Repeats = integer_to_list(Repeats0),
|
||||||
Args = ["-h", Hash, "-n", integer_to_list(Nonce), "-r", Repeats | string:tokens(MinerExtraArgs, " ")],
|
Args = ["-h", Hash, "-n", integer_to_list(Nonce), "-r", Repeats | string:tokens(MinerExtraArgs, " ")],
|
||||||
?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),
|
Old = process_flag(trap_exit, true),
|
||||||
try exec_run(MinerBin, MinerBinDir, Args) of
|
try exec_run(MinerBin, MinerBinDir, Args) of
|
||||||
{ok, Port, OsPid} ->
|
{ok, Port, OsPid} ->
|
||||||
@ -344,7 +340,7 @@ verify_proof_(Header, Solution, EdgeBits) ->
|
|||||||
end
|
end
|
||||||
catch
|
catch
|
||||||
throw:{error, Rsn} ->
|
throw:{error, Rsn} ->
|
||||||
?info("Proof verification failed for ~p: ~p", [Solution, Rsn]),
|
?log(info, "Proof verification failed for ~p: ~p", [Solution, Rsn]),
|
||||||
false
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -499,20 +495,20 @@ parse_generation_result(["Solution" ++ NonceValuesStr | Rest],
|
|||||||
stop_execution(OsPid),
|
stop_execution(OsPid),
|
||||||
case parse_nonce_str(NonceStr) of
|
case parse_nonce_str(NonceStr) of
|
||||||
{ok, Nonce} ->
|
{ok, Nonce} ->
|
||||||
?debug("Solution found: ~p", [Soln]),
|
?log(debug, "Solution found: ~p", [Soln]),
|
||||||
{ok, Nonce, Soln};
|
{ok, Nonce, Soln};
|
||||||
Err = {error, _} ->
|
Err = {error, _} ->
|
||||||
?debug("Bad nonce: ~p", [Err]),
|
?log(debug, "Bad nonce: ~p", [Err]),
|
||||||
Err
|
Err
|
||||||
end;
|
end;
|
||||||
{N, _} when N /= ?SOLUTION_SIZE ->
|
{N, _} when N /= ?SOLUTION_SIZE ->
|
||||||
?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?
|
%% No nonce in solution, old miner exec?
|
||||||
stop_execution(OsPid),
|
stop_execution(OsPid),
|
||||||
{error, bad_miner};
|
{error, bad_miner};
|
||||||
{_, false} ->
|
{_, false} ->
|
||||||
%% failed to meet target: go on, we may find another solution
|
%% failed to meet target: go on, we may find another solution
|
||||||
?debug("Failed to meet target (~p)", [Target]),
|
?log(debug, "Failed to meet target (~p)", [Target]),
|
||||||
parse_generation_result(Rest, State)
|
parse_generation_result(Rest, State)
|
||||||
end;
|
end;
|
||||||
parse_generation_result([_Msg | T], State) ->
|
parse_generation_result([_Msg | T], State) ->
|
||||||
@ -530,7 +526,7 @@ parse_nonce_str(S) ->
|
|||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
stop_execution(OsPid) ->
|
stop_execution(OsPid) ->
|
||||||
exec_kill(OsPid),
|
exec_kill(OsPid),
|
||||||
?debug("Mining OS process ~p stopped", [OsPid]),
|
?log(debug, "Mining OS process ~p stopped", [OsPid]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
@ -562,10 +558,10 @@ exec_run(Cmd, Dir, Args) ->
|
|||||||
Port = erlang:open_port(PortName, PortSettings),
|
Port = erlang:open_port(PortName, PortSettings),
|
||||||
case erlang:port_info(Port, os_pid) of
|
case erlang:port_info(Port, os_pid) of
|
||||||
{os_pid, OsPid} ->
|
{os_pid, OsPid} ->
|
||||||
?debug("External mining process started with OS pid ~p", [OsPid]),
|
?log(debug, "External mining process started with OS pid ~p", [OsPid]),
|
||||||
{ok, Port, OsPid};
|
{ok, Port, OsPid};
|
||||||
undefined ->
|
undefined ->
|
||||||
?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}
|
{ok, Port, undefined}
|
||||||
end
|
end
|
||||||
catch
|
catch
|
||||||
|
Loading…
x
Reference in New Issue
Block a user