Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Companion for #7005 #2433

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 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
3 changes: 2 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions parachains/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ xcm-executor = { git = "https://github.com/paritytech/polkadot", default-feature
pallet-collator-selection = { path = "../../pallets/collator-selection", default-features = false }
cumulus-primitives-core = { path = "../../primitives/core", default-features = false }
cumulus-primitives-utility = { path = "../../primitives/utility", default-features = false }
parachain-info = { path = "../pallets/parachain-info", default-features = false }

[dev-dependencies]
pallet-authorship = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
Expand Down
8 changes: 7 additions & 1 deletion parachains/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ mod types {
/// Common constants of parachains.
mod constants {
use super::types::BlockNumber;
use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight};
use frame_support::{
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
PalletId,
};
use sp_runtime::Perbill;
/// This determines the average expected block time that we are targeting. Blocks will be
/// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by
Expand Down Expand Up @@ -96,6 +99,9 @@ mod constants {
WEIGHT_REF_TIME_PER_SECOND.saturating_div(2),
polkadot_primitives::MAX_POV_SIZE as u64,
);

/// Treasury pallet id of the local chain, used to convert into AccountId
pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry");
}

/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
Expand Down
23 changes: 22 additions & 1 deletion parachains/common/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::impls::AccountIdOf;
use core::marker::PhantomData;
use frame_support::{
log,
traits::{fungibles::Inspect, tokens::ConversionToAssetBalance, ContainsPair},
traits::{fungibles::Inspect, tokens::ConversionToAssetBalance, Contains, ContainsPair},
weights::Weight,
};
use sp_runtime::traits::Get;
Expand Down Expand Up @@ -63,3 +63,24 @@ impl<Location: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
matches!(asset.id, Concrete(ref id) if id == origin && origin == &Location::get())
}
}

pub struct RelayOrOtherSystemParachains<
SystemParachainMatcher: Contains<MultiLocation>,
Runtime: parachain_info::Config,
> {
_runtime: PhantomData<(SystemParachainMatcher, Runtime)>,
}
impl<SystemParachainMatcher: Contains<MultiLocation>, Runtime: parachain_info::Config>
Contains<MultiLocation> for RelayOrOtherSystemParachains<SystemParachainMatcher, Runtime>
{
fn contains(l: &MultiLocation) -> bool {
let self_para_id: u32 = parachain_info::Pallet::<Runtime>::get().into();
if let MultiLocation { parents: 0, interior: X1(Parachain(para_id)) } = l {
if *para_id == self_para_id {
return false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here should be probably return true, because we want to waive runtime itself not to pay fees (used for XcmFeesToAccount),
with return false runtime itself wont be waived, means it needs to pay

other question is if matching of MultiLocation { parents: 0, interior: X1(Parachain(para_id)) shouldnt be replaced with Here or better just remove this if for self-detection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we avoided matching ourself for the asset-conversion because we started trying to asset transfer native assets - we have explicit checks in the asset-coversion pallet now so I don't think this exception is now needed.

}
}
matches!(l, MultiLocation { parents: 1, interior: Here }) ||
SystemParachainMatcher::contains(l)
}
}
14 changes: 12 additions & 2 deletions parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ use frame_support::{
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{impls::ToStakingPot, xcm_config::AssetFeeAsExistentialDepositMultiplier};
use xcm_builder::XcmFeesToAccount;

use kusama_runtime_constants::system_parachain::SystemParachains;
use parachains_common::{xcm_config::RelayOrOtherSystemParachains, TREASURY_PALLET_ID};
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::ConvertInto;
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand All @@ -55,6 +59,7 @@ parameter_types! {
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
pub const GovernanceLocation: MultiLocation = MultiLocation::parent();
pub const FellowshipLocation: MultiLocation = MultiLocation::parent();
pub TreasuryAccount: Option<AccountId> = Some(TREASURY_PALLET_ID.into_account_truncating());
}

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down Expand Up @@ -422,7 +427,12 @@ impl xcm_executor::Config for XcmConfig {
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager = ();
type FeeManager = XcmFeesToAccount<
Self,
RelayOrOtherSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
20 changes: 16 additions & 4 deletions parachains/runtimes/assets/asset-hub-polkadot/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ use frame_support::{
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{impls::ToStakingPot, xcm_config::AssetFeeAsExistentialDepositMultiplier};
use parachains_common::{
impls::ToStakingPot,
xcm_config::{AssetFeeAsExistentialDepositMultiplier, RelayOrOtherSystemParachains},
TREASURY_PALLET_ID,
};
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::ConvertInto;
use polkadot_runtime_constants::system_parachain::SystemParachains;
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand All @@ -39,7 +44,7 @@ use xcm_builder::{
NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, UsingComponents, WeightInfoBounds,
WithComputedOrigin,
WithComputedOrigin, XcmFeesToAccount,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -167,6 +172,8 @@ parameter_types! {
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 64;
pub XcmAssetFeesReceiver: Option<AccountId> = Authorship::author();

pub TreasuryAccount: Option<AccountId> = Some(TREASURY_PALLET_ID.into_account_truncating());
}

match_types! {
Expand Down Expand Up @@ -429,7 +436,12 @@ impl xcm_executor::Config for XcmConfig {
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager = ();
type FeeManager = XcmFeesToAccount<
Self,
RelayOrOtherSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ use frame_support::{
traits::{ConstU32, Contains, Everything, Nothing},
};
use frame_system::EnsureRoot;
use kusama_runtime_constants::system_parachain::SystemParachains;
use pallet_xcm::XcmPassthrough;
use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom};
use parachains_common::{
impls::ToStakingPot,
xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains},
TREASURY_PALLET_ID,
};
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::AccountIdConversion;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand All @@ -34,6 +40,7 @@ use xcm_builder::{
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
XcmFeesToAccount,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand All @@ -47,6 +54,7 @@ parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;
pub const GovernanceLocation: MultiLocation = MultiLocation::parent();
pub const FellowshipLocation: MultiLocation = MultiLocation::parent();
pub TreasuryAccount: Option<AccountId> = Some(TREASURY_PALLET_ID.into_account_truncating());
}

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down Expand Up @@ -205,7 +213,12 @@ impl xcm_executor::Config for XcmConfig {
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager = ();
type FeeManager = XcmFeesToAccount<
Self,
RelayOrOtherSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ use frame_support::{
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom};
use parachains_common::{
impls::ToStakingPot,
xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains},
TREASURY_PALLET_ID,
};
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_constants::system_parachain::SystemParachains;
use sp_runtime::traits::AccountIdConversion;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, CurrencyAdapter,
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, IsConcrete, ParentAsSuperuser,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents, WeightInfoBounds, WithComputedOrigin,
UsingComponents, WeightInfoBounds, WithComputedOrigin, XcmFeesToAccount,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand All @@ -47,6 +53,7 @@ parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;
pub FellowshipLocation: MultiLocation = MultiLocation::new(1, Parachain(1001));
pub const GovernanceLocation: MultiLocation = MultiLocation::parent();
pub TreasuryAccount: Option<AccountId> = Some(TREASURY_PALLET_ID.into_account_truncating());
}

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down Expand Up @@ -206,7 +213,12 @@ impl xcm_executor::Config for XcmConfig {
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager = ();
type FeeManager = XcmFeesToAccount<
Self,
RelayOrOtherSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ use frame_support::{
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom};
use parachains_common::{
impls::ToStakingPot,
xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains},
TREASURY_PALLET_ID,
};
use polkadot_parachain::primitives::Sibling;
use rococo_runtime_constants::system_parachain::SystemParachains;
use sp_core::Get;
use sp_runtime::traits::AccountIdConversion;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand All @@ -41,7 +47,7 @@ use xcm_builder::{
ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeesToAccount,
};
use xcm_executor::{
traits::{ExportXcm, WithOriginFilter},
Expand All @@ -55,6 +61,7 @@ parameter_types! {
X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into()));
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 64;
pub TreasuryAccount: Option<AccountId> = Some(TREASURY_PALLET_ID.into_account_truncating());
}

pub struct RelayNetwork;
Expand Down Expand Up @@ -252,7 +259,12 @@ impl xcm_executor::Config for XcmConfig {
type SubscriptionService = PolkadotXcm;
type PalletInstancesInfo = AllPalletsWithSystem;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type FeeManager = ();
type FeeManager = XcmFeesToAccount<
Self,
RelayOrOtherSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = BridgeHubRococoOrBridgeHubWococoSwitchExporter;
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ use frame_support::{
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom};
use parachains_common::{
impls::ToStakingPot,
xcm_config::{ConcreteNativeAssetFrom, RelayOrOtherSystemParachains},
TREASURY_PALLET_ID,
};
use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_constants::system_parachain::SystemParachains;
use sp_runtime::traits::AccountIdConversion;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand All @@ -34,7 +40,7 @@ use xcm_builder::{
OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
WithComputedOrigin,
WithComputedOrigin, XcmFeesToAccount,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand All @@ -46,6 +52,8 @@ parameter_types! {
X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into()));
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
pub const GovernanceLocation: MultiLocation = MultiLocation::parent();
pub TreasuryAccount: Option<AccountId> = Some(TREASURY_PALLET_ID.into_account_truncating());

}

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down Expand Up @@ -249,7 +257,12 @@ impl xcm_executor::Config for XcmConfig {
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager = ();
type FeeManager = XcmFeesToAccount<
Self,
RelayOrOtherSystemParachains<SystemParachains, Runtime>,
AccountId,
TreasuryAccount,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = WithOriginFilter<SafeCallFilter>;
Expand Down
4 changes: 2 additions & 2 deletions parachains/runtimes/contracts/contracts-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pallet-contracts = { git = "https://github.com/paritytech/substrate", default-fe
pallet-contracts-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }

# Polkadot
kusama-runtime-constants = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
rococo-runtime-constants = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
Expand Down Expand Up @@ -86,8 +86,8 @@ std = [
"frame-support/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"rococo-runtime-constants/std",
"frame-try-runtime/std",
"kusama-runtime-constants/std",
"pallet-aura/std",
"pallet-authorship/std",
"pallet-balances/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// limitations under the License.

pub mod currency {
use kusama_runtime_constants as constants;
use polkadot_core_primitives::Balance;
use rococo_runtime_constants as constants;

/// The existential deposit. Set to 1/10 of its parent Relay Chain.
pub const EXISTENTIAL_DEPOSIT: Balance = constants::currency::EXISTENTIAL_DEPOSIT / 10;
Expand Down
Loading