From 2804b40a1c32fcc05dc6abac234fbe79f7b79622 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Sun, 9 Aug 2020 01:24:34 +0200 Subject: [PATCH] pallet-evm: move gas price check to execute_evm (#6837) --- substrate/frame/evm/src/lib.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/substrate/frame/evm/src/lib.rs b/substrate/frame/evm/src/lib.rs index 0dcc4526c7..013da0cca9 100644 --- a/substrate/frame/evm/src/lib.rs +++ b/substrate/frame/evm/src/lib.rs @@ -326,7 +326,6 @@ decl_module! { gas_price: U256, nonce: Option, ) -> DispatchResult { - ensure!(gas_price >= T::FeeCalculator::min_gas_price(), Error::::GasPriceTooLow); T::CallOrigin::ensure_address_origin(&source, origin)?; match Self::execute_call( @@ -335,7 +334,7 @@ decl_module! { input, value, gas_limit, - gas_price, + Some(gas_price), nonce, true, )? { @@ -362,7 +361,6 @@ decl_module! { gas_price: U256, nonce: Option, ) -> DispatchResult { - ensure!(gas_price >= T::FeeCalculator::min_gas_price(), Error::::GasPriceTooLow); T::CallOrigin::ensure_address_origin(&source, origin)?; match Self::execute_create( @@ -370,7 +368,7 @@ decl_module! { init, value, gas_limit, - gas_price, + Some(gas_price), nonce, true, )? { @@ -397,7 +395,6 @@ decl_module! { gas_price: U256, nonce: Option, ) -> DispatchResult { - ensure!(gas_price >= T::FeeCalculator::min_gas_price(), Error::::GasPriceTooLow); T::CallOrigin::ensure_address_origin(&source, origin)?; match Self::execute_create2( @@ -406,7 +403,7 @@ decl_module! { salt, value, gas_limit, - gas_price, + Some(gas_price), nonce, true, )? { @@ -486,7 +483,7 @@ impl Module { init: Vec, value: U256, gas_limit: u32, - gas_price: U256, + gas_price: Option, nonce: Option, apply_state: bool, ) -> Result<(ExitReason, H160, U256), Error> { @@ -518,7 +515,7 @@ impl Module { salt: H256, value: U256, gas_limit: u32, - gas_price: U256, + gas_price: Option, nonce: Option, apply_state: bool, ) -> Result<(ExitReason, H160, U256), Error> { @@ -552,7 +549,7 @@ impl Module { input: Vec, value: U256, gas_limit: u32, - gas_price: U256, + gas_price: Option, nonce: Option, apply_state: bool, ) -> Result<(ExitReason, Vec, U256), Error> { @@ -578,13 +575,21 @@ impl Module { source: H160, value: U256, gas_limit: u32, - gas_price: U256, + gas_price: Option, nonce: Option, apply_state: bool, f: F, ) -> Result<(ExitReason, R, U256), Error> where F: FnOnce(&mut StackExecutor>) -> (ExitReason, R), { + let gas_price = match gas_price { + Some(gas_price) => { + ensure!(gas_price >= T::FeeCalculator::min_gas_price(), Error::::GasPriceTooLow); + gas_price + }, + None => U256::zero(), + }; + let vicinity = Vicinity { gas_price, origin: source,