From 1b534e2fffe83659d372dc440f6ee028a5b43357 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Sun, 9 Aug 2020 18:55:32 +0200 Subject: [PATCH 1/2] pallet-evm: avoid double fee payment --- frame/evm/src/lib.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index 013da0cca97e5..44e686a7e8b95 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -33,7 +33,7 @@ use codec::{Encode, Decode}; #[cfg(feature = "std")] use serde::{Serialize, Deserialize}; use frame_support::{ensure, decl_module, decl_storage, decl_event, decl_error}; -use frame_support::weights::Weight; +use frame_support::weights::{Weight, Pays}; use frame_support::traits::{Currency, ExistenceRequirement, Get}; use frame_system::RawOrigin; use sp_core::{U256, H256, H160, Hasher}; @@ -315,7 +315,10 @@ decl_module! { } /// Issue an EVM call operation. This is similar to a message call transaction in Ethereum. - #[weight = (*gas_price).saturated_into::().saturating_mul(*gas_limit as Weight)] + #[weight = ( + (*gas_price).saturated_into::().saturating_mul(*gas_limit as Weight), + Pays::No, + )] fn call( origin, source: H160, @@ -351,7 +354,10 @@ decl_module! { /// Issue an EVM create operation. This is similar to a contract creation transaction in /// Ethereum. - #[weight = (*gas_price).saturated_into::().saturating_mul(*gas_limit as Weight)] + #[weight = ( + (*gas_price).saturated_into::().saturating_mul(*gas_limit as Weight), + Pays::No, + )] fn create( origin, source: H160, @@ -384,7 +390,10 @@ decl_module! { } /// Issue an EVM create2 operation. - #[weight = (*gas_price).saturated_into::().saturating_mul(*gas_limit as Weight)] + #[weight = ( + (*gas_price).saturated_into::().saturating_mul(*gas_limit as Weight), + Pays::No, + )] fn create2( origin, source: H160, From 25506e7a50fb5e1e0f561d73fd967a2d4be49674 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 13 Aug 2020 01:28:09 +0200 Subject: [PATCH 2/2] Only skip fee payment for successful calls --- frame/evm/src/lib.rs | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index 44e686a7e8b95..4bf105ad8aa48 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -35,11 +35,10 @@ use serde::{Serialize, Deserialize}; use frame_support::{ensure, decl_module, decl_storage, decl_event, decl_error}; use frame_support::weights::{Weight, Pays}; use frame_support::traits::{Currency, ExistenceRequirement, Get}; +use frame_support::dispatch::DispatchResultWithPostInfo; use frame_system::RawOrigin; use sp_core::{U256, H256, H160, Hasher}; -use sp_runtime::{ - DispatchResult, AccountId32, traits::{UniqueSaturatedInto, SaturatedConversion, BadOrigin}, -}; +use sp_runtime::{AccountId32, traits::{UniqueSaturatedInto, SaturatedConversion, BadOrigin}}; use sha3::{Digest, Keccak256}; pub use evm::{ExitReason, ExitSucceed, ExitError, ExitRevert, ExitFatal}; use evm::Config; @@ -315,10 +314,7 @@ decl_module! { } /// Issue an EVM call operation. This is similar to a message call transaction in Ethereum. - #[weight = ( - (*gas_price).saturated_into::().saturating_mul(*gas_limit as Weight), - Pays::No, - )] + #[weight = (*gas_price).saturated_into::().saturating_mul(*gas_limit as Weight)] fn call( origin, source: H160, @@ -328,7 +324,7 @@ decl_module! { gas_limit: u32, gas_price: U256, nonce: Option, - ) -> DispatchResult { + ) -> DispatchResultWithPostInfo { T::CallOrigin::ensure_address_origin(&source, origin)?; match Self::execute_call( @@ -349,15 +345,12 @@ decl_module! { }, } - Ok(()) + Ok(Pays::No.into()) } /// Issue an EVM create operation. This is similar to a contract creation transaction in /// Ethereum. - #[weight = ( - (*gas_price).saturated_into::().saturating_mul(*gas_limit as Weight), - Pays::No, - )] + #[weight = (*gas_price).saturated_into::().saturating_mul(*gas_limit as Weight)] fn create( origin, source: H160, @@ -366,7 +359,7 @@ decl_module! { gas_limit: u32, gas_price: U256, nonce: Option, - ) -> DispatchResult { + ) -> DispatchResultWithPostInfo { T::CallOrigin::ensure_address_origin(&source, origin)?; match Self::execute_create( @@ -386,14 +379,11 @@ decl_module! { }, } - Ok(()) + Ok(Pays::No.into()) } /// Issue an EVM create2 operation. - #[weight = ( - (*gas_price).saturated_into::().saturating_mul(*gas_limit as Weight), - Pays::No, - )] + #[weight = (*gas_price).saturated_into::().saturating_mul(*gas_limit as Weight)] fn create2( origin, source: H160, @@ -403,7 +393,7 @@ decl_module! { gas_limit: u32, gas_price: U256, nonce: Option, - ) -> DispatchResult { + ) -> DispatchResultWithPostInfo { T::CallOrigin::ensure_address_origin(&source, origin)?; match Self::execute_create2( @@ -424,7 +414,7 @@ decl_module! { }, } - Ok(()) + Ok(Pays::No.into()) } } }