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

Commit

Permalink
Updates and use the var hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagabond committed Feb 15, 2022
1 parent 79f35ff commit a8701aa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/blockchain_vars.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
%% determines which hexing type to use for gateways: hex_h3dex | h3dex or not set
%% hex_h3dex will result in both hexes and h3dex being updated
%% h3dex will result in only h3dex being updated
%% not set will result in hexes being updated
%% not set will result in both hexes and h3dex being updated
-define(poc_hexing_type, poc_hexing_type).

%% max number of hexes to GC in the h3dex per block: integer
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/v1/blockchain_ledger_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4416,7 +4416,7 @@ add_gw_to_h3dex(Hex, GWAddr, Res, Ledger) ->
BinHex = h3_to_key(Hex),
case cache_get(Ledger, H3CF, BinHex, []) of
not_found ->
case count_gateways_in_hex(h3:parent(Hex, 5), Ledger) of
case count_gateways_in_hex(h3:parent(Hex, Res), Ledger) of
0 ->
%% populating a hex means we need to recalculate the set of populated
%% hexes
Expand Down
30 changes: 30 additions & 0 deletions src/transactions/v1/blockchain_txn_vars_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,40 @@ process_hooks(Vars, Unsets, Ledger) ->
%% Separate out hook functions and call them in separate functions below the hook section.

-spec var_hook(Var :: atom(), Value :: any(), Ledger :: blockchain_ledger_v1:ledger()) -> ok.
var_hook(?poc_targeting_version, 4, Ledger) ->
%% v4 targeting enabled, build the h3dex lookup
{ok, Res} = blockchain_ledger_v1:config(?poc_target_hex_parent_res, Ledger),
blockchain_ledger_v1:build_random_hex_targeting_lookup(Res, Ledger),
ok;
var_hook(?poc_targeting_version, 3, Ledger) ->
%% v3 targeting enabled, remove the h3dex lookup
blockchain_ledger_v1:clean_random_hex_targeting_lookup(Ledger),
ok;
var_hook(?poc_target_hex_parent_res, Value, Ledger) ->
%% targeting resolution changed, rebuild h3dex lookup
blockchain_ledger_v1:clean_random_hex_targeting_lookup(Ledger),
blockchain_ledger_v1:build_random_hex_targeting_lookup(Value, Ledger),
ok;
var_hook(?poc_hexing_type, h3dex, Ledger) ->
%% the hexes keys should be safe to remove now
blockchain_ledger_v1:clean_all_hexes(Ledger),
ok;
var_hook(?poc_hexing_type, hex_h3dex, Ledger) ->
%% rebuild hexes since we're back to updating them
blockchain:bootstrap_hexes(Ledger),
ok;
var_hook(_Var, _Value, _Ledger) ->
ok.

-spec unset_hook(Var :: atom(), Ledger :: blockchain_ledger_v1:ledger()) -> ok.
unset_hook(?poc_targeting_version, Ledger) ->
%% going back to the default, which is v3 so remove the h3dex lookup
blockchain_ledger_v1:clean_random_hex_targeting_lookup(Ledger),
ok;
unset_hook(?poc_hexing_type, Ledger) ->
%% rebuild hexes since we're back to updating them
blockchain:bootstrap_hexes(Ledger),
ok;
unset_hook(_Var, _Ledger) ->
ok.

Expand Down

0 comments on commit a8701aa

Please sign in to comment.