Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade generic-template to polkadot-stable2412 #401

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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
4,664 changes: 2,795 additions & 1,869 deletions generic-template/Cargo.lock

Large diffs are not rendered by default.

238 changes: 118 additions & 120 deletions generic-template/Cargo.toml

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions generic-template/runtime/src/configs/asset_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ 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 {
impl From<xcm::v4::Location> for AssetType {
fn from(location: xcm::v4::Location) -> Self {
Self::Xcm(location)
}
}
Expand All @@ -40,7 +40,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),
Expand Down Expand Up @@ -155,7 +155,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
}
}

Expand Down Expand Up @@ -272,18 +272,18 @@ 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(xcm::v4::Junction::OnlyChild),
};
let asset_type = AssetType::from(location);

Expand All @@ -294,8 +294,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");

Expand All @@ -304,15 +304,15 @@ mod tests {

#[test]
fn test_asset_type_into_location() {
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 asset_type = AssetType::Xcm(location);
let converted: Option<xcm::v3::Location> = asset_type.into();
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);

Expand Down
5 changes: 3 additions & 2 deletions generic-template/runtime/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down
55 changes: 48 additions & 7 deletions generic-template/runtime/src/configs/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -124,7 +122,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.
Expand Down Expand Up @@ -314,6 +312,49 @@ 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())
}
}
}

/// This struct offers uses RelativeReserveProvider to output relative views of multilocations
/// However, 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 {
Expand Down
2 changes: 1 addition & 1 deletion generic-template/runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
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.
Expand Down
1 change: 1 addition & 0 deletions generic-template/runtime/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions generic-template/runtime/src/weights/pallet_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
10 changes: 10 additions & 0 deletions generic-template/runtime/src/weights/pallet_sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
43 changes: 43 additions & 0 deletions generic-template/runtime/src/weights/pallet_transaction_payment.rs
Original file line number Diff line number Diff line change
@@ -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))
}
}
2 changes: 1 addition & 1 deletion generic-template/runtime/tests/constants_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod runtime_tests {
impl_version: 0,
apis: generic_runtime_template::apis::RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
system_version: 1,
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion generic-template/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2024-06-12"
channel = "nightly-2024-10-17"
targets = ["wasm32-unknown-unknown"]
components = ["rustfmt", "clippy", "rust-src"]
Loading