Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Andymck/poc grpc plus vals as chall #23

Merged
merged 3 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 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,"5881ad571903c1908fbbaed396a59bc7efa505ce"}},
{ref,"14e30b5e7f298e37ff51ff10ea45df749625833a"}},
0},
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.8.0">>},2},
{<<"chatterbox">>,
Expand Down Expand Up @@ -78,7 +78,7 @@
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.18.0">>},1},
{<<"helium_proto">>,
{git,"https://github.com/helium/proto.git",
{ref,"f743a80e534bdc78805e3c5438cb466bec3c0b6f"}},
{ref,"9ac2d99e591bb929219dbcadc0cd7e2a49d23526"}},
1},
{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},2},
{<<"idna">>,{pkg,<<"idna">>,<<"6.1.1">>},2},
Expand Down
19 changes: 16 additions & 3 deletions src/sibyl_mgr.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
-define(SIGFUN, sigfun).
-define(SERVER, ?MODULE).
-define(VALIDATORS, validators).
-define(VALIDATOR_COUNT, validator_count).
-define(ROUTING_CF_NAME, routing).
-define(STATE_CHANNEL_CF_NAME, state_channels).

-ifdef(TEST).
-define(VALIDATOR_CACHE_REFRESH, 5).
-define(VALIDATOR_CACHE_REFRESH, 1).
-else.
-define(VALIDATOR_CACHE_REFRESH, 100).
-endif.
Expand All @@ -30,6 +31,7 @@
-type event_types() :: [event_type()].
-type event() :: {event, binary(), any()} | {event, binary()}.
-type state() :: #state{}.
-type val_data() :: {libp2p_crypto:pubkey_bin(), string()}.

-export_type([event_type/0, event_types/0, event/0]).
%% ------------------------------------------------------------------
Expand All @@ -54,7 +56,8 @@
blockchain/0,
height/0,
sigfun/0,
validators/0
validators/0,
validator_count/0
]).

%% ------------------------------------------------------------------
Expand Down Expand Up @@ -113,14 +116,22 @@ sigfun() ->
_:_ -> undefined
end.

-spec validators() -> function() | undefined.
-spec validators() -> [val_data()].
validators() ->
try ets:lookup_element(?TID, ?VALIDATORS, 2) of
X -> X
catch
_:_ -> []
end.

-spec validator_count() -> integer().
validator_count() ->
try ets:lookup_element(?TID, ?VALIDATOR_COUNT, 2) of
X -> X
catch
_:_ -> 0
end.

make_ets_table() ->
ets:new(
?TID,
Expand Down Expand Up @@ -344,6 +355,8 @@ update_validator_cache(Ledger) ->
Ledger
),
_ = ets:insert(?TID, {?VALIDATORS, Vals}),
%% keep a count of the number of vals in our cache
_ = ets:insert(?TID, {?VALIDATOR_COUNT, length(Vals)}),
ok.

%% get a public route to the specified validator
Expand Down
4 changes: 1 addition & 3 deletions src/sibyl_poc_mgr.erl
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,15 @@ handle_add_block_event(
%% a POC will be active for each key
%% for each notify all GWs in the target region
%% telling them they have to contact the challenger to check if they are the actual target
{ok, CGMembers} = blockchain_ledger_v1:consensus_members(Ledger),
[
begin
ChallengerAddr = lists:nth(CGPos, CGMembers),
spawn_link(
fun() ->
run_poc_targetting(ChallengerAddr, Key, Ledger, BlockHash, Vars)
end
)
end
|| {CGPos, Key} <- PocEphemeralKeys
|| {ChallengerAddr, Key} <- PocEphemeralKeys
],
{noreply, State#state{}};
_ ->
Expand Down