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

XCM Integration #687

Merged
merged 22 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use cumulus_primitives_core::ParaId;
use primitives::{AccountId, Balance, Signature};
use runtime_eden::{
constants::{EXISTENTIAL_DEPOSIT, NODL},
AuraId, BalancesConfig, CollatorSelectionConfig, GenesisConfig, ParachainInfoConfig, SessionConfig, SessionKeys,
SystemConfig, TechnicalMembershipConfig, WASM_BINARY,
AuraId, BalancesConfig, CollatorSelectionConfig, GenesisConfig, ParachainInfoConfig, PolkadotXcmConfig,
SessionConfig, SessionKeys, SystemConfig, TechnicalMembershipConfig, WASM_BINARY,
};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
Expand All @@ -34,6 +34,7 @@ use sp_runtime::{
bounded_vec,
traits::{IdentifyAccount, Verify},
};
const SAFE_XCM_VERSION: u32 = xcm::v2::VERSION;

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, Extensions>;
Expand Down Expand Up @@ -161,6 +162,10 @@ fn eden_testnet_genesis(

// DAO
dao_reserve: Default::default(),

polkadot_xcm: PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
},
}
}

Expand Down
14 changes: 10 additions & 4 deletions runtimes/eden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ std = [
"pallet-contracts-primitives/std",
"pallet-contracts-rpc-runtime-api/std",
"pallet-contracts/std",
#"pallet-xcm/std",
"pallet-xcm/std",
Hounsette marked this conversation as resolved.
Show resolved Hide resolved
"polkadot-parachain/std",
"polkadot-runtime-common/std",
"xcm/std",
Expand All @@ -50,7 +50,7 @@ std = [
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-xcm/std",
#"cumulus-pallet-xcmp-queue/std",
"cumulus-pallet-xcmp-queue/std",
Hounsette marked this conversation as resolved.
Show resolved Hide resolved
"cumulus-primitives-core/std",
"cumulus-primitives-timestamp/std",
"cumulus-primitives-utility/std",
Expand Down Expand Up @@ -94,10 +94,11 @@ runtime-benchmarks = [
"pallet-collator-selection/runtime-benchmarks",
"pallet-membership/runtime-benchmarks",
"pallet-contracts/runtime-benchmarks",
#"pallet-xcm/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"xcm/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
Expand Down Expand Up @@ -132,6 +133,8 @@ try-runtime = [
"cumulus-pallet-dmp-queue/try-runtime",
"cumulus-pallet-parachain-system/try-runtime",
"cumulus-pallet-xcm/try-runtime",
"cumulus-pallet-xcmp-queue/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
]
# Make contract callable functions marked as __unstable__ available. Do not enable
Expand Down Expand Up @@ -177,7 +180,10 @@ pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/parityt
pallet-uniques = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29" }
pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29" }
pallet-aura = { git = "https://github.com/paritytech/substrate.git", default-features = false, branch = "polkadot-v0.9.29" }
#pallet-xcm = { git = "https://github.com/paritytech/polkadot.git", default-features = false, branch = "release-v0.9.29" }

cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.29", default-features = false }
pallet-xcm = { git = "https://github.com/paritytech/polkadot.git", default-features = false, branch = "release-v0.9.29" }
aliXsed marked this conversation as resolved.
Show resolved Hide resolved

pallet-contracts = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29" }
pallet-contracts-primitives = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29" }
pallet-contracts-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.29" }
Expand Down
6 changes: 3 additions & 3 deletions runtimes/eden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ mod pallets_system;
mod pallets_util;
mod version;
mod weights;
mod xcm_config;
Hounsette marked this conversation as resolved.
Show resolved Hide resolved

pub use pallets_consensus::SessionKeys;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -103,8 +104,8 @@ construct_runtime! {
ParachainInfo: parachain_info = 31,
CumulusXcm: cumulus_pallet_xcm = 32,
DmpQueue: cumulus_pallet_dmp_queue = 33,
// XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 34,
// PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config} = 35,
XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 34,
PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config} = 35,
aliXsed marked this conversation as resolved.
Show resolved Hide resolved

// Neat things
Utility: pallet_utility = 40,
Expand All @@ -124,7 +125,6 @@ construct_runtime! {
Contracts: pallet_contracts = 62,
}
}

/// The address format for describing accounts.
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
/// Block header type as expected by this runtime.
Expand Down
62 changes: 5 additions & 57 deletions runtimes/eden/src/pallets_parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,71 +17,19 @@
*/

use crate::{
constants, pallets_governance::EnsureRootOrMoreThanHalfOfTechComm, Call, DmpQueue, Event, Origin, ParachainInfo,
Runtime,
constants, pallets_governance::EnsureRootOrMoreThanHalfOfTechComm, xcm_config::XcmConfig, DmpQueue, Event, Runtime,
XcmpQueue,
};
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use frame_support::{dispatch::Weight, match_types, parameter_types};
use primitives::AccountId;
use xcm::latest::prelude::*;
use xcm_builder::{
AllowUnpaidExecutionFrom, FixedWeightBounds, LocationInverter, ParentAsSuperuser, ParentIsPreset,
SovereignSignedViaLocation,
};
use xcm_executor::XcmExecutor;

parameter_types! {
pub const RococoLocation: MultiLocation = MultiLocation::parent();
pub const RococoNetwork: NetworkId = NetworkId::Polkadot;
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
/// bias the kind of local `Origin` it will become.
pub type XcmOriginToTransactDispatchOrigin = (
// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
// foreign chains who want to have a local sovereign account on this chain which they control.
SovereignSignedViaLocation<ParentIsPreset<AccountId>, Origin>,
// Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a
// transaction from the Root origin.
ParentAsSuperuser<Origin>,
);
use xcm_executor::XcmExecutor;

match_types! {
pub type JustTheParent: impl Contains<MultiLocation> = { MultiLocation { parents:1, interior: Here } };
}

parameter_types! {
// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
pub UnitWeightCost: u64 = 1_000_000_000;
pub const MaxInstructions: u32 = 100;
}

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type Call = Call;
type XcmSender = (); // sending XCM not supported
type AssetTransactor = (); // balances not supported
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = (); // balances not supported
type IsTeleporter = (); // balances not supported
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = AllowUnpaidExecutionFrom<JustTheParent>;
type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>; // balances not supported
type Trader = (); // balances not supported
type ResponseHandler = (); // Don't handle responses for now.
type AssetTrap = (); // don't trap for now
type AssetClaims = (); // don't claim for now
type SubscriptionService = (); // don't handle subscriptions for now
}

impl cumulus_pallet_xcm::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
}

impl cumulus_pallet_dmp_queue::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
Expand All @@ -96,10 +44,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type Event = Event;
type OnSystemEvent = ();
type SelfParaId = parachain_info::Pallet<Runtime>;
type OutboundXcmpMessageSource = ();
type OutboundXcmpMessageSource = XcmpQueue;
type DmpMessageHandler = DmpQueue;
type ReservedDmpWeight = ReservedDmpWeight;
type XcmpMessageHandler = ();
type XcmpMessageHandler = XcmpQueue;
type ReservedXcmpWeight = ();
type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases;
}
Expand Down
152 changes: 152 additions & 0 deletions runtimes/eden/src/xcm_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
use super::{
AccountId, Balance, Balances, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, XcmpQueue,
};
use crate::implementations::DealWithFees;
use frame_support::{
parameter_types,
traits::{Everything, Nothing},
weights::IdentityFee,
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use polkadot_parachain::primitives::Sibling;
use xcm::{latest::NetworkId, prelude::*};
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom,
CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
};
use xcm_executor::XcmExecutor;

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
/// when determining ownership of accounts for asset transacting and when attempting to use XCM
/// `Transact` in order to determine the dispatch RuntimeOrigin.
pub type LocationToAccountId = (
// The parent (Relay-chain) origin converts to the default `AccountId`.
ParentIsPreset<AccountId>,
// Sibling parachain origins convert to AccountId via the `ParaId::into`.
SiblingParachainConvertsVia<Sibling, AccountId>,
// Straight up local `AccountId32` origins just alias directly to `AccountId`.
AccountId32Aliases<RelayNetwork, AccountId>,
);

pub type Barrier = (
TakeWeightCredit,
// If the message is one that immediately attempts to pay for execution, then allow it.
AllowTopLevelPaidExecutionFrom<Everything>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<Everything>,
);

pub type LocalOriginToLocation = SignedToAccountId32<Origin, AccountId, RelayNetwork>;

/// The means for routing XCM messages which are not for local execution into the right message
/// queues.
pub type XcmRouter = (
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);
parameter_types! {
pub RelayLocation: MultiLocation = MultiLocation::parent();
pub const NodlLocation: MultiLocation = Here.into();
pub const RelayNetwork: NetworkId = NetworkId::Any;
aliXsed marked this conversation as resolved.
Show resolved Hide resolved
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
/// biases the kind of local `Origin` it will become.
pub type XcmOriginToTransactDispatchOrigin = (
// Sovereign account converter; this attempts to derive an `AccountId` from the origin location
// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
// foreign chains who want to have a local sovereign account on this chain which they control.
SovereignSignedViaLocation<LocationToAccountId, Origin>,
// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when
// recognised.
RelayChainAsNative<RelayChainOrigin, Origin>,
// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when
// recognised.
SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,
// Native signed account converter; this just converts an `AccountId32` origin into a normal
// `Origin::Signed` origin of the same 32-byte value.
SignedAccountId32AsNative<RelayNetwork, Origin>,
// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
XcmPassthrough<Origin>,
);
/// Means for transacting assets on this chain.
pub type AssetTransactors = CurrencyTransactor;

/// Means for transacting the native currency on this chain.
pub type CurrencyTransactor = CurrencyAdapter<
// Use this currency:
Balances,
// Use this currency when it is a fungible asset matching the given location or name:
IsConcrete<NodlLocation>,
// Convert an XCM MultiLocation into a local account id:
LocationToAccountId,
// Our chain's account ID type (we can't get away without mentioning it explicitly):
AccountId,
// We don't track any teleports of `Balances`.
(),
>;
parameter_types! {
// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
pub UnitWeightCost: u64 = 1_000_000_000;
pub const MaxInstructions: u32 = 100;
}

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type Call = Call;
type XcmSender = XcmRouter;
type AssetTransactor = AssetTransactors;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = NativeAsset;
type IsTeleporter = ();
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
type Trader = UsingComponents<IdentityFee<Balance>, RelayLocation, AccountId, Balances, DealWithFees>;
type ResponseHandler = (); // Don't handle responses for now.
Hounsette marked this conversation as resolved.
Show resolved Hide resolved
type AssetTrap = PolkadotXcm;
type AssetClaims = PolkadotXcm;
type SubscriptionService = PolkadotXcm;
}

impl pallet_xcm::Config for Runtime {
type Event = Event;
type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;
type XcmExecuteFilter = Nothing;
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Nothing;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
type LocationInverter = LocationInverter<Ancestry>;
type Origin = Origin;
type Call = Call;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the significance of 100? Why not 50 or 200? Have you compared this param in different parachains?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a reference here as to why the value is 100. It seems to be set the same by 4 parachains that I have checked

Copy link
Contributor

Choose a reason for hiding this comment

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

@Hounsette I couldn't find anything related to the version discovery in the link that you have refrenced. If you could clarify it a bit more here, it could be a good to have it as a reference. But I'm not going to hold this PR for that.

type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
}

impl cumulus_pallet_xcmp_queue::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
type ChannelInfo = ParachainSystem;
type VersionWrapper = PolkadotXcm;
type ExecuteOverweightOrigin = EnsureRoot<AccountId>;
type ControllerOrigin = EnsureRoot<AccountId>;
type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;
type WeightInfo = cumulus_pallet_xcmp_queue::weights::SubstrateWeight<Self>;
}
impl cumulus_pallet_xcm::Config for Runtime {
type Event = Event;
type XcmExecutor = XcmExecutor<XcmConfig>;
}