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

reject poc requests txns if chainvar set #1339

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/blockchain_vars.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@
%% from POC targets :: boolean()
-define(poc_activity_filter_enabled, poc_activity_filter_enabled).

%% If set to true, all incoming poc request txns will be rejected : boolean
-define(poc_reject_requests, poc_reject_requests).

%% Number of blocks to wait before a hotspot can be eligible to participate in a poc
%% challenge. This would avoid new hotspots getting challenged before they sync to an
%% acceptable height.
Expand Down
6 changes: 5 additions & 1 deletion src/transactions/v1/blockchain_txn_poc_request_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ is_valid(Txn, Chain) ->
BaseTxn = Txn#blockchain_txn_poc_request_v1_pb{signature = <<>>},
EncodedTxn = blockchain_txn_poc_request_v1_pb:encode_msg(BaseTxn),

%% if this var is enabled reject request txns
case blockchain:config(?poc_reject_requests, Ledger) of
{ok, true} -> throw({error, poc_requests_not_accepted});
_ -> ok
end,
case blockchain_txn:validate_fields([{{secret_hash, ?MODULE:secret_hash(Txn)}, {binary, 32}},
{{onion_key_hash, ?MODULE:secret_hash(Txn)}, {binary, 32}},
{{block_hash, ?MODULE:secret_hash(Txn)}, {binary, 32}}]) of
Expand Down Expand Up @@ -274,7 +279,6 @@ maybe_log_duration(Type, Start) ->
_ -> ok
end.


%% ------------------------------------------------------------------
%% EUNIT Tests
%% ------------------------------------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion src/transactions/v1/blockchain_txn_vars_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,12 @@ validate_var(?poc_proposal_gc_window_check, Value) ->
false -> ok;
_ -> throw({error, {poc_proposal_gc_window_check, Value}})
end;

validate_var(?poc_reject_requests, Value) ->
case Value of
true -> ok;
false -> ok;
Comment on lines +1040 to +1042
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case Value of
true -> ok;
false -> ok;
case Value of
Bool when is_boolean(Bool) -> ok;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally, I like

validate_var(?poc_reject_requests, Value) when is_boolean(Value) -> ok;
validate_var(?poc_reject_requests, Value) -> throw({error, {poc_reject_requests, Value}}).

but I know that multi-head style is controversial

_ -> throw({error, {poc_reject_requests, Value}})
end;
validate_var(?poc_challenge_sync_interval, Value) ->
validate_int(Value, "poc_challenge_sync_interval", 10, 1440, false);
validate_var(?poc_path_limit, undefined) ->
Expand Down