diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index f1c911008ae7..d64f21b9f50b 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -3066,7 +3066,7 @@ impl_runtime_apis! { storage_deposit_limit.unwrap_or(u128::MAX), pallet_revive::DebugInfo::UnsafeDebug, pallet_revive::CollectEvents::UnsafeCollect, - ).map(pallet_transaction_payment::Pallet::::compute_fee) + ) } fn call( diff --git a/substrate/frame/revive/src/lib.rs b/substrate/frame/revive/src/lib.rs index 79906e127c9b..76adbd490954 100644 --- a/substrate/frame/revive/src/lib.rs +++ b/substrate/frame/revive/src/lib.rs @@ -41,7 +41,6 @@ pub mod evm; pub mod test_utils; pub mod weights; -pub use crate::exec::MomentOf; use crate::{ exec::{AccountIdOf, ExecError, Executable, Ext, Key, Origin, Stack as ExecStack}, gas::GasMeter, @@ -68,7 +67,7 @@ use frame_system::{ pallet_prelude::{BlockNumberFor, OriginFor}, EventRecord, Pallet as System, }; -pub use primitives::*; +use pallet_transaction_payment::OnChargeTransaction; use scale_info::TypeInfo; use sp_core::{H160, H256, U256}; use sp_runtime::{ @@ -79,8 +78,10 @@ use sp_runtime::{ pub use crate::{ address::{create1, create2, AddressMapper, DefaultAddressMapper}, debug::Tracing, + exec::MomentOf, pallet::*, }; +pub use primitives::*; pub use weights::WeightInfo; #[cfg(doc)] @@ -89,6 +90,7 @@ pub use crate::wasm::SyscallDoc; type TrieId = BoundedVec>; type BalanceOf = <::Currency as Inspect<::AccountId>>::Balance; +type OnChargeTransactionBalanceOf = <::OnChargeTransaction as OnChargeTransaction>::Balance; type CodeVec = BoundedVec>; type EventRecordOf = EventRecord<::RuntimeEvent, ::Hash>; @@ -1149,10 +1151,14 @@ where storage_deposit_limit: BalanceOf, debug: DebugInfo, collect_events: CollectEvents, - ) -> EthContractResultDetails> + ) -> EthContractResult> where + T: pallet_transaction_payment::Config, + ::RuntimeCall: + Dispatchable, ::RuntimeCall: From>, ::RuntimeCall: Encode, + OnChargeTransactionBalanceOf: Into>, T::Nonce: Into, { use crate::evm::TransactionLegacyUnsigned; @@ -1191,12 +1197,18 @@ where } .into(); - EthContractResultDetails { - dispatch_info: dispatch_call.get_dispatch_info(), - len: dispatch_call.encode().len() as u32, + let dispatch_info = dispatch_call.get_dispatch_info(); + let len = dispatch_call.encode().len() as u32; + EthContractResult { gas_limit: result.gas_required, storage_deposit: result.storage_deposit.charge_or_zero(), result: result.result.map(|v| v.data), + fee: pallet_transaction_payment::Pallet::::compute_fee( + len as u32, + &dispatch_info, + 0u32.into(), + ) + .into(), } } else { let tx = TransactionLegacyUnsigned { @@ -1227,12 +1239,18 @@ where storage_deposit_limit: 0u32.into(), }; - return EthContractResultDetails { - dispatch_info: dispatch_call.get_dispatch_info(), + let dispatch_info = dispatch_call.get_dispatch_info(); + let len = dispatch_call.encode().len() as u32; + return EthContractResult { gas_limit: Default::default(), storage_deposit: Default::default(), - len: dispatch_call.encode().len() as u32, result: Err(>::DecodingFailed.into()), + fee: pallet_transaction_payment::Pallet::::compute_fee( + len as u32, + &dispatch_info, + 0u32.into(), + ) + .into(), } }; @@ -1255,12 +1273,18 @@ where } .into(); - EthContractResultDetails { - dispatch_info: dispatch_call.get_dispatch_info(), - len: dispatch_call.encode().len() as u32, + let dispatch_info = dispatch_call.get_dispatch_info(); + let len = dispatch_call.encode().len() as u32; + EthContractResult { gas_limit: result.gas_required, storage_deposit: result.storage_deposit.charge_or_zero(), result: result.result.map(|v| v.result.data), + fee: pallet_transaction_payment::Pallet::::compute_fee( + len as u32, + &dispatch_info, + 0u32.into(), + ) + .into(), } } } diff --git a/substrate/frame/revive/src/primitives.rs b/substrate/frame/revive/src/primitives.rs index e33b8914d010..513a6cbdb4d8 100644 --- a/substrate/frame/revive/src/primitives.rs +++ b/substrate/frame/revive/src/primitives.rs @@ -20,7 +20,7 @@ use crate::H160; use alloc::vec::Vec; use codec::{Decode, Encode, MaxEncodedLen}; -use frame_support::{dispatch::DispatchInfo, weights::Weight}; +use frame_support::weights::Weight; use pallet_revive_uapi::ReturnFlags; use scale_info::TypeInfo; use sp_runtime::{ @@ -83,40 +83,6 @@ pub struct ContractResult { } /// The result of the execution of a `eth_transact` call. -pub struct EthContractResultDetails { - /// The call's dispatch info. - pub dispatch_info: DispatchInfo, - /// Length of the encoded call. - pub len: u32, - /// Gas limit of the transaction. - pub gas_limit: Weight, - /// Storage deposit charged. - pub storage_deposit: Balance, - /// The execution result. - pub result: Result, DispatchError>, -} - -impl> EthContractResultDetails { - /// Map to a EthContractResult, using the provided compute_fee function. - /// - /// # Parameters - /// - /// - `compute_fee`: A function that takes the length of the encoded call, the dispatch info and - /// the tip and returns the fee. - pub fn map( - self, - compute_fee: impl FnOnce(u32, &DispatchInfo, Balance) -> Balance, - ) -> EthContractResult { - EthContractResult { - result: self.result, - gas_limit: self.gas_limit, - storage_deposit: self.storage_deposit, - fee: compute_fee(self.len, &self.dispatch_info, 0.into()), - } - } -} - -/// Similar to `EthContractResultDetails` but with the fee instead of dispatch info and len. #[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct EthContractResult { /// The fee charged for the execution.