Skip to content

Commit 2f0746f

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

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

src/grpc/helium_stream_poc_impl.erl

Lines changed: 39 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,21 @@ 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()) ->
217+
error | undefined | pos_integer().
218+
get_gateway_last_challenge(GWAddr, Ledger) ->
219+
case blockchain_ledger_v1:find_gateway_last_challenge(GWAddr, Ledger) of
220+
{error, _Reason} -> error;
221+
{ok, undefined} -> undefined;
222+
{ok, V} -> V
223+
end.
224+
225+
-spec get_gateway_location(libp2p_crypto:pubkey_bin(), blockchain_ledger_v1:ledger()) ->
226+
error | undefined | integer().
227+
get_gateway_location(GWAddr, Ledger) ->
228+
case blockchain_ledger_v1:find_gateway_location(GWAddr, Ledger) of
229+
{error, _Reason} -> error;
230+
{ok, undefined} -> undefined;
231+
{ok, V} -> V
232+
end.

0 commit comments

Comments
 (0)