WIP
This commit is contained in:
parent
6d0d371d5d
commit
54a70d4b0b
@ -31,7 +31,8 @@
|
|||||||
max_cores = 2 :: pos_integer(),
|
max_cores = 2 :: pos_integer(),
|
||||||
max_mem = 3550722201 :: pos_integer(),
|
max_mem = 3550722201 :: pos_integer(),
|
||||||
prefs = #{} :: #{},
|
prefs = #{} :: #{},
|
||||||
gmc_conf = none :: none | reference()}).
|
gmc_conf = none :: none | reference(),
|
||||||
|
toggle = {stop, 0} :: {start | stop, integer()}}).
|
||||||
|
|
||||||
-type state() :: #s{}.
|
-type state() :: #s{}.
|
||||||
|
|
||||||
@ -102,15 +103,15 @@ start_link() ->
|
|||||||
init(none) ->
|
init(none) ->
|
||||||
ok = log(info, "Starting"),
|
ok = log(info, "Starting"),
|
||||||
{AProcs, AMem} = proc_mem(),
|
{AProcs, AMem} = proc_mem(),
|
||||||
TwoMaps = default_spec(mem) * 2,
|
TwoGraphs = default_spec(mem) * 2,
|
||||||
RProcs =
|
RProcs =
|
||||||
case AProcs >= 2 of
|
case AProcs >= 2 of
|
||||||
true -> 2;
|
true -> 2;
|
||||||
false -> 1
|
false -> 1
|
||||||
end,
|
end,
|
||||||
RMem =
|
RMem =
|
||||||
case AMem >= TwoMaps of
|
case AMem >= TwoGraphs of
|
||||||
true -> TwoMaps;
|
true -> TwoGraphs;
|
||||||
false -> default_spec(mem)
|
false -> default_spec(mem)
|
||||||
end,
|
end,
|
||||||
{Acc, Keys, Network, MaxCores, MaxMem} =
|
{Acc, Keys, Network, MaxCores, MaxMem} =
|
||||||
@ -125,6 +126,14 @@ init(none) ->
|
|||||||
{none, [], <<"mainnet">>, RProcs, RMem}
|
{none, [], <<"mainnet">>, RProcs, RMem}
|
||||||
end,
|
end,
|
||||||
State = #s{network = Network, acc = Acc, keys = Keys, max_cores = MaxCores, max_mem = MaxMem},
|
State = #s{network = Network, acc = Acc, keys = Keys, max_cores = MaxCores, max_mem = MaxMem},
|
||||||
|
Events =
|
||||||
|
[pool_notification,
|
||||||
|
connected,
|
||||||
|
puzzle,
|
||||||
|
result,
|
||||||
|
error,
|
||||||
|
disconnected],
|
||||||
|
ok = lists:foreach(fun gmhc_events:ensure_subscribed/1, Events),
|
||||||
{ok, start_gui(State)}.
|
{ok, start_gui(State)}.
|
||||||
|
|
||||||
|
|
||||||
@ -155,8 +164,8 @@ handle_call(Unexpected, From, State) ->
|
|||||||
|
|
||||||
|
|
||||||
handle_cast(start_stop, State) ->
|
handle_cast(start_stop, State) ->
|
||||||
ok = do_start_stop(State),
|
NewState = do_start_stop(State),
|
||||||
{noreply, State};
|
{noreply, NewState};
|
||||||
handle_cast(gajudesk, State) ->
|
handle_cast(gajudesk, State) ->
|
||||||
ok = do_gajudesk(),
|
ok = do_gajudesk(),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
@ -176,7 +185,7 @@ handle_cast(Unexpected, State) ->
|
|||||||
|
|
||||||
|
|
||||||
handle_info({gproc_ps_event, Event, Data}, State) ->
|
handle_info({gproc_ps_event, Event, Data}, State) ->
|
||||||
ok = gmc_gui:message({Event, Data}),
|
ok = gproc_ps_event({Event, Data}),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info({'DOWN', Mon, process, PID, Info}, State = #s{gmc_conf = Mon}) ->
|
handle_info({'DOWN', Mon, process, PID, Info}, State = #s{gmc_conf = Mon}) ->
|
||||||
ok = log(info, "gmc_conf ~p closed with ~p", [PID, Info]),
|
ok = log(info, "gmc_conf ~p closed with ~p", [PID, Info]),
|
||||||
@ -187,6 +196,15 @@ handle_info(Unexpected, State) ->
|
|||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
|
gproc_ps_event(Info = {disconnect, #{info := #{reconnecting := false, error := #{code := Code, message := Message}}}}) ->
|
||||||
|
ok = log(error, "Error terminal event received. Code: ~p. Message: ~p", [Code, Message]),
|
||||||
|
Outcome = application:stop(gmhive_client),
|
||||||
|
ok = log(info, "application:stop(gmhivie_client) -> ~p", [Outcome]),
|
||||||
|
gmc_gui:message(Info);
|
||||||
|
gproc_ps_event(Info) ->
|
||||||
|
gmc_gui:message(Info).
|
||||||
|
|
||||||
|
|
||||||
code_change(_, State, _) ->
|
code_change(_, State, _) ->
|
||||||
{ok, State}.
|
{ok, State}.
|
||||||
|
|
||||||
@ -209,7 +227,20 @@ do_stop() ->
|
|||||||
|
|
||||||
%%% Doers
|
%%% Doers
|
||||||
|
|
||||||
do_start_stop(#s{acc = PubKey, keys = Keys, network = Network, max_cores = MaxCores, max_mem = MaxMem}) ->
|
do_start_stop(State = #s{toggle = {Last, TS}}) ->
|
||||||
|
Now = erlang:system_time(second),
|
||||||
|
Clicklimit = Now - 5,
|
||||||
|
case TS < Clicklimit of
|
||||||
|
true ->
|
||||||
|
case Last of
|
||||||
|
stop -> do_start(State#s{toggle = {start, Now}});
|
||||||
|
start -> do_stop(State#s{toggle = {stop, Now}})
|
||||||
|
end;
|
||||||
|
false -> State
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
do_start(State = #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
|
||||||
@ -251,29 +282,31 @@ do_start_stop(#s{acc = PubKey, keys = Keys, network = Network, max_cores = MaxCo
|
|||||||
Started = io_lib:format("Apps started:~n ~p", [Apps]),
|
Started = io_lib:format("Apps started:~n ~p", [Apps]),
|
||||||
ok = log(info, Started),
|
ok = log(info, Started),
|
||||||
ok = gmc_gui:message({notice, Started}),
|
ok = gmc_gui:message({notice, Started}),
|
||||||
Events =
|
State.
|
||||||
[pool_notification,
|
|
||||||
connected,
|
|
||||||
puzzle,
|
do_stop(State) ->
|
||||||
result,
|
ok =
|
||||||
error,
|
case application:stop(gmhive_client) of
|
||||||
disconnected],
|
ok -> ok;
|
||||||
lists:foreach(fun gmhc_events:ensure_subscribed/1, Events).
|
Error -> log(warning, "application:stop(gmhive_client) returned: ~p", [Error])
|
||||||
|
end,
|
||||||
|
State.
|
||||||
|
|
||||||
|
|
||||||
optimize_count(MaxC, MaxM) ->
|
optimize_count(MaxC, MaxM) ->
|
||||||
MapSize = 3550722201,
|
GraphSize = 3550722201,
|
||||||
MaxCores = max(1, MaxC),
|
MaxCores = max(1, MaxC),
|
||||||
MaxMem = max(MapSize, MaxM),
|
MaxMem = max(GraphSize, MaxM),
|
||||||
{Procs, Memory} = proc_mem(),
|
{Procs, Memory} = proc_mem(),
|
||||||
MeanMaps = min(MaxMem, Memory) div MapSize,
|
MeanGraphs = min(MaxMem, Memory) div GraphSize,
|
||||||
Recommended = min(MaxCores, min(Procs, MeanMaps)),
|
Recommended = min(MaxCores, min(Procs, MeanGraphs)),
|
||||||
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 Processor Commit: ~p", [MaxCores]),
|
||||||
ok = Notice("Max Memory Commit: ~p", [MaxMem]),
|
ok = Notice("Max Memory Commit: ~p", [MaxMem]),
|
||||||
ok = Notice("29-bit Mean Map Space: ~p", [MeanMaps]),
|
ok = Notice("29-bit Mean Graph Space: ~p", [MeanGraphs]),
|
||||||
ok = Notice("Workers: ~p", [Recommended]),
|
ok = Notice("Workers: ~p", [Recommended]),
|
||||||
Recommended.
|
Recommended.
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,9 @@
|
|||||||
% solved = 0 :: non_neg_integer(), % TODO: Add a widget to show this. Maybe
|
% solved = 0 :: non_neg_integer(), % TODO: Add a widget to show this. Maybe
|
||||||
mess = none :: none | wx:wx_object(),
|
mess = none :: none | wx:wx_object(),
|
||||||
buff = new_buff() :: buff(),
|
buff = new_buff() :: buff(),
|
||||||
buttons = [] :: [#w{}]}).
|
buttons = [] :: [#w{}],
|
||||||
|
toggle = start :: stop | start,
|
||||||
|
toggle_t = none :: none | reference()}).
|
||||||
|
|
||||||
ts() ->
|
ts() ->
|
||||||
erlang:system_time(microsecond).
|
erlang:system_time(microsecond).
|
||||||
@ -203,6 +205,9 @@ handle_cast(Unexpected, State) ->
|
|||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
|
handle_info(toggle, State) ->
|
||||||
|
NewState = toggle(State),
|
||||||
|
{noreply, NewState};
|
||||||
handle_info(Unexpected, State) ->
|
handle_info(Unexpected, State) ->
|
||||||
ok = log(warning, "Unexpected info: ~tp~n", [Unexpected]),
|
ok = log(warning, "Unexpected info: ~tp~n", [Unexpected]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
@ -295,10 +300,29 @@ do_message({pool_notification, #{info := #{msg := MSG}}}, State = #s{height = He
|
|||||||
do_message2(Entry, State)
|
do_message2(Entry, State)
|
||||||
end;
|
end;
|
||||||
do_message({connected, _}, State) ->
|
do_message({connected, _}, State) ->
|
||||||
Entry = "\nConnected!",
|
Entry = "\nConnected",
|
||||||
|
do_message2(Entry, State);
|
||||||
|
do_message({disconnected, #{info := #{error := #{code := Code, message := Message}}}}, State = #s{}) ->
|
||||||
|
% -32000 -> % mining_disabled
|
||||||
|
% -32001 -> % nyi
|
||||||
|
% -32002 -> % pool_not_found
|
||||||
|
% -32003 -> % pool_exists
|
||||||
|
% -32004 -> % unknown_contract
|
||||||
|
% -32005 -> % invalid_prefix
|
||||||
|
% -32006 -> % invalid_encoding
|
||||||
|
% -32007 -> % outdated
|
||||||
|
% -32008 -> % solution_mismatch
|
||||||
|
% -32009 -> % invalid_input
|
||||||
|
% -32010 -> % session_limit
|
||||||
|
% -32011 -> % accounts_limit
|
||||||
|
% -32012 -> % duplicate_accounts
|
||||||
|
% -32601 -> % unknown_method
|
||||||
|
% -32603 -> % internal error
|
||||||
|
Format = "~nAn issue has been reported by the Hive Leader.~nError code: ~p '~s'~nStopping.",
|
||||||
|
Entry = io_lib:format(Format, [Code, Message]),
|
||||||
do_message2(Entry, State);
|
do_message2(Entry, State);
|
||||||
do_message({disconnected, _}, State) ->
|
do_message({disconnected, _}, State) ->
|
||||||
Entry = "\nDisconnected!",
|
Entry = "\nDisconnected",
|
||||||
do_message2(Entry, State);
|
do_message2(Entry, State);
|
||||||
do_message({error, #{info := #{info := #{error := get_failed, data := {error, #{code := 404}}, url := URL}}}}, State) ->
|
do_message({error, #{info := #{info := #{error := get_failed, data := {error, #{code := 404}}, url := URL}}}}, State) ->
|
||||||
ID =
|
ID =
|
||||||
@ -372,11 +396,29 @@ add_message2(Entry, {OMax, 0, IMax, 0, []}) ->
|
|||||||
{append, {OMax, 1, IMax, 1, [[Entry]]}}.
|
{append, {OMax, 1, IMax, 1, [[Entry]]}}.
|
||||||
|
|
||||||
|
|
||||||
start_stop(State = #s{buttons = Buttons}) ->
|
start_stop(State = #s{buttons = Buttons, toggle = Last, toggle_t = none}) ->
|
||||||
#w{wx = SSB} = lists:keyfind(start_stop, #w.name, Buttons),
|
#w{wx = SSB} = lists:keyfind(start_stop, #w.name, Buttons),
|
||||||
_ = wxButton:disable(SSB),
|
_ = wxButton:disable(SSB),
|
||||||
ok = gmc_con:start_stop(),
|
ok = gmc_con:start_stop(),
|
||||||
State.
|
Timer = erlang:send_after(5000, self(), toggle),
|
||||||
|
Next =
|
||||||
|
case Last of
|
||||||
|
stop -> start;
|
||||||
|
start -> stop
|
||||||
|
end,
|
||||||
|
State#s{toggle = Next, toggle_t = Timer}.
|
||||||
|
|
||||||
|
|
||||||
|
toggle(State = #s{buttons = Buttons, toggle = Next, j = J}) ->
|
||||||
|
#w{wx = SSB} = lists:keyfind(start_stop, #w.name, Buttons),
|
||||||
|
Label =
|
||||||
|
case Next of
|
||||||
|
start -> J("Start");
|
||||||
|
stop -> J("Stop")
|
||||||
|
end,
|
||||||
|
ok = wxButton:setLabel(SSB, Label),
|
||||||
|
_ = wxButton:enable(SSB),
|
||||||
|
State#s{toggle_t = none}.
|
||||||
|
|
||||||
|
|
||||||
gajudesk(State) ->
|
gajudesk(State) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user