Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
validator generated POCs over grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Mar 15, 2022
1 parent 9ffc737 commit 4bedc19
Show file tree
Hide file tree
Showing 37 changed files with 5,255 additions and 190 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ deps:

compile:
REBAR_CONFIG="config/grpc_client_gen_local.config" $(REBAR) grpc gen
REBAR_CONFIG="config/grpc_client_gen.config" $(REBAR) grpc gen
$(MAKE) external_svcs
$(REBAR) compile

Expand Down Expand Up @@ -72,6 +73,7 @@ devrelease:
grpc:
@echo "generating miner grpc services"
REBAR_CONFIG="config/grpc_client_gen_local.config" $(REBAR) grpc gen
REBAR_CONFIG="config/grpc_client_gen.config" $(REBAR) grpc gen

$(GRPC_SERVICE_DIR):
@echo "miner grpc service directory $(directory) does not exist"
Expand Down
8 changes: 8 additions & 0 deletions config/docker-testnet.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
{miner,
[
{network, testnet},
{mode, gateway},
{gateways_run_chain, false},
{seed_validators, [
{"1ZPNnNd9k5qiQXXigKifQpCPiy5HTbszQDSyLM56ywk7ihNRvt6", "18.223.171.149", 8080}, %% test-val2
{"1ZYe21WzqJGkWjXvyEt2c8ALSrufPfjzqfQP2SGy61UJd2h9EbL", "3.17.164.253", 8080}, %% test-val3
{"1ZAxCrEsigGVbLUM37Jki6p88kyZ5NVqjVC6oHSbqu49t7bQDym", "18.191.60.231", 8080} %% test-val6
]
},
{api_base_url, "https://testnet-api.helium.wtf/v1"},
{jsonrpc_ip, {0,0,0,0}}, %% bind jsonrpc to host when in docker container
{gateway_and_mux_enable, false},
Expand Down
31 changes: 31 additions & 0 deletions config/grpc_client_gen.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{plugins, [
{grpcbox_plugin,
{git, "https://github.com/andymck/grpcbox_plugin.git",
{branch, "andymck/ts-master/combined-opts-and-template-changes"}}}
]}.

{grpc, [
{proto_files, [
"_build/default/lib/helium_proto/src/service/gateway.proto"
]},
{beam_out_dir, "src/grpc/autogen/client"},
{out_dir, "src/grpc/autogen/client"},
{keep_beams, false},
{create_services, false},
{override_gpb_defaults, true},
{gpb_opts, [
{rename,{msg_fqname,base_name}},
use_packages,
{report_errors, false},
{descriptor, false},
{recursive, false},
{i, "_build/default/lib/helium_proto/src"},
{o, "src/grpc/autogen/client"},
{module_name_prefix, ""},
{module_name_suffix, "_miner_client_pb"},
{rename, {msg_name, {suffix, "_pb"}}},
{strings_as_binaries, false},
type_specs,
{defs_as_proplists, true}
]}
]}.
12 changes: 12 additions & 0 deletions config/sys.config
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
{log_file_time_to_roll, 86400} %% rotate logs once a day
]}
]},
{sibyl,
[
{validator_ignore_list, []}
]},
{miner,
[
{denylist_keys, ["1SbEYKju337P6aYsRd9DT2k4qgK5ZK62kXbSvnJgqeaxK3hqQrYURZjL"]},
Expand All @@ -101,6 +105,7 @@
{jsonrpc_ip, {127,0,0,1}}, %% bind JSONRPC to localhost only
{jsonrpc_port, 4467},
{mode, gateway},
{gateways_run_chain, true}, %% if false, gateways will no longer follow the chain
{use_ebus, true},
{batch_size, 2500},
{curve, 'SS512'},
Expand All @@ -115,6 +120,13 @@
{default_routers, ["/p2p/11w77YQLhgUt8HUJrMtntGGr97RyXmot1ofs5Ct2ELTmbFoYsQa","/p2p/11afuQSrmk52mgxLu91AdtDXbJ9wmqWBUxC3hvjejoXkxEZfPvY"]},
{mark_mods, [miner_hbbft_handler]},
{stabilization_period, 50000},
{seed_validators, [
{"11tk4zzbyfMPYYHYda255ACoqfYFVdrUSoCWrCYfn8BoyuYrERK", "52.49.199.40", 8080}, %% ireland
{"115PmCR6fpFihdjw626JXYdUEdzwjh66yoWzWkMvB9CRGEx1U6G", "3.132.190.192", 8080}, %% ohio
{"11pUovhssQdXzrfcYMTUrNNTQossgny8WqhfdbprrAVFyHcmvAN", "35.84.173.125", 8080}, %% oregon
{"11yJXQPG9deHqvw2ac6VWtNP7gZj8X3t3Qb3Gqm9j729p4AsdaA", "3.38.70.101", 8080}, %% seoul
{"11Gx2yPEmBGUrbHUiUWQs9vV7JDHQLZSddQs6e3WB2uvqSMUDBW", "54.251.77.229", 8080} %% singapore
]},
{reg_domains_file, "countries_reg_domains.csv"},
{frequency_data, #{'US915' => [903.9, 904.1, 904.3, 904.5, 904.7, 904.9, 905.1, 905.3],
'EU868' => [867.1, 867.3, 867.5, 867.7, 867.9, 868.1, 868.3, 868.5],
Expand Down
5 changes: 5 additions & 0 deletions config/test.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
{libp2p, [
{use_dns_for_seeds, false}
]},
{sibyl,
[
{poc_mgr_mod, miner_poc_mgr},
{poc_report_handler, miner_poc_report_handler}
]},
{blockchain,
[
{seed_dns_cname, ""},
Expand Down
8 changes: 7 additions & 1 deletion config/test_val.config.src
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
%% as without one miner_lora is not started
%% including the params anyway in case someone needs it in this env
{region_override, 'US915'},
{gateway_and_mux_enable, false}
{gateway_and_mux_enable, false},
{seed_validators, [
{"1ZPNnNd9k5qiQXXigKifQpCPiy5HTbszQDSyLM56ywk7ihNRvt6", "18.223.171.149", 8080}, %% test-val2
{"1ZYe21WzqJGkWjXvyEt2c8ALSrufPfjzqfQP2SGy61UJd2h9EbL", "3.17.164.253", 8080}, %% test-val3
{"1ZAxCrEsigGVbLUM37Jki6p88kyZ5NVqjVC6oHSbqu49t7bQDym", "18.191.60.231", 8080} %% test-val6
]
}
]}
].
16 changes: 9 additions & 7 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

{deps, [
{blockchain, {git, "https://github.com/helium/blockchain-core.git",
{branch, "master"}}},
{branch, "andymck/poc-grpc-v2"}}},
{sibyl, {git, "https://github.com/helium/sibyl.git",
{branch, "master"}}},
{branch, "andymck/poc-grpc"}}},
{hbbft, {git, "https://github.com/helium/erlang-hbbft.git",
{branch, "master"}}},
{dkg, {git, "https://github.com/helium/erlang-dkg.git", {branch, "master"}}},
Expand All @@ -21,8 +21,10 @@
{jsx, "3.1.0"},
{kvc, {git, "https://github.com/etrepum/kvc", {tag, "v1.7.0"}}},
{longfi, {git, "https://github.com/helium/longfi-erlang", {tag, "0.2.2"}}},
{grpc_lib, {git, "https://github.com/Bluehouse-Technology/grpc_lib", {branch, "master"}}},
{grpc_client, {git, "https://github.com/Bluehouse-Technology/grpc_client.git", {branch, "master"}}},
{http2_client, {git, "https://github.com/Bluehouse-Technology/http2_client", {branch, "master"}}},
{http2_client, {git, "https://github.com/Bluehouse-Technology/http2_client",
{branch, "master"}}},
recon,
{elli, "3.3.0"},
{jsonrpc2, {git, "https://github.com/zuiderkwast/jsonrpc2-erlang",
Expand All @@ -33,14 +35,14 @@

{xref_checks, [
undefined_function_calls,
undefined_functions,
undefined_functions
%locals_not_used,
deprecated_function_calls,
deprecated_functions
%deprecated_function_calls,
%deprecated_functions
]}.

{plugins, [
{grpcbox_plugin, {git, "https://github.com/andymck/grpcbox_plugin.git", {branch, "andymck/ts-master"}}},
{grpcbox_plugin, {git, "https://github.com/andymck/grpcbox_plugin.git", {branch, "andymck/ts-master/combined-opts-and-template-changes"}}},
{rebar3_gpb_plugin, "2.15.0"},
{rebar3_eqc, "1.3.0"}
]}.
Expand Down
10 changes: 5 additions & 5 deletions rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{<<"base64url">>,{pkg,<<"base64url">>,<<"1.0.1">>},1},
{<<"blockchain">>,
{git,"https://github.com/helium/blockchain-core.git",
{ref,"943339691c1505c8a40ebaefd2046b29902c160f"}},
{ref,"1d2bd57b95923b939d51cf044a8472f912ca14ac"}},
0},
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.8.0">>},2},
{<<"chatterbox">>,
Expand Down Expand Up @@ -82,7 +82,7 @@
1},
{<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},3},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},2},
{<<"gpb">>,{pkg,<<"gpb">>,<<"4.19.2">>},2},
{<<"gpb">>,{pkg,<<"gpb">>,<<"4.19.2">>},1},
{<<"gproc">>,{pkg,<<"gproc">>,<<"0.8.0">>},2},
{<<"grpc_client">>,
{git,"https://github.com/Bluehouse-Technology/grpc_client.git",
Expand All @@ -91,7 +91,7 @@
{<<"grpc_lib">>,
{git,"https://github.com/Bluehouse-Technology/grpc_lib",
{ref,"a77686b55b60b052d6c7cd927d04dde429bbdabf"}},
1},
0},
{<<"grpcbox">>,
{git,"https://github.com/andymck/grpcbox.git",
{ref,"fbf689bb9c25fc2943155c891974e1f745ce5ac7"}},
Expand All @@ -107,7 +107,7 @@
0},
{<<"helium_proto">>,
{git,"https://github.com/helium/proto.git",
{ref,"30f17c5d1a7942297923f4e743c681c46f917fc3"}},
{ref,"f743a80e534bdc78805e3c5438cb466bec3c0b6f"}},
1},
{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},3},
{<<"http2_client">>,
Expand Down Expand Up @@ -176,7 +176,7 @@
3},
{<<"sibyl">>,
{git,"https://github.com/helium/sibyl.git",
{ref,"4d16f60fba28eafd70e256976cbe3644911ac16b"}},
{ref,"e1227336e4aa919d1beb081e06d683c627664d54"}},
0},
{<<"sidejob">>,{pkg,<<"sidejob">>,<<"2.1.0">>},2},
{<<"small_ints">>,{pkg,<<"small_ints">>,<<"0.1.0">>},4},
Expand Down
9 changes: 5 additions & 4 deletions src/cli/miner_cli_info.erl
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ info_region_usage() ->
].

info_region(["info", "region"], [], []) ->
case miner_lora:region() of
LoraMod = application:get_env(miner, lora_mod, miner_lora),
case LoraMod:region() of
{ok, undefined} ->
{exit_status, 1, [clique_status:text("undefined")]};
{ok, Region} ->
Expand Down Expand Up @@ -271,7 +272,7 @@ info_onboarding(["info", "onboarding"], [], Flags) ->
ProvidedKey
end,
PayerOutputOnly = proplists:is_defined(just_payer, Flags),

case OnboardingKey of
undefined ->
error_message("This miner has no onboarding key, no onboarding info available.");
Expand All @@ -293,7 +294,7 @@ info_onboarding(["info", "onboarding"], [], Flags) ->
%%
-spec onboarding_info_for_key(string()) -> {ok, {map(), map()}} | notfound | {error, non_neg_integer()}.
onboarding_info_for_key(OnboardingKey) ->
Url = ?ONBOARDING_API_URL_BASE ++ "/hotspots/" ++ OnboardingKey,
Url = ?ONBOARDING_API_URL_BASE ++ "/hotspots/" ++ OnboardingKey,
case get_api_json_as_map(Url) of
{ok, OnboardingResult} ->
OnboardingData = maps:get(<<"data">>, OnboardingResult),
Expand All @@ -308,7 +309,7 @@ onboarding_info_for_key(OnboardingKey) ->
-spec clique_status_for_onboarding_info({map(), map()}, boolean()) -> list().
clique_status_for_onboarding_info({MinerData, MakerData}, PayerOutputOnly) ->
case PayerOutputOnly of
true ->
true ->
PayerAddress = maps:get(<<"address">>, MakerData),
PayerAddressString = binary_to_list(PayerAddress),
[ clique_status:text(PayerAddressString) ];
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/miner_discovery_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ handle_data(server, Data, State) ->
Sig
]);
true ->
case miner_lora:location_ok() of
LoraMod = application:get_env(miner, lora_mod, miner_lora),
case LoraMod:location_ok() of
true ->
miner_discovery_worker:start(Packets);
false ->
Expand Down
49 changes: 47 additions & 2 deletions src/handlers/miner_hbbft_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
%% TODO No need to pass Meta when tuple. Use sum type: {map, Meta} | tuple
metadata(Version, Meta, Chain) ->
{ok, HeadHash} = blockchain:head_hash(Chain),
Ledger = blockchain:ledger(Chain),
{ok, N} = blockchain:config(?num_consensus_members, Ledger),
%% construct a 2-tuple of the system time and the current head block hash as our stamp data
case Version of
tuple ->
Expand Down Expand Up @@ -93,7 +95,37 @@ metadata(Version, Meta, Chain) ->
lager:info("no snapshot interval configured"),
ChainMeta0
end,
t2b(maps:merge(Meta, ChainMeta))
ChainMeta1 =
case blockchain:config(?poc_challenger_type, Ledger) of
{ok, validator} ->
%% generate a set of ephemeral keys for POC usage
%% the hashes of the public keys are added to metadata
ChallengeRate =
case blockchain:config(?poc_challenge_rate, Ledger) of
{ok, CR} -> CR;
_ -> 1
end,
lager:debug("poc challenge rate ~p", [ChallengeRate] ),
%% if a val is in the ignore list then dont generate poc keys for it
%% TODO: this is a temp hack. remove when testing finished
IgnoreVals = application:get_env(sibyl, validator_ignore_list, []),
SelfPubKeyBin = blockchain_swarm:pubkey_bin(),
case not lists:member(SelfPubKeyBin, IgnoreVals) of
true ->
{EmpKeys, EmpKeyHashes} = generate_ephemeral_keys(N, ChallengeRate),
lager:debug("poc ephemeral keys ~p", [EmpKeys]),
lager:debug("node ~p generating poc ephemeral key hashes ~p", [SelfPubKeyBin, EmpKeyHashes]),
ok = miner_poc_mgr:save_poc_keys(Height, EmpKeys),
maps:put(poc_keys, {SelfPubKeyBin, EmpKeyHashes}, ChainMeta);
false ->
ChainMeta
end;
_ ->
ChainMeta

end,
lager:info("ChainMeta1 ~p", [ChainMeta1]),
t2b(maps:merge(Meta, ChainMeta1))
end.

init([Members, Id, N, F, BatchSize, SK, Chain]) ->
Expand All @@ -119,7 +151,8 @@ init([Members, Id, N, F, BatchSize, SK, Chain, Round, Buf]) ->
signatures_required = N - F,
hbbft = HBBFT,
swarm_keys = {MyPubKey, SignFun}, % For re-signing on var-autoskip
chain = Chain1}}.
chain = Chain1
}}.

handle_command(start_acs, State) ->
case hbbft:start_on_demand(State#state.hbbft) of
Expand Down Expand Up @@ -821,6 +854,18 @@ bin_to_msg(<<Bin/binary>>) ->
{error, truncated}
end.

-spec generate_ephemeral_keys(pos_integer(), pos_integer()) ->{[#{secret => libp2p_crypto:privkey(), public => libp2p_crypto:pubkey()}], [binary()]}.
generate_ephemeral_keys(N, ChallengeRate) ->
NumKeys = max(1, trunc(ChallengeRate / (((N-1)/3) * 2 ))),
lists:foldl(
fun(_N, {AccKeys, AccHashes})->
Keys = libp2p_crypto:generate_keys(ecc_compact),
#{public := OnionCompactKey} = Keys,
OnionHash = crypto:hash(sha256, libp2p_crypto:pubkey_to_bin(OnionCompactKey)),
{[Keys | AccKeys], [OnionHash | AccHashes]}
end,
{[], []}, lists:seq(1, NumKeys)).

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

Expand Down
3 changes: 2 additions & 1 deletion src/jsonrpc/miner_jsonrpc_info.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ handle_rpc(<<"info_p2p_status">>, []) ->
height => ?TO_VALUE(list_to_integer(Height))
};
handle_rpc(<<"info_region">>, []) ->
LoraMod = application:get_env(miner, lora_mod, miner_lora),
R =
case miner_lora:region() of
case LoraMod:region() of
{ok, undefined} -> null;
{ok, Region} -> atom_to_binary(Region, utf8)
end,
Expand Down
Loading

0 comments on commit 4bedc19

Please sign in to comment.