Skip to content

Commit

Permalink
fix runtime: pallet_aura::Config
Browse files Browse the repository at this point in the history
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
  • Loading branch information
higherordertech committed Nov 11, 2024
1 parent c9098cb commit 6b6c923
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 24 deletions.
97 changes: 92 additions & 5 deletions parachain/runtime/litentry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ where
{
if let Some(author_index) = pallet_aura::Pallet::<T>::find_author(digests) {
let authority_id =
<pallet_aura::Pallet<T>>::authorities()[author_index as usize].clone();
pallet_aura::Authorities::<Runtime>::get()[author_index as usize].clone();
return Some(H160::from_slice(&authority_id.encode()[4..24]));
}

Expand Down Expand Up @@ -1356,7 +1356,7 @@ impl_runtime_apis! {
Executive::execute_block(block);
}

fn initialize_block(header: &<Block as BlockT>::Header) {
fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
Executive::initialize_block(header)
}
}
Expand Down Expand Up @@ -1429,7 +1429,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down Expand Up @@ -1719,6 +1719,7 @@ impl_runtime_apis! {
fn trace_transaction(
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
traced_transaction: &pallet_ethereum::Transaction,
header: &<Block as BlockT>::Header,
) -> Result<
(),
sp_runtime::DispatchError,
Expand Down Expand Up @@ -1748,6 +1749,7 @@ impl_runtime_apis! {
fn trace_block(
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
known_transactions: Vec<H256>,
header: &<Block as BlockT>::Header,
) -> Result<
(),
sp_runtime::DispatchError,
Expand Down Expand Up @@ -1777,6 +1779,91 @@ impl_runtime_apis! {

Ok(())
}

fn trace_call(
header: &<Block as BlockT>::Header,
from: H160,
to: H160,
data: Vec<u8>,
value: U256,
gas_limit: U256,
max_fee_per_gas: Option<U256>,
max_priority_fee_per_gas: Option<U256>,
nonce: Option<U256>,
access_list: Option<Vec<(H160, Vec<H256>)>>,
) -> 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 <Runtime as pallet_evm::Config>::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 _ = <Runtime as pallet_evm::Config>::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,
<Runtime as pallet_evm::Config>::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<Block> for Runtime {
Expand Down Expand Up @@ -1820,15 +1907,15 @@ 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,
block.header.hash(),
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")
}
}

Expand Down
29 changes: 23 additions & 6 deletions parachain/runtime/litentry/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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::{
Expand Down Expand Up @@ -70,6 +71,12 @@ parameter_types! {
pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}

impl Get<Junctions> 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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<usize> for MaxAssetsForTransfer {
fn get() -> usize {
3
}
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
99 changes: 93 additions & 6 deletions parachain/runtime/paseo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ impl SortedMembers<AccountId> for CouncilProvider {
}

fn sorted_members() -> Vec<AccountId> {
Council::members()
pallet_collective::pallet::Members::<T, I>::get()
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -1114,7 +1114,7 @@ where
{
if let Some(author_index) = pallet_aura::Pallet::<T>::find_author(digests) {
let authority_id =
<pallet_aura::Pallet<T>>::authorities()[author_index as usize].clone();
pallet_aura::Authorities::<Runtime>::get()[author_index as usize].clone();
return Some(H160::from_slice(&authority_id.encode()[4..24]));
}

Expand Down Expand Up @@ -1417,7 +1417,7 @@ impl_runtime_apis! {
Executive::execute_block(block);
}

fn initialize_block(header: &<Block as BlockT>::Header) {
fn initialize_block(header: &<Block as BlockT>::Header) -> sp_runtime::ExtrinsicInclusionMode {
Executive::initialize_block(header)
}
}
Expand Down Expand Up @@ -1490,7 +1490,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down Expand Up @@ -1780,6 +1780,7 @@ impl_runtime_apis! {
fn trace_transaction(
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
traced_transaction: &pallet_ethereum::Transaction,
header: &<Block as BlockT>::Header,
) -> Result<
(),
sp_runtime::DispatchError,
Expand Down Expand Up @@ -1809,6 +1810,7 @@ impl_runtime_apis! {
fn trace_block(
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
known_transactions: Vec<H256>,
header: &<Block as BlockT>::Header,
) -> Result<
(),
sp_runtime::DispatchError,
Expand Down Expand Up @@ -1838,6 +1840,91 @@ impl_runtime_apis! {

Ok(())
}

fn trace_call(
header: &<Block as BlockT>::Header,
from: H160,
to: H160,
data: Vec<u8>,
value: U256,
gas_limit: U256,
max_fee_per_gas: Option<U256>,
max_priority_fee_per_gas: Option<U256>,
nonce: Option<U256>,
access_list: Option<Vec<(H160, Vec<H256>)>>,
) -> 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 <Runtime as pallet_evm::Config>::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 _ = <Runtime as pallet_evm::Config>::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,
<Runtime as pallet_evm::Config>::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<Block> for Runtime {
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 6b6c923

Please sign in to comment.