Skip to content

Commit e6378ab

Browse files
committed
dont reactive unasserted GWs
1 parent 88c6850 commit e6378ab

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

src/grpc/helium_stream_poc_impl.erl

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,29 @@ check_if_reactivated_gw(GWAddr, Chain) ->
169169
{ok, CurHeight} = blockchain_ledger_v1:current_height(Ledger),
170170
case blockchain:config(poc_activity_filter_enabled, Ledger) of
171171
{ok, true} ->
172-
case blockchain_ledger_v1:find_gateway_last_challenge(GWAddr, Ledger) of
173-
{error, _Reason} ->
174-
%% if GW not found or some other issue, ignore
172+
%% TODO: quicker to perform two denorm reads that one find_gateway_info?
173+
GWLocation = get_gateway_location(GWAddr, Ledger),
174+
GWLastChallenge = get_gateway_last_challenge (GWAddr, Ledger),
175+
case {GWLocation, GWLastChallenge} of
176+
{undefined, _} ->
177+
%% if GW not asserted then do nothing further
175178
ok;
176-
{ok, undefined} ->
177-
%% No activity set, so include in list to reactivate
178-
%% this means it will become available for POC
179+
{error, _} ->
180+
%% failed to get gw location
181+
%% maybe gw is not on chain - do nothing
182+
ok;
183+
{_, error} ->
184+
%% failed to get gw last challenger
185+
%% maybe gw is not on chain - do nothing
186+
ok;
187+
{_Loc, undefined} ->
188+
%% No activity set, add to reactivation list
189+
lager:debug("reactivating gw ~p", [?TO_ANIMAL_NAME(GWAddr)]),
179190
true = sibyl_poc_mgr:cache_reactivated_gw(GWAddr);
180-
{ok, C} ->
181-
{ok, MaxActivityAge} =
182-
case
183-
blockchain:config(
184-
?harmonize_activity_on_hip17_interactivity_blocks, Ledger
185-
)
186-
of
187-
{ok, true} -> blockchain:config(?hip17_interactivity_blocks, Ledger);
188-
_ -> blockchain:config(?poc_v4_target_challenge_age, Ledger)
189-
end,
190-
case (CurHeight - C) > MaxActivityAge of
191-
true ->
191+
{_Loc, LastActivity} when is_integer(LastActivity) ->
192+
MaxActivityAge = blockchain_utils:max_activity_age(Ledger),
193+
case blockchain_utils:is_gw_active(CurHeight, LastActivity, MaxActivityAge) of
194+
false ->
192195
lager:debug("reactivating gw ~p", [?TO_ANIMAL_NAME(GWAddr)]),
193196
true = sibyl_poc_mgr:cache_reactivated_gw(GWAddr);
194197
false ->
@@ -209,3 +212,19 @@ subscribe_to_events(Addr) ->
209212
POCTopic = sibyl_utils:make_poc_topic(Addr),
210213
[sibyl_bus:sub(E, self()) || E <- [?EVENT_ACTIVITY_CHECK_NOTIFICATION, POCTopic]],
211214
ok.
215+
216+
-spec get_gateway_last_challenge(libp2p_crypto:pubkey_bin(), blockchain_ledger_v1:ledger()) -> error | undefined | pos_integer().
217+
get_gateway_last_challenge(GWAddr, Ledger) ->
218+
case blockchain_ledger_v1:find_gateway_last_challenge(GWAddr, Ledger) of
219+
{error, _Reason} -> error;
220+
{ok, undefined} -> undefined;
221+
{ok, V} -> V
222+
end.
223+
224+
-spec get_gateway_location(libp2p_crypto:pubkey_bin(), blockchain_ledger_v1:ledger()) -> error | undefined | integer().
225+
get_gateway_location(GWAddr, Ledger) ->
226+
case blockchain_ledger_v1:find_gateway_location(GWAddr, Ledger) of
227+
{error, _Reason} -> error;
228+
{ok, undefined} -> undefined;
229+
{ok, V} -> V
230+
end.

src/sibyl_poc_mgr.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ cache_reactivated_gw(GWAddr) ->
7575

7676
cached_reactivated_gws() ->
7777
L = ets:tab2list(?REACTIVATED_GWS),
78-
[Addr || {Addr} <- L].
78+
lists:reverse([Addr || {Addr} <- L]).
7979

8080
delete_reactivated_gws(L) ->
8181
[ets:delete(?REACTIVATED_GWS, GWAddr) || GWAddr <- L].

0 commit comments

Comments
 (0)