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 #1359 from helium/jg/skip_receipt_val_var
Browse files Browse the repository at this point in the history
var gated bypass of witness validation
  • Loading branch information
evanmcc authored May 21, 2022
2 parents 3680616 + da211c1 commit ce5f544
Show file tree
Hide file tree
Showing 5 changed files with 385 additions and 15 deletions.
3 changes: 3 additions & 0 deletions include/blockchain_vars.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@
%% the number of random hexes to utilize when targeting: integer
-define(poc_target_pool_size, poc_target_pool_size).

%% whether or not to process validation of poc receipt witnesses
-define(poc_receipt_witness_validation, poc_receipt_witness_validation).

%%%
%%% score vars
%%%
Expand Down
2 changes: 2 additions & 0 deletions src/transactions/v1/blockchain_txn_vars_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,8 @@ validate_var(?poc_hexing_type, Value) ->
end;
validate_var(?poc_validator_ct_scale, Value) ->
validate_float(Value, "poc_validator_ct_scale", 0.1, 1.0);
validate_var(?poc_receipt_witness_validation, Value) when is_boolean(Value) -> ok;
validate_var(?poc_receipt_witness_validation, Value) -> throw({error, poc_receipt_witness_validation, Value});

%% score vars
validate_var(?alpha_decay, Value) ->
Expand Down
25 changes: 18 additions & 7 deletions src/transactions/v2/blockchain_txn_poc_receipts_v2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,13 @@ poc_particpants(Txn, Chain) ->
_ ->
{lists:nth(ElementPos - 1, Path), lists:nth(ElementPos - 1, Channels), lists:nth(ElementPos, Channels)}
end,
Witnesses = valid_witness_addrs(Element, WitnessChannel, Ledger),
Witnesses = case blockchain:config(?poc_receipt_witness_validation, Ledger) of
{ok, false} ->
UnvalidatedWitnesses = lists:reverse(blockchain_poc_path_element_v1:witnesses(Element)),
[W#blockchain_poc_witness_v1_pb.gateway || W <- UnvalidatedWitnesses];
_ ->
valid_witness_addrs(Element, WitnessChannel, Ledger)
end,
%% only include the challengee in the poc participants list
%% if we have received a receipt
ElemParticipants =
Expand Down Expand Up @@ -855,8 +861,8 @@ valid_receipt(PreviousElement, Element, Channel, Ledger) ->
Channel :: non_neg_integer(),
Ledger :: blockchain_ledger_v1:ledger()) -> blockchain_poc_witness_v1:poc_witnesses().
valid_witnesses(Element, Channel, Ledger) ->
TaggedWitnesses = tagged_witnesses(Element, Channel, Ledger),
[ W || {true, _, W} <- TaggedWitnesses ].
{ok, RegionVars} = blockchain_region_v1:get_all_region_bins(Ledger),
valid_witnesses(Element, Channel, RegionVars, Ledger).

valid_witnesses(Element, Channel, RegionVars, Ledger) ->
TaggedWitnesses = tagged_witnesses(Element, Channel, RegionVars, Ledger),
Expand All @@ -866,8 +872,8 @@ valid_witnesses(Element, Channel, RegionVars, Ledger) ->
Channel :: non_neg_integer(),
Ledger :: blockchain_ledger_v1:ledger()) -> [libp2p_crypto:pubkey_bin()].
valid_witness_addrs(Element, Channel, Ledger) ->
TaggedWitnesses = tagged_witnesses(Element, Channel, Ledger),
[ W#blockchain_poc_witness_v1_pb.gateway || {true, _, W} <- TaggedWitnesses ].
ValidWitnesses = valid_witnesses(Element, Channel, Ledger),
[W#blockchain_poc_witness_v1_pb.gateway || W <- ValidWitnesses].

-spec is_too_far(Limit :: any(),
SrcLoc :: h3:h3_index(),
Expand Down Expand Up @@ -943,7 +949,7 @@ tagged_witnesses(Element, Channel, RegionVars0, Ledger) ->
Limit = blockchain:config(?poc_distance_limit, Ledger),
Version = poc_version(Ledger),

lists:foldl(fun(Witness, Acc) ->
TaggedWitnesses = lists:foldl(fun(Witness, Acc) ->
DstPubkeyBin = blockchain_poc_witness_v1:gateway(Witness),
{ok, DestinationLoc} = blockchain_ledger_v1:find_gateway_location(DstPubkeyBin, Ledger),
%% case blockchain_region_v1:h3_to_region(DestinationLoc, Ledger, RegionVars) of
Expand Down Expand Up @@ -1036,7 +1042,12 @@ tagged_witnesses(Element, Channel, RegionVars0, Ledger) ->
end
end
end
end, [], Witnesses).
end, [], Witnesses),
WitnessCount = length(Witnesses),
TaggedWitnessCount = length(TaggedWitnesses),
lager:debug("filtered ~p of ~p witnesses for receipt ~p", [(WitnessCount - TaggedWitnessCount),
WitnessCount, blockchain_poc_path_element_v1:receipt(Element)]),
TaggedWitnesses.

-spec get_channels(Txn :: txn_poc_receipts(),
Chain :: blockchain:blockchain()) -> {ok, [non_neg_integer()]} | {error, any()}.
Expand Down
3 changes: 1 addition & 2 deletions src/transactions/v2/blockchain_txn_rewards_v2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1223,8 +1223,7 @@ poc_witness_reward(Txn, AccIn,
ValidWitnesses =
case get({KeyHash, ElemHash}) of
undefined ->
VW = TxnType:valid_witnesses(Elem, WitnessChannel,
RegionVars, Ledger),
VW = TxnType:valid_witnesses(Elem, WitnessChannel, RegionVars, Ledger),
put({KeyHash, ElemHash}, VW),
VW;
VW -> VW
Expand Down
Loading

0 comments on commit ce5f544

Please sign in to comment.