Test candidate 1
This commit is contained in:
parent
f901ba6c9d
commit
562f86e078
@ -11,7 +11,6 @@
|
|||||||
-behavior(gen_server).
|
-behavior(gen_server).
|
||||||
-export([start_stop/0, gajudesk/0]).
|
-export([start_stop/0, gajudesk/0]).
|
||||||
-export([conf/0, conf/1]).
|
-export([conf/0, conf/1]).
|
||||||
-export([bin_dir/0]).
|
|
||||||
-export([network/0]).
|
-export([network/0]).
|
||||||
-export([start_link/0, stop/0]).
|
-export([start_link/0, stop/0]).
|
||||||
-export([init/1, terminate/2, code_change/3,
|
-export([init/1, terminate/2, code_change/3,
|
||||||
@ -27,7 +26,6 @@
|
|||||||
{version = 1 :: integer(),
|
{version = 1 :: integer(),
|
||||||
window = none :: none | wx:wx_object(),
|
window = none :: none | wx:wx_object(),
|
||||||
network = <<"mainnet">> :: binary(), % <<"testnet">> | <<"mainnet">>
|
network = <<"mainnet">> :: binary(), % <<"testnet">> | <<"mainnet">>
|
||||||
exec_dir = platform_dir() :: file:filename(),
|
|
||||||
acc = none :: none | binary(),
|
acc = none :: none | binary(),
|
||||||
keys = [] :: [],
|
keys = [] :: [],
|
||||||
max_cores = 2 :: pos_integer(),
|
max_cores = 2 :: pos_integer(),
|
||||||
@ -70,12 +68,6 @@ conf(Info) ->
|
|||||||
gen_server:cast(?MODULE, {conf, Info}).
|
gen_server:cast(?MODULE, {conf, Info}).
|
||||||
|
|
||||||
|
|
||||||
-spec bin_dir() -> file:filename().
|
|
||||||
|
|
||||||
bin_dir() ->
|
|
||||||
gen_server:call(?MODULE, bin_dir).
|
|
||||||
|
|
||||||
|
|
||||||
-spec network() -> mainnet | testnet | none.
|
-spec network() -> mainnet | testnet | none.
|
||||||
|
|
||||||
network() ->
|
network() ->
|
||||||
@ -109,7 +101,6 @@ start_link() ->
|
|||||||
|
|
||||||
init(none) ->
|
init(none) ->
|
||||||
ok = log(info, "Starting"),
|
ok = log(info, "Starting"),
|
||||||
_ = process_flag(sensitive, true),
|
|
||||||
{Acc, Keys, Network, MaxCores, MaxMem} =
|
{Acc, Keys, Network, MaxCores, MaxMem} =
|
||||||
case read_conf() of
|
case read_conf() of
|
||||||
{ok, C} ->
|
{ok, C} ->
|
||||||
@ -125,29 +116,14 @@ init(none) ->
|
|||||||
{ok, start_gui(State)}.
|
{ok, start_gui(State)}.
|
||||||
|
|
||||||
|
|
||||||
platform_dir() ->
|
|
||||||
#{deps := Deps} = zx_daemon:meta(),
|
|
||||||
AppID = lists:keyfind("cuckoo_cpu", 2, Deps),
|
|
||||||
Priv = filename:join(zx_lib:ppath(lib, AppID), "priv"),
|
|
||||||
Dir =
|
|
||||||
case os:type() of
|
|
||||||
{unix, linux} ->
|
|
||||||
"linux_x86_64";
|
|
||||||
{unix, darwin} ->
|
|
||||||
% TODO: Check M2 vs x86
|
|
||||||
"mac_m2";
|
|
||||||
{win32, nt} ->
|
|
||||||
"win_x86_64"
|
|
||||||
end,
|
|
||||||
filename:join(Priv, Dir).
|
|
||||||
|
|
||||||
|
|
||||||
start_gui(State = #s{acc = none}) ->
|
start_gui(State = #s{acc = none}) ->
|
||||||
Window = gmc_gui:start_link(#{}),
|
Window = gmc_gui:start_link(#{}),
|
||||||
ok = gmc_gui:ask_conf(),
|
ok = gmc_gui:ask_conf(),
|
||||||
State#s{window = Window};
|
State#s{window = Window};
|
||||||
start_gui(State) ->
|
start_gui(State = #s{acc = AccID}) ->
|
||||||
Window = gmc_gui:start_link(#{}),
|
Window = gmc_gui:start_link(#{}),
|
||||||
|
ok = gmc_gui:set_account(AccID),
|
||||||
State#s{window = Window}.
|
State#s{window = Window}.
|
||||||
|
|
||||||
|
|
||||||
@ -156,8 +132,6 @@ start_gui(State) ->
|
|||||||
|
|
||||||
handle_call(network, _, State = #s{network = Network}) ->
|
handle_call(network, _, State = #s{network = Network}) ->
|
||||||
{reply, Network, State};
|
{reply, Network, State};
|
||||||
handle_call(bin_dir, _, State = #s{exec_dir = BinDir}) ->
|
|
||||||
{reply, BinDir, State};
|
|
||||||
handle_call(Unexpected, From, State) ->
|
handle_call(Unexpected, From, State) ->
|
||||||
ok = log(warning, "Unexpected call from ~tp: ~tp~n", [From, Unexpected]),
|
ok = log(warning, "Unexpected call from ~tp: ~tp~n", [From, Unexpected]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
@ -221,7 +195,7 @@ do_stop() ->
|
|||||||
|
|
||||||
%%% Doers
|
%%% Doers
|
||||||
|
|
||||||
do_start_stop(#s{acc = PubKey, network = Network, max_mem = MaxMem}) ->
|
do_start_stop(#s{acc = PubKey, keys = Keys, network = Network, max_cores = MaxCores, max_mem = MaxMem}) ->
|
||||||
% smrt guy stuff happens here
|
% smrt guy stuff happens here
|
||||||
{Bits, Eureka} =
|
{Bits, Eureka} =
|
||||||
case Network of
|
case Network of
|
||||||
@ -247,14 +221,15 @@ do_start_stop(#s{acc = PubKey, network = Network, max_mem = MaxMem}) ->
|
|||||||
<<"testnet">> -> {"mean", "generic.exe"}
|
<<"testnet">> -> {"mean", "generic.exe"}
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
Miner = unicode:characters_to_binary([Fatness, Bits, "-", Type]),
|
Miner = filename:join(platform_dir(), unicode:characters_to_binary([Fatness, Bits, "-", Type])),
|
||||||
Count = optimize_count(MaxMem),
|
Count = optimize_count(MaxCores, MaxMem),
|
||||||
Instance = #{<<"executable">> => Miner},
|
Instance = #{<<"executable">> => Miner},
|
||||||
Workers = lists:duplicate(Count, Instance),
|
Workers = lists:duplicate(Count, Instance),
|
||||||
Profile =
|
Profile =
|
||||||
[{pubkey, PubKey},
|
[{pubkey, PubKey},
|
||||||
{workers, Workers},
|
{workers, Workers},
|
||||||
{pool_admin_url, Eureka}],
|
{pool_admin_url, Eureka},
|
||||||
|
{additional_keys, Keys}],
|
||||||
ok = gmc_gui:message({notice, "Starting..."}),
|
ok = gmc_gui:message({notice, "Starting..."}),
|
||||||
ok = gmc_gui:message({notice, ["Miner: ", Miner]}),
|
ok = gmc_gui:message({notice, ["Miner: ", Miner]}),
|
||||||
{ok, Apps} = gmhc_app:start(Profile),
|
{ok, Apps} = gmhc_app:start(Profile),
|
||||||
@ -270,17 +245,41 @@ do_start_stop(#s{acc = PubKey, network = Network, max_mem = MaxMem}) ->
|
|||||||
disconnected],
|
disconnected],
|
||||||
lists:foreach(fun gmhc_events:ensure_subscribed/1, Events).
|
lists:foreach(fun gmhc_events:ensure_subscribed/1, Events).
|
||||||
|
|
||||||
optimize_count(MaxMem) ->
|
|
||||||
|
optimize_count(MaxC, MaxM) ->
|
||||||
|
MapSize = 3550722201,
|
||||||
|
MaxCores = max(1, MaxC),
|
||||||
|
MaxMem = max(MapSize, MaxM),
|
||||||
{Procs, Memory} = proc_mem(),
|
{Procs, Memory} = proc_mem(),
|
||||||
MeanMaps = min(MaxMem, Memory) div 3550722201,
|
MeanMaps = min(MaxMem, Memory) div MapSize,
|
||||||
Recommended = max(min(Procs, MeanMaps) - 1, 1),
|
Recommended = min(MaxCores, max(min(Procs, MeanMaps) - 1, 1)),
|
||||||
Notice = fun(F, A) -> gmc_gui:message({notice, io_lib:format(F, A)}) end,
|
Notice = fun(F, A) -> gmc_gui:message({notice, io_lib:format(F, A)}) end,
|
||||||
ok = Notice("Physical Processors: ~p", [Procs]),
|
ok = Notice("Physical Processors: ~p", [Procs]),
|
||||||
ok = Notice("Physical Memory: ~p", [Memory]),
|
ok = Notice("Physical Memory: ~p", [Memory]),
|
||||||
|
ok = Notice("Max Processor Commit: ~p", [MaxCores]),
|
||||||
|
ok = Notice("Max Memory Commit: ~p", [MaxMem]),
|
||||||
ok = Notice("29-bit Mean Map Space: ~p", [MeanMaps]),
|
ok = Notice("29-bit Mean Map Space: ~p", [MeanMaps]),
|
||||||
ok = Notice("Workers: ~p", [Recommended]),
|
ok = Notice("Workers: ~p", [Recommended]),
|
||||||
Recommended.
|
Recommended.
|
||||||
|
|
||||||
|
|
||||||
|
platform_dir() ->
|
||||||
|
#{deps := Deps} = zx_daemon:meta(),
|
||||||
|
AppID = lists:keyfind("cuckoo_cpu", 2, Deps),
|
||||||
|
Priv = filename:join(zx_lib:ppath(lib, AppID), "priv"),
|
||||||
|
Dir =
|
||||||
|
case os:type() of
|
||||||
|
{unix, linux} ->
|
||||||
|
"linux_x86_64";
|
||||||
|
{unix, darwin} ->
|
||||||
|
% TODO: Check M2 vs x86
|
||||||
|
"mac_m2";
|
||||||
|
{win32, nt} ->
|
||||||
|
"win_x86_64"
|
||||||
|
end,
|
||||||
|
filename:join(Priv, Dir).
|
||||||
|
|
||||||
|
|
||||||
proc_mem() ->
|
proc_mem() ->
|
||||||
case os:type() of
|
case os:type() of
|
||||||
{unix, linux} ->
|
{unix, linux} ->
|
||||||
@ -334,7 +333,15 @@ run_gmc_conf(State) ->
|
|||||||
|
|
||||||
|
|
||||||
do_conf({Network, AccID, Keys, MaxCores, MaxMem}, State) ->
|
do_conf({Network, AccID, Keys, MaxCores, MaxMem}, State) ->
|
||||||
State#s{network = Network, acc = AccID, keys = Keys, max_cores = MaxCores, max_mem = MaxMem}.
|
ok = gmc_gui:set_account(AccID),
|
||||||
|
NewState =
|
||||||
|
State#s{network = Network,
|
||||||
|
acc = AccID,
|
||||||
|
keys = Keys,
|
||||||
|
max_cores = MaxCores,
|
||||||
|
max_mem = MaxMem},
|
||||||
|
ok = persist(NewState),
|
||||||
|
NewState.
|
||||||
|
|
||||||
|
|
||||||
%%% Utils
|
%%% Utils
|
||||||
|
Loading…
x
Reference in New Issue
Block a user