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

polkadot-sdk v1.13.0 uplift #1358

Merged
merged 29 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6068a3f
deps uplift
ipapandinas Sep 5, 2024
4fc0e05
RuntimeGenesisConfig generic type removed from GenericChainSpec
ipapandinas Sep 5, 2024
d190155
XcmRecorder type added xcm_executor config
ipapandinas Sep 5, 2024
b6506cc
MaxActiveOutboundChannels & MaxPageSize types added, xcmp queue palle…
ipapandinas Sep 5, 2024
6d63a79
XcmPaymentApi refactored, DryRunApi implemented
ipapandinas Sep 5, 2024
fc812f5
preservation Protect added to burn_from in pallet balances
ipapandinas Sep 5, 2024
277e37a
pallet balances weights updated
ipapandinas Sep 5, 2024
02f1c99
xcm api integration test extended
ipapandinas Sep 7, 2024
a411c7e
xcm api integration test extended
ipapandinas Sep 7, 2024
97551a6
xcm api implemented in fake_runtime_apis
ipapandinas Sep 7, 2024
4c1e26b
runtime used to generate genesis state for benchmarking
ipapandinas Sep 7, 2024
6738535
vendor libs updated
ipapandinas Sep 9, 2024
caae82b
cargo fmt
ipapandinas Sep 9, 2024
c3fe841
Small typo fixed and 'Preserve' used in burn_from
ipapandinas Sep 10, 2024
2c46cb3
fix zepter CI
ipapandinas Sep 10, 2024
b5a7618
revert xcm api implementation in fake_runtime_apis
ipapandinas Sep 10, 2024
a0f665b
Update scripts/run_benchmarks.sh
ipapandinas Sep 10, 2024
661ab10
Revert "vendor libs updated"
ipapandinas Sep 11, 2024
753df36
XcmRecorder relies on PolkadotXcm for production runtimes
ipapandinas Sep 11, 2024
1c2c599
fix to ensure asset XCM version conversion
ipapandinas Sep 11, 2024
cab7465
Revert "Update scripts/run_benchmarks.sh"
ipapandinas Sep 11, 2024
0187025
Revert "runtime used to generate genesis state for benchmarking"
ipapandinas Sep 11, 2024
0546708
weight_to_fee implemeted in pallet-xc-asset-config
ipapandinas Sep 11, 2024
ab3ec8c
fix typo
ipapandinas Sep 12, 2024
936d410
XcmRecorder integration test
ipapandinas Sep 12, 2024
fd33f7c
fix zepter CI
ipapandinas Sep 12, 2024
e593d3b
XcmRecorder integration test from Runtime XcmConfig
ipapandinas Sep 12, 2024
7141da7
DryRunApi integration tests improved
ipapandinas Sep 13, 2024
2a1dc19
todo comment added
ipapandinas Sep 16, 2024
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
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
10 changes: 0 additions & 10 deletions primitives/src/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
//! - `FixedRateOfForeignAsset` - weight trader for execution payment in foreign asset
//! - `ReserveAssetFilter` - used to check whether asset/origin are a valid reserve location
//! - `XcmFungibleFeeHandler` - used to handle XCM fee execution fees
//! - `WeightToForeignAssetFee` - used to convert weight to fee based on units per second and weight.
//!
//! Please refer to implementation below for more info.
//!
Expand Down Expand Up @@ -356,12 +355,3 @@ impl<T: Contains<Location>> ShouldExecute for AllowTopLevelPaidExecutionFrom<T>
Ok(())
}
}

pub struct WeightToForeignAssetFee;
impl WeightToForeignAssetFee {
/// 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)
}
}
33 changes: 17 additions & 16 deletions runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ use sp_runtime::{
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
use xcm::{
v4::{AssetId as XcmAssetId, Location as XcmLocation},
VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
};
use xcm_fee_payment_runtime_api::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
Expand All @@ -83,7 +83,7 @@ use astar_primitives::{
},
evm::EvmRevertCodeHandler,
oracle::{CurrencyAmount, CurrencyId, DummyCombineData, Price},
xcm::{AssetLocationIdConverter, WeightToForeignAssetFee},
xcm::AssetLocationIdConverter,
Address, AssetId, BlockNumber, Hash, Header, Nonce, UnfreezeChainOnFailedMigration,
};
pub use astar_primitives::{governance::OracleMembershipInst, AccountId, Balance, Signature};
Expand Down Expand Up @@ -1933,22 +1933,23 @@ impl_runtime_apis! {
}

fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
match asset.try_as::<XcmAssetId>() {
// for native token
Ok(asset_id) if asset_id.0 == xcm_config::AstarLocation::get() => {
Ok(WeightToFee::weight_to_fee(&weight))
}
// for foreign assets that have 'units per second' configured
Ok(asset_id) => {
let versioned_location = VersionedLocation::V4(asset_id.0.clone());
let asset = asset.into_version(xcm::v4::VERSION).map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
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 that have 'units per second' configures
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
else {
let versioned_location = VersionedLocation::V4(asset_id.0);

match pallet_xc_asset_config::AssetLocationUnitsPerSecond::<Runtime>::get(versioned_location) {
Some(units_per_sec) => Ok(WeightToForeignAssetFee::weight_to_fee(weight, units_per_sec)),
None => Err(XcmPaymentApiError::AssetNotFound),
match pallet_xc_asset_config::AssetLocationUnitsPerSecond::<Runtime>::get(versioned_location) {
Some(units_per_sec) => {
Ok(pallet_xc_asset_config::Pallet::<Runtime>::weight_to_fee(weight, units_per_sec))
}
},
// for failed asset conversion
Err(_) => Err(XcmPaymentApiError::VersionedConversionFailed)
None => Err(XcmPaymentApiError::AssetNotFound),
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/astar/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl xcm_executor::Config for XcmConfig {
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
type XcmRecorder = ();
type XcmRecorder = PolkadotXcm;
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
}

/// Local origins on this chain are allowed to dispatch XCM sends/executions.
Expand Down
33 changes: 17 additions & 16 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use sp_runtime::{
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
use xcm::{
v4::{AssetId as XcmAssetId, Location as XcmLocation},
VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
};
use xcm_fee_payment_runtime_api::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
Expand All @@ -93,7 +93,7 @@ use astar_primitives::{
TechnicalCommitteeMembershipInst,
},
oracle::{CurrencyAmount, CurrencyId, DummyCombineData, Price},
xcm::{AssetLocationIdConverter, WeightToForeignAssetFee},
xcm::AssetLocationIdConverter,
Address, AssetId, BlockNumber, Hash, Header, Nonce, UnfreezeChainOnFailedMigration,
};
pub use astar_primitives::{AccountId, Balance, Signature};
Expand Down Expand Up @@ -2264,22 +2264,23 @@ impl_runtime_apis! {
}

fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
match asset.try_as::<XcmAssetId>() {
// for native token
Ok(asset_id) if asset_id.0 == xcm_config::ShibuyaLocation::get() => {
Ok(WeightToFee::weight_to_fee(&weight))
}
// for foreign assets that have 'units per second' configured
Ok(asset_id) => {
let versioned_location = VersionedLocation::V4(asset_id.0.clone());
let asset = asset.into_version(xcm::v4::VERSION).map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
let asset_id: XcmAssetId = asset.try_into().map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;

// for native token
if asset_id.0 == xcm_config::ShibuyaLocation::get() {
Ok(WeightToFee::weight_to_fee(&weight))
}
// for foreign assets that have 'units per second' configures
else {
let versioned_location = VersionedLocation::V4(asset_id.0);

match pallet_xc_asset_config::AssetLocationUnitsPerSecond::<Runtime>::get(versioned_location) {
Some(units_per_sec) => Ok(WeightToForeignAssetFee::weight_to_fee(weight, units_per_sec)),
None => Err(XcmPaymentApiError::AssetNotFound),
match pallet_xc_asset_config::AssetLocationUnitsPerSecond::<Runtime>::get(versioned_location) {
Some(units_per_sec) => {
Ok(pallet_xc_asset_config::Pallet::<Runtime>::weight_to_fee(weight, units_per_sec))
}
},
// for failed asset conversion
Err(_) => Err(XcmPaymentApiError::VersionedConversionFailed)
None => Err(XcmPaymentApiError::AssetNotFound),
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/shibuya/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl xcm_executor::Config for XcmConfig {
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
type XcmRecorder = ();
type XcmRecorder = PolkadotXcm;
}

/// Local origins on this chain are allowed to dispatch XCM sends/executions.
Expand Down
Loading
Loading