Fix zomp's app file, config from cmd line, add network config

This commit is contained in:
Ulf Wiger 2025-05-20 23:40:54 +02:00
parent 4a701102c1
commit 29fbfb3c87
5 changed files with 70 additions and 136 deletions

View File

@ -1,102 +1,16 @@
{application,gmhive_client, {application,gmhive_client,
[{description,"Gajumaru Hive client"}, [{description,"Gajumaru Hive Client"},
{vsn,"0.2.1"}, {vsn,"0.1.0"},
{registered,[]}, {registered,[]},
{applications,[kernel,stdlib,sasl,gproc,enoise,gmconfig, {applications,[kernel,stdlib,sasl,gproc,inets,ssl,enoise,
gmhive_protocol,gmhive_worker]}, gmconfig,gmhive_protocol,gmhive_worker]},
{mod,{gmhive_client,[]}}, {mod,{gmhc_app,[]}},
{start_phases,[{connect_to_primary,[]}]}, {start_phases,[{connect_to_primary,[]}]},
{env,[]}, {env,[]},
{modules,[base58,eblake2,eblake2_tests,timing,enacl_eqc, {modules,[gmhc_app,gmhc_config,gmhc_config_schema,
enacl_ext_eqc,enacl,enacl_ext,enacl_nif,enacl_SUITE,
enoise,enoise_cipher_state,enoise_connection,
enoise_crypto,enoise_hs_state,enoise_keypair,
enoise_protocol,enoise_sym_state,
enoise_bad_data_tests,enoise_chiper_state_tests,
enoise_crypto_tests,enoise_hs_state_tests,
enoise_protocol_tests,enoise_sym_state_tests,
enoise_tests,enoise_utils,test_utils,gmconfig,
gmconfig_schema_helpers,gmconfig_schema_utils,
gmcuckoo,gmhc_app,gmhc_config,gmhc_config_schema,
gmhc_connector,gmhc_connectors_sup,gmhc_counters, gmhc_connector,gmhc_connectors_sup,gmhc_counters,
gmhc_eureka,gmhc_events,gmhc_handler,gmhc_server, gmhc_eureka,gmhc_events,gmhc_handler,gmhc_server,
gmhc_sup,gmhc_workers,gmhive_client,gmhp_msgs, gmhc_sup,gmhc_workers,gmhive_client]},
gmhw_blake2b_256,gmhw_pow,gmhw_pow_cuckoo,
gmhw_siphash24,gmcuckoo_SUITE,gmhw_pow_cuckoo_tests,
gmhw_pow_tests,gmser_api_encoder,gmser_chain_objects,
gmser_contract_code,gmser_delegation,gmser_dyn,
gmser_id,gmser_rlp,gmserialization,
gmser_api_encoder_tests,gmser_chain_objects_tests,
gmser_contract_code_tests,gmser_delegation_tests,
gmser_rlp_tests,gproc,gproc_app,gproc_bcast,
gproc_dist,gproc_info,gproc_init,gproc_lib,
gproc_monitor,gproc_pool,gproc_ps,gproc_pt,gproc_sup,
setup,setup_app,setup_file,setup_file_io_server,
setup_gen,setup_lib,setup_srv,setup_sup,setup_zomp,
testapp_app,testapp_sup,testapp_app,testapp_sup,
hex_api,hex_api_auth,hex_api_key,hex_api_organization,
hex_api_organization_member,hex_api_package,
hex_api_package_owner,hex_api_release,hex_api_user,
hex_core,hex_erl_tar,hex_filename,hex_http,
hex_http_httpc,hex_licenses,hex_pb_names,
hex_pb_package,hex_pb_signed,hex_pb_versions,
hex_registry,hex_repo,hex_tarball,safe_erl_term,pc,
pc_compilation,pc_port_env,pc_port_specs,pc_prv_clean,
pc_prv_compile,pc_util,rebar3_hex,rebar3_hex_app,
rebar3_hex_build,rebar3_hex_client,rebar3_hex_config,
rebar3_hex_cut,rebar3_hex_error,rebar3_hex_file,
rebar3_hex_httpc_adapter,rebar3_hex_io,rebar3_hex_key,
rebar3_hex_organization,rebar3_hex_owner,
rebar3_hex_publish,rebar3_hex_results,
rebar3_hex_retire,rebar3_hex_search,rebar3_hex_user,
rebar3_hex_version,
rebar_aecuckooprebuilt_app_with_priv_from_git_resource,
rebar_aecuckooprebuilt_dep,verl,verl_parser,base58,
eblake2,eblake2_tests,timing,enacl_eqc,enacl_ext_eqc,
enacl,enacl_ext,enacl_nif,enacl_SUITE,enoise,
enoise_cipher_state,enoise_connection,enoise_crypto,
enoise_hs_state,enoise_keypair,enoise_protocol,
enoise_sym_state,enoise_bad_data_tests,
enoise_chiper_state_tests,enoise_crypto_tests,
enoise_hs_state_tests,enoise_protocol_tests,
enoise_sym_state_tests,enoise_tests,enoise_utils,
test_utils,gmconfig,gmconfig_schema_helpers,
gmconfig_schema_utils,gmcuckoo,gmhp_msgs,
gmhw_blake2b_256,gmhw_pow,gmhw_pow_cuckoo,
gmhw_siphash24,gmcuckoo_SUITE,gmhw_pow_cuckoo_tests,
gmhw_pow_tests,gmser_api_encoder,gmser_chain_objects,
gmser_contract_code,gmser_delegation,gmser_dyn,
gmser_id,gmser_rlp,gmserialization,
gmser_api_encoder_tests,gmser_chain_objects_tests,
gmser_contract_code_tests,gmser_delegation_tests,
gmser_rlp_tests,gproc,gproc_app,gproc_bcast,
gproc_dist,gproc_info,gproc_init,gproc_lib,
gproc_monitor,gproc_pool,gproc_ps,gproc_pt,gproc_sup,
setup,setup_app,setup_file,setup_file_io_server,
setup_gen,setup_lib,setup_srv,setup_sup,setup_zomp,
testapp_app,testapp_sup,testapp_app,testapp_sup,
hex_api,hex_api_auth,hex_api_key,hex_api_organization,
hex_api_organization_member,hex_api_package,
hex_api_package_owner,hex_api_release,hex_api_user,
hex_core,hex_erl_tar,hex_filename,hex_http,
hex_http_httpc,hex_licenses,hex_pb_names,
hex_pb_package,hex_pb_signed,hex_pb_versions,
hex_registry,hex_repo,hex_tarball,safe_erl_term,pc,
pc_compilation,pc_port_env,pc_port_specs,pc_prv_clean,
pc_prv_compile,pc_util,rebar3_hex,rebar3_hex_app,
rebar3_hex_build,rebar3_hex_client,rebar3_hex_config,
rebar3_hex_cut,rebar3_hex_error,rebar3_hex_file,
rebar3_hex_httpc_adapter,rebar3_hex_io,rebar3_hex_key,
rebar3_hex_organization,rebar3_hex_owner,
rebar3_hex_publish,rebar3_hex_results,
rebar3_hex_retire,rebar3_hex_search,rebar3_hex_user,
rebar3_hex_version,
rebar_aecuckooprebuilt_app_with_priv_from_git_resource,
rebar_aecuckooprebuilt_dep,verl,verl_parser,gmhc_app,
gmhc_config,gmhc_config_schema,gmhc_connector,
gmhc_connectors_sup,gmhc_counters,gmhc_eureka,
gmhc_events,gmhc_handler,gmhc_server,gmhc_sup,
gmhc_workers,gmhive_client]},
{maintainers,["QPQ IaaS AG"]}, {maintainers,["QPQ IaaS AG"]},
{licensens,["ISC"]}, {licensens,["ISC"]},
{links,[{"gitea","https://git.qpq.swiss/gmhive_client"}]}]}. {links,[{"gitea","https://git.qpq.swiss/gmhive_client"}]}]}.

View File

@ -2,7 +2,6 @@
-export([ load_config/0 -export([ load_config/0
, get_config/1 , get_config/1
, verify_cfg_props/1
]). ]).
-include_lib("kernel/include/logger.hrl"). -include_lib("kernel/include/logger.hrl").
@ -13,6 +12,7 @@ load_config() ->
gmconfig:load_user_config(report), gmconfig:load_user_config(report),
gmconfig:apply_os_env(), gmconfig:apply_os_env(),
gmconfig:process_plain_args(), gmconfig:process_plain_args(),
check_application_env(),
ok. ok.
instrument_gmconfig() -> instrument_gmconfig() ->
@ -31,37 +31,31 @@ gmconfig_env() ->
get_config(Path) -> get_config(Path) ->
gmconfig:get_config(Path, cpath(Path)). gmconfig:get_config(Path, cpath(Path)).
cpath([<<"pubkey">>]) -> [user_config, env(pubkey ) ]; check_application_env() ->
cpath([<<"extra_pubkeys">>]) -> [user_config, env(extra_pubkeys ), schema_default]; case lists:foldl(fun appl_env/2, #{}, env_keys()) of
cpath([<<"pool_admin">>, <<"url">>]) -> [user_config, env(pool_admin_url), schema_default]; C when map_size(C) == 0 ->
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) ->
ok; ok;
Other -> C ->
error({invalid_config, Other}) 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. end.
to_cfg_map(K, V) -> appl_env(pubkey , K , C) -> C#{<<"pubkey">> => K};
to_cfg_map(K, V, #{}). 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) -> env_keys() -> [pubkey, extra_pubkeys, pool_admin_url, workers].
M#{H => V};
to_cfg_map([H|T], V, M) ->
M#{H => to_cfg_map(T, V, M)}.
env(K) -> cpath([<<"pubkey">>]) -> [user_config ];
{env, gmhive_client, K}. 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).

View File

@ -24,7 +24,8 @@ to_json() ->
schema() -> schema() ->
obj(schema_init(), obj(schema_init(),
#{ #{
pubkey => str(#{pattern => ?ACCOUNT_PATTERN}, network => str(#{ default => <<"mainnet">> })
, pubkey => str(#{pattern => ?ACCOUNT_PATTERN},
<<"Primary client pubkey">>) <<"Primary client pubkey">>)
, extra_pubkeys => array(#{ description => , extra_pubkeys => array(#{ description =>
<<"Additional worker pubkeys, sharing rewards">> <<"Additional worker pubkeys, sharing rewards">>
@ -52,12 +53,20 @@ pool() ->
pool_admin() -> pool_admin() ->
obj(#{ obj(#{
url => str(#{ default => <<"https://test.gajumining.com/api/workers/{CLIENT_ID}">> 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() -> workers() ->
array( array(
#{default => [#{executable => <<"mean29-generic">>}], #{default => [#{executable => <<"mean29-generic">>,
executable_group => <<"aecuckoo">>}],
description => description =>
<<"Definitions of workers' configurations. If no worker are configured one worker " <<"Definitions of workers' configurations. If no worker are configured one worker "
"is used as default, i.e. 'mean29-generic' executable without any extra args.">>}, "is used as default, i.e. 'mean29-generic' executable without any extra args.">>},
@ -74,7 +83,8 @@ workers() ->
"from faster CPU supporting AVX2 instructions).">>}), "from faster CPU supporting AVX2 instructions).">>}),
executable_group => executable_group =>
str(#{description => <<"Group of executable binaries of the worker.">>, str(#{description => <<"Group of executable binaries of the worker.">>,
enum => [ <<"aecuckoo">>, <<"aecuckooprebuilt">>, <<"gmcuckoo">>, <<"cuda">>, <<"gajumine">> ], enum => [ <<"aecuckoo">>, <<"aecuckooprebuilt">>,
<<"gmcuckoo">>, <<"cuda">>, <<"gajumine">> ],
default => <<"aecuckoo">>}), default => <<"aecuckoo">>}),
extra_args => extra_args =>
str(#{description => <<"Extra arguments to pass to the worker executable binary. " str(#{description => <<"Extra arguments to pass to the worker executable binary. "

View File

@ -6,15 +6,27 @@
-include("gmhc_events.hrl"). -include("gmhc_events.hrl").
get_pool_address() -> get_pool_address() ->
URL0 = gmhc_config:get_config([<<"pool_admin">>, <<"url">>]), case gmconfig:find_config([<<"pool_admin">>, <<"url">>], [user_config]) of
{ok, URL0} ->
case expand_url(URL0) of case expand_url(URL0) of
<<"local">> -> <<"local">> ->
#{<<"address">> => <<"127.0.0.1">>, #{<<"address">> => <<"127.0.0.1">>,
<<"port">> => gmconfig:get_config([<<"pool">>, <<"port">>], [schema_default]), <<"port">> => gmconfig:get_config(
[<<"pool">>, <<"port">>], [schema_default]),
<<"pool_id">> => gmhc_config:get_config([<<"pool">>, <<"id">>]) }; <<"pool_id">> => gmhc_config:get_config([<<"pool">>, <<"id">>]) };
URL -> URL ->
?LOG_INFO("Trying to connect to ~p", [URL]), ?LOG_INFO("Trying to connect to ~p", [URL]),
connect1(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. end.
connect1(URL0) -> connect1(URL0) ->

View File

@ -5,7 +5,11 @@
{desc,"Gajumaru Hive Client"}. {desc,"Gajumaru Hive Client"}.
{author,"Ulf Wiger, QPQ AG"}. {author,"Ulf Wiger, QPQ AG"}.
{package_id,{"uwiger","gmhive_client",{0,2,1}}}. {package_id,{"uwiger","gmhive_client",{0,2,1}}}.
{deps,[{"uwiger","gmhive_worker",{0,1,1}}, {deps,[{"otpr","eblake2",{1,0,1}},
{"uwiger","gmcuckoo",{1,1,1}},
{"otpr","base58",{0,1,1}},
{"otpr","gmserialization",{0,1,3}},
{"uwiger","gmhive_worker",{0,1,1}},
{"uwiger","gmhive_protocol",{0,1,1}}, {"uwiger","gmhive_protocol",{0,1,1}},
{"uwiger","setup",{2,2,4}}, {"uwiger","setup",{2,2,4}},
{"uwiger","gproc",{1,0,1}}, {"uwiger","gproc",{1,0,1}},