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 15 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
2,743 changes: 1,394 additions & 1,349 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.

5 changes: 5 additions & 0 deletions bin/collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ polkadot-parachain = { workspace = true, features = ["std"] }
polkadot-primitives = { workspace = true, features = ["std"] }
polkadot-service = { workspace = true }

# xcm dependencies
xcm = { workspace = true }
xcm-fee-payment-runtime-api = { workspace = true }

# benchmark dependencies
frame-benchmarking = { workspace = true, features = ["std"] }
frame-benchmarking-cli = { workspace = true }
Expand Down Expand Up @@ -188,6 +192,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"cumulus-primitives-core/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"xcm-fee-payment-runtime-api/runtime-benchmarks",
]
try-runtime = [
"local-runtime/try-runtime",
Expand Down
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
33 changes: 33 additions & 0 deletions bin/collator/src/parachain/fake_runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ use sp_runtime::{
ApplyExtrinsicResult, Permill,
};
use sp_version::RuntimeVersion;
use xcm::{VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm};
use xcm_fee_payment_runtime_api::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::Error as XcmPaymentApiError,
};

pub struct Runtime;

Expand Down Expand Up @@ -137,6 +142,34 @@ impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::fees::XcmPaymentApi<Block> for Runtime {
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
fn query_acceptable_payment_assets(_: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
unimplemented!()
}

fn query_weight_to_asset_fee(_: Weight, _: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
unimplemented!()
}

fn query_xcm_weight(_: VersionedXcm<()>) -> Result<Weight, XcmPaymentApiError> {
unimplemented!()
}

fn query_delivery_fees(_: VersionedLocation, _: VersionedXcm<()>) -> Result<VersionedAssets, XcmPaymentApiError> {
unimplemented!()
}
}

impl xcm_fee_payment_runtime_api::dry_run::DryRunApi<Block, (), (), ()> for Runtime {
fn dry_run_call(_: (), _: ()) -> Result<CallDryRunEffects<()>, XcmDryRunApiError> {
unimplemented!()
}

fn dry_run_xcm(_: VersionedLocation, _: VersionedXcm<()>) -> Result<XcmDryRunEffects<()>, XcmDryRunApiError> {
unimplemented!()
}
}

impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {
fn chain_id() -> u64 {
unimplemented!()
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,
)
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
}
}

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
10 changes: 10 additions & 0 deletions primitives/src/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//! - `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 @@ -355,3 +356,12 @@ 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)
}
}
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
82 changes: 44 additions & 38 deletions runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ use sp_runtime::{
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
use xcm::{
v4::{AssetId as XcmAssetId, Location as XcmLocation},
IntoVersion, VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
VersionedAssetId, VersionedAssets, VersionedLocation, VersionedXcm,
};
use xcm_fee_payment_runtime_api::{
dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects},
fees::Error as XcmPaymentApiError,
};
use xcm_fee_payment_runtime_api::Error as XcmPaymentApiError;

use astar_primitives::{
dapp_staking::{
Expand All @@ -80,7 +83,7 @@ use astar_primitives::{
},
evm::EvmRevertCodeHandler,
oracle::{CurrencyAmount, CurrencyId, DummyCombineData, Price},
xcm::AssetLocationIdConverter,
xcm::{AssetLocationIdConverter, WeightToForeignAssetFee},
Address, AssetId, BlockNumber, Hash, Header, Nonce, UnfreezeChainOnFailedMigration,
};
pub use astar_primitives::{governance::OracleMembershipInst, AccountId, Balance, Signature};
Expand Down Expand Up @@ -1907,52 +1910,45 @@ 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)?;

if native_asset == asset {
Ok(XcmWeightToFee::weight_to_fee(&weight))
} else {
let asset_id: XcmAssetId = asset.try_into().map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
let versioned_location = VersionedLocation::V4(asset_id.0);
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());
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved

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))
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),
}
None => Err(XcmPaymentApiError::AssetNotFound),
}
},
// for failed asset conversion
Err(_) => Err(XcmPaymentApiError::VersionedConversionFailed)
}
}

Expand All @@ -1965,6 +1961,16 @@ impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::dry_run::DryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
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 = ();
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
}

/// 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
Loading