mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +00:00
Integrate a governance XCM origin (#407)
* Introduce the converter into the hub * Parachain recognises Rococo governance body as admin * Whitespace * Use UsingComponents for fee payment in XCM * Fixes * Fixes for XCM permissions * Remove encode_call test * Fixes * Fixes * Fixes
This commit is contained in:
@@ -27,6 +27,7 @@ sp-inherents = { git = "https://github.com/paritytech/substrate", default-featur
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
pallet-assets = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
@@ -48,6 +49,10 @@ xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features
|
||||
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
|
||||
pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
|
||||
|
||||
[dev-dependencies]
|
||||
hex-literal = "0.3.1"
|
||||
hex = "0.4.3"
|
||||
|
||||
[build-dependencies]
|
||||
substrate-wasm-builder = "3.0.0"
|
||||
|
||||
@@ -71,6 +76,7 @@ std = [
|
||||
"frame-support/std",
|
||||
"frame-executive/std",
|
||||
"frame-system/std",
|
||||
"pallet-assets/std",
|
||||
"pallet-balances/std",
|
||||
"pallet-randomness-collective-flip/std",
|
||||
"pallet-timestamp/std",
|
||||
|
||||
@@ -27,7 +27,7 @@ use sp_api::impl_runtime_apis;
|
||||
use sp_core::OpaqueMetadata;
|
||||
use sp_runtime::{
|
||||
create_runtime_str, generic, impl_opaque_keys,
|
||||
traits::{BlakeTwo256, Block as BlockT, IdentityLookup},
|
||||
traits::{BlakeTwo256, Block as BlockT, AccountIdLookup},
|
||||
transaction_validity::{TransactionSource, TransactionValidity},
|
||||
ApplyExtrinsicResult,
|
||||
};
|
||||
@@ -55,15 +55,16 @@ pub use sp_runtime::{Perbill, Permill};
|
||||
|
||||
// XCM imports
|
||||
use polkadot_parachain::primitives::Sibling;
|
||||
use xcm::v0::{Junction, MultiLocation, NetworkId};
|
||||
use xcm::v0::{Junction::*, MultiLocation, MultiLocation::*, NetworkId, BodyId};
|
||||
use xcm_builder::{
|
||||
AccountId32Aliases, CurrencyAdapter, LocationInverter, ParentIsDefault, RelayChainAsNative,
|
||||
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
|
||||
SovereignSignedViaLocation, FixedRateOfConcreteFungible, EnsureXcmOrigin,
|
||||
SovereignSignedViaLocation, EnsureXcmOrigin, AllowUnpaidExecutionFrom, ParentAsSuperuser,
|
||||
AllowTopLevelPaidExecutionFrom, TakeWeightCredit, FixedWeightBounds, IsConcrete, NativeAsset,
|
||||
AllowUnpaidExecutionFrom, ParentAsSuperuser,
|
||||
UsingComponents,
|
||||
};
|
||||
use xcm_executor::{Config, XcmExecutor};
|
||||
use pallet_xcm::{XcmPassthrough, EnsureXcm, IsMajorityOfBody};
|
||||
|
||||
pub type SessionHandlers = ();
|
||||
|
||||
@@ -73,10 +74,10 @@ impl_opaque_keys! {
|
||||
|
||||
/// This runtime version.
|
||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("cumulus-test-parachain"),
|
||||
impl_name: create_runtime_str!("cumulus-test-parachain"),
|
||||
spec_name: create_runtime_str!("test-parachain"),
|
||||
impl_name: create_runtime_str!("test-parachain"),
|
||||
authoring_version: 1,
|
||||
spec_version: 18,
|
||||
spec_version: 9,
|
||||
impl_version: 0,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 1,
|
||||
@@ -93,15 +94,13 @@ pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
|
||||
pub const HOURS: BlockNumber = MINUTES * 60;
|
||||
pub const DAYS: BlockNumber = HOURS * 24;
|
||||
|
||||
pub const ROC: Balance = 1_000_000_000_000;
|
||||
pub const MILLIROC: Balance = 1_000_000_000;
|
||||
pub const MICROROC: Balance = 1_000_000;
|
||||
|
||||
// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
|
||||
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
|
||||
|
||||
#[derive(codec::Encode, codec::Decode)]
|
||||
pub enum XCMPMessage<XAccountId, XBalance> {
|
||||
/// Transfer tokens to the given account from the Parachain account.
|
||||
TransferToken(XAccountId, XBalance),
|
||||
}
|
||||
|
||||
/// The version information used to identify this runtime when compiled natively.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn native_version() -> NativeVersion {
|
||||
@@ -152,7 +151,7 @@ impl frame_system::Config for Runtime {
|
||||
/// The aggregated dispatch type that is available for extrinsics.
|
||||
type Call = Call;
|
||||
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
|
||||
type Lookup = IdentityLookup<AccountId>;
|
||||
type Lookup = AccountIdLookup<AccountId, ()>;
|
||||
/// The index type for storing how many extrinsics an account has signed.
|
||||
type Index = Index;
|
||||
/// The index type for blocks.
|
||||
@@ -198,10 +197,10 @@ impl pallet_timestamp::Config for Runtime {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: u128 = 500;
|
||||
pub const TransferFee: u128 = 0;
|
||||
pub const CreationFee: u128 = 0;
|
||||
pub const TransactionByteFee: u128 = 1;
|
||||
pub const ExistentialDeposit: u128 = 1 * MILLIROC;
|
||||
pub const TransferFee: u128 = 1 * MILLIROC;
|
||||
pub const CreationFee: u128 = 1 * MILLIROC;
|
||||
pub const TransactionByteFee: u128 = 1 * MICROROC;
|
||||
pub const MaxLocks: u32 = 50;
|
||||
}
|
||||
|
||||
@@ -237,11 +236,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
|
||||
type Event = Event;
|
||||
type OnValidationData = ();
|
||||
type SelfParaId = parachain_info::Module<Runtime>;
|
||||
type DownwardMessageHandlers = cumulus_primitives_utility::UnqueuedDmpAsParent<
|
||||
MaxDownwardMessageWeight,
|
||||
XcmExecutor<XcmConfig>,
|
||||
Call,
|
||||
>;
|
||||
type DownwardMessageHandlers = CumulusXcm;
|
||||
type OutboundXcmpMessageSource = XcmpQueue;
|
||||
type XcmpMessageHandler = XcmpQueue;
|
||||
type ReservedXcmpWeight = ReservedXcmpWeight;
|
||||
@@ -250,12 +245,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
|
||||
impl parachain_info::Config for Runtime {}
|
||||
|
||||
parameter_types! {
|
||||
pub const RococoLocation: MultiLocation = MultiLocation::X1(Junction::Parent);
|
||||
pub const RocLocation: MultiLocation = X1(Parent);
|
||||
pub const RococoNetwork: NetworkId = NetworkId::Polkadot;
|
||||
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
|
||||
pub Ancestry: MultiLocation = Junction::Parachain(
|
||||
ParachainInfo::parachain_id().into()
|
||||
).into();
|
||||
pub Ancestry: MultiLocation = X1(Parachain(ParachainInfo::parachain_id().into()));
|
||||
}
|
||||
|
||||
/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
|
||||
@@ -275,7 +268,7 @@ pub type LocalAssetTransactor = CurrencyAdapter<
|
||||
// Use this currency:
|
||||
Balances,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
IsConcrete<RococoLocation>,
|
||||
IsConcrete<RocLocation>,
|
||||
// Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:
|
||||
LocationToAccountId,
|
||||
// Our chain's account ID type (we can't get away without mentioning it explicitly):
|
||||
@@ -302,23 +295,39 @@ pub type XcmOriginToTransactDispatchOrigin = (
|
||||
// Native signed account converter; this just converts an `AccountId32` origin into a normal
|
||||
// `Origin::Signed` origin of the same 32-byte value.
|
||||
SignedAccountId32AsNative<RococoNetwork, Origin>,
|
||||
// Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
|
||||
XcmPassthrough<Origin>,
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
pub UnitWeightCost: Weight = 1_000;
|
||||
// One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.
|
||||
pub UnitWeightCost: Weight = 1_000_000;
|
||||
// One ROC buys 1 second of weight.
|
||||
pub const WeightPrice: (MultiLocation, u128) = (X1(Parent), ROC);
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
// 1_000_000_000_000 => 1 unit of asset for 1 unit of Weight.
|
||||
// TODO: Should take the actual weight price. This is just 1_000 ROC per second of weight.
|
||||
pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::X1(Junction::Parent), 1_000);
|
||||
pub AllowUnpaidFrom: Vec<MultiLocation> = vec![ MultiLocation::X1(Junction::Parent) ];
|
||||
macro_rules! match_type {
|
||||
( pub type $n:ident: impl Contains<$t:ty> = { $phead:pat $( | $ptail:pat )* } ; ) => {
|
||||
pub struct $n;
|
||||
impl frame_support::traits::Contains<$t> for $n {
|
||||
fn contains(l: &$t) -> bool {
|
||||
matches!(l, $phead $( | $ptail )* )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match_type! {
|
||||
pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {
|
||||
X1(Parent) | X2(Parent, Plurality { id: BodyId::Unit, .. })
|
||||
};
|
||||
}
|
||||
|
||||
pub type Barrier = (
|
||||
TakeWeightCredit,
|
||||
AllowTopLevelPaidExecutionFrom<All<MultiLocation>>,
|
||||
AllowUnpaidExecutionFrom<IsInVec<AllowUnpaidFrom>>, // <- Parent gets free execution
|
||||
AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,
|
||||
// ^^^ Parent & its unit plurality gets free execution
|
||||
);
|
||||
|
||||
pub struct XcmConfig;
|
||||
@@ -333,7 +342,7 @@ impl Config for XcmConfig {
|
||||
type LocationInverter = LocationInverter<Ancestry>;
|
||||
type Barrier = Barrier;
|
||||
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
|
||||
type Trader = FixedRateOfConcreteFungible<WeightPrice, ()>;
|
||||
type Trader = UsingComponents<IdentityFee<Balance>, RocLocation, AccountId, Balances, ()>;
|
||||
type ResponseHandler = (); // Don't handle responses for now.
|
||||
}
|
||||
|
||||
@@ -361,7 +370,11 @@ impl pallet_xcm::Config for Runtime {
|
||||
type XcmExecutor = XcmExecutor<XcmConfig>;
|
||||
}
|
||||
|
||||
impl cumulus_pallet_xcm::Config for Runtime {}
|
||||
impl cumulus_pallet_xcm::Config for Runtime {
|
||||
type Event = Event;
|
||||
type XcmExecutor = XcmExecutor<XcmConfig>;
|
||||
type MaxWeight = MaxDownwardMessageWeight;
|
||||
}
|
||||
|
||||
impl cumulus_pallet_xcmp_queue::Config for Runtime {
|
||||
type Event = Event;
|
||||
@@ -376,6 +389,34 @@ impl cumulus_ping::Config for Runtime {
|
||||
type XcmSender = XcmRouter;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const AssetDeposit: Balance = 1 * ROC;
|
||||
pub const ApprovalDeposit: Balance = 100 * MILLIROC;
|
||||
pub const StringLimit: u32 = 50;
|
||||
pub const MetadataDepositBase: Balance = 1 * ROC;
|
||||
pub const MetadataDepositPerByte: Balance = 10 * MILLIROC;
|
||||
pub const UnitBody: BodyId = BodyId::Unit;
|
||||
}
|
||||
|
||||
/// A majority of the Unit body from Rococo over XCM is our required administration origin.
|
||||
pub type AdminOrigin = EnsureXcm<IsMajorityOfBody<RocLocation, UnitBody>>;
|
||||
|
||||
impl pallet_assets::Config for Runtime {
|
||||
type Event = Event;
|
||||
type Balance = u64;
|
||||
type AssetId = u32;
|
||||
type Currency = Balances;
|
||||
type ForceOrigin = AdminOrigin;
|
||||
type AssetDeposit = AssetDeposit;
|
||||
type MetadataDepositBase = MetadataDepositBase;
|
||||
type MetadataDepositPerByte = MetadataDepositPerByte;
|
||||
type ApprovalDeposit = ApprovalDeposit;
|
||||
type StringLimit = StringLimit;
|
||||
type Freezer = ();
|
||||
type Extra = ();
|
||||
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
|
||||
construct_runtime! {
|
||||
pub enum Runtime where
|
||||
Block = Block,
|
||||
@@ -384,24 +425,27 @@ construct_runtime! {
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
|
||||
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage},
|
||||
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
ParachainInfo: parachain_info::{Pallet, Storage, Config},
|
||||
|
||||
ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event<T>} = 20,
|
||||
ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,
|
||||
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,
|
||||
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>} = 31,
|
||||
|
||||
// XCM helpers.
|
||||
XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>},
|
||||
PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin},
|
||||
CumulusXcm: cumulus_pallet_xcm::{Pallet, Origin},
|
||||
XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,
|
||||
PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,
|
||||
CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,
|
||||
|
||||
Spambot: cumulus_ping::{Pallet, Call, Storage, Event<T>} = 99,
|
||||
}
|
||||
}
|
||||
|
||||
/// The address format for describing accounts.
|
||||
pub type Address = AccountId;
|
||||
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
|
||||
/// Block header type as expected by this runtime.
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
/// Block type as expected by this runtime.
|
||||
|
||||
Reference in New Issue
Block a user