Skip to content

Commit

Permalink
polkadot-sdk v1.13.0 uplift (#1358)
Browse files Browse the repository at this point in the history
* deps uplift

* RuntimeGenesisConfig generic type removed from GenericChainSpec

* XcmRecorder type added xcm_executor config, relies on PolkadotXcm for production runtimes

* MaxActiveOutboundChannels & MaxPageSize types added, xcmp queue pallet bounded

* XcmPaymentApi refactored, DryRunApi implemented

* preservation Preserve added to burn_from in pallet balances

* pallet balances weights updated

* xcm api integration test extended with DryRunApi

* weight_to_fee implemeted in pallet-xc-asset-config

* XcmRecorder integration test from Runtime XcmConfig
  • Loading branch information
ipapandinas authored Sep 16, 2024
1 parent da7e689 commit ae88fd4
Show file tree
Hide file tree
Showing 26 changed files with 1,868 additions and 1,631 deletions.
2,747 changes: 1,396 additions & 1,351 deletions Cargo.lock

Large diffs are not rendered by default.

312 changes: 154 additions & 158 deletions Cargo.toml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bin/collator/src/local/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use local_runtime::wasm_binary_unwrap;
use sc_service::ChainType;

/// Specialized `ChainSpec` for local network.
pub type ChainSpec = sc_service::GenericChainSpec<local_runtime::RuntimeGenesisConfig>;
pub type ChainSpec = sc_service::GenericChainSpec;

/// Development config.
pub fn development_config() -> ChainSpec {
Expand Down
3 changes: 1 addition & 2 deletions bin/collator/src/parachain/chain_spec/astar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ use astar_runtime::wasm_binary_unwrap;
use sc_service::ChainType;

/// Specialized `ChainSpec` for Astar Network.
pub type AstarChainSpec =
sc_service::GenericChainSpec<astar_runtime::RuntimeGenesisConfig, Extensions>;
pub type AstarChainSpec = sc_service::GenericChainSpec<Extensions>;

/// Get Astar chain specification.
pub fn get_chain_spec() -> AstarChainSpec {
Expand Down
4 changes: 2 additions & 2 deletions bin/collator/src/parachain/chain_spec/shibuya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
use super::Extensions;
use astar_primitives::parachain::SHIBUYA_ID;
use sc_service::ChainType;
use shibuya_runtime::{wasm_binary_unwrap, RuntimeGenesisConfig};
use shibuya_runtime::wasm_binary_unwrap;

/// Specialized `ChainSpec` for Shibuya testnet.
pub type ShibuyaChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig, Extensions>;
pub type ShibuyaChainSpec = sc_service::GenericChainSpec<Extensions>;

/// Gen Shibuya chain specification.
pub fn get_chain_spec() -> ShibuyaChainSpec {
Expand Down
3 changes: 1 addition & 2 deletions bin/collator/src/parachain/chain_spec/shiden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ use sc_service::ChainType;
use shiden_runtime::wasm_binary_unwrap;

/// Specialized `ChainSpec` for Shiden Network.
pub type ShidenChainSpec =
sc_service::GenericChainSpec<shiden_runtime::RuntimeGenesisConfig, Extensions>;
pub type ShidenChainSpec = sc_service::GenericChainSpec<Extensions>;

/// Gen Shiden chain specification.
pub fn get_chain_spec() -> ShidenChainSpec {
Expand Down
1 change: 1 addition & 0 deletions pallets/astar-xcm-benchmarks/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ impl xcm_executor::Config for XcmConfig {
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
type XcmRecorder = ();
}

impl pallet_xcm_benchmarks::Config for Test {
Expand Down
10 changes: 8 additions & 2 deletions pallets/unified-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub mod pallet {
/// - `signature`: A signature generated by the address to prove ownership
///
/// WARNING:
/// - This extrisic only handles transfer of native balance, if your EVM
/// - This extrinsic only handles transfer of native balance, if your EVM
/// address contains any other native assets like XC20, DAppStaking unclaimed rewards,
/// etc you need to transfer them before hand, otherwise FUNDS WILL BE LOST FOREVER.
/// - Once connected user cannot change their mapping EVER.
Expand Down Expand Up @@ -277,7 +277,13 @@ impl<T: Config> Pallet<T> {
let balance = T::Currency::reducible_balance(who, Preserve, Polite);
let fee = T::AccountMappingStorageFee::get();
ensure!(balance >= fee, Error::<T>::FundsUnavailable);
T::Currency::burn_from(who, T::AccountMappingStorageFee::get(), Exact, Polite)
T::Currency::burn_from(
who,
T::AccountMappingStorageFee::get(),
Preserve,
Exact,
Polite,
)
}
}

Expand Down
13 changes: 12 additions & 1 deletion pallets/xc-asset-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
//! `ExecutionPaymentRate` interface for fetching `units per second` if asset is supported payment asset
//! - `get_units_per_second`
//!
//! - `weight_to_fee` method is used to convert weight to fee based on units per second and weight.

#![cfg_attr(not(feature = "std"), no_std)]

Expand All @@ -72,7 +73,9 @@ pub use weights::WeightInfo;
pub mod pallet {

use crate::weights::WeightInfo;
use frame_support::{pallet_prelude::*, traits::EnsureOrigin};
use frame_support::{
pallet_prelude::*, traits::EnsureOrigin, weights::constants::WEIGHT_REF_TIME_PER_SECOND,
};
use frame_system::pallet_prelude::*;
use parity_scale_codec::HasCompact;
use sp_std::boxed::Box;
Expand Down Expand Up @@ -116,6 +119,14 @@ pub mod pallet {
}
}

impl<T: Config> Pallet<T> {
/// Convert weight to fee based on units per second and weight.
pub fn weight_to_fee(weight: Weight, units_per_second: u128) -> u128 {
units_per_second.saturating_mul(weight.ref_time() as u128)
/ (WEIGHT_REF_TIME_PER_SECOND as u128)
}
}

#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand Down
1 change: 1 addition & 0 deletions precompiles/xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ impl xcm_executor::Config for XcmConfig {
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
type XcmRecorder = ();
}

parameter_types! {
Expand Down
3 changes: 2 additions & 1 deletion runtime/astar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pallet-xcm-benchmarks = { workspace = true, optional = true }

# cumulus dependencies
cumulus-pallet-aura-ext = { workspace = true }
cumulus-pallet-parachain-system = { workspace = true, features = ["parameterized-consensus-hook"] }
cumulus-pallet-parachain-system = { workspace = true }
cumulus-pallet-xcm = { workspace = true }
cumulus-pallet-xcmp-queue = { workspace = true }
cumulus-primitives-aura = { workspace = true }
Expand Down Expand Up @@ -285,6 +285,7 @@ runtime-benchmarks = [
"polkadot-primitives/runtime-benchmarks",
"polkadot-runtime-common/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"xcm-fee-payment-runtime-api/runtime-benchmarks",
"cumulus-primitives-core/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"orml-oracle/runtime-benchmarks",
Expand Down
69 changes: 38 additions & 31 deletions runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ use xcm::{
v4::{AssetId as XcmAssetId, Location as XcmLocation},
IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
};
use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;
use xcm_fee_payment_runtime_api::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::Error as XcmPaymentApiError,
};

use astar_primitives::{
dapp_staking::{
Expand Down Expand Up @@ -105,7 +108,7 @@ mod chain_extensions;
pub mod genesis_config;
mod precompiles;
mod weights;
mod xcm_config;
pub mod xcm_config;

pub type AstarAssetLocationIdConverter = AssetLocationIdConverter<AssetId, XcAssetConfig>;

Expand Down Expand Up @@ -1907,49 +1910,43 @@ impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::XcmPaymentApi<Block> for Runtime {
impl xcm_fee_payment_runtime_api::fees::XcmPaymentApi<Block> for Runtime {
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
if !matches!(xcm_version, xcm::v3::VERSION | xcm::v4::VERSION) {
return Err(XcmPaymentApiError::UnhandledXcmVersion);
}

// Native asset is always supported
let native_asset_location: XcmLocation = XcmLocation::try_from(xcm_config::AstarLocation::get())
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;

Ok([VersionedAssetId::V4(native_asset_location.into())]
.into_iter()
// Acquire foreign assets which have 'units per second' configured
.chain(
pallet_xc_asset_config::AssetLocationUnitsPerSecond::<Runtime>::iter_keys().filter_map(|asset_location| {

match XcmLocation::try_from(asset_location) {
Ok(asset) => Some(VersionedAssetId::V4(asset.into())),
Err(_) => None,
}
})
).filter_map(|asset| asset.into_version(xcm_version).ok()).collect())
let mut acceptable_assets = vec![XcmAssetId::from(xcm_config::AstarLocation::get())];

// Add foreign assets that have 'units per second' configured
acceptable_assets.extend(
pallet_xc_asset_config::AssetLocationUnitsPerSecond::<Runtime>::iter_keys().filter_map(
|asset_location| match XcmLocation::try_from(asset_location) {
Ok(location) => Some(XcmAssetId::from(location)),
Err(_) => None,
},
),
);

PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)
}

fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
let native_asset_location = XcmLocation::try_from(xcm_config::AstarLocation::get())
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
let native_asset = VersionedAssetId::V4(native_asset_location.into());

let asset = asset
.into_version(xcm::v4::VERSION)
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
let asset = asset.into_version(xcm::v4::VERSION).map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
let asset_id: XcmAssetId = asset.try_into().map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;

if native_asset == asset {
Ok(XcmWeightToFee::weight_to_fee(&weight))
} else {
let asset_id: XcmAssetId = asset.try_into().map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
// for native token
if asset_id.0 == xcm_config::AstarLocation::get() {
Ok(WeightToFee::weight_to_fee(&weight))
}
// for foreign assets with “units per second” configurations
else {
let versioned_location = VersionedLocation::V4(asset_id.0);

match pallet_xc_asset_config::AssetLocationUnitsPerSecond::<Runtime>::get(versioned_location) {
Some(units_per_sec) => {
Ok(units_per_sec.saturating_mul(weight.ref_time() as u128)
/ (WEIGHT_REF_TIME_PER_SECOND as u128))
Ok(pallet_xc_asset_config::Pallet::<Runtime>::weight_to_fee(weight, units_per_sec))
}
None => Err(XcmPaymentApiError::AssetNotFound),
}
Expand All @@ -1965,6 +1962,16 @@ impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<CallDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
PolkadotXcm::dry_run_call::<Runtime, xcm_config::XcmRouter, OriginCaller, RuntimeCall>(origin, call)
}

fn dry_run_xcm(origin_location: VersionedLocation, xcm: VersionedXcm<RuntimeCall>) -> Result<XcmDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
PolkadotXcm::dry_run_xcm::<Runtime, xcm_config::XcmRouter, RuntimeCall, xcm_config::XcmConfig>(origin_location, xcm)
}
}

impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {

fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
Expand Down
3 changes: 3 additions & 0 deletions runtime/astar/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ impl xcm_executor::Config for XcmConfig {
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
type XcmRecorder = PolkadotXcm;
}

/// Local origins on this chain are allowed to dispatch XCM sends/executions.
Expand Down Expand Up @@ -335,6 +336,8 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type VersionWrapper = PolkadotXcm;
type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
type MaxInboundSuspended = ConstU32<1_000>;
type MaxActiveOutboundChannels = ConstU32<128>;
type MaxPageSize = ConstU32<{ 128 * 1024 }>;
type ControllerOrigin = EnsureRoot<AccountId>;
type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
type PriceForSiblingDelivery = NoPriceForMessageDelivery<ParaId>;
Expand Down
18 changes: 14 additions & 4 deletions runtime/local/src/weights/pallet_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,22 @@ impl<T: frame_system::Config> pallet_balances::WeightInfo for SubstrateWeight<T>
// Minimum execution time: 5_975_000 picoseconds.
Weight::from_parts(6_179_000, 0)
}

fn burn() -> Weight {

/// Storage: `UnifiedAccounts::NativeToEvm` (r:1 w:0)
/// Proof: `UnifiedAccounts::NativeToEvm` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`)
fn burn_allow_death() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `3533`
// Minimum execution time: 35_000_000 picoseconds.
Weight::from_parts(36_000_000, 3533)
.saturating_add(RocksDbWeight::get().reads(1_u64))
}
fn burn_keep_alive() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 30_151_000 picoseconds.
Weight::from_parts(30_968_000, 0)
// Minimum execution time: 22_000_000 picoseconds.
Weight::from_parts(22_000_000, 0)
}
}
3 changes: 2 additions & 1 deletion runtime/shibuya/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ vesting-mbm = { workspace = true }

# cumulus dependencies
cumulus-pallet-aura-ext = { workspace = true }
cumulus-pallet-parachain-system = { workspace = true, features = ["parameterized-consensus-hook"] }
cumulus-pallet-parachain-system = { workspace = true }
cumulus-pallet-xcm = { workspace = true }
cumulus-pallet-xcmp-queue = { workspace = true }
cumulus-primitives-aura = { workspace = true }
Expand Down Expand Up @@ -320,6 +320,7 @@ runtime-benchmarks = [
"polkadot-primitives/runtime-benchmarks",
"polkadot-runtime-common/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"xcm-fee-payment-runtime-api/runtime-benchmarks",
"cumulus-primitives-core/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"orml-oracle/runtime-benchmarks",
Expand Down
Loading

0 comments on commit ae88fd4

Please sign in to comment.