Skip to content

[pallet-revive] fix block-gas-limit #8920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions substrate/frame/revive/rpc/src/fee_history_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
rewards: Vec<u128>,
}

/// Manages the fee history cache.
Expand All @@ -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::<Vec<_>>();
Expand All @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions substrate/frame/revive/src/evm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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::{
Expand Down Expand Up @@ -119,8 +118,6 @@ impl<Address: TypeInfo, Signature: TypeInfo, E: EthExtra> ExtrinsicCall
}
}

type OnChargeTransactionBalanceOf<T> = <<T as pallet_transaction_payment::Config>::OnChargeTransaction as OnChargeTransaction<T>>::Balance;

impl<LookupSource, Signature, E, Lookup> Checkable<Lookup>
for UncheckedExtrinsic<LookupSource, Signature, E>
where
Expand Down
17 changes: 16 additions & 1 deletion substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -106,6 +107,7 @@ pub type BalanceOf<T> =
type TrieId = BoundedVec<u8, ConstU32<128>>;
type CodeVec = BoundedVec<u8, ConstU32<{ limits::code::BLOB_BYTES }>>;
type ImmutableData = BoundedVec<u8, ConstU32<{ limits::IMMUTABLE_BYTES }>>;
pub(crate) type OnChargeTransactionBalanceOf<T> = <<T as pallet_transaction_payment::Config>::OnChargeTransaction as OnChargeTransaction<T>>::Balance;

/// Used as a sentinel value when reading and writing contract memory.
///
Expand Down Expand Up @@ -1181,6 +1183,8 @@ where
where
<T as frame_system::Config>::RuntimeCall:
Dispatchable<Info = frame_support::dispatch::DispatchInfo>,
T: pallet_transaction_payment::Config,
OnChargeTransactionBalanceOf<T>: Into<BalanceOf<T>>,
<T as Config>::RuntimeCall: From<crate::Call<T>>,
<T as Config>::RuntimeCall: Encode,
T::Nonce: Into<U256>,
Expand Down Expand Up @@ -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
<T as frame_system::Config>::RuntimeCall:
Dispatchable<Info = frame_support::dispatch::DispatchInfo>,
T: pallet_transaction_payment::Config,
OnChargeTransactionBalanceOf<T>: Into<BalanceOf<T>>,
{
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::<T>::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.
Expand Down
Loading