Skip to content

Commit

Permalink
val pool as challenger changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Mar 16, 2022
1 parent e122733 commit 8076fbf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

{deps, [
lager,
{blockchain, {git, "https://github.com/helium/blockchain-core.git", {branch, "andymck/poc-grpc-v2"}}},
{blockchain, {git, "https://github.com/helium/blockchain-core.git", {branch, "andymck/poc-grpc-v2-plus-vals-as-chall"}}},
{grpcbox, {git, "https://github.com/andymck/grpcbox.git", {branch, "andymck/ts-master/stream-handler-changes"}}}
]}.

Expand Down
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,"1d2bd57b95923b939d51cf044a8472f912ca14ac"}},
{ref,"ba0e51b505b614f91356b369503f8c627dc0dcb0"}},
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,"5e663437950c3e6d71fbd230e1435005be26603f"}},
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

0 comments on commit 8076fbf

Please sign in to comment.