Test candidate 1
This commit is contained in:
parent
f901ba6c9d
commit
562f86e078
@ -11,7 +11,6 @@
|
||||
-behavior(gen_server).
|
||||
-export([start_stop/0, gajudesk/0]).
|
||||
-export([conf/0, conf/1]).
|
||||
-export([bin_dir/0]).
|
||||
-export([network/0]).
|
||||
-export([start_link/0, stop/0]).
|
||||
-export([init/1, terminate/2, code_change/3,
|
||||
@ -27,7 +26,6 @@
|
||||
{version = 1 :: integer(),
|
||||
window = none :: none | wx:wx_object(),
|
||||
network = <<"mainnet">> :: binary(), % <<"testnet">> | <<"mainnet">>
|
||||
exec_dir = platform_dir() :: file:filename(),
|
||||
acc = none :: none | binary(),
|
||||
keys = [] :: [],
|
||||
max_cores = 2 :: pos_integer(),
|
||||
@ -70,12 +68,6 @@ 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.
|
||||
|
||||
network() ->
|
||||
@ -109,7 +101,6 @@ start_link() ->
|
||||
|
||||
init(none) ->
|
||||
ok = log(info, "Starting"),
|
||||
_ = process_flag(sensitive, true),
|
||||
{Acc, Keys, Network, MaxCores, MaxMem} =
|
||||
case read_conf() of
|
||||
{ok, C} ->
|
||||
@ -125,29 +116,14 @@ init(none) ->
|
||||
{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}) ->
|
||||
Window = gmc_gui:start_link(#{}),
|
||||
ok = gmc_gui:ask_conf(),
|
||||
State#s{window = Window};
|
||||
start_gui(State) ->
|
||||
start_gui(State = #s{acc = AccID}) ->
|
||||
Window = gmc_gui:start_link(#{}),
|
||||
ok = gmc_gui:set_account(AccID),
|
||||
State#s{window = Window}.
|
||||
|
||||
|
||||
@ -156,8 +132,6 @@ start_gui(State) ->
|
||||
|
||||
handle_call(network, _, State = #s{network = Network}) ->
|
||||
{reply, Network, State};
|
||||
handle_call(bin_dir, _, State = #s{exec_dir = BinDir}) ->
|
||||
{reply, BinDir, State};
|
||||
handle_call(Unexpected, From, State) ->
|
||||
ok = log(warning, "Unexpected call from ~tp: ~tp~n", [From, Unexpected]),
|
||||
{noreply, State}.
|
||||
@ -221,7 +195,7 @@ do_stop() ->
|
||||
|
||||
%%% 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
|
||||
{Bits, Eureka} =
|
||||
case Network of
|
||||
@ -247,14 +221,15 @@ do_start_stop(#s{acc = PubKey, network = Network, max_mem = MaxMem}) ->
|
||||
<<"testnet">> -> {"mean", "generic.exe"}
|
||||
end
|
||||
end,
|
||||
Miner = unicode:characters_to_binary([Fatness, Bits, "-", Type]),
|
||||
Count = optimize_count(MaxMem),
|
||||
Miner = filename:join(platform_dir(), unicode:characters_to_binary([Fatness, Bits, "-", Type])),
|
||||
Count = optimize_count(MaxCores, MaxMem),
|
||||
Instance = #{<<"executable">> => Miner},
|
||||
Workers = lists:duplicate(Count, Instance),
|
||||
Profile =
|
||||
[{pubkey, PubKey},
|
||||
{workers, Workers},
|
||||
{pool_admin_url, Eureka}],
|
||||
{pool_admin_url, Eureka},
|
||||
{additional_keys, Keys}],
|
||||
ok = gmc_gui:message({notice, "Starting..."}),
|
||||
ok = gmc_gui:message({notice, ["Miner: ", Miner]}),
|
||||
{ok, Apps} = gmhc_app:start(Profile),
|
||||
@ -270,17 +245,41 @@ do_start_stop(#s{acc = PubKey, network = Network, max_mem = MaxMem}) ->
|
||||
disconnected],
|
||||
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(),
|
||||
MeanMaps = min(MaxMem, Memory) div 3550722201,
|
||||
Recommended = max(min(Procs, MeanMaps) - 1, 1),
|
||||
MeanMaps = min(MaxMem, Memory) div MapSize,
|
||||
Recommended = min(MaxCores, max(min(Procs, MeanMaps) - 1, 1)),
|
||||
Notice = fun(F, A) -> gmc_gui:message({notice, io_lib:format(F, A)}) end,
|
||||
ok = Notice("Physical Processors: ~p", [Procs]),
|
||||
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("Workers: ~p", [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() ->
|
||||
case os:type() of
|
||||
{unix, linux} ->
|
||||
@ -334,7 +333,15 @@ run_gmc_conf(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
|
||||
|
Loading…
x
Reference in New Issue
Block a user