Fix zomp's app file, config from cmd line, add network config
This commit is contained in:
+24
-30
@@ -2,7 +2,6 @@
|
||||
|
||||
-export([ load_config/0
|
||||
, get_config/1
|
||||
, verify_cfg_props/1
|
||||
]).
|
||||
|
||||
-include_lib("kernel/include/logger.hrl").
|
||||
@@ -13,6 +12,7 @@ load_config() ->
|
||||
gmconfig:load_user_config(report),
|
||||
gmconfig:apply_os_env(),
|
||||
gmconfig:process_plain_args(),
|
||||
check_application_env(),
|
||||
ok.
|
||||
|
||||
instrument_gmconfig() ->
|
||||
@@ -31,37 +31,31 @@ gmconfig_env() ->
|
||||
get_config(Path) ->
|
||||
gmconfig:get_config(Path, cpath(Path)).
|
||||
|
||||
cpath([<<"pubkey">>]) -> [user_config, env(pubkey ) ];
|
||||
cpath([<<"extra_pubkeys">>]) -> [user_config, env(extra_pubkeys ), schema_default];
|
||||
cpath([<<"pool_admin">>, <<"url">>]) -> [user_config, env(pool_admin_url), schema_default];
|
||||
cpath([<<"workers">>]) -> [user_config, env(workers ), schema_default];
|
||||
cpath(_) -> [user_config, schema_default].
|
||||
|
||||
env2cpath(pubkey ) -> [<<"pubkey">>];
|
||||
env2cpath(extra_pubkeys ) -> [<<"extra_pubkeys">>];
|
||||
env2cpath(pool_admin_url) -> [<<"pool_admin">>, <<"url">>];
|
||||
env2cpath(workers ) -> [<<"workers">>].
|
||||
|
||||
verify_cfg_props(PropList) ->
|
||||
Cfg = lists:foldl(
|
||||
fun({K,V}, M) ->
|
||||
CfgK = env2cpath(K),
|
||||
gmconfig:merge_config_maps(M, to_cfg_map(CfgK, V))
|
||||
end, #{}, PropList),
|
||||
case gmconfig_schema_utils:valid(Cfg) of
|
||||
Ok when is_map(Ok) ->
|
||||
check_application_env() ->
|
||||
case lists:foldl(fun appl_env/2, #{}, env_keys()) of
|
||||
C when map_size(C) == 0 ->
|
||||
ok;
|
||||
Other ->
|
||||
error({invalid_config, Other})
|
||||
C ->
|
||||
gmconfig:update_config(C)
|
||||
end.
|
||||
appl_env(K, C) ->
|
||||
case application:get_env(gmhive_client, K) of
|
||||
{ok, V} -> appl_env(K, V, C);
|
||||
undefined -> C
|
||||
end.
|
||||
|
||||
to_cfg_map(K, V) ->
|
||||
to_cfg_map(K, V, #{}).
|
||||
appl_env(pubkey , K , C) -> C#{<<"pubkey">> => K};
|
||||
appl_env(extra_pubkeys , Ks, C) -> C#{<<"extra_pubkeys">> => Ks};
|
||||
appl_env(pool_admin_url, U , C) -> merge(C, #{<<"pool_admin">> => #{<<"url">> => U}});
|
||||
appl_env(workers , Ws, C) -> C#{<<"workers">> => Ws}.
|
||||
|
||||
to_cfg_map([H], V, M) ->
|
||||
M#{H => V};
|
||||
to_cfg_map([H|T], V, M) ->
|
||||
M#{H => to_cfg_map(T, V, M)}.
|
||||
env_keys() -> [pubkey, extra_pubkeys, pool_admin_url, workers].
|
||||
|
||||
env(K) ->
|
||||
{env, gmhive_client, K}.
|
||||
cpath([<<"pubkey">>]) -> [user_config ];
|
||||
cpath([<<"extra_pubkeys">>]) -> [user_config, schema_default];
|
||||
cpath([<<"pool_admin">>, <<"url">>]) -> [user_config, schema_default];
|
||||
cpath([<<"workers">>]) -> [user_config, schema_default];
|
||||
cpath(_) -> [user_config, schema_default].
|
||||
|
||||
merge(A, B) ->
|
||||
gmconfig:merge_config_maps(A, B).
|
||||
|
||||
@@ -24,7 +24,8 @@ to_json() ->
|
||||
schema() ->
|
||||
obj(schema_init(),
|
||||
#{
|
||||
pubkey => str(#{pattern => ?ACCOUNT_PATTERN},
|
||||
network => str(#{ default => <<"mainnet">> })
|
||||
, pubkey => str(#{pattern => ?ACCOUNT_PATTERN},
|
||||
<<"Primary client pubkey">>)
|
||||
, extra_pubkeys => array(#{ description =>
|
||||
<<"Additional worker pubkeys, sharing rewards">>
|
||||
@@ -52,12 +53,20 @@ pool() ->
|
||||
pool_admin() ->
|
||||
obj(#{
|
||||
url => str(#{ default => <<"https://test.gajumining.com/api/workers/{CLIENT_ID}">>
|
||||
, description => <<"URL of Eureka worker api">> })
|
||||
, description => <<"URL of Eureka worker api">> }),
|
||||
default_per_network =>
|
||||
obj(#{
|
||||
testnet =>
|
||||
str(#{default => <<"https://test.gajumining.com/api/workers/{CLIENT_ID}">>})
|
||||
, mainnet =>
|
||||
str(#{default => <<"https://gajumining.com/api/workers/{CLIENT_ID}">>})
|
||||
})
|
||||
}).
|
||||
|
||||
workers() ->
|
||||
array(
|
||||
#{default => [#{executable => <<"mean29-generic">>}],
|
||||
#{default => [#{executable => <<"mean29-generic">>,
|
||||
executable_group => <<"aecuckoo">>}],
|
||||
description =>
|
||||
<<"Definitions of workers' configurations. If no worker are configured one worker "
|
||||
"is used as default, i.e. 'mean29-generic' executable without any extra args.">>},
|
||||
@@ -74,7 +83,8 @@ workers() ->
|
||||
"from faster CPU supporting AVX2 instructions).">>}),
|
||||
executable_group =>
|
||||
str(#{description => <<"Group of executable binaries of the worker.">>,
|
||||
enum => [ <<"aecuckoo">>, <<"aecuckooprebuilt">>, <<"gmcuckoo">>, <<"cuda">>, <<"gajumine">> ],
|
||||
enum => [ <<"aecuckoo">>, <<"aecuckooprebuilt">>,
|
||||
<<"gmcuckoo">>, <<"cuda">>, <<"gajumine">> ],
|
||||
default => <<"aecuckoo">>}),
|
||||
extra_args =>
|
||||
str(#{description => <<"Extra arguments to pass to the worker executable binary. "
|
||||
|
||||
+20
-8
@@ -6,14 +6,26 @@
|
||||
-include("gmhc_events.hrl").
|
||||
|
||||
get_pool_address() ->
|
||||
URL0 = gmhc_config:get_config([<<"pool_admin">>, <<"url">>]),
|
||||
case expand_url(URL0) of
|
||||
<<"local">> ->
|
||||
#{<<"address">> => <<"127.0.0.1">>,
|
||||
<<"port">> => gmconfig:get_config([<<"pool">>, <<"port">>], [schema_default]),
|
||||
<<"pool_id">> => gmhc_config:get_config([<<"pool">>, <<"id">>]) };
|
||||
URL ->
|
||||
?LOG_INFO("Trying to connect to ~p", [URL]),
|
||||
case gmconfig:find_config([<<"pool_admin">>, <<"url">>], [user_config]) of
|
||||
{ok, URL0} ->
|
||||
case expand_url(URL0) of
|
||||
<<"local">> ->
|
||||
#{<<"address">> => <<"127.0.0.1">>,
|
||||
<<"port">> => gmconfig:get_config(
|
||||
[<<"pool">>, <<"port">>], [schema_default]),
|
||||
<<"pool_id">> => gmhc_config:get_config([<<"pool">>, <<"id">>]) };
|
||||
URL ->
|
||||
?LOG_INFO("Trying to connect to ~p", [URL]),
|
||||
connect1(URL)
|
||||
end;
|
||||
undefined ->
|
||||
Network = gmconfig:get_config([<<"network">>]),
|
||||
URL0 = gmconfig:get_config([ <<"pool_admin">>
|
||||
, <<"default_per_network">>
|
||||
, Network ],
|
||||
[schema_default]),
|
||||
URL = expand_url(URL0),
|
||||
?LOG_INFO("Using default for ~p: ~p", [Network, URL]),
|
||||
connect1(URL)
|
||||
end.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user