From 6b6c92370893b311597a95d9e352c61de1840b1f Mon Sep 17 00:00:00 2001 From: higherordertech Date: Wed, 6 Nov 2024 19:35:02 +1100 Subject: [PATCH] fix runtime: pallet_aura::Config fix runtime: sp_api::Core fix runtime: sp_consensus_aura::AuraApi fix runtime: moonbeam_rpc_primitives_debug::DebugRuntimeApi fix runtime: frame_try_runtime::TryRuntime fix xcm: xcm_executor::Config fix xcm: impl orml_xtokens::Config --- parachain/runtime/litentry/src/lib.rs | 97 ++++++++++++++++++- parachain/runtime/litentry/src/xcm_config.rs | 29 ++++-- parachain/runtime/paseo/src/lib.rs | 99 ++++++++++++++++++-- parachain/runtime/paseo/src/xcm_config.rs | 33 ++++++- parachain/runtime/rococo/src/xcm_config.rs | 16 +++- 5 files changed, 250 insertions(+), 24 deletions(-) diff --git a/parachain/runtime/litentry/src/lib.rs b/parachain/runtime/litentry/src/lib.rs index 4d73a4a2bd..fde74d0b14 100644 --- a/parachain/runtime/litentry/src/lib.rs +++ b/parachain/runtime/litentry/src/lib.rs @@ -1071,7 +1071,7 @@ where { if let Some(author_index) = pallet_aura::Pallet::::find_author(digests) { let authority_id = - >::authorities()[author_index as usize].clone(); + pallet_aura::Authorities::::get()[author_index as usize].clone(); return Some(H160::from_slice(&authority_id.encode()[4..24])); } @@ -1356,7 +1356,7 @@ impl_runtime_apis! { Executive::execute_block(block); } - fn initialize_block(header: &::Header) { + fn initialize_block(header: &::Header) -> sp_runtime::ExtrinsicInclusionMode { Executive::initialize_block(header) } } @@ -1429,7 +1429,7 @@ impl_runtime_apis! { } fn authorities() -> Vec { - Aura::authorities().into_inner() + pallet_aura::Authorities::::get().into_inner() } } @@ -1719,6 +1719,7 @@ impl_runtime_apis! { fn trace_transaction( extrinsics: Vec<::Extrinsic>, traced_transaction: &pallet_ethereum::Transaction, + header: &::Header, ) -> Result< (), sp_runtime::DispatchError, @@ -1748,6 +1749,7 @@ impl_runtime_apis! { fn trace_block( extrinsics: Vec<::Extrinsic>, known_transactions: Vec, + header: &::Header, ) -> Result< (), sp_runtime::DispatchError, @@ -1777,6 +1779,91 @@ impl_runtime_apis! { Ok(()) } + + fn trace_call( + header: &::Header, + from: H160, + to: H160, + data: Vec, + value: U256, + gas_limit: U256, + max_fee_per_gas: Option, + max_priority_fee_per_gas: Option, + nonce: Option, + access_list: Option)>>, + ) -> Result<(), sp_runtime::DispatchError> { + #[cfg(feature = "evm-tracing")] + { + use moonbeam_evm_tracer::tracer::EvmTracer; + + // Initialize block: calls the "on_initialize" hook on every pallet + // in AllPalletsWithSystem. + Executive::initialize_block(header); + + EvmTracer::new().trace(|| { + let is_transactional = false; + let validate = true; + let without_base_extrinsic_weight = true; + + + // Estimated encoded transaction size must be based on the heaviest transaction + // type (EIP1559Transaction) to be compatible with all transaction types. + let mut estimated_transaction_len = data.len() + + // pallet ethereum index: 1 + // transact call index: 1 + // Transaction enum variant: 1 + // chain_id 8 bytes + // nonce: 32 + // max_priority_fee_per_gas: 32 + // max_fee_per_gas: 32 + // gas_limit: 32 + // action: 21 (enum varianrt + call address) + // value: 32 + // access_list: 1 (empty vec size) + // 65 bytes signature + 258; + + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; + + let _ = ::Runner::call( + from, + to, + data, + value, + gas_limit, + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list.unwrap_or_default(), + is_transactional, + validate, + weight_limit, + proof_size_base_cost, + ::config(), + ); + }); + Ok(()) + } + #[cfg(not(feature = "evm-tracing"))] + Err(sp_runtime::DispatchError::Other( + "Missing `evm-tracing` compile time feature flag.", + )) + } } impl moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi for Runtime { @@ -1820,7 +1907,7 @@ impl_runtime_apis! { (weight, RuntimeBlockWeights::get().max_block) } - fn execute_block(block: Block, state_root_check: bool, signature_check: bool,select: frame_try_runtime::TryStateSelect) -> Weight { + fn execute_block(block: Block, state_root_check: bool,signature_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight { log::info!( target: "runtime::Litentry", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", block.header.number, @@ -1828,7 +1915,7 @@ impl_runtime_apis! { state_root_check, select, ); - Executive::try_execute_block(block, state_root_check,signature_check, select).expect("try_execute_block failed") + Executive::try_execute_block(block, state_root_check, signature_check,select).expect("try_execute_block failed") } } diff --git a/parachain/runtime/litentry/src/xcm_config.rs b/parachain/runtime/litentry/src/xcm_config.rs index 1ae780cb34..701307d98e 100644 --- a/parachain/runtime/litentry/src/xcm_config.rs +++ b/parachain/runtime/litentry/src/xcm_config.rs @@ -20,7 +20,7 @@ use frame_support::{ match_types, pallet_prelude::ConstU32, parameter_types, - traits::{Everything, Nothing}, + traits::{ConstU32 as TConstU32, Everything, Nothing}, weights::ConstantMultiplier, PalletId, }; @@ -36,12 +36,13 @@ use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, - EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, IsConcrete, ParentIsPreset, + EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, FungiblesAdapter, IsConcrete, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, }; use xcm_executor::{traits::JustTry, XcmExecutor}; +use sp_std::sync::Arc; use core_primitives::{AccountId, Weight}; use runtime_common::{ @@ -70,6 +71,12 @@ parameter_types! { pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); } +impl Get for UniversalLocation { + fn get() -> Junctions { + UniversalLocation::get() + } +} + /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used /// when determining ownership of accounts for asset transacting and when attempting to use XCM /// `Transact` in order to determine the dispatch Origin. @@ -242,6 +249,10 @@ impl xcm_executor::Config for XcmConfig { type CallDispatcher = RuntimeCall; type SafeCallFilter = Everything; type Aliasers = (); + type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// No local origins on this chain are allowed to dispatch XCM sends/executions. @@ -285,12 +296,18 @@ parameter_type_with_key! { parameter_types! { pub SelfLocation: MultiLocation = MultiLocation { parents:1, - interior: Junctions::X1( + interior: Junctions::X1(Arc::new([ Parachain(ParachainInfo::parachain_id().into()) - ) + ])) }; - pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000u64, 0); - pub const MaxAssetsForTransfer: usize = 3; + pub const BaseXcmWeight: u64 = 100_000_000; +} + +pub struct MaxAssetsForTransfer; +impl orml_traits::parameters::frame_support::traits::Get for MaxAssetsForTransfer { + fn get() -> usize { + 3 + } } #[cfg(feature = "runtime-benchmarks")] diff --git a/parachain/runtime/paseo/src/lib.rs b/parachain/runtime/paseo/src/lib.rs index add8ad0724..6b7972e84b 100644 --- a/parachain/runtime/paseo/src/lib.rs +++ b/parachain/runtime/paseo/src/lib.rs @@ -694,7 +694,7 @@ impl SortedMembers for CouncilProvider { } fn sorted_members() -> Vec { - Council::members() + pallet_collective::pallet::Members::::get() } #[cfg(feature = "runtime-benchmarks")] @@ -1114,7 +1114,7 @@ where { if let Some(author_index) = pallet_aura::Pallet::::find_author(digests) { let authority_id = - >::authorities()[author_index as usize].clone(); + pallet_aura::Authorities::::get()[author_index as usize].clone(); return Some(H160::from_slice(&authority_id.encode()[4..24])); } @@ -1417,7 +1417,7 @@ impl_runtime_apis! { Executive::execute_block(block); } - fn initialize_block(header: &::Header) { + fn initialize_block(header: &::Header) -> sp_runtime::ExtrinsicInclusionMode { Executive::initialize_block(header) } } @@ -1490,7 +1490,7 @@ impl_runtime_apis! { } fn authorities() -> Vec { - Aura::authorities().into_inner() + pallet_aura::Authorities::::get().into_inner() } } @@ -1780,6 +1780,7 @@ impl_runtime_apis! { fn trace_transaction( extrinsics: Vec<::Extrinsic>, traced_transaction: &pallet_ethereum::Transaction, + header: &::Header, ) -> Result< (), sp_runtime::DispatchError, @@ -1809,6 +1810,7 @@ impl_runtime_apis! { fn trace_block( extrinsics: Vec<::Extrinsic>, known_transactions: Vec, + header: &::Header, ) -> Result< (), sp_runtime::DispatchError, @@ -1838,6 +1840,91 @@ impl_runtime_apis! { Ok(()) } + + fn trace_call( + header: &::Header, + from: H160, + to: H160, + data: Vec, + value: U256, + gas_limit: U256, + max_fee_per_gas: Option, + max_priority_fee_per_gas: Option, + nonce: Option, + access_list: Option)>>, + ) -> Result<(), sp_runtime::DispatchError> { + #[cfg(feature = "evm-tracing")] + { + use moonbeam_evm_tracer::tracer::EvmTracer; + + // Initialize block: calls the "on_initialize" hook on every pallet + // in AllPalletsWithSystem. + Executive::initialize_block(header); + + EvmTracer::new().trace(|| { + let is_transactional = false; + let validate = true; + let without_base_extrinsic_weight = true; + + + // Estimated encoded transaction size must be based on the heaviest transaction + // type (EIP1559Transaction) to be compatible with all transaction types. + let mut estimated_transaction_len = data.len() + + // pallet ethereum index: 1 + // transact call index: 1 + // Transaction enum variant: 1 + // chain_id 8 bytes + // nonce: 32 + // max_priority_fee_per_gas: 32 + // max_fee_per_gas: 32 + // gas_limit: 32 + // action: 21 (enum varianrt + call address) + // value: 32 + // access_list: 1 (empty vec size) + // 65 bytes signature + 258; + + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; + + let _ = ::Runner::call( + from, + to, + data, + value, + gas_limit, + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list.unwrap_or_default(), + is_transactional, + validate, + weight_limit, + proof_size_base_cost, + ::config(), + ); + }); + Ok(()) + } + #[cfg(not(feature = "evm-tracing"))] + Err(sp_runtime::DispatchError::Other( + "Missing `evm-tracing` compile time feature flag.", + )) + } } impl moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi for Runtime { @@ -1876,14 +1963,14 @@ impl_runtime_apis! { // NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to // have a backtrace here. If any of the pre/post migration checks fail, we shall stop // right here and right now. - log::info!("try-runtime::on_runtime_upgrade rococo."); + log::info!("try-runtime::on_runtime_upgrade paseo."); let weight = Executive::try_runtime_upgrade(checks).unwrap(); (weight, RuntimeBlockWeights::get().max_block) } fn execute_block(block: Block, state_root_check: bool,signature_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight { log::info!( - target: "runtime::Rococo", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", + target: "runtime::Paseo", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", block.header.number, block.header.hash(), state_root_check, diff --git a/parachain/runtime/paseo/src/xcm_config.rs b/parachain/runtime/paseo/src/xcm_config.rs index f631139a4c..d9d1bc4cf8 100644 --- a/parachain/runtime/paseo/src/xcm_config.rs +++ b/parachain/runtime/paseo/src/xcm_config.rs @@ -45,12 +45,13 @@ use sp_runtime::traits::AccountIdConversion; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, - EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, IsConcrete, ParentIsPreset, + EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, FungiblesAdapter, IsConcrete, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, }; use xcm_executor::{traits::JustTry, XcmExecutor}; +use sp_std::sync::Arc; #[cfg(test)] use crate::tests::setup::ParachainXcmRouter; @@ -69,6 +70,12 @@ parameter_types! { pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); } +impl Get for UniversalLocation { + fn get() -> Junctions { + UniversalLocation::get() + } +} + /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used /// when determining ownership of accounts for asset transacting and when attempting to use XCM /// `Transact` in order to determine the dispatch Origin. @@ -241,6 +248,10 @@ impl xcm_executor::Config for XcmConfig { type CallDispatcher = RuntimeCall; type SafeCallFilter = Everything; type Aliasers = (); + type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); } /// No local origins on this chain are allowed to dispatch XCM sends/executions. @@ -281,15 +292,27 @@ parameter_type_with_key! { }; } +impl GetByKey> for ParachainMinFee { + fn get_by_key(key: MultiLocation) -> Option { + Some(ParachainMinFee::get()) + } +} + parameter_types! { pub SelfLocation: MultiLocation = MultiLocation { parents:1, - interior: Junctions::X1( + interior: Junctions::X1(Arc::new([ Parachain(ParachainInfo::parachain_id().into()) - ) + ])) }; - pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000u64, 0); - pub const MaxAssetsForTransfer: usize = 3; + pub const BaseXcmWeight: u64 = 100_000_000; +} + +pub struct MaxAssetsForTransfer; +impl orml_traits::parameters::frame_support::traits::Get for MaxAssetsForTransfer { + fn get() -> usize { + 3 + } } #[cfg(feature = "runtime-benchmarks")] diff --git a/parachain/runtime/rococo/src/xcm_config.rs b/parachain/runtime/rococo/src/xcm_config.rs index 6a2652365c..193b973f16 100644 --- a/parachain/runtime/rococo/src/xcm_config.rs +++ b/parachain/runtime/rococo/src/xcm_config.rs @@ -286,6 +286,12 @@ parameter_type_with_key! { }; } +impl GetByKey> for ParachainMinFee { + fn get_by_key(key: MultiLocation) -> Option { + Some(ParachainMinFee::get()) + } +} + parameter_types! { pub SelfLocation: MultiLocation = MultiLocation { parents:1, @@ -293,8 +299,14 @@ parameter_types! { Parachain(ParachainInfo::parachain_id().into()) ])) }; - pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000u64, 0); - pub const MaxAssetsForTransfer: usize = 3; + pub const BaseXcmWeight: u64 = 100_000_000; +} + +pub struct MaxAssetsForTransfer; +impl orml_traits::parameters::frame_support::traits::Get for MaxAssetsForTransfer { + fn get() -> usize { + 3 + } } #[cfg(feature = "runtime-benchmarks")]