From 092fdbb74f2e3db495c8d333c29a7668628765b2 Mon Sep 17 00:00:00 2001 From: pgherveou Date: Wed, 18 Jun 2025 17:03:30 +0200 Subject: [PATCH 1/7] fix extension-weight --- substrate/frame/revive/src/lib.rs | 42 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/substrate/frame/revive/src/lib.rs b/substrate/frame/revive/src/lib.rs index 57b0c41cb613c..8cd66b9ceb7e9 100644 --- a/substrate/frame/revive/src/lib.rs +++ b/substrate/frame/revive/src/lib.rs @@ -1171,11 +1171,12 @@ where /// /// - `tx`: The Ethereum transaction to simulate. /// - `gas_limit`: The gas limit enforced during contract execution. - /// - `tx_fee`: A function that returns the fee for the given call and dispatch info. + /// - `tx_fee`: A function that returns the fee for the computed eth_transact and actual + /// dispatched call pub fn dry_run_eth_transact( mut tx: GenericTransaction, gas_limit: Weight, - tx_fee: impl Fn(Call, DispatchInfo) -> BalanceOf, + tx_fee: impl Fn(Call, ::RuntimeCall) -> BalanceOf, ) -> Result>, EthTransactError> where ::RuntimeCall: @@ -1247,7 +1248,7 @@ where }; // Dry run the call - let (mut result, dispatch_info) = match tx.to { + let (mut result, dispatch_call) = match tx.to { // A contract call. Some(dest) => { if dest == RUNTIME_PALLETS_ADDR { @@ -1258,19 +1259,20 @@ where ))); }; - let dispatch_info = dispatch_call.get_dispatch_info(); - if let Err(err) = dispatch_call.dispatch(RawOrigin::Signed(origin).into()) { + if let Err(err) = + dispatch_call.clone().dispatch(RawOrigin::Signed(origin).into()) + { return Err(EthTransactError::Message(format!( "Failed to dispatch call: {err:?}" ))); }; let result = EthTransactInfo { - gas_required: dispatch_info.total_weight(), + gas_required: dispatch_call.get_dispatch_info().total_weight(), ..Default::default() }; - (result, dispatch_info) + (result, dispatch_call) } else { // Dry run the call. let result = crate::Pallet::::bare_call( @@ -1291,7 +1293,7 @@ where }, Err(err) => { log::debug!(target: LOG_TARGET, "Failed to execute call: {err:?}"); - return extract_error(err) + return extract_error(err); }, }; @@ -1314,7 +1316,7 @@ where data: input.clone(), } .into(); - (result, dispatch_call.get_dispatch_info()) + (result, dispatch_call) } }, // A contract deployment @@ -1353,7 +1355,7 @@ where }, Err(err) => { log::debug!(target: LOG_TARGET, "Failed to instantiate: {err:?}"); - return extract_error(err) + return extract_error(err); }, }; @@ -1378,7 +1380,7 @@ where data: data.to_vec(), } .into(); - (result, dispatch_call.get_dispatch_info()) + (result, dispatch_call) }, }; @@ -1386,9 +1388,9 @@ where return Err(EthTransactError::Message("Invalid transaction".into())); }; - let eth_dispatch_call = + let eth_transact_call = crate::Call::::eth_transact { payload: unsigned_tx.dummy_signed_payload() }; - let fee = tx_fee(eth_dispatch_call, dispatch_info); + let fee = tx_fee(eth_transact_call, dispatch_call); let raw_gas = Self::evm_fee_to_gas(fee); let eth_gas = T::EthGasEncoder::encode(raw_gas, result.gas_required, result.storage_deposit); @@ -1547,7 +1549,7 @@ where precision: ConversionPrecision, ) -> Result, Error> { if value.is_zero() { - return Ok(Zero::zero()) + return Ok(Zero::zero()); } let (quotient, remainder) = value.div_mod(T::NativeToEthRatio::get().into()); @@ -1758,15 +1760,21 @@ macro_rules! impl_runtime_apis_plus_revive { sp_runtime::traits::Block as BlockT }; - let tx_fee = |pallet_call, mut dispatch_info: $crate::DispatchInfo| { + let tx_fee = |eth_transact_call, dispatch_call: ::RuntimeCall| { + // Build the eth_transact call let call = - ::RuntimeCall::from(pallet_call); + ::RuntimeCall::from(eth_transact_call); + + // Get the dispatch info of the actual call dispatched + let mut dispatch_info = dispatch_call.get_dispatch_info(); dispatch_info.extension_weight = - <$EthExtra>::get_eth_extension(0, 0u32.into()).weight(&call); + <$EthExtra>::get_eth_extension(0, 0u32.into()).weight(&dispatch_call); + // Build the extrinsic let uxt: ::Extrinsic = $crate::sp_runtime::generic::UncheckedExtrinsic::new_bare(call).into(); + // Compute the fee of the extrinsic $crate::pallet_transaction_payment::Pallet::::compute_fee( uxt.encoded_size() as u32, &dispatch_info, From 5a90e75c02d82b3ae5db2519e22a49c73676a826 Mon Sep 17 00:00:00 2001 From: pgherveou Date: Wed, 18 Jun 2025 17:09:27 +0200 Subject: [PATCH 2/7] fix --- substrate/frame/revive/src/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/substrate/frame/revive/src/lib.rs b/substrate/frame/revive/src/lib.rs index 8cd66b9ceb7e9..c1fd3d64b99fd 100644 --- a/substrate/frame/revive/src/lib.rs +++ b/substrate/frame/revive/src/lib.rs @@ -1176,7 +1176,7 @@ where pub fn dry_run_eth_transact( mut tx: GenericTransaction, gas_limit: Weight, - tx_fee: impl Fn(Call, ::RuntimeCall) -> BalanceOf, + tx_fee: impl Fn(::RuntimeCall, ::RuntimeCall) -> BalanceOf, ) -> Result>, EthTransactError> where ::RuntimeCall: @@ -1390,7 +1390,7 @@ where let eth_transact_call = crate::Call::::eth_transact { payload: unsigned_tx.dummy_signed_payload() }; - let fee = tx_fee(eth_transact_call, dispatch_call); + let fee = tx_fee(eth_transact_call.into(), dispatch_call); let raw_gas = Self::evm_fee_to_gas(fee); let eth_gas = T::EthGasEncoder::encode(raw_gas, result.gas_required, result.storage_deposit); @@ -1760,11 +1760,7 @@ macro_rules! impl_runtime_apis_plus_revive { sp_runtime::traits::Block as BlockT }; - let tx_fee = |eth_transact_call, dispatch_call: ::RuntimeCall| { - // Build the eth_transact call - let call = - ::RuntimeCall::from(eth_transact_call); - + let tx_fee = |call: ::RuntimeCall, dispatch_call: ::RuntimeCall| { // Get the dispatch info of the actual call dispatched let mut dispatch_info = dispatch_call.get_dispatch_info(); dispatch_info.extension_weight = From eadfed36232e721069eebb4563a47c6106e457e8 Mon Sep 17 00:00:00 2001 From: pgherveou Date: Wed, 18 Jun 2025 20:56:27 +0200 Subject: [PATCH 3/7] use decode_with_ref_limit --- substrate/frame/revive/src/evm/runtime.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/substrate/frame/revive/src/evm/runtime.rs b/substrate/frame/revive/src/evm/runtime.rs index c6603173753b2..13e77c7a30a98 100644 --- a/substrate/frame/revive/src/evm/runtime.rs +++ b/substrate/frame/revive/src/evm/runtime.rs @@ -24,10 +24,11 @@ use crate::{ LOG_TARGET, RUNTIME_PALLETS_ADDR, }; use alloc::vec::Vec; -use codec::{Decode, DecodeWithMemTracking, Encode}; +use codec::{Decode, DecodeLimit, DecodeWithMemTracking, Encode}; use frame_support::{ dispatch::{DispatchInfo, GetDispatchInfo}, traits::{InherentBuilder, IsSubType, SignedTransactionBuilder}, + MAX_EXTRINSIC_DEPTH, }; use pallet_transaction_payment::OnChargeTransaction; use scale_info::{StaticTypeInfo, TypeInfo}; @@ -334,7 +335,11 @@ pub trait EthExtra { let call = if let Some(dest) = to { if dest == RUNTIME_PALLETS_ADDR { - let call = CallOf::::decode(&mut &data[..]).map_err(|_| { + let call = CallOf::::decode_all_with_depth_limit( + MAX_EXTRINSIC_DEPTH, + &mut &data[..], + ) + .map_err(|_| { log::debug!(target: LOG_TARGET, "Failed to decode data as Call"); InvalidTransaction::Call })?; From d21cdb0742bf15c7fa8a48f34469b252316ca460 Mon Sep 17 00:00:00 2001 From: pgherveou Date: Thu, 19 Jun 2025 14:39:53 +0200 Subject: [PATCH 4/7] missing use import --- substrate/frame/revive/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substrate/frame/revive/src/lib.rs b/substrate/frame/revive/src/lib.rs index c1fd3d64b99fd..24659d90a66c9 100644 --- a/substrate/frame/revive/src/lib.rs +++ b/substrate/frame/revive/src/lib.rs @@ -1761,6 +1761,8 @@ macro_rules! impl_runtime_apis_plus_revive { }; let tx_fee = |call: ::RuntimeCall, dispatch_call: ::RuntimeCall| { + use $crate::frame_support::dispatch::GetDispatchInfo; + // Get the dispatch info of the actual call dispatched let mut dispatch_info = dispatch_call.get_dispatch_info(); dispatch_info.extension_weight = From 7618aaf3410aa6c32ab8179c6dff78b0ed5a830a Mon Sep 17 00:00:00 2001 From: pgherveou Date: Fri, 20 Jun 2025 11:38:47 +0200 Subject: [PATCH 5/7] fix block gas limit --- .../revive/rpc/src/fee_history_provider.rs | 18 +++++++++--------- substrate/frame/revive/src/evm/runtime.rs | 7 ++----- substrate/frame/revive/src/lib.rs | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/substrate/frame/revive/rpc/src/fee_history_provider.rs b/substrate/frame/revive/rpc/src/fee_history_provider.rs index 677431eb75fb1..5f4483a0453f1 100644 --- a/substrate/frame/revive/rpc/src/fee_history_provider.rs +++ b/substrate/frame/revive/rpc/src/fee_history_provider.rs @@ -25,9 +25,9 @@ const CACHE_SIZE: u32 = 1024; #[derive(Default, Clone)] struct FeeHistoryCacheItem { - base_fee: u64, + base_fee: u128, gas_used_ratio: f64, - rewards: Vec, + rewards: Vec, } /// Manages the fee history cache. @@ -47,17 +47,17 @@ impl FeeHistoryProvider { let block_number: SubstrateBlockNumber = block.number.try_into().expect("Block number is always valid"); - let base_fee = block.base_fee_per_gas.unwrap_or_default().as_u64(); - let gas_used = block.gas_used.as_u64(); - let gas_used_ratio = (gas_used as f64) / (block.gas_limit.as_u64() as f64); + let base_fee = block.base_fee_per_gas.unwrap_or_default().as_u128(); + let gas_used = block.gas_used.as_u128(); + let gas_used_ratio = (gas_used as f64) / (block.gas_limit.as_u128() as f64); let mut result = FeeHistoryCacheItem { base_fee, gas_used_ratio, rewards: vec![] }; let mut receipts = receipts .iter() .map(|receipt| { - let gas_used = receipt.gas_used.as_u64(); + let gas_used = receipt.gas_used.as_u128(); let effective_reward = - receipt.effective_gas_price.as_u64().saturating_sub(base_fee); + receipt.effective_gas_price.as_u128().saturating_sub(base_fee); (gas_used, effective_reward) }) .collect::>(); @@ -67,8 +67,8 @@ impl FeeHistoryProvider { result.rewards = reward_percentiles .into_iter() .filter_map(|p| { - let target_gas = (p * gas_used as f64 / 100f64) as u64; - let mut sum_gas = 0u64; + let target_gas = (p * gas_used as f64 / 100f64) as u128; + let mut sum_gas = 0u128; for (gas_used, reward) in &receipts { sum_gas += gas_used; if target_gas <= sum_gas { diff --git a/substrate/frame/revive/src/evm/runtime.rs b/substrate/frame/revive/src/evm/runtime.rs index 13e77c7a30a98..86c07f8481a71 100644 --- a/substrate/frame/revive/src/evm/runtime.rs +++ b/substrate/frame/revive/src/evm/runtime.rs @@ -20,8 +20,8 @@ use crate::{ api::{GenericTransaction, TransactionSigned}, GasEncoder, }, - AccountIdOf, AddressMapper, BalanceOf, Config, ConversionPrecision, MomentOf, Pallet, - LOG_TARGET, RUNTIME_PALLETS_ADDR, + AccountIdOf, AddressMapper, BalanceOf, Config, ConversionPrecision, MomentOf, + OnChargeTransactionBalanceOf, Pallet, LOG_TARGET, RUNTIME_PALLETS_ADDR, }; use alloc::vec::Vec; use codec::{Decode, DecodeLimit, DecodeWithMemTracking, Encode}; @@ -30,7 +30,6 @@ use frame_support::{ traits::{InherentBuilder, IsSubType, SignedTransactionBuilder}, MAX_EXTRINSIC_DEPTH, }; -use pallet_transaction_payment::OnChargeTransaction; use scale_info::{StaticTypeInfo, TypeInfo}; use sp_core::{Get, H256, U256}; use sp_runtime::{ @@ -119,8 +118,6 @@ impl ExtrinsicCall } } -type OnChargeTransactionBalanceOf = <::OnChargeTransaction as OnChargeTransaction>::Balance; - impl Checkable for UncheckedExtrinsic where diff --git a/substrate/frame/revive/src/lib.rs b/substrate/frame/revive/src/lib.rs index 24659d90a66c9..c85537b6fd6b7 100644 --- a/substrate/frame/revive/src/lib.rs +++ b/substrate/frame/revive/src/lib.rs @@ -76,6 +76,7 @@ use frame_system::{ pallet_prelude::{BlockNumberFor, OriginFor}, Pallet as System, }; +use pallet_transaction_payment::OnChargeTransaction; use scale_info::TypeInfo; use sp_runtime::{ traits::{BadOrigin, Bounded, Convert, Dispatchable, Saturating, Zero}, @@ -106,6 +107,7 @@ pub type BalanceOf = type TrieId = BoundedVec>; type CodeVec = BoundedVec>; type ImmutableData = BoundedVec>; +pub(crate) type OnChargeTransactionBalanceOf = <::OnChargeTransaction as OnChargeTransaction>::Balance; /// Used as a sentinel value when reading and writing contract memory. /// @@ -1181,6 +1183,8 @@ where where ::RuntimeCall: Dispatchable, + T: pallet_transaction_payment::Config, + OnChargeTransactionBalanceOf: Into>, ::RuntimeCall: From>, ::RuntimeCall: Encode, T::Nonce: Into, @@ -1441,13 +1445,24 @@ where } /// Get the block gas limit. - pub fn evm_block_gas_limit() -> U256 { + pub fn evm_block_gas_limit() -> U256 + where + ::RuntimeCall: + Dispatchable, + T: pallet_transaction_payment::Config, + OnChargeTransactionBalanceOf: Into>, + { let max_block_weight = T::BlockWeights::get() .get(DispatchClass::Normal) .max_total .unwrap_or_else(|| T::BlockWeights::get().max_block); + let length_fee = pallet_transaction_payment::Pallet::::length_to_fee( + 5 * 1024 * 1024, // 5 MB + ); + Self::evm_gas_from_weight(max_block_weight) + .saturating_add(Self::evm_fee_to_gas(length_fee.into())) } /// Get the gas price. From ac7ee4e91986f8c20c5034bdfcb53c64b6cf50a5 Mon Sep 17 00:00:00 2001 From: pgherveou Date: Fri, 20 Jun 2025 11:44:40 +0200 Subject: [PATCH 6/7] Revert "fix block gas limit" This reverts commit 7618aaf3410aa6c32ab8179c6dff78b0ed5a830a. --- .../revive/rpc/src/fee_history_provider.rs | 18 +++++++++--------- substrate/frame/revive/src/evm/runtime.rs | 7 +++++-- substrate/frame/revive/src/lib.rs | 17 +---------------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/substrate/frame/revive/rpc/src/fee_history_provider.rs b/substrate/frame/revive/rpc/src/fee_history_provider.rs index 5f4483a0453f1..677431eb75fb1 100644 --- a/substrate/frame/revive/rpc/src/fee_history_provider.rs +++ b/substrate/frame/revive/rpc/src/fee_history_provider.rs @@ -25,9 +25,9 @@ const CACHE_SIZE: u32 = 1024; #[derive(Default, Clone)] struct FeeHistoryCacheItem { - base_fee: u128, + base_fee: u64, gas_used_ratio: f64, - rewards: Vec, + rewards: Vec, } /// Manages the fee history cache. @@ -47,17 +47,17 @@ impl FeeHistoryProvider { let block_number: SubstrateBlockNumber = block.number.try_into().expect("Block number is always valid"); - let base_fee = block.base_fee_per_gas.unwrap_or_default().as_u128(); - let gas_used = block.gas_used.as_u128(); - let gas_used_ratio = (gas_used as f64) / (block.gas_limit.as_u128() as f64); + let base_fee = block.base_fee_per_gas.unwrap_or_default().as_u64(); + let gas_used = block.gas_used.as_u64(); + let gas_used_ratio = (gas_used as f64) / (block.gas_limit.as_u64() as f64); let mut result = FeeHistoryCacheItem { base_fee, gas_used_ratio, rewards: vec![] }; let mut receipts = receipts .iter() .map(|receipt| { - let gas_used = receipt.gas_used.as_u128(); + let gas_used = receipt.gas_used.as_u64(); let effective_reward = - receipt.effective_gas_price.as_u128().saturating_sub(base_fee); + receipt.effective_gas_price.as_u64().saturating_sub(base_fee); (gas_used, effective_reward) }) .collect::>(); @@ -67,8 +67,8 @@ impl FeeHistoryProvider { result.rewards = reward_percentiles .into_iter() .filter_map(|p| { - let target_gas = (p * gas_used as f64 / 100f64) as u128; - let mut sum_gas = 0u128; + let target_gas = (p * gas_used as f64 / 100f64) as u64; + let mut sum_gas = 0u64; for (gas_used, reward) in &receipts { sum_gas += gas_used; if target_gas <= sum_gas { diff --git a/substrate/frame/revive/src/evm/runtime.rs b/substrate/frame/revive/src/evm/runtime.rs index 86c07f8481a71..13e77c7a30a98 100644 --- a/substrate/frame/revive/src/evm/runtime.rs +++ b/substrate/frame/revive/src/evm/runtime.rs @@ -20,8 +20,8 @@ use crate::{ api::{GenericTransaction, TransactionSigned}, GasEncoder, }, - AccountIdOf, AddressMapper, BalanceOf, Config, ConversionPrecision, MomentOf, - OnChargeTransactionBalanceOf, Pallet, LOG_TARGET, RUNTIME_PALLETS_ADDR, + AccountIdOf, AddressMapper, BalanceOf, Config, ConversionPrecision, MomentOf, Pallet, + LOG_TARGET, RUNTIME_PALLETS_ADDR, }; use alloc::vec::Vec; use codec::{Decode, DecodeLimit, DecodeWithMemTracking, Encode}; @@ -30,6 +30,7 @@ use frame_support::{ traits::{InherentBuilder, IsSubType, SignedTransactionBuilder}, MAX_EXTRINSIC_DEPTH, }; +use pallet_transaction_payment::OnChargeTransaction; use scale_info::{StaticTypeInfo, TypeInfo}; use sp_core::{Get, H256, U256}; use sp_runtime::{ @@ -118,6 +119,8 @@ impl ExtrinsicCall } } +type OnChargeTransactionBalanceOf = <::OnChargeTransaction as OnChargeTransaction>::Balance; + impl Checkable for UncheckedExtrinsic where diff --git a/substrate/frame/revive/src/lib.rs b/substrate/frame/revive/src/lib.rs index c85537b6fd6b7..24659d90a66c9 100644 --- a/substrate/frame/revive/src/lib.rs +++ b/substrate/frame/revive/src/lib.rs @@ -76,7 +76,6 @@ use frame_system::{ pallet_prelude::{BlockNumberFor, OriginFor}, Pallet as System, }; -use pallet_transaction_payment::OnChargeTransaction; use scale_info::TypeInfo; use sp_runtime::{ traits::{BadOrigin, Bounded, Convert, Dispatchable, Saturating, Zero}, @@ -107,7 +106,6 @@ pub type BalanceOf = type TrieId = BoundedVec>; type CodeVec = BoundedVec>; type ImmutableData = BoundedVec>; -pub(crate) type OnChargeTransactionBalanceOf = <::OnChargeTransaction as OnChargeTransaction>::Balance; /// Used as a sentinel value when reading and writing contract memory. /// @@ -1183,8 +1181,6 @@ where where ::RuntimeCall: Dispatchable, - T: pallet_transaction_payment::Config, - OnChargeTransactionBalanceOf: Into>, ::RuntimeCall: From>, ::RuntimeCall: Encode, T::Nonce: Into, @@ -1445,24 +1441,13 @@ where } /// Get the block gas limit. - pub fn evm_block_gas_limit() -> U256 - where - ::RuntimeCall: - Dispatchable, - T: pallet_transaction_payment::Config, - OnChargeTransactionBalanceOf: Into>, - { + pub fn evm_block_gas_limit() -> U256 { let max_block_weight = T::BlockWeights::get() .get(DispatchClass::Normal) .max_total .unwrap_or_else(|| T::BlockWeights::get().max_block); - let length_fee = pallet_transaction_payment::Pallet::::length_to_fee( - 5 * 1024 * 1024, // 5 MB - ); - Self::evm_gas_from_weight(max_block_weight) - .saturating_add(Self::evm_fee_to_gas(length_fee.into())) } /// Get the gas price. From ef55947a709b726e165047b3ba607df3177c5ea0 Mon Sep 17 00:00:00 2001 From: PG Herveou Date: Fri, 20 Jun 2025 13:13:59 +0200 Subject: [PATCH 7/7] [pallet-revive] fix block-gas-limit (#8920) Fix block gas limit fix http://github.com/paritytech/contract-issues/issues/110 --- .../revive/rpc/src/fee_history_provider.rs | 18 +++++++++--------- substrate/frame/revive/src/evm/runtime.rs | 7 ++----- substrate/frame/revive/src/lib.rs | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/substrate/frame/revive/rpc/src/fee_history_provider.rs b/substrate/frame/revive/rpc/src/fee_history_provider.rs index 677431eb75fb1..5f4483a0453f1 100644 --- a/substrate/frame/revive/rpc/src/fee_history_provider.rs +++ b/substrate/frame/revive/rpc/src/fee_history_provider.rs @@ -25,9 +25,9 @@ const CACHE_SIZE: u32 = 1024; #[derive(Default, Clone)] struct FeeHistoryCacheItem { - base_fee: u64, + base_fee: u128, gas_used_ratio: f64, - rewards: Vec, + rewards: Vec, } /// Manages the fee history cache. @@ -47,17 +47,17 @@ impl FeeHistoryProvider { let block_number: SubstrateBlockNumber = block.number.try_into().expect("Block number is always valid"); - let base_fee = block.base_fee_per_gas.unwrap_or_default().as_u64(); - let gas_used = block.gas_used.as_u64(); - let gas_used_ratio = (gas_used as f64) / (block.gas_limit.as_u64() as f64); + let base_fee = block.base_fee_per_gas.unwrap_or_default().as_u128(); + let gas_used = block.gas_used.as_u128(); + let gas_used_ratio = (gas_used as f64) / (block.gas_limit.as_u128() as f64); let mut result = FeeHistoryCacheItem { base_fee, gas_used_ratio, rewards: vec![] }; let mut receipts = receipts .iter() .map(|receipt| { - let gas_used = receipt.gas_used.as_u64(); + let gas_used = receipt.gas_used.as_u128(); let effective_reward = - receipt.effective_gas_price.as_u64().saturating_sub(base_fee); + receipt.effective_gas_price.as_u128().saturating_sub(base_fee); (gas_used, effective_reward) }) .collect::>(); @@ -67,8 +67,8 @@ impl FeeHistoryProvider { result.rewards = reward_percentiles .into_iter() .filter_map(|p| { - let target_gas = (p * gas_used as f64 / 100f64) as u64; - let mut sum_gas = 0u64; + let target_gas = (p * gas_used as f64 / 100f64) as u128; + let mut sum_gas = 0u128; for (gas_used, reward) in &receipts { sum_gas += gas_used; if target_gas <= sum_gas { diff --git a/substrate/frame/revive/src/evm/runtime.rs b/substrate/frame/revive/src/evm/runtime.rs index 13e77c7a30a98..86c07f8481a71 100644 --- a/substrate/frame/revive/src/evm/runtime.rs +++ b/substrate/frame/revive/src/evm/runtime.rs @@ -20,8 +20,8 @@ use crate::{ api::{GenericTransaction, TransactionSigned}, GasEncoder, }, - AccountIdOf, AddressMapper, BalanceOf, Config, ConversionPrecision, MomentOf, Pallet, - LOG_TARGET, RUNTIME_PALLETS_ADDR, + AccountIdOf, AddressMapper, BalanceOf, Config, ConversionPrecision, MomentOf, + OnChargeTransactionBalanceOf, Pallet, LOG_TARGET, RUNTIME_PALLETS_ADDR, }; use alloc::vec::Vec; use codec::{Decode, DecodeLimit, DecodeWithMemTracking, Encode}; @@ -30,7 +30,6 @@ use frame_support::{ traits::{InherentBuilder, IsSubType, SignedTransactionBuilder}, MAX_EXTRINSIC_DEPTH, }; -use pallet_transaction_payment::OnChargeTransaction; use scale_info::{StaticTypeInfo, TypeInfo}; use sp_core::{Get, H256, U256}; use sp_runtime::{ @@ -119,8 +118,6 @@ impl ExtrinsicCall } } -type OnChargeTransactionBalanceOf = <::OnChargeTransaction as OnChargeTransaction>::Balance; - impl Checkable for UncheckedExtrinsic where diff --git a/substrate/frame/revive/src/lib.rs b/substrate/frame/revive/src/lib.rs index 24659d90a66c9..c85537b6fd6b7 100644 --- a/substrate/frame/revive/src/lib.rs +++ b/substrate/frame/revive/src/lib.rs @@ -76,6 +76,7 @@ use frame_system::{ pallet_prelude::{BlockNumberFor, OriginFor}, Pallet as System, }; +use pallet_transaction_payment::OnChargeTransaction; use scale_info::TypeInfo; use sp_runtime::{ traits::{BadOrigin, Bounded, Convert, Dispatchable, Saturating, Zero}, @@ -106,6 +107,7 @@ pub type BalanceOf = type TrieId = BoundedVec>; type CodeVec = BoundedVec>; type ImmutableData = BoundedVec>; +pub(crate) type OnChargeTransactionBalanceOf = <::OnChargeTransaction as OnChargeTransaction>::Balance; /// Used as a sentinel value when reading and writing contract memory. /// @@ -1181,6 +1183,8 @@ where where ::RuntimeCall: Dispatchable, + T: pallet_transaction_payment::Config, + OnChargeTransactionBalanceOf: Into>, ::RuntimeCall: From>, ::RuntimeCall: Encode, T::Nonce: Into, @@ -1441,13 +1445,24 @@ where } /// Get the block gas limit. - pub fn evm_block_gas_limit() -> U256 { + pub fn evm_block_gas_limit() -> U256 + where + ::RuntimeCall: + Dispatchable, + T: pallet_transaction_payment::Config, + OnChargeTransactionBalanceOf: Into>, + { let max_block_weight = T::BlockWeights::get() .get(DispatchClass::Normal) .max_total .unwrap_or_else(|| T::BlockWeights::get().max_block); + let length_fee = pallet_transaction_payment::Pallet::::length_to_fee( + 5 * 1024 * 1024, // 5 MB + ); + Self::evm_gas_from_weight(max_block_weight) + .saturating_add(Self::evm_fee_to_gas(length_fee.into())) } /// Get the gas price.