Skip to content
Closed
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: 14 additions & 4 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ use sp_runtime::{
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use testnet_parachains_constants::westend::{
consensus::*, currency::*, fee::WeightToFee, snowbridge::EthereumNetwork, time::*,
consensus::*, currency::*, snowbridge::EthereumNetwork, time::*,
};
use westend_runtime_constants::time::DAYS as RC_DAYS;
use xcm_config::{
Expand Down Expand Up @@ -247,6 +247,18 @@ parameter_types! {
pub const TransactionByteFee: Balance = MILLICENTS;
}

/// `pallet_revive` requires this specific `WeightToFee` implementation.
///
/// This is needed because we make certain assumptions about how weight
/// is mapped to fees. Enforced at compile time.
type WeightToFee = pallet_revive::evm::fees::BlockRatioFee<
// p
CENTS,
// q
{ 100 * ExtrinsicBaseWeight::get().ref_time() as u128 },
Runtime,
>;

impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction =
Expand Down Expand Up @@ -1169,7 +1181,6 @@ impl pallet_revive::Config for Runtime {
type RuntimeCall = RuntimeCall;
type DepositPerItem = DepositPerItem;
type DepositPerByte = DepositPerByte;
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
type Precompiles = (
ERC20<Self, InlineIdConfig<0x120>, TrustBackedAssetsInstance>,
Expand All @@ -1190,9 +1201,8 @@ impl pallet_revive::Config for Runtime {
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
type ChainId = ConstU64<420_420_421>;
type NativeToEthRatio = ConstU32<1_000_000>; // 10^(18 - 12) Eth is 10^18, Native is 10^12.
type EthGasEncoder = ();
type FindAuthor = <Runtime as pallet_authorship::Config>::FindAuthor;
type DepositSource = ();
type FeeInfo = pallet_revive::evm::fees::Info<Address, Signature, EthExtraImpl>;
}

parameter_types! {
Expand Down
14 changes: 8 additions & 6 deletions cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ parameter_types! {
impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>;
type WeightToFee = WeightToFee;
type WeightToFee = pallet_revive::evm::fees::BlockRatioFee<1, 1, Self>;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
type OperationalFeeMultiplier = ConstU8<5>;
Expand Down Expand Up @@ -816,7 +816,6 @@ impl pallet_revive::Config for Runtime {
type RuntimeCall = RuntimeCall;
type DepositPerItem = DepositPerItem;
type DepositPerByte = DepositPerByte;
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
type Precompiles = ();
type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
Expand All @@ -830,9 +829,8 @@ impl pallet_revive::Config for Runtime {
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
type ChainId = ConstU64<420_420_999>;
type NativeToEthRatio = ConstU32<1_000_000>; // 10^(18 - 12) Eth is 10^18, Native is 10^12.
type EthGasEncoder = ();
type FindAuthor = <Runtime as pallet_authorship::Config>::FindAuthor;
type DepositSource = ();
type FeeInfo = pallet_revive::evm::fees::Info<Address, Signature, EthExtraImpl>;
}

impl pallet_sudo::Config for Runtime {
Expand Down Expand Up @@ -908,7 +906,11 @@ mod benches {
);
}

impl_runtime_apis! {
pallet_revive::impl_runtime_apis_plus_revive!(
Runtime,
Executive,
EthExtraImpl,

impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION)
Expand Down Expand Up @@ -1213,7 +1215,7 @@ impl_runtime_apis! {
ConsensusHook::can_build_upon(included_hash, slot)
}
}
}
);

cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
Expand Down
8 changes: 3 additions & 5 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use frame_support::{
constants::{
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
},
ConstantMultiplier, IdentityFee, Weight,
ConstantMultiplier, Weight,
},
BoundedVec, PalletId,
};
Expand Down Expand Up @@ -614,7 +614,7 @@ impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees>;
type OperationalFeeMultiplier = OperationalFeeMultiplier;
type WeightToFee = IdentityFee<Balance>;
type WeightToFee = pallet_revive::evm::fees::BlockRatioFee<1, 1, Self>;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type FeeMultiplierUpdate = TargetedFeeAdjustment<
Self,
Expand Down Expand Up @@ -1475,7 +1475,6 @@ impl pallet_revive::Config for Runtime {
type RuntimeCall = RuntimeCall;
type DepositPerItem = DepositPerItem;
type DepositPerByte = DepositPerByte;
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
type Precompiles =
(ERC20<Self, InlineIdConfig<0x1>, Instance1>, ERC20<Self, InlineIdConfig<0x2>, Instance2>);
Expand All @@ -1489,10 +1488,9 @@ impl pallet_revive::Config for Runtime {
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
type ChainId = ConstU64<420_420_420>;
type NativeToEthRatio = ConstU32<1_000_000>; // 10^(18 - 12) Eth is 10^18, Native is 10^12.
type EthGasEncoder = ();
type FindAuthor = <Runtime as pallet_authorship::Config>::FindAuthor;
type AllowEVMBytecode = ConstBool<true>;
type DepositSource = ();
type FeeInfo = pallet_revive::evm::fees::Info<Address, Signature, EthExtraImpl>;
}

impl pallet_sudo::Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/revive/dev-node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ polkadot-sdk = { workspace = true, features = [
"pallet-transaction-payment",
"pallet-transaction-payment-rpc-runtime-api",
"parachains-common",
"polkadot-runtime-common",
"runtime",
"with-tracing",
] }
Expand Down
22 changes: 15 additions & 7 deletions substrate/frame/revive/dev-node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ use frame_support::weights::{
Weight,
};
use frame_system::limits::BlockWeights;
use pallet_revive::{evm::runtime::EthExtra, AccountId32Mapper};
use pallet_revive::{
evm::{
fees::{BlockRatioFee, Info as FeeInfo},
runtime::EthExtra,
},
AccountId32Mapper,
};
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use polkadot_sdk::{
polkadot_sdk_frame::{
Expand All @@ -39,7 +45,7 @@ use polkadot_sdk::{
},
*,
};
use sp_weights::{ConstantMultiplier, IdentityFee};
use sp_weights::ConstantMultiplier;

pub use polkadot_sdk::{
parachains_common::{AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature},
Expand All @@ -48,9 +54,9 @@ pub use polkadot_sdk::{

pub mod currency {
use super::Balance;
pub const MILLICENTS: Balance = 1_000_000_000;
pub const CENTS: Balance = 1_000 * MILLICENTS;
pub const DOLLARS: Balance = 100 * CENTS;
pub const DOLLARS: Balance = 1_000_000_000_000;
pub const CENTS: Balance = DOLLARS / 100;
pub const MILLICENTS: Balance = CENTS / 1_000;
}

/// Provides getters for genesis configuration presets.
Expand Down Expand Up @@ -284,7 +290,7 @@ impl frame_system::Config for Runtime {
}

parameter_types! {
pub const ExistentialDeposit: Balance = DOLLARS;
pub const ExistentialDeposit: Balance = CENTS;
}

// Implements the types required for the balances pallet.
Expand All @@ -311,8 +317,9 @@ parameter_types! {
#[derive_impl(pallet_transaction_payment::config_preludes::TestDefaultConfig)]
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>;
type WeightToFee = IdentityFee<Balance>;
type WeightToFee = BlockRatioFee<1, 1, Self>;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type FeeMultiplierUpdate = polkadot_sdk::polkadot_runtime_common::SlowAdjustingFeeUpdate<Self>;
}

parameter_types! {
Expand All @@ -329,6 +336,7 @@ impl pallet_revive::Config for Runtime {
type UploadOrigin = EnsureSigned<Self::AccountId>;
type InstantiateOrigin = EnsureSigned<Self::AccountId>;
type Time = Timestamp;
type FeeInfo = FeeInfo<Address, Signature, EthExtraImpl>;
}

pallet_revive::impl_runtime_apis_plus_revive!(
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/revive/rpc/src/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<Client: EthRpcClient + Send + Sync> TransactionBuilder<Client> {
.with_context(|| "send_raw_transaction failed")?;

Ok(SubmittedTransaction {
tx: GenericTransaction::from_signed(signed_tx, gas_price, Some(from)),
tx: GenericTransaction::from_signed(signed_tx, Some(from)),
hash,
client,
})
Expand Down
5 changes: 2 additions & 3 deletions substrate/frame/revive/rpc/src/receipt_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ impl ReceiptExtractor {
})?;

let base_gas_price = (self.fetch_gas_price)(block_hash).await?;
let tx_info =
GenericTransaction::from_signed(signed_tx.clone(), base_gas_price, Some(from));
let gas_price = tx_info.gas_price.unwrap_or_default();
let tx_info = GenericTransaction::from_signed(signed_tx.clone(), Some(from));
let gas_price = tx_info.effective_gas_price(base_gas_price).unwrap_or_default();
let gas_used = U256::from(tx_fees.tip.saturating_add(tx_fees.actual_fee))
.saturating_mul(self.native_to_eth_ratio.into())
.checked_div(gas_price)
Expand Down
27 changes: 4 additions & 23 deletions substrate/frame/revive/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#![cfg(feature = "runtime-benchmarks")]
use crate::{
call_builder::{caller_funding, default_deposit_limit, CallSetup, Contract, VmBinaryModule},
evm::runtime::GAS_PRICE,
exec::{Key, MomentOf, PrecompileExt},
limits,
precompiles::{
Expand Down Expand Up @@ -299,13 +298,13 @@ mod benchmarks {

assert!(AccountInfoOf::<T>::get(&deployer).is_none());

let hold_reason = T::DepositSource::get();
let hold_reason = T::FeeInfo::deposit_source();
if let Some(hold_reason) = hold_reason.as_ref() {
T::Currency::set_balance_on_hold(hold_reason, &caller, caller_funding::<T>()).unwrap();
}

#[extrinsic_call]
_(origin, evm_value, Weight::MAX, storage_deposit, code, input);
_(origin, evm_value, Weight::MAX, storage_deposit, code, input, 0u32.into());

let deposit =
T::Currency::balance_on_hold(&HoldReason::StorageDepositReserve.into(), &account_id);
Expand Down Expand Up @@ -453,7 +452,7 @@ mod benchmarks {
let before = Pallet::<T>::evm_balance(&instance.address);
let storage_deposit = default_deposit_limit::<T>();
#[extrinsic_call]
_(origin, instance.address, evm_value, Weight::MAX, storage_deposit, data);
_(origin, instance.address, evm_value, Weight::MAX, storage_deposit, data, 0u32.into());
let deposit = T::Currency::balance_on_hold(
&HoldReason::StorageDepositReserve.into(),
&instance.account_id,
Expand Down Expand Up @@ -951,7 +950,7 @@ mod benchmarks {
{
result = runtime.bench_gas_price(memory.as_mut_slice());
}
assert_eq!(result.unwrap(), u64::from(GAS_PRICE));
assert_eq!(U256::from(result.unwrap()), <Pallet<T>>::evm_gas_price());
}

#[benchmark(pov_mode = Measured)]
Expand Down Expand Up @@ -1064,24 +1063,6 @@ mod benchmarks {
assert_eq!(U256::from_little_endian(&memory[..]), runtime.ext().now());
}

#[benchmark(pov_mode = Measured)]
fn seal_weight_to_fee() {
build_runtime!(runtime, memory: [[0u8;32], ]);
let weight = Weight::from_parts(500_000, 300_000);
let result;
#[block]
{
result = runtime.bench_weight_to_fee(
memory.as_mut_slice(),
weight.ref_time(),
weight.proof_size(),
0,
);
}
assert_ok!(result);
assert_eq!(U256::from_little_endian(&memory[..]), runtime.ext().get_weight_price(weight));
}

#[benchmark(pov_mode = Measured)]
fn seal_copy_to_contract(n: Linear<0, { limits::code::BLOB_BYTES - 4 }>) {
let mut setup = CallSetup::<T>::default();
Expand Down
5 changes: 3 additions & 2 deletions substrate/frame/revive/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ mod api;
pub use api::*;
mod tracing;
pub use tracing::*;
mod gas_encoder;
pub use gas_encoder::*;
pub mod fees;
pub mod runtime;
pub use alloy_core::sol_types::decode_revert_reason;

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