mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Merge branch 'master' into gav-xcm-v3
This commit is contained in:
+19
-18
@@ -6,22 +6,23 @@ edition = "2021"
|
||||
description = "AURA consensus extension pallet for parachains"
|
||||
|
||||
[dependencies]
|
||||
# Substrate dependencies
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-application-crypto = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
# Other Dependencies
|
||||
codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"]}
|
||||
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
|
||||
scale-info = { version = "2.0.0", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0.132", optional = true, features = ["derive"] }
|
||||
|
||||
# Substrate
|
||||
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
frame-support = { 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-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-application-crypto = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
# Cumulus
|
||||
cumulus-pallet-parachain-system = { path = "../parachain-system" }
|
||||
|
||||
[features]
|
||||
@@ -30,12 +31,12 @@ std = [
|
||||
"codec/std",
|
||||
"scale-info/std",
|
||||
"serde",
|
||||
"frame-executive/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
"pallet-aura/std",
|
||||
"sp-application-crypto/std",
|
||||
"sp-consensus-aura/std",
|
||||
"sp-runtime/std",
|
||||
"sp-std/std",
|
||||
"frame-system/std",
|
||||
"frame-executive/std",
|
||||
"pallet-aura/std",
|
||||
"sp-consensus-aura/std",
|
||||
"sp-application-crypto/std",
|
||||
]
|
||||
|
||||
@@ -56,6 +56,7 @@ pub mod pallet {
|
||||
pub trait Config: pallet_aura::Config + frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
|
||||
@@ -14,9 +14,9 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
log = { version = "0.4.0", default-features = false }
|
||||
codec = { default-features = false, features = ["derive"], package = "parity-scale-codec", version = "2.3.0" }
|
||||
rand = { version = "0.7.2", default-features = false }
|
||||
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
|
||||
codec = { default-features = false, features = ["derive"], package = "parity-scale-codec", version = "3.0.0" }
|
||||
rand = { version = "0.8.5", features = ["std_rng"], default-features = false }
|
||||
scale-info = { version = "2.0.0", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0.132", default-features = false }
|
||||
|
||||
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
@@ -84,12 +84,14 @@ fn validator<T: Config + session::Config>(c: u32) -> (T::AccountId, <T as sessio
|
||||
(create_funded_user::<T>("candidate", c, 1000), keys::<T>(c))
|
||||
}
|
||||
|
||||
fn register_validators<T: Config + session::Config>(count: u32) {
|
||||
fn register_validators<T: Config + session::Config>(count: u32) -> Vec<T::AccountId> {
|
||||
let validators = (0..count).map(|c| validator::<T>(c)).collect::<Vec<_>>();
|
||||
|
||||
for (who, keys) in validators {
|
||||
for (who, keys) in validators.clone() {
|
||||
<session::Pallet<T>>::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()).unwrap();
|
||||
}
|
||||
|
||||
validators.into_iter().map(|(who, _)| who).collect()
|
||||
}
|
||||
|
||||
fn register_candidates<T: Config>(count: u32) {
|
||||
@@ -107,7 +109,7 @@ benchmarks! {
|
||||
|
||||
set_invulnerables {
|
||||
let b in 1 .. T::MaxInvulnerables::get();
|
||||
let new_invulnerables = (0..b).map(|c| account("candidate", c, SEED)).collect::<Vec<_>>();
|
||||
let new_invulnerables = register_validators::<T>(b);
|
||||
let origin = T::UpdateOrigin::successful_origin();
|
||||
}: {
|
||||
assert_ok!(
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
//!
|
||||
//! ## Implementation
|
||||
//!
|
||||
//! The final [`Collators`] are aggregated from two individual lists:
|
||||
//! The final `Collators` are aggregated from two individual lists:
|
||||
//!
|
||||
//! 1. [`Invulnerables`]: a set of collators appointed by governance. These accounts will always be
|
||||
//! collators.
|
||||
@@ -168,6 +168,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
/// The invulnerable, fixed collators.
|
||||
@@ -194,7 +195,9 @@ pub mod pallet {
|
||||
#[pallet::getter(fn desired_candidates)]
|
||||
pub type DesiredCandidates<T> = StorageValue<_, u32, ValueQuery>;
|
||||
|
||||
/// Fixed deposit bond for each candidate.
|
||||
/// Fixed amount to deposit to become a collator.
|
||||
///
|
||||
/// When a collator calls `leave_intent` they immediately receive the deposit back.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn candidacy_bond)]
|
||||
pub type CandidacyBond<T> = StorageValue<_, BalanceOf<T>, ValueQuery>;
|
||||
@@ -280,6 +283,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Set the list of invulnerable (fixed) collators.
|
||||
#[pallet::weight(T::WeightInfo::set_invulnerables(new.len() as u32))]
|
||||
pub fn set_invulnerables(
|
||||
origin: OriginFor<T>,
|
||||
@@ -292,11 +296,25 @@ pub mod pallet {
|
||||
"invulnerables > T::MaxInvulnerables; you might need to run benchmarks again"
|
||||
);
|
||||
}
|
||||
|
||||
// check if the invulnerables have associated validator keys before they are set
|
||||
for account_id in &new {
|
||||
let validator_key = T::ValidatorIdOf::convert(account_id.clone())
|
||||
.ok_or(Error::<T>::NoAssociatedValidatorId)?;
|
||||
ensure!(
|
||||
T::ValidatorRegistration::is_registered(&validator_key),
|
||||
Error::<T>::ValidatorNotRegistered
|
||||
);
|
||||
}
|
||||
|
||||
<Invulnerables<T>>::put(&new);
|
||||
Self::deposit_event(Event::NewInvulnerables(new));
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
/// Set the ideal number of collators (not including the invulnerables).
|
||||
/// If lowering this number, then the number of running collators could be higher than this figure.
|
||||
/// Aside from that edge case, there should be no other way to have more collators than the desired number.
|
||||
#[pallet::weight(T::WeightInfo::set_desired_candidates())]
|
||||
pub fn set_desired_candidates(
|
||||
origin: OriginFor<T>,
|
||||
@@ -312,6 +330,7 @@ pub mod pallet {
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
/// Set the candidacy bond amount.
|
||||
#[pallet::weight(T::WeightInfo::set_candidacy_bond())]
|
||||
pub fn set_candidacy_bond(
|
||||
origin: OriginFor<T>,
|
||||
@@ -323,6 +342,10 @@ pub mod pallet {
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
/// Register this account as a collator candidate. The account must (a) already have
|
||||
/// registered session keys and (b) be able to reserve the `CandidacyBond`.
|
||||
///
|
||||
/// This call is not available to `Invulnerable` collators.
|
||||
#[pallet::weight(T::WeightInfo::register_as_candidate(T::MaxCandidates::get()))]
|
||||
pub fn register_as_candidate(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
@@ -362,6 +385,12 @@ pub mod pallet {
|
||||
Ok(Some(T::WeightInfo::register_as_candidate(current_count as u32)).into())
|
||||
}
|
||||
|
||||
/// Deregister `origin` as a collator candidate. Note that the collator can only leave on
|
||||
/// session change. The `CandidacyBond` will be unreserved immediately.
|
||||
///
|
||||
/// This call will fail if the total number of candidates would drop below `MinCandidates`.
|
||||
///
|
||||
/// This call is not available to `Invulnerable` collators.
|
||||
#[pallet::weight(T::WeightInfo::leave_intent(T::MaxCandidates::get()))]
|
||||
pub fn leave_intent(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
@@ -48,6 +48,16 @@ fn it_should_set_invulnerables() {
|
||||
CollatorSelection::set_invulnerables(Origin::signed(1), new_set.clone()),
|
||||
BadOrigin
|
||||
);
|
||||
|
||||
// cannot set invulnerables without associated validator keys
|
||||
let invulnerables = vec![7];
|
||||
assert_noop!(
|
||||
CollatorSelection::set_invulnerables(
|
||||
Origin::signed(RootAccount::get()),
|
||||
invulnerables.clone()
|
||||
),
|
||||
Error::<Test>::ValidatorNotRegistered
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,23 +5,22 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
# Other dependencies
|
||||
codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ], default-features = false }
|
||||
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", features = [ "derive" ], default-features = false }
|
||||
log = { version = "0.4.14", default-features = false }
|
||||
scale-info = { version = "2.0.0", default-features = false, features = ["derive"] }
|
||||
|
||||
# Substrate Dependencies
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
# Substrate
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
# Polkadot Dependencies
|
||||
# Polkadot
|
||||
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
|
||||
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
|
||||
|
||||
# Cumulus Dependencies
|
||||
# Cumulus
|
||||
cumulus-primitives-core = { path = "../../primitives/core", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
@@ -32,14 +31,14 @@ sp-version = { git = "https://github.com/paritytech/substrate", default-features
|
||||
default = [ "std" ]
|
||||
std = [
|
||||
"codec/std",
|
||||
"log/std",
|
||||
"scale-info/std",
|
||||
"sp-std/std",
|
||||
"sp-io/std",
|
||||
"sp-runtime/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
"cumulus-primitives-core/std",
|
||||
"xcm/std",
|
||||
"log/std",
|
||||
"sp-io/std",
|
||||
"sp-runtime/std",
|
||||
"sp-std/std",
|
||||
"xcm-executor/std",
|
||||
"xcm/std",
|
||||
"cumulus-primitives-core/std",
|
||||
]
|
||||
|
||||
@@ -77,6 +77,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
/// The module configuration trait.
|
||||
@@ -222,12 +223,12 @@ pub mod pallet {
|
||||
pub(crate) fn try_service_message(
|
||||
limit: Weight,
|
||||
_sent_at: RelayBlockNumber,
|
||||
data: &[u8],
|
||||
mut data: &[u8],
|
||||
) -> Result<Weight, (MessageId, Weight)> {
|
||||
let id = sp_io::hashing::blake2_256(&data[..]);
|
||||
let id = sp_io::hashing::blake2_256(data);
|
||||
let maybe_msg = VersionedXcm::<T::Call>::decode_all_with_depth_limit(
|
||||
MAX_XCM_DECODE_DEPTH,
|
||||
&mut &data[..],
|
||||
&mut data,
|
||||
)
|
||||
.map(Xcm::<T::Call>::try_from);
|
||||
match maybe_msg {
|
||||
|
||||
@@ -6,71 +6,70 @@ edition = "2021"
|
||||
description = "Base pallet for cumulus-based parachains"
|
||||
|
||||
[dependencies]
|
||||
# Cumulus dependencies
|
||||
cumulus-primitives-core = { path = "../../primitives/core", default-features = false }
|
||||
cumulus-primitives-parachain-inherent = { path = "../../primitives/parachain-inherent", default-features = false }
|
||||
cumulus-pallet-parachain-system-proc-macro = { path = "proc-macro", default-features = false }
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
|
||||
environmental = { version = "1.1.2", default-features = false }
|
||||
impl-trait-for-tuples = "0.2.1"
|
||||
log = { version = "0.4.14", default-features = false }
|
||||
scale-info = { version = "2.0.0", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0.132", optional = true, features = ["derive"] }
|
||||
|
||||
# Polkadot dependencies
|
||||
# Substrate
|
||||
frame-support = { 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-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-externalities = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-state-machine = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
# Polkadot
|
||||
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, features = [ "wasm-api" ], branch = "master" }
|
||||
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
|
||||
|
||||
# Substrate dependencies
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-state-machine = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-externalities = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
# Other Dependencies
|
||||
codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"]}
|
||||
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0.132", optional = true, features = ["derive"] }
|
||||
log = { version = "0.4.14", default-features = false }
|
||||
environmental = { version = "1.1.2", default-features = false }
|
||||
# Cumulus
|
||||
cumulus-pallet-parachain-system-proc-macro = { path = "proc-macro", default-features = false }
|
||||
cumulus-primitives-core = { path = "../../primitives/core", default-features = false }
|
||||
cumulus-primitives-parachain-inherent = { path = "../../primitives/parachain-inherent", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
# Other Dependencies
|
||||
hex-literal = "0.2.1"
|
||||
hex-literal = "0.3.4"
|
||||
lazy_static = "1.4"
|
||||
|
||||
# Substrate dependencies
|
||||
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
# Substrate
|
||||
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
# Cumulus dependencies
|
||||
# Cumulus
|
||||
cumulus-test-client = { path = "../../test/client" }
|
||||
cumulus-test-relay-sproof-builder = { path = "../../test/relay-sproof-builder" }
|
||||
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
std = [
|
||||
"serde",
|
||||
"codec/std",
|
||||
"scale-info/std",
|
||||
"frame-support/std",
|
||||
"pallet-balances/std",
|
||||
"sp-core/std",
|
||||
"sp-runtime/std",
|
||||
"sp-io/std",
|
||||
"sp-std/std",
|
||||
"environmental/std",
|
||||
"log/std",
|
||||
"sp-state-machine/std",
|
||||
"sp-trie/std",
|
||||
"sp-externalities/std",
|
||||
"frame-system/std",
|
||||
"scale-info/std",
|
||||
"serde",
|
||||
"cumulus-pallet-parachain-system-proc-macro/std",
|
||||
"cumulus-primitives-core/std",
|
||||
"cumulus-primitives-parachain-inherent/std",
|
||||
"cumulus-pallet-parachain-system-proc-macro/std",
|
||||
"environmental/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
"pallet-balances/std",
|
||||
"sp-core/std",
|
||||
"sp-externalities/std",
|
||||
"sp-io/std",
|
||||
"sp-runtime/std",
|
||||
"sp-state-machine/std",
|
||||
"sp-std/std",
|
||||
"sp-trie/std",
|
||||
"xcm/std"
|
||||
]
|
||||
|
||||
@@ -12,7 +12,7 @@ proc-macro = true
|
||||
syn = "1.0.81"
|
||||
proc-macro2 = "1.0.36"
|
||||
quote = "1.0.9"
|
||||
proc-macro-crate = "1.0.0"
|
||||
proc-macro-crate = "1.1.3"
|
||||
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
//!
|
||||
//! Users must ensure that they register this pallet as an inherent provider.
|
||||
|
||||
use codec::Encode;
|
||||
use cumulus_primitives_core::{
|
||||
relay_chain, AbridgedHostConfiguration, ChannelStatus, CollationInfo, DmpMessageHandler,
|
||||
GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage, MessageSendError, OnValidationData,
|
||||
GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage, MessageSendError,
|
||||
OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage, UpwardMessageSender,
|
||||
XcmpMessageHandler, XcmpMessageSource,
|
||||
};
|
||||
@@ -44,7 +45,6 @@ use frame_support::{
|
||||
};
|
||||
use frame_system::{ensure_none, ensure_root};
|
||||
use polkadot_parachain::primitives::RelayChainBlockNumber;
|
||||
use relay_state_snapshot::MessagingStateSnapshot;
|
||||
use sp_runtime::{
|
||||
traits::{Block as BlockT, BlockNumberProvider, Hash},
|
||||
transaction_validity::{
|
||||
@@ -84,7 +84,7 @@ mod tests;
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
pub use cumulus_pallet_parachain_system_proc_macro::register_validate_block;
|
||||
pub use relay_state_snapshot::RelayChainStateProof;
|
||||
pub use relay_state_snapshot::{MessagingStateSnapshot, RelayChainStateProof};
|
||||
|
||||
pub use pallet::*;
|
||||
|
||||
@@ -96,6 +96,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::storage_version(migration::STORAGE_VERSION)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
@@ -104,7 +105,7 @@ pub mod pallet {
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
|
||||
/// Something which can be notified when the validation data is set.
|
||||
type OnValidationData: OnValidationData;
|
||||
type OnSystemEvent: OnSystemEvent;
|
||||
|
||||
/// Returns the parachain ID we are running with.
|
||||
type SelfParaId: Get<ParaId>;
|
||||
@@ -328,6 +329,7 @@ pub mod pallet {
|
||||
let validation_code = <PendingValidationCode<T>>::take();
|
||||
|
||||
Self::put_parachain_code(&validation_code);
|
||||
<T::OnSystemEvent as OnSystemEvent>::on_validation_code_applied();
|
||||
Self::deposit_event(Event::ValidationFunctionApplied(vfp.relay_parent_number));
|
||||
},
|
||||
Some(relay_chain::v1::UpgradeGoAhead::Abort) => {
|
||||
@@ -353,7 +355,7 @@ pub mod pallet {
|
||||
<RelevantMessagingState<T>>::put(relevant_messaging_state.clone());
|
||||
<HostConfiguration<T>>::put(host_config);
|
||||
|
||||
<T::OnValidationData as OnValidationData>::on_validation_data(&vfp);
|
||||
<T::OnSystemEvent as OnSystemEvent>::on_validation_data(&vfp);
|
||||
|
||||
// TODO: This is more than zero, but will need benchmarking to figure out what.
|
||||
let mut total_weight = 0;
|
||||
@@ -396,7 +398,7 @@ pub mod pallet {
|
||||
code: Vec<u8>,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
Self::validate_authorized_upgrade(&code[..])?;
|
||||
Self::set_code_impl(code)?;
|
||||
Self::schedule_code_upgrade(code)?;
|
||||
AuthorizedUpgrade::<T>::kill();
|
||||
Ok(Pays::No.into())
|
||||
}
|
||||
@@ -602,7 +604,7 @@ pub mod pallet {
|
||||
#[pallet::genesis_build]
|
||||
impl<T: Config> GenesisBuild<T> for GenesisConfig {
|
||||
fn build(&self) {
|
||||
//TODO: Remove after https://github.com/paritytech/cumulus/issues/479
|
||||
// TODO: Remove after https://github.com/paritytech/cumulus/issues/479
|
||||
sp_io::storage::set(b":c", &[]);
|
||||
}
|
||||
}
|
||||
@@ -882,7 +884,7 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
/// The implementation of the runtime upgrade functionality for parachains.
|
||||
fn set_code_impl(validation_function: Vec<u8>) -> DispatchResult {
|
||||
pub fn schedule_code_upgrade(validation_function: Vec<u8>) -> DispatchResult {
|
||||
// Ensure that `ValidationData` exists. We do not care about the validation data per se,
|
||||
// but we do care about the [`UpgradeRestrictionSignal`] which arrives with the same inherent.
|
||||
ensure!(<ValidationData<T>>::exists(), Error::<T>::ValidationDataNotAvailable,);
|
||||
@@ -908,15 +910,22 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Returns the [`CollationInfo`] of the current active block.
|
||||
///
|
||||
/// The given `header` is the header of the built block we are collecting the collation info for.
|
||||
///
|
||||
/// This is expected to be used by the
|
||||
/// [`CollectCollationInfo`](cumulus_primitives_core::CollectCollationInfo) runtime api.
|
||||
pub fn collect_collation_info() -> CollationInfo {
|
||||
pub fn collect_collation_info(header: &T::Header) -> CollationInfo {
|
||||
CollationInfo {
|
||||
hrmp_watermark: HrmpWatermark::<T>::get(),
|
||||
horizontal_messages: HrmpOutboundMessages::<T>::get(),
|
||||
upward_messages: UpwardMessages::<T>::get(),
|
||||
processed_downward_messages: ProcessedDownwardMessages::<T>::get(),
|
||||
new_validation_code: NewValidationCode::<T>::get().map(Into::into),
|
||||
// Check if there is a custom header that will also be returned by the validation phase.
|
||||
// If so, we need to also return it here.
|
||||
head_data: CustomValidationHeadData::<T>::get()
|
||||
.map_or_else(|| header.encode(), |v| v)
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -941,7 +950,7 @@ pub struct ParachainSetCode<T>(sp_std::marker::PhantomData<T>);
|
||||
|
||||
impl<T: Config> frame_system::SetCode<T> for ParachainSetCode<T> {
|
||||
fn set_code(code: Vec<u8>) -> DispatchResult {
|
||||
Pallet::<T>::set_code_impl(code)
|
||||
Pallet::<T>::schedule_code_upgrade(code)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -999,6 +1008,21 @@ pub trait CheckInherents<Block: BlockT> {
|
||||
) -> frame_support::inherent::CheckInherentsResult;
|
||||
}
|
||||
|
||||
/// Something that should be informed about system related events.
|
||||
///
|
||||
/// This includes events like [`on_validation_data`](Self::on_validation_data) that is being
|
||||
/// called when the parachain inherent is executed that contains the validation data.
|
||||
/// Or like [`on_validation_code_applied`](Self::on_validation_code_applied) that is called
|
||||
/// when the new validation is written to the state. This means that
|
||||
/// from the next block the runtime is being using this new code.
|
||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||
pub trait OnSystemEvent {
|
||||
/// Called in each blocks once when the validation data is set by the inherent.
|
||||
fn on_validation_data(data: &PersistedValidationData);
|
||||
/// Called when the validation code is being applied, aka from the next block on this is the new runtime.
|
||||
fn on_validation_code_applied();
|
||||
}
|
||||
|
||||
/// Implements [`BlockNumberProvider`] that returns relay chain block number fetched from
|
||||
/// validation data.
|
||||
/// NTOE: When validation data is not available (e.g. within on_initialize), 0 will be returned.
|
||||
|
||||
@@ -29,7 +29,7 @@ use frame_support::{
|
||||
traits::{OnFinalize, OnInitialize},
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_system::{InitKind, RawOrigin};
|
||||
use frame_system::RawOrigin;
|
||||
use hex_literal::hex;
|
||||
use relay_chain::v1::HrmpChannelId;
|
||||
use sp_core::H256;
|
||||
@@ -100,7 +100,7 @@ impl frame_system::Config for Test {
|
||||
}
|
||||
impl Config for Test {
|
||||
type Event = Event;
|
||||
type OnValidationData = ();
|
||||
type OnSystemEvent = ();
|
||||
type SelfParaId = ParachainId;
|
||||
type OutboundXcmpMessageSource = FromThreadLocal;
|
||||
type DmpMessageHandler = SaveIntoThreadLocal;
|
||||
@@ -303,7 +303,8 @@ impl BlockTests {
|
||||
}
|
||||
|
||||
// begin initialization
|
||||
System::initialize(&n, &Default::default(), &Default::default(), InitKind::Full);
|
||||
System::reset_events();
|
||||
System::initialize(&n, &Default::default(), &Default::default());
|
||||
|
||||
// now mess with the storage the way validate_block does
|
||||
let mut sproof_builder = RelayStateSproofBuilder::default();
|
||||
@@ -719,6 +720,69 @@ fn receive_dmp() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn receive_dmp_after_pause() {
|
||||
lazy_static::lazy_static! {
|
||||
static ref MSG_1: InboundDownwardMessage = InboundDownwardMessage {
|
||||
sent_at: 1,
|
||||
msg: b"down1".to_vec(),
|
||||
};
|
||||
static ref MSG_2: InboundDownwardMessage = InboundDownwardMessage {
|
||||
sent_at: 3,
|
||||
msg: b"down2".to_vec(),
|
||||
};
|
||||
}
|
||||
|
||||
BlockTests::new()
|
||||
.with_relay_sproof_builder(|_, relay_block_num, sproof| match relay_block_num {
|
||||
1 => {
|
||||
sproof.dmq_mqc_head =
|
||||
Some(MessageQueueChain::default().extend_downward(&MSG_1).head());
|
||||
},
|
||||
2 => {
|
||||
// no new messages, mqc stayed the same.
|
||||
sproof.dmq_mqc_head =
|
||||
Some(MessageQueueChain::default().extend_downward(&MSG_1).head());
|
||||
},
|
||||
3 => {
|
||||
sproof.dmq_mqc_head = Some(
|
||||
MessageQueueChain::default()
|
||||
.extend_downward(&MSG_1)
|
||||
.extend_downward(&MSG_2)
|
||||
.head(),
|
||||
);
|
||||
},
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.with_inherent_data(|_, relay_block_num, data| match relay_block_num {
|
||||
1 => {
|
||||
data.downward_messages.push(MSG_1.clone());
|
||||
},
|
||||
2 => {
|
||||
// no new messages
|
||||
},
|
||||
3 => {
|
||||
data.downward_messages.push(MSG_2.clone());
|
||||
},
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.add(1, || {
|
||||
HANDLED_DMP_MESSAGES.with(|m| {
|
||||
let mut m = m.borrow_mut();
|
||||
assert_eq!(&*m, &[(MSG_1.sent_at, MSG_1.msg.clone())]);
|
||||
m.clear();
|
||||
});
|
||||
})
|
||||
.add(2, || {})
|
||||
.add(3, || {
|
||||
HANDLED_DMP_MESSAGES.with(|m| {
|
||||
let mut m = m.borrow_mut();
|
||||
assert_eq!(&*m, &[(MSG_2.sent_at, MSG_2.msg.clone())]);
|
||||
m.clear();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn receive_hrmp() {
|
||||
lazy_static::lazy_static! {
|
||||
@@ -752,8 +816,8 @@ fn receive_hrmp() {
|
||||
Some(MessageQueueChain::default().extend_hrmp(&MSG_1).head());
|
||||
},
|
||||
2 => {
|
||||
// 200 - two new messages
|
||||
// 300 - now present with one message.
|
||||
// 200 - now present with one message
|
||||
// 300 - two new messages
|
||||
sproof.upsert_inbound_channel(ParaId::from(200)).mqc_head =
|
||||
Some(MessageQueueChain::default().extend_hrmp(&MSG_4).head());
|
||||
sproof.upsert_inbound_channel(ParaId::from(300)).mqc_head = Some(
|
||||
|
||||
@@ -13,7 +13,7 @@ readme = "README.md"
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
parity-scale-codec = { version = "2.3.1", default-features = false }
|
||||
parity-scale-codec = { version = "3.0.0", default-features = false }
|
||||
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
[package]
|
||||
name = "cumulus-pallet-solo-to-para"
|
||||
version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2021"
|
||||
description = "Adds functionality to migrate from a Solo to a Parachain"
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
|
||||
scale-info = { version = "2.0.0", default-features = false, features = ["derive"] }
|
||||
|
||||
# Substrate
|
||||
frame-support = { 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-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
# Polkadot
|
||||
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
|
||||
|
||||
# Cumulus
|
||||
cumulus-pallet-parachain-system = { default-features = false, path = "../parachain-system" }
|
||||
cumulus-primitives-core = { path = "../../primitives/core", default-features = false }
|
||||
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
std = [
|
||||
"codec/std",
|
||||
"scale-info/std",
|
||||
"cumulus-pallet-parachain-system/std",
|
||||
"cumulus-primitives-core/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
"pallet-sudo/std",
|
||||
"polkadot-primitives/std",
|
||||
"sp-runtime/std",
|
||||
"sp-std/std",
|
||||
]
|
||||
@@ -0,0 +1,182 @@
|
||||
// Copyright 2022 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Cumulus is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Cumulus is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use cumulus_pallet_parachain_system as parachain_system;
|
||||
use frame_support::{dispatch::DispatchResult, pallet_prelude::*, weights::DispatchInfo};
|
||||
use frame_system::pallet_prelude::*;
|
||||
pub use pallet::*;
|
||||
use polkadot_primitives::v1::PersistedValidationData;
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
traits::{DispatchInfoOf, Dispatchable, SignedExtension},
|
||||
transaction_validity::{
|
||||
InvalidTransaction, TransactionLongevity, TransactionPriority, TransactionValidity,
|
||||
TransactionValidityError, ValidTransaction,
|
||||
},
|
||||
};
|
||||
use sp_std::{prelude::*, vec::Vec};
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config:
|
||||
frame_system::Config + parachain_system::Config + pallet_sudo::Config
|
||||
{
|
||||
type Event: From<Event> + IsType<<Self as frame_system::Config>::Event>;
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
/// In case of a scheduled migration, this storage field contains the custom head data to be applied.
|
||||
#[pallet::storage]
|
||||
pub(super) type PendingCustomValidationHeadData<T: Config> =
|
||||
StorageValue<_, Vec<u8>, OptionQuery>;
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event {
|
||||
/// The custom validation head data has been scheduled to apply.
|
||||
CustomValidationHeadDataStored,
|
||||
/// The custom validation head data was applied as of the contained relay chain block number.
|
||||
CustomValidationHeadDataApplied,
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
/// CustomHeadData is not stored in storage.
|
||||
NoCustomHeadData,
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(0)]
|
||||
pub fn schedule_migration(
|
||||
origin: OriginFor<T>,
|
||||
code: Vec<u8>,
|
||||
head_data: Vec<u8>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
|
||||
parachain_system::Pallet::<T>::schedule_code_upgrade(code)?;
|
||||
Self::store_pending_custom_validation_head_data(head_data);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Set a custom head data that should only be applied when upgradeGoAheadSignal from
|
||||
/// the Relay Chain is GoAhead
|
||||
fn store_pending_custom_validation_head_data(head_data: Vec<u8>) {
|
||||
PendingCustomValidationHeadData::<T>::put(head_data);
|
||||
Self::deposit_event(Event::CustomValidationHeadDataStored);
|
||||
}
|
||||
|
||||
/// Set pending custom head data as head data that will be returned by `validate_block`. on the relay chain.
|
||||
fn set_pending_custom_validation_head_data() {
|
||||
if let Some(head_data) = <PendingCustomValidationHeadData<T>>::take() {
|
||||
parachain_system::Pallet::<T>::set_custom_validation_head_data(head_data);
|
||||
Self::deposit_event(Event::CustomValidationHeadDataApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> parachain_system::OnSystemEvent for Pallet<T> {
|
||||
fn on_validation_data(_data: &PersistedValidationData) {}
|
||||
fn on_validation_code_applied() {
|
||||
crate::Pallet::<T>::set_pending_custom_validation_head_data();
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure that signed transactions are only valid if they are signed by root.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo, Default)]
|
||||
#[scale_info(skip_type_params(T))]
|
||||
pub struct CheckSudo<T: Config + Send + Sync>(sp_std::marker::PhantomData<T>);
|
||||
|
||||
impl<T: Config + Send + Sync> CheckSudo<T> {
|
||||
pub fn new() -> Self {
|
||||
Self(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config + Send + Sync> sp_std::fmt::Debug for CheckSudo<T> {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
|
||||
write!(f, "CheckSudo")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config + Send + Sync> SignedExtension for CheckSudo<T>
|
||||
where
|
||||
<T as frame_system::Config>::Call: Dispatchable<Info = DispatchInfo>,
|
||||
{
|
||||
type AccountId = T::AccountId;
|
||||
type Call = <T as frame_system::Config>::Call;
|
||||
type AdditionalSigned = ();
|
||||
type Pre = ();
|
||||
const IDENTIFIER: &'static str = "CheckSudo";
|
||||
|
||||
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn pre_dispatch(
|
||||
self,
|
||||
who: &Self::AccountId,
|
||||
call: &Self::Call,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
Ok(self.validate(who, call, info, len).map(|_| ())?)
|
||||
}
|
||||
|
||||
fn validate(
|
||||
&self,
|
||||
who: &Self::AccountId,
|
||||
_call: &Self::Call,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
_len: usize,
|
||||
) -> TransactionValidity {
|
||||
let root_account = match pallet_sudo::Pallet::<T>::key() {
|
||||
Some(account) => account,
|
||||
None => return Err(InvalidTransaction::BadSigner.into()),
|
||||
};
|
||||
|
||||
if *who == root_account {
|
||||
Ok(ValidTransaction {
|
||||
priority: info.weight as TransactionPriority,
|
||||
longevity: TransactionLongevity::max_value(),
|
||||
propagate: true,
|
||||
..Default::default()
|
||||
})
|
||||
} else {
|
||||
Err(InvalidTransaction::BadSigner.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ name = "cumulus-pallet-xcm"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "2.3.0", default-features = false, features = ["derive"] }
|
||||
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
|
||||
scale-info = { version = "2.0.0", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0.132", optional = true, features = ["derive"] }
|
||||
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
@@ -117,7 +117,7 @@ impl<T: Config> DmpMessageHandler for UnlimitedDmpExecution<T> {
|
||||
let id = sp_io::hashing::twox_64(&data[..]);
|
||||
let msg = VersionedXcm::<T::Call>::decode_all_with_depth_limit(
|
||||
MAX_XCM_DECODE_DEPTH,
|
||||
&mut &data[..],
|
||||
&mut data.as_slice(),
|
||||
)
|
||||
.map(Xcm::<T::Call>::try_from);
|
||||
match msg {
|
||||
@@ -150,7 +150,7 @@ impl<T: Config> DmpMessageHandler for LimitAndDropDmpExecution<T> {
|
||||
let id = sp_io::hashing::twox_64(&data[..]);
|
||||
let msg = VersionedXcm::<T::Call>::decode_all_with_depth_limit(
|
||||
MAX_XCM_DECODE_DEPTH,
|
||||
&mut &data[..],
|
||||
&mut data.as_slice(),
|
||||
)
|
||||
.map(Xcm::<T::Call>::try_from);
|
||||
match msg {
|
||||
|
||||
@@ -5,43 +5,57 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
# Other dependencies
|
||||
codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ], default-features = false }
|
||||
rand_chacha = { version = "0.3.0", default-features = false }
|
||||
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", features = [ "derive" ], default-features = false }
|
||||
log = { version = "0.4.14", default-features = false }
|
||||
rand_chacha = { version = "0.3.0", default-features = false }
|
||||
scale-info = { version = "2.0.0", default-features = false, features = ["derive"] }
|
||||
|
||||
# Substrate Dependencies
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
# Substrate
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
# Polkadot Dependencies
|
||||
# Polkadot
|
||||
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
|
||||
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
|
||||
|
||||
# Cumulus Dependencies
|
||||
# Cumulus
|
||||
cumulus-primitives-core = { path = "../../primitives/core", default-features = false }
|
||||
|
||||
# Optional import for benchmarking
|
||||
frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
# Substrate
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
cumulus-pallet-parachain-system = { path = "../parachain-system" }
|
||||
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "master" }
|
||||
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
# Polkadot
|
||||
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "master" }
|
||||
|
||||
# Cumulus
|
||||
cumulus-pallet-parachain-system = { path = "../parachain-system" }
|
||||
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
std = [
|
||||
"codec/std",
|
||||
"log/std",
|
||||
"scale-info/std",
|
||||
"sp-std/std",
|
||||
"sp-runtime/std",
|
||||
"cumulus-primitives-core/std",
|
||||
"frame-support/std",
|
||||
"frame-system/std",
|
||||
"cumulus-primitives-core/std",
|
||||
"xcm/std",
|
||||
"log/std",
|
||||
"sp-runtime/std",
|
||||
"sp-std/std",
|
||||
"xcm-executor/std",
|
||||
"xcm/std",
|
||||
]
|
||||
|
||||
runtime-benchmarks = [
|
||||
"frame-benchmarking/runtime-benchmarks",
|
||||
"frame-support/runtime-benchmarks",
|
||||
"frame-system/runtime-benchmarks",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Benchmarking setup for cumulus-pallet-xcmp-queue
|
||||
|
||||
use crate::*;
|
||||
|
||||
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};
|
||||
use frame_system::RawOrigin;
|
||||
|
||||
benchmarks! {
|
||||
set_config_with_u32 {}: update_resume_threshold(RawOrigin::Root, 100)
|
||||
set_config_with_weight {}: update_weight_restrict_decay(RawOrigin::Root, 3_000_000 as Weight)
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
|
||||
+173
-32
@@ -33,12 +33,20 @@ mod mock;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use codec::{Decode, DecodeAll, DecodeLimit, Encode};
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmarking;
|
||||
pub mod weights;
|
||||
pub use weights::WeightInfo;
|
||||
|
||||
use codec::{Decode, DecodeLimit, Encode};
|
||||
use cumulus_primitives_core::{
|
||||
relay_chain::BlockNumber as RelayBlockNumber, ChannelStatus, GetChannelInfo, MessageSendError,
|
||||
ParaId, XcmpMessageFormat, XcmpMessageHandler, XcmpMessageSource,
|
||||
};
|
||||
use frame_support::weights::{constants::WEIGHT_PER_MILLIS, Weight};
|
||||
use frame_support::{
|
||||
traits::EnsureOrigin,
|
||||
weights::{constants::WEIGHT_PER_MILLIS, Weight},
|
||||
};
|
||||
use rand_chacha::{
|
||||
rand_core::{RngCore, SeedableRng},
|
||||
ChaChaRng,
|
||||
@@ -47,6 +55,7 @@ use scale_info::TypeInfo;
|
||||
use sp_runtime::{traits::Hash, RuntimeDebug};
|
||||
use sp_std::{convert::TryFrom, prelude::*};
|
||||
use xcm::{latest::prelude::*, VersionedXcm, WrapVersion, MAX_XCM_DECODE_DEPTH};
|
||||
use xcm_executor::traits::ConvertOrigin;
|
||||
|
||||
pub use pallet::*;
|
||||
|
||||
@@ -64,6 +73,7 @@ pub mod pallet {
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::storage_version(migration::STORAGE_VERSION)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
@@ -81,6 +91,16 @@ pub mod pallet {
|
||||
|
||||
/// The origin that is allowed to execute overweight messages.
|
||||
type ExecuteOverweightOrigin: EnsureOrigin<Self::Origin>;
|
||||
|
||||
/// The origin that is allowed to resume or suspend the XCMP queue.
|
||||
type ControllerOrigin: EnsureOrigin<Self::Origin>;
|
||||
|
||||
/// The conversion function used to attempt to convert an XCM `MultiLocation` origin to a
|
||||
/// superuser origin.
|
||||
type ControllerOriginConverter: ConvertOrigin<Self::Origin>;
|
||||
|
||||
/// The weight information of this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
@@ -110,7 +130,7 @@ pub mod pallet {
|
||||
///
|
||||
/// Events:
|
||||
/// - `OverweightServiced`: On success.
|
||||
#[pallet::weight(weight_limit.saturating_add(1_000_000))]
|
||||
#[pallet::weight((weight_limit.saturating_add(1_000_000), DispatchClass::Operational,))]
|
||||
pub fn service_overweight(
|
||||
origin: OriginFor<T>,
|
||||
index: OverweightIndex,
|
||||
@@ -120,15 +140,123 @@ pub mod pallet {
|
||||
|
||||
let (sender, sent_at, data) =
|
||||
Overweight::<T>::get(index).ok_or(Error::<T>::BadOverweightIndex)?;
|
||||
let xcm =
|
||||
VersionedXcm::<T::Call>::decode_all_with_depth_limit(MAX_XCM_DECODE_DEPTH, &data)
|
||||
.map_err(|_| Error::<T>::BadXcm)?;
|
||||
let xcm = VersionedXcm::<T::Call>::decode_all_with_depth_limit(
|
||||
MAX_XCM_DECODE_DEPTH,
|
||||
&mut data.as_slice(),
|
||||
)
|
||||
.map_err(|_| Error::<T>::BadXcm)?;
|
||||
let used = Self::handle_xcm_message(sender, sent_at, xcm, weight_limit)
|
||||
.map_err(|_| Error::<T>::WeightOverLimit)?;
|
||||
Overweight::<T>::remove(index);
|
||||
Self::deposit_event(Event::OverweightServiced(index, used));
|
||||
Ok(Some(used.saturating_add(1_000_000)).into())
|
||||
}
|
||||
|
||||
/// Suspends all XCM executions for the XCMP queue, regardless of the sender's origin.
|
||||
///
|
||||
/// - `origin`: Must pass `ControllerOrigin`.
|
||||
#[pallet::weight((T::DbWeight::get().writes(1), DispatchClass::Operational,))]
|
||||
pub fn suspend_xcm_execution(origin: OriginFor<T>) -> DispatchResult {
|
||||
T::ControllerOrigin::ensure_origin(origin)?;
|
||||
|
||||
QueueSuspended::<T>::put(true);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Resumes all XCM executions for the XCMP queue.
|
||||
///
|
||||
/// Note that this function doesn't change the status of the in/out bound channels.
|
||||
///
|
||||
/// - `origin`: Must pass `ControllerOrigin`.
|
||||
#[pallet::weight((T::DbWeight::get().writes(1), DispatchClass::Operational,))]
|
||||
pub fn resume_xcm_execution(origin: OriginFor<T>) -> DispatchResult {
|
||||
T::ControllerOrigin::ensure_origin(origin)?;
|
||||
|
||||
QueueSuspended::<T>::put(false);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Overwrites the number of pages of messages which must be in the queue for the other side to be told to
|
||||
/// suspend their sending.
|
||||
///
|
||||
/// - `origin`: Must pass `Root`.
|
||||
/// - `new`: Desired value for `QueueConfigData.suspend_value`
|
||||
#[pallet::weight((T::WeightInfo::set_config_with_u32(), DispatchClass::Operational,))]
|
||||
pub fn update_suspend_threshold(origin: OriginFor<T>, new: u32) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
QueueConfig::<T>::mutate(|data| data.suspend_threshold = new);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Overwrites the number of pages of messages which must be in the queue after which we drop any further
|
||||
/// messages from the channel.
|
||||
///
|
||||
/// - `origin`: Must pass `Root`.
|
||||
/// - `new`: Desired value for `QueueConfigData.drop_threshold`
|
||||
#[pallet::weight((T::WeightInfo::set_config_with_u32(),DispatchClass::Operational,))]
|
||||
pub fn update_drop_threshold(origin: OriginFor<T>, new: u32) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
QueueConfig::<T>::mutate(|data| data.drop_threshold = new);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Overwrites the number of pages of messages which the queue must be reduced to before it signals that
|
||||
/// message sending may recommence after it has been suspended.
|
||||
///
|
||||
/// - `origin`: Must pass `Root`.
|
||||
/// - `new`: Desired value for `QueueConfigData.resume_threshold`
|
||||
#[pallet::weight((T::WeightInfo::set_config_with_u32(), DispatchClass::Operational,))]
|
||||
pub fn update_resume_threshold(origin: OriginFor<T>, new: u32) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
QueueConfig::<T>::mutate(|data| data.resume_threshold = new);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Overwrites the amount of remaining weight under which we stop processing messages.
|
||||
///
|
||||
/// - `origin`: Must pass `Root`.
|
||||
/// - `new`: Desired value for `QueueConfigData.threshold_weight`
|
||||
#[pallet::weight((T::WeightInfo::set_config_with_weight(), DispatchClass::Operational,))]
|
||||
pub fn update_threshold_weight(origin: OriginFor<T>, new: Weight) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
QueueConfig::<T>::mutate(|data| data.threshold_weight = new);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Overwrites the speed to which the available weight approaches the maximum weight.
|
||||
/// A lower number results in a faster progression. A value of 1 makes the entire weight available initially.
|
||||
///
|
||||
/// - `origin`: Must pass `Root`.
|
||||
/// - `new`: Desired value for `QueueConfigData.weight_restrict_decay`.
|
||||
#[pallet::weight((T::WeightInfo::set_config_with_weight(), DispatchClass::Operational,))]
|
||||
pub fn update_weight_restrict_decay(origin: OriginFor<T>, new: Weight) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
QueueConfig::<T>::mutate(|data| data.weight_restrict_decay = new);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Overwrite the maximum amount of weight any individual message may consume.
|
||||
/// Messages above this weight go into the overweight queue and may only be serviced explicitly.
|
||||
///
|
||||
/// - `origin`: Must pass `Root`.
|
||||
/// - `new`: Desired value for `QueueConfigData.xcmp_max_individual_weight`.
|
||||
#[pallet::weight((T::WeightInfo::set_config_with_weight(), DispatchClass::Operational,))]
|
||||
pub fn update_xcmp_max_individual_weight(
|
||||
origin: OriginFor<T>,
|
||||
new: Weight,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
QueueConfig::<T>::mutate(|data| data.xcmp_max_individual_weight = new);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
@@ -220,6 +348,10 @@ pub mod pallet {
|
||||
/// available free overweight index.
|
||||
#[pallet::storage]
|
||||
pub(super) type OverweightCount<T: Config> = StorageValue<_, OverweightIndex, ValueQuery>;
|
||||
|
||||
/// Whether or not the XCMP queue is suspended from executing incoming XCMs or not.
|
||||
#[pallet::storage]
|
||||
pub(super) type QueueSuspended<T: Config> = StorageValue<_, bool, ValueQuery>;
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, TypeInfo)]
|
||||
@@ -370,10 +502,8 @@ impl<T: Config> Pallet<T> {
|
||||
let have_active = s[index].last_index > s[index].first_index;
|
||||
let appended = have_active &&
|
||||
<OutboundXcmpMessages<T>>::mutate(recipient, s[index].last_index - 1, |s| {
|
||||
if XcmpMessageFormat::decode_and_advance_with_depth_limit(
|
||||
MAX_XCM_DECODE_DEPTH,
|
||||
&mut &s[..],
|
||||
) != Ok(format)
|
||||
if XcmpMessageFormat::decode_with_depth_limit(MAX_XCM_DECODE_DEPTH, &mut &s[..]) !=
|
||||
Ok(format)
|
||||
{
|
||||
return false
|
||||
}
|
||||
@@ -497,7 +627,7 @@ impl<T: Config> Pallet<T> {
|
||||
XcmpMessageFormat::ConcatenatedVersionedXcm => {
|
||||
while !remaining_fragments.is_empty() {
|
||||
last_remaining_fragments = remaining_fragments;
|
||||
if let Ok(xcm) = VersionedXcm::<T::Call>::decode_and_advance_with_depth_limit(
|
||||
if let Ok(xcm) = VersionedXcm::<T::Call>::decode_with_depth_limit(
|
||||
MAX_XCM_DECODE_DEPTH,
|
||||
&mut remaining_fragments,
|
||||
) {
|
||||
@@ -538,26 +668,24 @@ impl<T: Config> Pallet<T> {
|
||||
XcmpMessageFormat::ConcatenatedEncodedBlob => {
|
||||
while !remaining_fragments.is_empty() {
|
||||
last_remaining_fragments = remaining_fragments;
|
||||
match <Vec<u8>>::decode_all(&mut remaining_fragments) {
|
||||
Ok(blob) if remaining_fragments.len() < last_remaining_fragments.len() => {
|
||||
let weight = max_weight - weight_used;
|
||||
match Self::handle_blob_message(sender, sent_at, blob, weight) {
|
||||
Ok(used) => weight_used = weight_used.saturating_add(used),
|
||||
Err(true) => {
|
||||
// That message didn't get processed this time because of being
|
||||
// too heavy. We leave it around for next time and bail.
|
||||
remaining_fragments = last_remaining_fragments;
|
||||
break
|
||||
},
|
||||
Err(false) => {
|
||||
// Message invalid; don't attempt to retry
|
||||
},
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
debug_assert!(false, "Invalid incoming blob message data");
|
||||
remaining_fragments = &b""[..];
|
||||
},
|
||||
|
||||
if let Ok(blob) = <Vec<u8>>::decode(&mut remaining_fragments) {
|
||||
let weight = max_weight - weight_used;
|
||||
match Self::handle_blob_message(sender, sent_at, blob, weight) {
|
||||
Ok(used) => weight_used = weight_used.saturating_add(used),
|
||||
Err(true) => {
|
||||
// That message didn't get processed this time because of being
|
||||
// too heavy. We leave it around for next time and bail.
|
||||
remaining_fragments = last_remaining_fragments;
|
||||
break
|
||||
},
|
||||
Err(false) => {
|
||||
// Message invalid; don't attempt to retry
|
||||
},
|
||||
}
|
||||
} else {
|
||||
debug_assert!(false, "Invalid incoming blob message data");
|
||||
remaining_fragments = &b""[..];
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -619,6 +747,8 @@ impl<T: Config> Pallet<T> {
|
||||
/// for the second &c. though empirical and or practical factors may give rise to adjusting it
|
||||
/// further.
|
||||
fn service_xcmp_queue(max_weight: Weight) -> Weight {
|
||||
let suspended = QueueSuspended::<T>::get();
|
||||
|
||||
let mut status = <InboundXcmpStatus<T>>::get(); // <- sorted.
|
||||
if status.len() == 0 {
|
||||
return 0
|
||||
@@ -650,6 +780,17 @@ impl<T: Config> Pallet<T> {
|
||||
{
|
||||
let index = shuffled[shuffle_index];
|
||||
let sender = status[index].sender;
|
||||
let sender_origin = T::ControllerOriginConverter::convert_origin(
|
||||
(1, Parachain(sender.into())),
|
||||
OriginKind::Superuser,
|
||||
);
|
||||
let is_controller = sender_origin
|
||||
.map_or(false, |origin| T::ControllerOrigin::try_origin(origin).is_ok());
|
||||
|
||||
if suspended && !is_controller {
|
||||
shuffle_index += 1;
|
||||
continue
|
||||
}
|
||||
|
||||
if weight_available != max_weight {
|
||||
// Get incrementally closer to freeing up max_weight for message execution over the
|
||||
@@ -760,7 +901,7 @@ impl<T: Config> XcmpMessageHandler for Pallet<T> {
|
||||
for (sender, sent_at, data) in iter {
|
||||
// Figure out the message format.
|
||||
let mut data_ref = data;
|
||||
let format = match XcmpMessageFormat::decode_and_advance_with_depth_limit(
|
||||
let format = match XcmpMessageFormat::decode_with_depth_limit(
|
||||
MAX_XCM_DECODE_DEPTH,
|
||||
&mut data_ref,
|
||||
) {
|
||||
|
||||
@@ -15,16 +15,20 @@
|
||||
|
||||
use super::*;
|
||||
use crate as xcmp_queue;
|
||||
use frame_support::parameter_types;
|
||||
use core::marker::PhantomData;
|
||||
use cumulus_primitives_core::{IsSystem, ParaId};
|
||||
use frame_support::{parameter_types, traits::OriginTrait};
|
||||
use frame_system::EnsureRoot;
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
};
|
||||
use xcm::prelude::*;
|
||||
use xcm_builder::{
|
||||
CurrencyAdapter, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentIsDefault,
|
||||
CurrencyAdapter, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentIsPreset,
|
||||
};
|
||||
use xcm_executor::traits::ConvertOrigin;
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
@@ -98,7 +102,7 @@ impl pallet_balances::Config for Test {
|
||||
|
||||
impl cumulus_pallet_parachain_system::Config for Test {
|
||||
type Event = Event;
|
||||
type OnValidationData = ();
|
||||
type OnSystemEvent = ();
|
||||
type SelfParaId = ();
|
||||
type OutboundXcmpMessageSource = XcmpQueue;
|
||||
type DmpMessageHandler = ();
|
||||
@@ -129,7 +133,7 @@ pub type LocalAssetTransactor = CurrencyAdapter<
|
||||
(),
|
||||
>;
|
||||
|
||||
pub type LocationToAccountId = (ParentIsDefault<AccountId>,);
|
||||
pub type LocationToAccountId = (ParentIsPreset<AccountId>,);
|
||||
|
||||
pub struct XcmConfig;
|
||||
impl xcm_executor::Config for XcmConfig {
|
||||
@@ -157,12 +161,37 @@ pub type XcmRouter = (
|
||||
XcmpQueue,
|
||||
);
|
||||
|
||||
pub struct SystemParachainAsSuperuser<Origin>(PhantomData<Origin>);
|
||||
impl<Origin: OriginTrait> ConvertOrigin<Origin> for SystemParachainAsSuperuser<Origin> {
|
||||
fn convert_origin(
|
||||
origin: impl Into<MultiLocation>,
|
||||
kind: OriginKind,
|
||||
) -> Result<Origin, MultiLocation> {
|
||||
let origin = origin.into();
|
||||
if kind == OriginKind::Superuser &&
|
||||
matches!(
|
||||
origin,
|
||||
MultiLocation {
|
||||
parents: 1,
|
||||
interior: X1(Parachain(id)),
|
||||
} if ParaId::from(id).is_system(),
|
||||
) {
|
||||
Ok(Origin::root())
|
||||
} else {
|
||||
Err(origin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config for Test {
|
||||
type Event = Event;
|
||||
type XcmExecutor = xcm_executor::XcmExecutor<XcmConfig>;
|
||||
type ChannelInfo = ParachainSystem;
|
||||
type VersionWrapper = ();
|
||||
type ExecuteOverweightOrigin = EnsureRoot<AccountId>;
|
||||
type ControllerOrigin = EnsureRoot<AccountId>;
|
||||
type ControllerOriginConverter = SystemParachainAsSuperuser<Origin>;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
|
||||
use super::*;
|
||||
use cumulus_primitives_core::XcmpMessageHandler;
|
||||
use frame_support::assert_noop;
|
||||
use mock::{new_test_ext, Origin, Test, XcmpQueue};
|
||||
use frame_support::{assert_noop, assert_ok};
|
||||
use mock::{new_test_ext, Call, Origin, Test, XcmpQueue};
|
||||
use sp_runtime::traits::BadOrigin;
|
||||
|
||||
#[test]
|
||||
fn one_message_does_not_panic() {
|
||||
@@ -46,10 +47,12 @@ fn bad_message_is_handled() {
|
||||
});
|
||||
}
|
||||
|
||||
/// Tests that a blob message is handled. Currently this isn't implemented and panics when debug assertions
|
||||
/// are enabled. When this feature is enabled, this test should be rewritten properly.
|
||||
#[test]
|
||||
#[should_panic = "Invalid incoming blob message data"]
|
||||
#[should_panic = "Blob messages not handled."]
|
||||
#[cfg(debug_assertions)]
|
||||
fn other_bad_message_is_handled() {
|
||||
fn handle_blob_message() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let bad_data = vec![
|
||||
1, 1, 1, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 64, 239,
|
||||
@@ -58,7 +61,6 @@ fn other_bad_message_is_handled() {
|
||||
];
|
||||
InboundXcmpMessages::<Test>::insert(ParaId::from(1000), 1, bad_data);
|
||||
let format = XcmpMessageFormat::ConcatenatedEncodedBlob;
|
||||
// This should exit with an error.
|
||||
XcmpQueue::process_xcmp_message(1000.into(), (1, format), 10_000_000_000, 10_000_000_000);
|
||||
});
|
||||
}
|
||||
@@ -82,3 +84,113 @@ fn service_overweight_bad_xcm_format() {
|
||||
assert_noop!(XcmpQueue::service_overweight(Origin::root(), 0, 1000), Error::<Test>::BadXcm);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn suspend_xcm_execution_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
QueueSuspended::<Test>::put(true);
|
||||
|
||||
let xcm = VersionedXcm::from(Xcm::<Call>(vec![Instruction::<Call>::ClearOrigin])).encode();
|
||||
let mut message_format = XcmpMessageFormat::ConcatenatedVersionedXcm.encode();
|
||||
message_format.extend(xcm.clone());
|
||||
let messages = vec![(ParaId::from(999), 1u32.into(), message_format.as_slice())];
|
||||
|
||||
// This should have executed the incoming XCM, because it came from a system parachain
|
||||
XcmpQueue::handle_xcmp_messages(messages.into_iter(), Weight::max_value());
|
||||
|
||||
let queued_xcm = InboundXcmpMessages::<Test>::get(ParaId::from(999), 1u32);
|
||||
assert!(queued_xcm.is_empty());
|
||||
|
||||
let messages = vec![(ParaId::from(2000), 1u32.into(), message_format.as_slice())];
|
||||
|
||||
// This shouldn't have executed the incoming XCM
|
||||
XcmpQueue::handle_xcmp_messages(messages.into_iter(), Weight::max_value());
|
||||
|
||||
let queued_xcm = InboundXcmpMessages::<Test>::get(ParaId::from(2000), 1u32);
|
||||
assert_eq!(queued_xcm, xcm);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_suspend_threshold_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||
assert_eq!(data.suspend_threshold, 2);
|
||||
assert_ok!(XcmpQueue::update_suspend_threshold(Origin::root(), 3));
|
||||
assert_noop!(XcmpQueue::update_suspend_threshold(Origin::signed(2), 5), BadOrigin);
|
||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||
|
||||
assert_eq!(data.suspend_threshold, 3);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_drop_threshold_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||
assert_eq!(data.drop_threshold, 5);
|
||||
assert_ok!(XcmpQueue::update_drop_threshold(Origin::root(), 6));
|
||||
assert_noop!(XcmpQueue::update_drop_threshold(Origin::signed(2), 7), BadOrigin);
|
||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||
|
||||
assert_eq!(data.drop_threshold, 6);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_resume_threshold_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||
assert_eq!(data.resume_threshold, 1);
|
||||
assert_ok!(XcmpQueue::update_resume_threshold(Origin::root(), 2));
|
||||
assert_noop!(XcmpQueue::update_resume_threshold(Origin::signed(7), 3), BadOrigin);
|
||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||
|
||||
assert_eq!(data.resume_threshold, 2);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_threshold_weight_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||
assert_eq!(data.threshold_weight, 100_000);
|
||||
assert_ok!(XcmpQueue::update_threshold_weight(Origin::root(), 10_000));
|
||||
assert_noop!(XcmpQueue::update_threshold_weight(Origin::signed(5), 10_000_000), BadOrigin);
|
||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||
|
||||
assert_eq!(data.threshold_weight, 10_000);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_weight_restrict_decay_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||
assert_eq!(data.weight_restrict_decay, 2);
|
||||
assert_ok!(XcmpQueue::update_weight_restrict_decay(Origin::root(), 5));
|
||||
assert_noop!(XcmpQueue::update_weight_restrict_decay(Origin::signed(6), 4), BadOrigin);
|
||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||
|
||||
assert_eq!(data.weight_restrict_decay, 5);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_xcmp_max_individual_weight() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||
assert_eq!(data.xcmp_max_individual_weight, 20 * WEIGHT_PER_MILLIS);
|
||||
assert_ok!(XcmpQueue::update_xcmp_max_individual_weight(
|
||||
Origin::root(),
|
||||
30 * WEIGHT_PER_MILLIS
|
||||
));
|
||||
assert_noop!(
|
||||
XcmpQueue::update_xcmp_max_individual_weight(Origin::signed(3), 10 * WEIGHT_PER_MILLIS),
|
||||
BadOrigin
|
||||
);
|
||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||
|
||||
assert_eq!(data.xcmp_max_individual_weight, 30 * WEIGHT_PER_MILLIS);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use frame_support::{
|
||||
traits::Get,
|
||||
weights::{constants::RocksDbWeight, Weight},
|
||||
};
|
||||
use sp_std::marker::PhantomData;
|
||||
|
||||
// Implemented by autogenerated benchmarking code.
|
||||
pub trait WeightInfo {
|
||||
fn set_config_with_u32() -> Weight;
|
||||
fn set_config_with_weight() -> Weight;
|
||||
}
|
||||
|
||||
pub struct SubstrateWeight<T>(PhantomData<T>);
|
||||
|
||||
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
// Storage: XcmpQueue QueueConfig (r:1 w:1)
|
||||
fn set_config_with_u32() -> Weight {
|
||||
(2_717_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
|
||||
// Storage: XcmpQueue QueueConfig (r:1 w:1)
|
||||
fn set_config_with_weight() -> Weight {
|
||||
(2_717_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
}
|
||||
|
||||
impl WeightInfo for () {
|
||||
// Storage: XcmpQueue QueueConfig (r:1 w:1)
|
||||
fn set_config_with_u32() -> Weight {
|
||||
(2_717_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
|
||||
// Storage: XcmpQueue QueueConfig (r:1 w:1)
|
||||
fn set_config_with_weight() -> Weight {
|
||||
(2_717_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user