3 Commits

Author SHA1 Message Date
Ulf Wiger d2ccf9429d remove debug printouts 2019-11-01 14:02:01 +01:00
Ulf Wiger a7b1a70e42 Filter rebar.lock if disabling cuckoo 2019-10-31 15:26:25 +01:00
Ulf Wiger 495fcb30d6 WIP: AE_DISABLE_CUCKOO env var support
revert rebar.lock to original
2019-10-31 13:03:52 +01:00
9 changed files with 89 additions and 26 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ version: 2.1
executors:
aebuilder:
docker:
- image: aeternity/builder:bionic-otp23
- image: aeternity/builder
user: builder
working_directory: ~/src
+3 -2
View File
@@ -1,4 +1,5 @@
{deps, [
{hut, "1.3.0"},
%% Cuckoo prebuilt CUDA binaries.
{aecuckooprebuilt,
@@ -7,11 +8,11 @@
%% Cuckoo CPU miners (not prebuilt).
{aecuckoo, {git, "https://github.com/aeternity/aecuckoo.git",
{ref, "996ffcd"}}},
{ref, "a1bff574dd0a965d3f9f2e23f980bbead8b4638d"}}},
%% This is used just in one place, just to get blake2b_256 hash.
{enacl, {git, "https://github.com/aeternity/enacl.git",
{ref, "67fceef"}}}
{ref, "26180f4"}}}
]}.
{plugins, [{rebar_aecuckooprebuilt_dep, {git, "https://github.com/aeternity/rebar3-cuckoo-prebuilt-plugin.git",
+16
View File
@@ -0,0 +1,16 @@
%% -*- mode:erlang; erlang-indent-level:4; indent-tabs-mode:nil -*-
case os:getenv("AE_DISABLE_CUCKOO") =/= false of
true ->
RemoveApps = [aecuckoo, aecuckooprebuilt],
RemovePlugins = [rebar_aecuckooprebuilt_dep],
{_, Deps} = lists:keyfind(deps, 1, CONFIG),
NewDeps = [D || D <- Deps,
not lists:member(element(1,D), RemoveApps)],
Plugins = proplists:get_value(plugins, CONFIG, []),
CONFIG1 = lists:keyreplace(deps, 1, CONFIG, {deps, NewDeps}),
Plugins1 = [P || P <- Plugins,
not lists:member(element(1,P), RemovePlugins)],
lists:keystore(plugins, 1, CONFIG1, {plugins, Plugins1});
false ->
CONFIG
end.
+7 -6
View File
@@ -1,7 +1,7 @@
{"1.2.0",
{"1.1.0",
[{<<"aecuckoo">>,
{git,"https://github.com/aeternity/aecuckoo.git",
{ref,"996ffcdb336f1c2254ea8e1b1a657b05b7ea4a81"}},
{ref,"a1bff574dd0a965d3f9f2e23f980bbead8b4638d"}},
0},
{<<"aecuckooprebuilt">>,
{aecuckooprebuilt_app_with_priv_from_git,
@@ -10,9 +10,10 @@
0},
{<<"enacl">>,
{git,"https://github.com/aeternity/enacl.git",
{ref,"67fceef42c0d055570f2e67b571f8d1f8de2f204"}},
0}]}.
{ref,"26180f42c0b3a450905d2efd8bc7fd5fd9cece75"}},
0},
{<<"hut">>,{pkg,<<"hut">>,<<"1.3.0">>},0}]}.
[
{pkg_hash,[]},
{pkg_hash_ext,[]}
{pkg_hash,[
{<<"hut">>, <<"71F2F054E657C03F959CF1ACC43F436EA87580696528CA2A55C8AFB1B06C85E7">>}]}
].
+29
View File
@@ -0,0 +1,29 @@
%% -*- erlang -*-
FilterCheck = (os:getenv("AE_DISABLE_CUCKOO") =/= false),
RemoveApps = [<<"aecuckoo">>, <<"aecuckooprebuilt">>],
Filter = fun(Apps) ->
case FilterCheck of
false ->
Apps;
true ->
lists:foldl(
fun(App, Acc) ->
lists:keydelete(App, 1, Acc)
end,
Apps,
RemoveApps
)
end
end,
case CONFIG of
[] ->
%% no lock file present, usually during unlock/upgrade
CONFIG;
[{Version, Deps}, [{pkg_hash, Pkgs}]] ->
Deps1 = Filter(Deps),
Pkgs1 = Filter(Pkgs),
[{Version, Deps1}, [{pkg_hash, Pkgs1}]]
end.
+1
View File
@@ -6,6 +6,7 @@
[kernel,
stdlib,
enacl,
hut,
aecuckoo,
aecuckooprebuilt
]},
+18
View File
@@ -0,0 +1,18 @@
%% -*- mode:erlang; erlang-indent-level:4; indent-tabs-mode:nil -*-
RemoveApps = [aecuckoo, aecuckooprebuilt].
Base = filename:basename(SCRIPT, ".script").
Dir = filename:dirname(SCRIPT).
{ok, [{application,_,Opts} = App]} = file:consult(filename:join(Dir, Base)).
case os:getenv("AE_DISABLE_CUCKOO") =/= false of
true ->
{_, Apps} = lists:keyfind(applications, 1, Opts),
Env = proplists:get_value(env, Opts, []),
Env1 = lists:keystore(use_cuckoo, 1, Env, {use_cuckoo, false}),
Apps1 = Apps -- RemoveApps,
Opts1 = lists:keyreplace(applications, 1, Opts, {applications, Apps1}),
Opts2 = lists:keystore(env, 1, Opts1, {env, Env1}),
setelement(3, App, Opts2);
false ->
App
end.
+2 -1
View File
@@ -14,5 +14,6 @@
-spec hash(hashable()) -> hash().
hash(Bin) ->
enacl:generichash(?HASH_BYTES_SIZE, Bin).
{ok, Hash} = enacl:generichash(?HASH_BYTES_SIZE, Bin),
Hash.
+12 -16
View File
@@ -53,13 +53,9 @@
]).
-endif.
-include_lib("hut/include/hut.hrl").
-include("aeminer.hrl").
-define(logger_meta, #{domain => [gaj, pow_cuckoo]}).
-define(debug(Fmt, Args) , logger:debug(Fmt, Args, ?logger_meta)).
-define(info(Fmt, Args) , logger:info(Fmt, Args, ?logger_meta)).
-define(warning(Fmt, Args), logger:warning(Fmt, Args, ?logger_meta)).
-type hashable() :: aeminer_blake2b_256:hashable().
-type hash() :: aeminer_blake2b_256:hash().
@@ -190,13 +186,13 @@ generate(Data, Target, Nonce, Config, Instance) when
{ok, {nonce(), solution()}} | {error, no_solution} | {error, {runtime, term()}}.
generate_from_hash(Hash, Target, Nonce, Config, Instance) ->
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]),
case generate_int(Hash64, Nonce, Target, Config, Instance) of
{ok, Nonce1, Soln} ->
{ok, {Nonce1, Soln}};
{error, no_value} ->
?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
@@ -266,7 +262,7 @@ generate_int(Hash, Nonce, Target, MinerBinDir, MinerBin, MinerExtraArgs,
#config{repeats = Repeats0, edge_bits = EdgeBits}) ->
Repeats = integer_to_list(Repeats0),
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),
try exec_run(MinerBin, MinerBinDir, Args) of
{ok, Port, OsPid} ->
@@ -344,7 +340,7 @@ verify_proof_(Header, Solution, EdgeBits) ->
end
catch
throw:{error, Rsn} ->
?info("Proof verification failed for ~p: ~p", [Solution, Rsn]),
?log(info, "Proof verification failed for ~p: ~p", [Solution, Rsn]),
false
end.
@@ -499,20 +495,20 @@ parse_generation_result(["Solution" ++ NonceValuesStr | Rest],
stop_execution(OsPid),
case parse_nonce_str(NonceStr) of
{ok, Nonce} ->
?debug("Solution found: ~p", [Soln]),
?log(debug, "Solution found: ~p", [Soln]),
{ok, Nonce, Soln};
Err = {error, _} ->
?debug("Bad nonce: ~p", [Err]),
?log(debug, "Bad nonce: ~p", [Err]),
Err
end;
{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?
stop_execution(OsPid),
{error, bad_miner};
{_, false} ->
%% 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)
end;
parse_generation_result([_Msg | T], State) ->
@@ -530,7 +526,7 @@ parse_nonce_str(S) ->
%%------------------------------------------------------------------------------
stop_execution(OsPid) ->
exec_kill(OsPid),
?debug("Mining OS process ~p stopped", [OsPid]),
?log(debug, "Mining OS process ~p stopped", [OsPid]),
ok.
%%------------------------------------------------------------------------------
@@ -562,10 +558,10 @@ exec_run(Cmd, Dir, Args) ->
Port = erlang:open_port(PortName, PortSettings),
case erlang:port_info(Port, os_pid) of
{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};
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}
end
catch