Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1403 from PaulVMo/h3dex-remove-gateway-fix
Browse files Browse the repository at this point in the history
bugfix for removing gateway from h3dex
  • Loading branch information
evanmcc authored Jun 24, 2022
2 parents a394008 + 84deb8f commit e46ddc3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
3 changes: 3 additions & 0 deletions include/blockchain_vars.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@
%% max number of hexes to GC in the h3dex per block: integer
-define(h3dex_gc_width, h3dex_gc_width).

%% determines whether or not to use the fix for a bug in removing gateways from h3dex : boolean
-define(h3dex_remove_gw_fix, h3dex_remove_gw_fix).

%% the version number of poc targeting in use: integer
%% if not set, code paths with default to 3 ( blockchain_poc_target_v3 )
-define(poc_targeting_version, poc_targeting_version).
Expand Down
26 changes: 17 additions & 9 deletions src/ledger/v1/blockchain_ledger_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5138,16 +5138,24 @@ remove_gw_from_h3dex(Hex, GWAddr, Res, Ledger) ->
{ok, BinGws} ->
case lists:delete(GWAddr, binary_to_term(BinGws)) of
[] ->
case count_gateways_in_hex(h3:parent(Hex, Res), Ledger) of
0 ->
%% removing a hex means we need to recalculate the set of populated
%% hexes
build_random_hex_targeting_lookup(Res, Ledger);
%% need to remove the hex and maybe recalc targeting lookup if no gateways remain in parent hex
%% includes chain var protected bug fix
case config(?h3dex_remove_gw_fix, Ledger) of
%% if fix enabled, delete the hex first, then count the parent hex's gateways
{ok, true} ->
cache_delete(Ledger, H3CF, BinHex),
case count_gateways_in_hex(h3:parent(Hex, Res), Ledger) of
0 -> build_random_hex_targeting_lookup(Res, Ledger);
_ -> ok
end;
%% otherwise, keep the wrong behavior of counting gateways then deleting the hex
_ ->
ok
end,

cache_delete(Ledger, H3CF, BinHex);
case count_gateways_in_hex(h3:parent(Hex, Res), Ledger) of
0 -> build_random_hex_targeting_lookup(Res, Ledger);
_ -> ok
end,
cache_delete(Ledger, H3CF, BinHex)
end;
NewGWs ->
cache_put(Ledger, H3CF, BinHex, term_to_binary(lists:sort(NewGWs), [compressed]))
end;
Expand Down
5 changes: 5 additions & 0 deletions src/transactions/v1/blockchain_txn_vars_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,11 @@ validate_var(?polyfill_resolution, Value) ->
validate_int(Value, "polyfill_resolution", 0, 15, false);
validate_var(?h3dex_gc_width, Value) ->
validate_int(Value, "h3dex_gc_width", 1, 10000, false);
validate_var(?h3dex_remove_gw_fix, Value) ->
case Value of
Val when is_boolean(Val) -> ok;
_ -> throw({error, {h3dex_gw_remove_fix, Value}})
end;
validate_var(?poc_target_pool_size, Value) ->
validate_int(Value, "poc_target_pool_size", 1, 1000000, false);
validate_var(?poc_targeting_version, Value) ->
Expand Down

0 comments on commit e46ddc3

Please sign in to comment.