From 81d8c90495790b809a0844c1b92f612bf4087071 Mon Sep 17 00:00:00 2001 From: Andrew McKenzie Date: Wed, 11 May 2022 19:22:22 +0100 Subject: [PATCH] reject poc requests txns if chainvar set --- include/blockchain_vars.hrl | 3 +++ src/transactions/v1/blockchain_txn_poc_request_v1.erl | 6 +++++- src/transactions/v1/blockchain_txn_vars_v1.erl | 7 ++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/blockchain_vars.hrl b/include/blockchain_vars.hrl index d80aa18057..cdc5cd1791 100644 --- a/include/blockchain_vars.hrl +++ b/include/blockchain_vars.hrl @@ -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. diff --git a/src/transactions/v1/blockchain_txn_poc_request_v1.erl b/src/transactions/v1/blockchain_txn_poc_request_v1.erl index 4951852266..046bc2f52f 100644 --- a/src/transactions/v1/blockchain_txn_poc_request_v1.erl +++ b/src/transactions/v1/blockchain_txn_poc_request_v1.erl @@ -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 @@ -274,7 +279,6 @@ maybe_log_duration(Type, Start) -> _ -> ok end. - %% ------------------------------------------------------------------ %% EUNIT Tests %% ------------------------------------------------------------------ diff --git a/src/transactions/v1/blockchain_txn_vars_v1.erl b/src/transactions/v1/blockchain_txn_vars_v1.erl index e00c0a8a6c..3613949983 100644 --- a/src/transactions/v1/blockchain_txn_vars_v1.erl +++ b/src/transactions/v1/blockchain_txn_vars_v1.erl @@ -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; + _ -> 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) ->