diff --git a/runtime/mainnet/src/apis.rs b/runtime/mainnet/src/apis.rs index f7f568427..dfbb2a08e 100644 --- a/runtime/mainnet/src/apis.rs +++ b/runtime/mainnet/src/apis.rs @@ -2,6 +2,7 @@ use alloc::vec::Vec; use codec::Encode; use frame_support::{ + dispatch::DispatchInfo, genesis_builder_helper::{build_state, get_preset}, traits::{ nonfungibles_v2::Inspect, @@ -9,12 +10,12 @@ use frame_support::{ }, weights::{Weight, WeightToFee as _}, }; -use pallet_revive::AddressMapper; +use pallet_revive::{evm::runtime::EthExtra, AddressMapper}; use sp_api::impl_runtime_apis; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160}; use sp_runtime::{ - traits::Block as BlockT, + traits::{Block as BlockT, TransactionExtension}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, }; @@ -32,8 +33,8 @@ use xcm_runtime_apis::{ // Local module imports use super::{ config::{monetary::fee::WeightToFee, system::RuntimeBlockWeights, xcm as xcm_config}, - AccountId, Balance, Balances, Block, BlockNumber, BlockWeights, EventRecord, Executive, - ExtrinsicInclusionMode, InherentDataExt, Nfts, Nonce, OriginCaller, ParachainSystem, + AccountId, Balance, Balances, Block, BlockNumber, BlockWeights, EthExtraImpl, EventRecord, + Executive, ExtrinsicInclusionMode, InherentDataExt, Nfts, Nonce, OriginCaller, ParachainSystem, PolkadotXcm, Revive, Runtime, RuntimeCall, RuntimeEvent, RuntimeGenesisConfig, RuntimeOrigin, SessionKeys, System, TransactionPayment, UncheckedExtrinsic, VERSION, }; @@ -406,35 +407,26 @@ impl_runtime_apis! { System::account_nonce(account) } - fn eth_transact( - from: H160, - dest: Option, - value: Balance, - input: Vec, - gas_limit: Option, - storage_deposit_limit: Option, - ) -> pallet_revive::EthContractResult + fn eth_transact(tx: pallet_revive::evm::GenericTransaction) -> Result, pallet_revive::EthTransactError> { - use pallet_revive::AddressMapper; let blockweights: BlockWeights = ::BlockWeights::get(); - let origin = ::AddressMapper::to_account_id(&from); - let encoded_size = |pallet_call| { + let tx_fee = |pallet_call, mut dispatch_info: DispatchInfo| { let call = RuntimeCall::Revive(pallet_call); + dispatch_info.extension_weight = EthExtraImpl::get_eth_extension(0, 0u32.into()).weight(&call); let uxt: UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic::new_bare(call).into(); - uxt.encoded_size() as u32 + + pallet_transaction_payment::Pallet::::compute_fee( + uxt.encoded_size() as u32, + &dispatch_info, + 0u32.into(), + ) }; Revive::bare_eth_transact( - origin, - dest, - value, - input, - gas_limit.unwrap_or(blockweights.max_block), - storage_deposit_limit.unwrap_or(u128::MAX), - encoded_size, - pallet_revive::DebugInfo::UnsafeDebug, - pallet_revive::CollectEvents::UnsafeCollect, + tx, + blockweights.max_block, + tx_fee, ) } @@ -451,7 +443,7 @@ impl_runtime_apis! { dest, value, gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block), - storage_deposit_limit.unwrap_or(u128::MAX), + pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)), input_data, pallet_revive::DebugInfo::UnsafeDebug, pallet_revive::CollectEvents::UnsafeCollect, @@ -472,7 +464,7 @@ impl_runtime_apis! { RuntimeOrigin::signed(origin), value, gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block), - storage_deposit_limit.unwrap_or(u128::MAX), + pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)), code, data, salt, diff --git a/runtime/testnet/src/lib.rs b/runtime/testnet/src/lib.rs index 08f15ed74..3a3a51823 100644 --- a/runtime/testnet/src/lib.rs +++ b/runtime/testnet/src/lib.rs @@ -30,7 +30,7 @@ use cumulus_primitives_core::AggregateMessageOrigin; use cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim; use frame_metadata_hash_extension::CheckMetadataHash; use frame_support::{ - dispatch::DispatchClass, + dispatch::{DispatchClass, DispatchInfo}, genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ @@ -52,7 +52,10 @@ use pallet_api::{fungibles, messaging}; use pallet_balances::Call as BalancesCall; use pallet_ismp::offchain::{Leaf, Proof, ProofKeys}; use pallet_nfts_sdk as pallet_nfts; -use pallet_revive::{evm::H160, AddressMapper}; +use pallet_revive::{ + evm::{runtime::EthExtra, H160}, + AddressMapper, +}; use pallet_transaction_payment::ChargeTransactionPayment; // Polkadot imports use polkadot_runtime_common::SlowAdjustingFeeUpdate; @@ -69,7 +72,7 @@ use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256}; pub use sp_runtime::BuildStorage; use sp_runtime::{ generic, impl_opaque_keys, - traits::{BlakeTwo256, Block as BlockT, Get, IdentifyAccount, Verify}, + traits::{BlakeTwo256, Block as BlockT, Get, IdentifyAccount, TransactionExtension, Verify}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, }; @@ -693,35 +696,26 @@ impl_runtime_apis! { System::account_nonce(account) } - fn eth_transact( - from: H160, - dest: Option, - value: Balance, - input: Vec, - gas_limit: Option, - storage_deposit_limit: Option, - ) -> pallet_revive::EthContractResult + fn eth_transact(tx: pallet_revive::evm::GenericTransaction) -> Result, pallet_revive::EthTransactError> { - use pallet_revive::AddressMapper; let blockweights: BlockWeights = ::BlockWeights::get(); - let origin = ::AddressMapper::to_account_id(&from); - let encoded_size = |pallet_call| { + let tx_fee = |pallet_call, mut dispatch_info: DispatchInfo| { let call = RuntimeCall::Revive(pallet_call); + dispatch_info.extension_weight = EthExtraImpl::get_eth_extension(0, 0u32.into()).weight(&call); let uxt: UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic::new_bare(call).into(); - uxt.encoded_size() as u32 + + pallet_transaction_payment::Pallet::::compute_fee( + uxt.encoded_size() as u32, + &dispatch_info, + 0u32.into(), + ) }; Revive::bare_eth_transact( - origin, - dest, - value, - input, - gas_limit.unwrap_or(blockweights.max_block), - storage_deposit_limit.unwrap_or(u128::MAX), - encoded_size, - pallet_revive::DebugInfo::UnsafeDebug, - pallet_revive::CollectEvents::UnsafeCollect, + tx, + blockweights.max_block, + tx_fee, ) } @@ -738,7 +732,7 @@ impl_runtime_apis! { dest, value, gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block), - storage_deposit_limit.unwrap_or(u128::MAX), + pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)), input_data, pallet_revive::DebugInfo::UnsafeDebug, pallet_revive::CollectEvents::UnsafeCollect, @@ -759,7 +753,7 @@ impl_runtime_apis! { RuntimeOrigin::signed(origin), value, gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block), - storage_deposit_limit.unwrap_or(u128::MAX), + pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)), code, data, salt,