mirror of
https://github.com/pezkuwichain/pezkuwi-runtime-templates.git
synced 2026-06-12 21:41:04 +00:00
Upgrade generic-template to polkadot-stable2412 (#401)
This commit is contained in:
@@ -8,6 +8,8 @@ use sp_std::{
|
||||
prelude::*,
|
||||
};
|
||||
use xcm::latest::Location;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
use xcm::v3::MultiLocation;
|
||||
|
||||
use crate::{
|
||||
types::{AccountId, AssetId, Balance},
|
||||
@@ -17,16 +19,31 @@ use crate::{
|
||||
// Our AssetType. For now we only handle Xcm Assets
|
||||
#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
|
||||
pub enum AssetType {
|
||||
Xcm(xcm::v3::Location),
|
||||
Xcm(xcm::v4::Location),
|
||||
}
|
||||
impl Default for AssetType {
|
||||
fn default() -> Self {
|
||||
Self::Xcm(xcm::v3::Location::here())
|
||||
Self::Xcm(xcm::v4::Location::here())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<xcm::v3::Location> for AssetType {
|
||||
fn from(location: xcm::v3::Location) -> Self {
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn convert_v3_to_v4(v3: MultiLocation) -> Option<xcm::v4::Location> {
|
||||
Some(xcm::v4::Location {
|
||||
parents: v3.parents,
|
||||
interior: xcm::v4::Junctions::try_from(v3.interior).ok()?, // Returns None if conversion fails
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
impl From<MultiLocation> for AssetType {
|
||||
fn from(value: MultiLocation) -> Self {
|
||||
Self::Xcm(convert_v3_to_v4(value).unwrap_or(xcm::v4::Location::default()))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<xcm::v4::Location> for AssetType {
|
||||
fn from(location: xcm::v4::Location) -> Self {
|
||||
Self::Xcm(location)
|
||||
}
|
||||
}
|
||||
@@ -40,7 +57,7 @@ impl TryFrom<Location> for AssetType {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AssetType> for Option<xcm::v3::Location> {
|
||||
impl From<AssetType> for Option<xcm::v4::Location> {
|
||||
fn from(val: AssetType) -> Self {
|
||||
match val {
|
||||
AssetType::Xcm(location) => Some(location),
|
||||
@@ -155,7 +172,7 @@ impl pallet_asset_manager::AssetRegistrar<Runtime> for AssetRegistrar {
|
||||
// This is the dispatch info of destroy
|
||||
RuntimeCall::Assets(pallet_assets::Call::<Runtime>::start_destroy { id: asset.into() })
|
||||
.get_dispatch_info()
|
||||
.weight
|
||||
.call_weight
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,6 +282,8 @@ mod tests {
|
||||
}
|
||||
|
||||
mod asset_type {
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{configs::AssetType, types::AssetId};
|
||||
|
||||
#[test]
|
||||
@@ -272,20 +291,20 @@ mod tests {
|
||||
let default_asset_type = AssetType::default();
|
||||
assert_eq!(
|
||||
default_asset_type,
|
||||
AssetType::Xcm(xcm::v3::Location {
|
||||
AssetType::Xcm(xcm::v4::Location {
|
||||
parents: 0,
|
||||
interior: xcm::v3::Junctions::Here
|
||||
interior: xcm::v4::Junctions::Here
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_asset_type_from_location_v3() {
|
||||
let location = xcm::v3::Location {
|
||||
let location = xcm::v4::Location {
|
||||
parents: 0,
|
||||
interior: xcm::v3::Junctions::X1(xcm::v3::Junction::OnlyChild),
|
||||
interior: xcm::v4::Junctions::X1(Arc::new([xcm::v4::Junction::OnlyChild])),
|
||||
};
|
||||
let asset_type = AssetType::from(location);
|
||||
let asset_type = AssetType::from(location.clone());
|
||||
|
||||
assert_eq!(asset_type, AssetType::Xcm(location));
|
||||
}
|
||||
@@ -294,8 +313,8 @@ mod tests {
|
||||
fn test_asset_type_try_from_location_v4() {
|
||||
let location =
|
||||
xcm::latest::Location { parents: 0, interior: xcm::latest::Junctions::Here };
|
||||
let old_location: xcm::v3::Location =
|
||||
xcm::v3::Location { parents: 0, interior: xcm::v3::Junctions::Here };
|
||||
let old_location: xcm::v4::Location =
|
||||
xcm::v4::Location { parents: 0, interior: xcm::v4::Junctions::Here };
|
||||
let asset_type = AssetType::try_from(location)
|
||||
.expect("AssetType conversion from location v4 failed");
|
||||
|
||||
@@ -304,15 +323,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_asset_type_into_location() {
|
||||
let location = xcm::v3::Location { parents: 0, interior: xcm::v3::Junctions::Here };
|
||||
let asset_type = AssetType::Xcm(location);
|
||||
let converted: Option<xcm::v3::Location> = asset_type.into();
|
||||
let location = xcm::v4::Location { parents: 0, interior: xcm::v4::Junctions::Here };
|
||||
let asset_type = AssetType::Xcm(location.clone());
|
||||
let converted: Option<xcm::v4::Location> = asset_type.into();
|
||||
assert_eq!(converted, Some(location));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_asset_type_into_asset_id() {
|
||||
let location = xcm::v3::Location { parents: 0, interior: xcm::v3::Junctions::Here };
|
||||
let location = xcm::v4::Location { parents: 0, interior: xcm::v4::Junctions::Here };
|
||||
let expected_asset_id: u32 = 3068126878;
|
||||
let asset_type = AssetType::Xcm(location);
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ use xcm_builder::{
|
||||
};
|
||||
use xcm_config::*;
|
||||
use xcm_executor::XcmExecutor;
|
||||
use xcm_primitives::{AbsoluteAndRelativeReserve, AsAssetType};
|
||||
use xcm_primitives::AsAssetType;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
use crate::benchmark::{OpenHrmpChannel, PayWithEnsure};
|
||||
@@ -163,7 +163,8 @@ impl XcmConfig for OpenZeppelinRuntime {
|
||||
type SelfReserve = SelfReserve;
|
||||
type SovereignAccountDispatcherOrigin = EnsureRoot<AccountId>;
|
||||
type Trader = pallet_xcm_weight_trader::Trader<Runtime>;
|
||||
type TransactorReserveProvider = AbsoluteAndRelativeReserve<SelfLocationAbsolute>;
|
||||
type TransactorReserveProvider =
|
||||
xcm_primitives::AbsoluteAndRelativeReserve<SelfLocationAbsolute>;
|
||||
type Transactors = Transactors;
|
||||
type UniversalLocation = UniversalLocation;
|
||||
type WeightToFee = WeightToFee;
|
||||
|
||||
@@ -30,10 +30,14 @@ impl ConsensusWeight for OpenZeppelinRuntime {
|
||||
|
||||
impl AssetsWeight for OpenZeppelinRuntime {
|
||||
type AssetManager = weights::pallet_asset_manager::WeightInfo<Runtime>;
|
||||
//TODO: fix weight
|
||||
type AssetTxPayment = ();
|
||||
type Assets = weights::pallet_assets::WeightInfo<Runtime>;
|
||||
// TODO: fix weight on release
|
||||
type OracleMembership = ();
|
||||
type OrmlOracle = (); // TODO: fix weight
|
||||
type OrmlOracle = ();
|
||||
// TODO: fix weight
|
||||
type TransactionPayment = weights::pallet_transaction_payment::WeightInfo<Runtime>;
|
||||
}
|
||||
|
||||
impl GovernanceWeight for OpenZeppelinRuntime {
|
||||
|
||||
@@ -16,13 +16,11 @@ use xcm::latest::{prelude::*, Junction::PalletInstance};
|
||||
use xcm_builder::{
|
||||
AccountId32Aliases, Case, FixedWeightBounds, FungibleAdapter, FungiblesAdapter,
|
||||
IsChildSystemParachain, IsConcrete, NoChecking, ParentIsPreset, RelayChainAsNative,
|
||||
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
|
||||
SignedToAccountId32, SovereignSignedViaLocation, WithUniqueTopic, XcmFeeManagerFromComponents,
|
||||
XcmFeeToAccount,
|
||||
};
|
||||
use xcm_primitives::{
|
||||
AbsoluteAndRelativeReserve, UtilityAvailableCalls, UtilityEncodeCall, XcmTransact,
|
||||
SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia,
|
||||
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, WithUniqueTopic,
|
||||
XcmFeeManagerFromComponents,
|
||||
};
|
||||
use xcm_primitives::{UtilityAvailableCalls, UtilityEncodeCall, XcmTransact};
|
||||
|
||||
use crate::{
|
||||
configs::{MaxInstructions, ParachainSystem, Runtime, RuntimeCall, UnitWeightCost, XcmpQueue},
|
||||
@@ -49,8 +47,9 @@ parameter_types! {
|
||||
};
|
||||
}
|
||||
|
||||
/// Type for specifying how a `Location` can be converted into an
|
||||
/// `AccountId`. This is used when determining ownership of accounts for asset
|
||||
/// Type for specifying how a `Location` 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.
|
||||
pub type LocationToAccountId = (
|
||||
@@ -100,8 +99,9 @@ pub type LocalFungiblesTransactor = FungiblesAdapter<
|
||||
/// Means for transacting assets on this chain.
|
||||
pub type AssetTransactors = (LocalAssetTransactor, LocalFungiblesTransactor);
|
||||
|
||||
/// This is the type we use to convert an (incoming) XCM origin into a local
|
||||
/// `Origin` instance, ready for dispatching a transaction with Xcm's
|
||||
/// Type used to convert an (incoming) XCM origin into a local `Origin` instance
|
||||
///
|
||||
/// Local `Origin` instance is ready for dispatching a transaction with Xcm's
|
||||
/// `Transact`. There is an `OriginKind` which can biases the kind of local
|
||||
/// `Origin` it will become.
|
||||
pub type XcmOriginToTransactDispatchOrigin = (
|
||||
@@ -124,7 +124,7 @@ pub type XcmOriginToTransactDispatchOrigin = (
|
||||
|
||||
pub type FeeManager = XcmFeeManagerFromComponents<
|
||||
IsChildSystemParachain<primitives::Id>,
|
||||
XcmFeeToAccount<AssetTransactors, AccountId, TreasuryAccount>,
|
||||
SendXcmFeeToAccount<AssetTransactors, TreasuryAccount>,
|
||||
>;
|
||||
|
||||
/// Matches foreign assets from a given origin.
|
||||
@@ -314,6 +314,50 @@ impl Reserve for BridgedAssetReserveProvider {
|
||||
}
|
||||
}
|
||||
|
||||
// Provide reserve in relative path view
|
||||
// Self tokens are represeneted as Here
|
||||
// Moved from Moonbeam to implement orml_traits::location::Reserve after Moonbeam
|
||||
// removed ORML dependencies
|
||||
pub struct RelativeReserveProvider;
|
||||
|
||||
impl Reserve for RelativeReserveProvider {
|
||||
fn reserve(asset: &Asset) -> Option<Location> {
|
||||
let AssetId(location) = &asset.id;
|
||||
if location.parents == 0
|
||||
&& !matches!(location.first_interior(), Some(Junction::Parachain(_)))
|
||||
{
|
||||
Some(Location::here())
|
||||
} else {
|
||||
Some(location.chain_location())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Struct that uses RelativeReserveProvider to output relative views of multilocations
|
||||
///
|
||||
/// Additionally accepts a Location that aims at representing the chain part
|
||||
/// (parent: 1, Parachain(paraId)) of the absolute representation of our chain.
|
||||
/// If a token reserve matches against this absolute view, we return Some(Location::here())
|
||||
/// This helps users by preventing errors when they try to transfer a token through xtokens
|
||||
/// to our chain (either inserting the relative or the absolute value).
|
||||
// Moved from Moonbeam to implement orml_traits::location::Reserve after Moonbeam
|
||||
// removed ORML dependencies
|
||||
pub struct AbsoluteAndRelativeReserve<AbsoluteMultiLocation>(PhantomData<AbsoluteMultiLocation>);
|
||||
impl<AbsoluteMultiLocation> Reserve for AbsoluteAndRelativeReserve<AbsoluteMultiLocation>
|
||||
where
|
||||
AbsoluteMultiLocation: Get<Location>,
|
||||
{
|
||||
fn reserve(asset: &Asset) -> Option<Location> {
|
||||
RelativeReserveProvider::reserve(asset).map(|relative_reserve| {
|
||||
if relative_reserve == AbsoluteMultiLocation::get() {
|
||||
Location::here()
|
||||
} else {
|
||||
relative_reserve
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ReserveProviders;
|
||||
|
||||
impl Reserve for ReserveProviders {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
extern crate alloc;
|
||||
|
||||
use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight};
|
||||
use sp_runtime::{create_runtime_str, Perbill};
|
||||
use sp_runtime::Perbill;
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
use crate::{apis, types::BlockNumber};
|
||||
@@ -26,14 +28,14 @@ pub const POLY_DEGREE: u8 = 1;
|
||||
|
||||
#[sp_version::runtime_version]
|
||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("template-parachain"),
|
||||
impl_name: create_runtime_str!("template-parachain"),
|
||||
spec_name: alloc::borrow::Cow::Borrowed("template-parachain"),
|
||||
impl_name: alloc::borrow::Cow::Borrowed("template-parachain"),
|
||||
authoring_version: 1,
|
||||
spec_version: 1,
|
||||
impl_version: 0,
|
||||
apis: apis::RUNTIME_API_VERSIONS,
|
||||
transaction_version: 1,
|
||||
state_version: 1,
|
||||
system_version: 1,
|
||||
};
|
||||
|
||||
/// This determines the average expected block time that we are targeting.
|
||||
|
||||
@@ -67,7 +67,9 @@ impl WeightToFeePolynomial for WeightToFee {
|
||||
}
|
||||
}
|
||||
|
||||
/// Opaque types. These are used by the CLI to instantiate machinery that don't
|
||||
/// Opaque types
|
||||
///
|
||||
/// These are used by the CLI to instantiate machinery that don't
|
||||
/// need to know the specifics of the runtime. They can then be made to be
|
||||
/// agnostic over specific formats of data like extrinsics, allowing for them to
|
||||
/// continue syncing the network through upgrades to even the core data
|
||||
|
||||
@@ -37,6 +37,7 @@ pub mod pallet_scheduler;
|
||||
pub mod pallet_session;
|
||||
pub mod pallet_sudo;
|
||||
pub mod pallet_timestamp;
|
||||
pub mod pallet_transaction_payment;
|
||||
pub mod pallet_treasury;
|
||||
pub mod pallet_utility;
|
||||
pub mod pallet_whitelist;
|
||||
|
||||
@@ -510,4 +510,10 @@ impl<T: frame_system::Config> pallet_assets::WeightInfo for WeightInfo<T> {
|
||||
.saturating_add(T::DbWeight::get().reads(2))
|
||||
.saturating_add(T::DbWeight::get().writes(1))
|
||||
}
|
||||
fn transfer_all() -> Weight {
|
||||
Weight::from_parts(19_482_000, 0)
|
||||
.saturating_add(Weight::from_parts(0, 3675))
|
||||
.saturating_add(T::DbWeight::get().reads(2))
|
||||
.saturating_add(T::DbWeight::get().writes(1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,4 +78,14 @@ impl<T: frame_system::Config> pallet_sudo::WeightInfo for WeightInfo<T> {
|
||||
.saturating_add(T::DbWeight::get().reads(1))
|
||||
.saturating_add(T::DbWeight::get().writes(1))
|
||||
}
|
||||
fn check_only_sudo_account() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `98`
|
||||
// Estimated: `1517`
|
||||
// Minimum execution time: 11_126_000 picoseconds.
|
||||
Weight::from_parts(11_411_000, 0)
|
||||
.saturating_add(Weight::from_parts(0, 1517))
|
||||
.saturating_add(T::DbWeight::get().reads(1))
|
||||
.saturating_add(T::DbWeight::get().writes(1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
//! Autogenerated weights for `pallet_transaction_payment`
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 42.0.0
|
||||
//! DATE: 2024-11-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! WORST CASE MAP SIZE: `1000000`
|
||||
//! HOSTNAME: `ip-172-31-15-118`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz`
|
||||
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024
|
||||
|
||||
// Executed Command:
|
||||
// target/release/generic-template-node
|
||||
// benchmark
|
||||
// pallet
|
||||
// --steps=50
|
||||
// --repeat=20
|
||||
// --extrinsic=*
|
||||
// --wasm-execution=compiled
|
||||
// --heap-pages=4096
|
||||
// --json-file=benchmarking/results/results-pallet_transaction_payment.json
|
||||
// --pallet=pallet_transaction_payment
|
||||
// --chain=dev
|
||||
// --output=benchmarking/new-benchmarks/pallet_transaction_payment.rs
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use frame_support::{traits::Get, weights::Weight};
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// Weight functions for `pallet_transaction_payment`.
|
||||
pub struct WeightInfo<T>(PhantomData<T>);
|
||||
impl<T: frame_system::Config> pallet_transaction_payment::WeightInfo for WeightInfo<T> {
|
||||
fn charge_transaction_payment() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `94`
|
||||
// Estimated: `0`
|
||||
// Minimum execution time: 3_838_000 picoseconds.
|
||||
Weight::from_parts(3_942_000, 0)
|
||||
.saturating_add(Weight::from_parts(0, 0))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user