From b981f7beef9a436f10ecf459d4a4fc91bc9bea65 Mon Sep 17 00:00:00 2001 From: POA <33550681+poa@users.noreply.github.com> Date: Fri, 12 Nov 2021 13:06:19 +0300 Subject: [PATCH] Add validateServiceTransactionsTransition spec option --- .../miner/src/service_transaction_checker.rs | 2 +- crates/ethcore/src/client/client.rs | 82 ++++++++++--------- crates/ethcore/src/spec/spec.rs | 6 ++ crates/ethjson/src/spec/params.rs | 2 + 4 files changed, 51 insertions(+), 41 deletions(-) diff --git a/crates/concensus/miner/src/service_transaction_checker.rs b/crates/concensus/miner/src/service_transaction_checker.rs index 0ad74db88..d4ccfc8f6 100644 --- a/crates/concensus/miner/src/service_transaction_checker.rs +++ b/crates/concensus/miner/src/service_transaction_checker.rs @@ -45,7 +45,7 @@ impl ServiceTransactionChecker { ) -> Result { let sender = tx.sender(); // Skip checking the contract if the transaction does not have zero gas price - if !tx.tx().gas_price.is_zero() { + if !tx.has_zero_gas_price() { return Ok(false); } diff --git a/crates/ethcore/src/client/client.rs b/crates/ethcore/src/client/client.rs index 739d1696a..5cc2ef553 100644 --- a/crates/ethcore/src/client/client.rs +++ b/crates/ethcore/src/client/client.rs @@ -488,48 +488,50 @@ impl Importer { .epoch_transition(parent.number(), *header.parent_hash()) .is_some(); - // Check if zero gas price transactions are certified to be service transactions - // using the Certifier contract. If they are not certified, the block is treated as invalid. - let service_transaction_checker = self.miner.service_transaction_checker(); - if service_transaction_checker.is_some() { - match service_transaction_checker.unwrap().refresh_cache(client) { - Ok(true) => { - trace!(target: "client", "Service transaction cache was refreshed successfully"); - } - Ok(false) => { - trace!(target: "client", "Registrar or/and service transactions contract does not exist"); - } - Err(e) => { - error!(target: "client", "Error occurred while refreshing service transaction cache: {}", e) - } - }; - }; - for t in &block.transactions { - if t.has_zero_gas_price() { - match self.miner.service_transaction_checker() { - None => { - let e = "Service transactions are not allowed. You need to enable Certifier contract."; - warn!(target: "client", "Service tx checker error: {:?}", e); - bail!(e); + if header.number() >= engine.params().validate_service_transactions_transition { + // Check if zero gas price transactions are certified to be service transactions + // using the Certifier contract. If they are not certified, the block is treated as invalid. + let service_transaction_checker = self.miner.service_transaction_checker(); + if service_transaction_checker.is_some() { + match service_transaction_checker.unwrap().refresh_cache(client) { + Ok(true) => { + trace!(target: "client", "Service transaction cache was refreshed successfully"); } - Some(ref checker) => match checker.check(client, &t) { - Ok(true) => {} - Ok(false) => { - let e = format!( - "Service transactions are not allowed for the sender {:?}", - t.sender() - ); - warn!(target: "client", "Service tx checker error: {:?}", e); - bail!(e); - } - Err(e) => { - debug!(target: "client", "Unable to verify service transaction: {:?}", e); - warn!(target: "client", "Service tx checker error: {:?}", e); - bail!(e); - } - }, - } + Ok(false) => { + trace!(target: "client", "Registrar or/and service transactions contract does not exist"); + } + Err(e) => { + error!(target: "client", "Error occurred while refreshing service transaction cache: {}", e) + } + }; }; + for t in &block.transactions { + if t.has_zero_gas_price() { + match self.miner.service_transaction_checker() { + None => { + let e = "Service transactions are not allowed. You need to enable Certifier contract."; + warn!(target: "client", "Service tx checker error: {:?}", e); + bail!(e); + } + Some(ref checker) => match checker.check(client, &t) { + Ok(true) => {} + Ok(false) => { + let e = format!( + "Service transactions are not allowed for the sender {:?}", + t.sender() + ); + warn!(target: "client", "Service tx checker error: {:?}", e); + bail!(e); + } + Err(e) => { + debug!(target: "client", "Unable to verify service transaction: {:?}", e); + warn!(target: "client", "Service tx checker error: {:?}", e); + bail!(e); + } + }, + } + }; + } } // t_nb 8.0 Block enacting. Execution of transactions. diff --git a/crates/ethcore/src/spec/spec.rs b/crates/ethcore/src/spec/spec.rs index ca838906c..b50d859d3 100644 --- a/crates/ethcore/src/spec/spec.rs +++ b/crates/ethcore/src/spec/spec.rs @@ -191,6 +191,8 @@ pub struct CommonParams { pub eip1559_fee_collector: Option
, /// Block at which the fee collector should start being used. pub eip1559_fee_collector_transition: BlockNumber, + /// Block at which zero gas price transactions start being checked with Certifier contract. + pub validate_service_transactions_transition: BlockNumber, } impl CommonParams { @@ -475,6 +477,9 @@ impl From for CommonParams { eip1559_fee_collector_transition: p .eip1559_fee_collector_transition .map_or_else(BlockNumber::max_value, Into::into), + validate_service_transactions_transition: p + .validate_service_transactions_transition + .map_or_else(BlockNumber::max_value, Into::into), } } } @@ -752,6 +757,7 @@ impl Spec { params.transaction_permission_contract_transition, params.eip1559_fee_collector_transition, params.eip1559_base_fee_min_value_transition, + params.validate_service_transactions_transition, ]; // BUG: Rinkeby has homestead transition at block 1 but we can't reflect that in specs for non-Ethash networks if params.network_id == 0x4 { diff --git a/crates/ethjson/src/spec/params.rs b/crates/ethjson/src/spec/params.rs index 12936323b..9e157ba1b 100644 --- a/crates/ethjson/src/spec/params.rs +++ b/crates/ethjson/src/spec/params.rs @@ -166,6 +166,8 @@ pub struct Params { pub eip1559_fee_collector: Option
, /// Block at which the fee collector should start being used. pub eip1559_fee_collector_transition: Option, + /// Block at which zero gas price transactions start being checked with Certifier contract. + pub validate_service_transactions_transition: Option, } #[cfg(test)]