mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-21 22:41:02 +00:00
Merge remote-tracking branch 'origin' into gav-xcm-v3
This commit is contained in:
@@ -8,7 +8,7 @@ description = "AURA consensus extension pallet for parachains"
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
|
||||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0.132", optional = true, features = ["derive"] }
|
||||
serde = { version = "1.0.143", optional = true, features = ["derive"] }
|
||||
|
||||
# Substrate
|
||||
frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
@@ -49,21 +49,19 @@ pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
/// The configuration trait.
|
||||
#[pallet::config]
|
||||
pub trait Config: pallet_aura::Config + frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn on_finalize(_: BlockNumberFor<T>) {
|
||||
// Update to the latest AuRa authorities.
|
||||
Authorities::<T>::put(Aura::<T>::authorities().into_inner());
|
||||
Authorities::<T>::put(Aura::<T>::authorities());
|
||||
}
|
||||
|
||||
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
|
||||
@@ -74,16 +72,17 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {}
|
||||
|
||||
/// Serves as cache for the authorities.
|
||||
///
|
||||
/// The authorities in AuRa are overwritten in `on_initialize` when we switch to a new session,
|
||||
/// but we require the old authorities to verify the seal when validating a PoV. This will always
|
||||
/// be updated to the latest AuRa authorities in `on_finalize`.
|
||||
#[pallet::storage]
|
||||
pub(crate) type Authorities<T: Config> = StorageValue<_, Vec<T::AuthorityId>, ValueQuery>;
|
||||
pub(crate) type Authorities<T: Config> = StorageValue<
|
||||
_,
|
||||
BoundedVec<T::AuthorityId, <T as pallet_aura::Config>::MaxAuthorities>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
#[pallet::genesis_config]
|
||||
#[derive(Default)]
|
||||
@@ -99,7 +98,7 @@ pub mod pallet {
|
||||
"AuRa authorities empty, maybe wrong order in `construct_runtime!`?",
|
||||
);
|
||||
|
||||
Authorities::<T>::put(authorities.into_inner());
|
||||
Authorities::<T>::put(authorities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@ version = "3.0.0"
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
log = { version = "0.4.16", default-features = false }
|
||||
log = { version = "0.4.17", default-features = false }
|
||||
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.1.1", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0.132", default-features = false }
|
||||
serde = { version = "1.0.143", 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" }
|
||||
|
||||
@@ -117,7 +117,7 @@ benchmarks! {
|
||||
);
|
||||
}
|
||||
verify {
|
||||
assert_last_event::<T>(Event::NewInvulnerables(new_invulnerables).into());
|
||||
assert_last_event::<T>(Event::NewInvulnerables{invulnerables: new_invulnerables}.into());
|
||||
}
|
||||
|
||||
set_desired_candidates {
|
||||
@@ -129,19 +129,19 @@ benchmarks! {
|
||||
);
|
||||
}
|
||||
verify {
|
||||
assert_last_event::<T>(Event::NewDesiredCandidates(max).into());
|
||||
assert_last_event::<T>(Event::NewDesiredCandidates{desired_candidates: max}.into());
|
||||
}
|
||||
|
||||
set_candidacy_bond {
|
||||
let bond: BalanceOf<T> = T::Currency::minimum_balance() * 10u32.into();
|
||||
let bond_amount: BalanceOf<T> = T::Currency::minimum_balance() * 10u32.into();
|
||||
let origin = T::UpdateOrigin::successful_origin();
|
||||
}: {
|
||||
assert_ok!(
|
||||
<CollatorSelection<T>>::set_candidacy_bond(origin, bond.clone())
|
||||
<CollatorSelection<T>>::set_candidacy_bond(origin, bond_amount.clone())
|
||||
);
|
||||
}
|
||||
verify {
|
||||
assert_last_event::<T>(Event::NewCandidacyBond(bond).into());
|
||||
assert_last_event::<T>(Event::NewCandidacyBond{bond_amount}.into());
|
||||
}
|
||||
|
||||
// worse case is when we have all the max-candidate slots filled except one, and we fill that
|
||||
@@ -167,7 +167,7 @@ benchmarks! {
|
||||
|
||||
}: _(RawOrigin::Signed(caller.clone()))
|
||||
verify {
|
||||
assert_last_event::<T>(Event::CandidateAdded(caller, bond / 2u32.into()).into());
|
||||
assert_last_event::<T>(Event::CandidateAdded{account_id: caller, deposit: bond / 2u32.into()}.into());
|
||||
}
|
||||
|
||||
// worse case is the last candidate leaving.
|
||||
@@ -183,7 +183,7 @@ benchmarks! {
|
||||
whitelist!(leaving);
|
||||
}: _(RawOrigin::Signed(leaving.clone()))
|
||||
verify {
|
||||
assert_last_event::<T>(Event::CandidateRemoved(leaving).into());
|
||||
assert_last_event::<T>(Event::CandidateRemoved{account_id: leaving}.into());
|
||||
}
|
||||
|
||||
// worse case is paying a non-existing candidate account.
|
||||
|
||||
@@ -89,7 +89,7 @@ pub mod pallet {
|
||||
ValidatorRegistration,
|
||||
},
|
||||
weights::DispatchClass,
|
||||
PalletId,
|
||||
BoundedVec, PalletId,
|
||||
};
|
||||
use frame_system::{pallet_prelude::*, Config as SystemConfig};
|
||||
use pallet_session::SessionManager;
|
||||
@@ -123,8 +123,7 @@ pub mod pallet {
|
||||
/// Account Identifier from which the internal Pot is generated.
|
||||
type PotId: Get<PalletId>;
|
||||
|
||||
/// Maximum number of candidates that we should have. This is used for benchmarking and is not
|
||||
/// enforced.
|
||||
/// Maximum number of candidates that we should have. This is enforced in code.
|
||||
///
|
||||
/// This does not take into account the invulnerables.
|
||||
type MaxCandidates: Get<u32>;
|
||||
@@ -134,9 +133,7 @@ pub mod pallet {
|
||||
/// This does not take into account the invulnerables.
|
||||
type MinCandidates: Get<u32>;
|
||||
|
||||
/// Maximum number of invulnerables.
|
||||
///
|
||||
/// Used only for benchmarking.
|
||||
/// Maximum number of invulnerables. This is enforced in code.
|
||||
type MaxInvulnerables: Get<u32>;
|
||||
|
||||
// Will be kicked if block is not produced in threshold.
|
||||
@@ -158,7 +155,9 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
/// Basic information about a collation candidate.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)]
|
||||
#[derive(
|
||||
PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo, MaxEncodedLen,
|
||||
)]
|
||||
pub struct CandidateInfo<AccountId, Balance> {
|
||||
/// Account identifier.
|
||||
pub who: AccountId,
|
||||
@@ -168,19 +167,22 @@ pub mod pallet {
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
/// The invulnerable, fixed collators.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn invulnerables)]
|
||||
pub type Invulnerables<T: Config> = StorageValue<_, Vec<T::AccountId>, ValueQuery>;
|
||||
pub type Invulnerables<T: Config> =
|
||||
StorageValue<_, BoundedVec<T::AccountId, T::MaxInvulnerables>, ValueQuery>;
|
||||
|
||||
/// The (community, limited) collation candidates.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn candidates)]
|
||||
pub type Candidates<T: Config> =
|
||||
StorageValue<_, Vec<CandidateInfo<T::AccountId, BalanceOf<T>>>, ValueQuery>;
|
||||
pub type Candidates<T: Config> = StorageValue<
|
||||
_,
|
||||
BoundedVec<CandidateInfo<T::AccountId, BalanceOf<T>>, T::MaxCandidates>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
/// Last block authored by collator.
|
||||
#[pallet::storage]
|
||||
@@ -230,10 +232,9 @@ pub mod pallet {
|
||||
"duplicate invulnerables in genesis."
|
||||
);
|
||||
|
||||
assert!(
|
||||
T::MaxInvulnerables::get() >= (self.invulnerables.len() as u32),
|
||||
"genesis invulnerables are more than T::MaxInvulnerables",
|
||||
);
|
||||
let bounded_invulnerables =
|
||||
BoundedVec::<_, T::MaxInvulnerables>::try_from(self.invulnerables.clone())
|
||||
.expect("genesis invulnerables are more than T::MaxInvulnerables");
|
||||
assert!(
|
||||
T::MaxCandidates::get() >= self.desired_candidates,
|
||||
"genesis desired_candidates are more than T::MaxCandidates",
|
||||
@@ -241,18 +242,18 @@ pub mod pallet {
|
||||
|
||||
<DesiredCandidates<T>>::put(&self.desired_candidates);
|
||||
<CandidacyBond<T>>::put(&self.candidacy_bond);
|
||||
<Invulnerables<T>>::put(&self.invulnerables);
|
||||
<Invulnerables<T>>::put(bounded_invulnerables);
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
NewInvulnerables(Vec<T::AccountId>),
|
||||
NewDesiredCandidates(u32),
|
||||
NewCandidacyBond(BalanceOf<T>),
|
||||
CandidateAdded(T::AccountId, BalanceOf<T>),
|
||||
CandidateRemoved(T::AccountId),
|
||||
NewInvulnerables { invulnerables: Vec<T::AccountId> },
|
||||
NewDesiredCandidates { desired_candidates: u32 },
|
||||
NewCandidacyBond { bond_amount: BalanceOf<T> },
|
||||
CandidateAdded { account_id: T::AccountId, deposit: BalanceOf<T> },
|
||||
CandidateRemoved { account_id: T::AccountId },
|
||||
}
|
||||
|
||||
// Errors inform users that something went wrong.
|
||||
@@ -270,6 +271,8 @@ pub mod pallet {
|
||||
AlreadyCandidate,
|
||||
/// User is not a candidate
|
||||
NotCandidate,
|
||||
/// Too many invulnerables
|
||||
TooManyInvulnerables,
|
||||
/// User is already an Invulnerable
|
||||
AlreadyInvulnerable,
|
||||
/// Account has no associated validator ID
|
||||
@@ -290,15 +293,11 @@ pub mod pallet {
|
||||
new: Vec<T::AccountId>,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
T::UpdateOrigin::ensure_origin(origin)?;
|
||||
// we trust origin calls, this is just a for more accurate benchmarking
|
||||
if (new.len() as u32) > T::MaxInvulnerables::get() {
|
||||
log::warn!(
|
||||
"invulnerables > T::MaxInvulnerables; you might need to run benchmarks again"
|
||||
);
|
||||
}
|
||||
let bounded_invulnerables = BoundedVec::<_, T::MaxInvulnerables>::try_from(new)
|
||||
.map_err(|_| Error::<T>::TooManyInvulnerables)?;
|
||||
|
||||
// check if the invulnerables have associated validator keys before they are set
|
||||
for account_id in &new {
|
||||
for account_id in bounded_invulnerables.iter() {
|
||||
let validator_key = T::ValidatorIdOf::convert(account_id.clone())
|
||||
.ok_or(Error::<T>::NoAssociatedValidatorId)?;
|
||||
ensure!(
|
||||
@@ -307,8 +306,10 @@ pub mod pallet {
|
||||
);
|
||||
}
|
||||
|
||||
<Invulnerables<T>>::put(&new);
|
||||
Self::deposit_event(Event::NewInvulnerables(new));
|
||||
<Invulnerables<T>>::put(&bounded_invulnerables);
|
||||
Self::deposit_event(Event::NewInvulnerables {
|
||||
invulnerables: bounded_invulnerables.to_vec(),
|
||||
});
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
@@ -326,7 +327,7 @@ pub mod pallet {
|
||||
log::warn!("max > T::MaxCandidates; you might need to run benchmarks again");
|
||||
}
|
||||
<DesiredCandidates<T>>::put(&max);
|
||||
Self::deposit_event(Event::NewDesiredCandidates(max));
|
||||
Self::deposit_event(Event::NewDesiredCandidates { desired_candidates: max });
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
@@ -338,7 +339,7 @@ pub mod pallet {
|
||||
) -> DispatchResultWithPostInfo {
|
||||
T::UpdateOrigin::ensure_origin(origin)?;
|
||||
<CandidacyBond<T>>::put(&bond);
|
||||
Self::deposit_event(Event::NewCandidacyBond(bond));
|
||||
Self::deposit_event(Event::NewCandidacyBond { bond_amount: bond });
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
@@ -372,7 +373,7 @@ pub mod pallet {
|
||||
Err(Error::<T>::AlreadyCandidate)?
|
||||
} else {
|
||||
T::Currency::reserve(&who, deposit)?;
|
||||
candidates.push(incoming);
|
||||
candidates.try_push(incoming).map_err(|_| Error::<T>::TooManyCandidates)?;
|
||||
<LastAuthoredBlock<T>>::insert(
|
||||
who.clone(),
|
||||
frame_system::Pallet::<T>::block_number() + T::KickThreshold::get(),
|
||||
@@ -381,7 +382,7 @@ pub mod pallet {
|
||||
}
|
||||
})?;
|
||||
|
||||
Self::deposit_event(Event::CandidateAdded(who, deposit));
|
||||
Self::deposit_event(Event::CandidateAdded { account_id: who, deposit });
|
||||
Ok(Some(T::WeightInfo::register_as_candidate(current_count as u32)).into())
|
||||
}
|
||||
|
||||
@@ -407,7 +408,7 @@ pub mod pallet {
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Get a unique, inaccessible account id from the `PotId`.
|
||||
pub fn account_id() -> T::AccountId {
|
||||
T::PotId::get().into_account()
|
||||
T::PotId::get().into_account_truncating()
|
||||
}
|
||||
|
||||
/// Removes a candidate if they exist and sends them back their deposit
|
||||
@@ -423,15 +424,17 @@ pub mod pallet {
|
||||
<LastAuthoredBlock<T>>::remove(who.clone());
|
||||
Ok(candidates.len())
|
||||
})?;
|
||||
Self::deposit_event(Event::CandidateRemoved(who.clone()));
|
||||
Self::deposit_event(Event::CandidateRemoved { account_id: who.clone() });
|
||||
Ok(current_count)
|
||||
}
|
||||
|
||||
/// Assemble the current set of candidates and invulnerables into the next collator set.
|
||||
///
|
||||
/// This is done on the fly, as frequent as we are told to do so, as the session manager.
|
||||
pub fn assemble_collators(candidates: Vec<T::AccountId>) -> Vec<T::AccountId> {
|
||||
let mut collators = Self::invulnerables();
|
||||
pub fn assemble_collators(
|
||||
candidates: BoundedVec<T::AccountId, T::MaxCandidates>,
|
||||
) -> Vec<T::AccountId> {
|
||||
let mut collators = Self::invulnerables().to_vec();
|
||||
collators.extend(candidates);
|
||||
collators
|
||||
}
|
||||
@@ -439,8 +442,8 @@ pub mod pallet {
|
||||
/// Kicks out candidates that did not produce a block in the kick threshold
|
||||
/// and refund their deposits.
|
||||
pub fn kick_stale_candidates(
|
||||
candidates: Vec<CandidateInfo<T::AccountId, BalanceOf<T>>>,
|
||||
) -> Vec<T::AccountId> {
|
||||
candidates: BoundedVec<CandidateInfo<T::AccountId, BalanceOf<T>>, T::MaxCandidates>,
|
||||
) -> BoundedVec<T::AccountId, T::MaxCandidates> {
|
||||
let now = frame_system::Pallet::<T>::block_number();
|
||||
let kick_threshold = T::KickThreshold::get();
|
||||
candidates
|
||||
@@ -461,7 +464,9 @@ pub mod pallet {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
.collect::<Vec<_>>()
|
||||
.try_into()
|
||||
.expect("filter_map operation can't result in a bounded vec larger than its original; qed")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", features = [ "derive" ], default-features = false }
|
||||
log = { version = "0.4.16", default-features = false }
|
||||
log = { version = "0.4.17", default-features = false }
|
||||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
|
||||
|
||||
# Substrate
|
||||
|
||||
@@ -149,11 +149,11 @@ pub mod pallet {
|
||||
T::ExecuteOverweightOrigin::ensure_origin(origin)?;
|
||||
|
||||
let (sent_at, data) = Overweight::<T>::get(index).ok_or(Error::<T>::Unknown)?;
|
||||
let used = Self::try_service_message(weight_limit, sent_at, &data[..])
|
||||
let weight_used = Self::try_service_message(weight_limit, sent_at, &data[..])
|
||||
.map_err(|_| Error::<T>::OverLimit)?;
|
||||
Overweight::<T>::remove(index);
|
||||
Self::deposit_event(Event::OverweightServiced(index, used));
|
||||
Ok(Some(used.saturating_add(1_000_000)).into())
|
||||
Self::deposit_event(Event::OverweightServiced { overweight_index: index, weight_used });
|
||||
Ok(Some(weight_used.saturating_add(1_000_000)).into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,23 +161,21 @@ pub mod pallet {
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// Downward message is invalid XCM.
|
||||
/// \[ id \]
|
||||
InvalidFormat(MessageId),
|
||||
InvalidFormat { message_id: MessageId },
|
||||
/// Downward message is unsupported version of XCM.
|
||||
/// \[ id \]
|
||||
UnsupportedVersion(MessageId),
|
||||
UnsupportedVersion { message_id: MessageId },
|
||||
/// Downward message executed with the given outcome.
|
||||
/// \[ id, outcome \]
|
||||
ExecutedDownward(MessageId, Outcome),
|
||||
ExecutedDownward { message_id: MessageId, outcome: Outcome },
|
||||
/// The weight limit for handling downward messages was reached.
|
||||
/// \[ id, remaining, required \]
|
||||
WeightExhausted(MessageId, Weight, Weight),
|
||||
WeightExhausted { message_id: MessageId, remaining_weight: Weight, required_weight: Weight },
|
||||
/// Downward message is overweight and was placed in the overweight queue.
|
||||
/// \[ id, index, required \]
|
||||
OverweightEnqueued(MessageId, OverweightIndex, Weight),
|
||||
OverweightEnqueued {
|
||||
message_id: MessageId,
|
||||
overweight_index: OverweightIndex,
|
||||
required_weight: Weight,
|
||||
},
|
||||
/// Downward message from the overweight queue was executed.
|
||||
/// \[ index, used \]
|
||||
OverweightServiced(OverweightIndex, Weight),
|
||||
OverweightServiced { overweight_index: OverweightIndex, weight_used: Weight },
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
@@ -225,7 +223,7 @@ pub mod pallet {
|
||||
_sent_at: RelayBlockNumber,
|
||||
mut data: &[u8],
|
||||
) -> Result<Weight, (MessageId, Weight)> {
|
||||
let id = sp_io::hashing::blake2_256(data);
|
||||
let message_id = sp_io::hashing::blake2_256(data);
|
||||
let maybe_msg = VersionedXcm::<T::Call>::decode_all_with_depth_limit(
|
||||
MAX_XCM_DECODE_DEPTH,
|
||||
&mut data,
|
||||
@@ -233,21 +231,21 @@ pub mod pallet {
|
||||
.map(Xcm::<T::Call>::try_from);
|
||||
match maybe_msg {
|
||||
Err(_) => {
|
||||
Self::deposit_event(Event::InvalidFormat(id));
|
||||
Self::deposit_event(Event::InvalidFormat { message_id });
|
||||
Ok(0)
|
||||
},
|
||||
Ok(Err(())) => {
|
||||
Self::deposit_event(Event::UnsupportedVersion(id));
|
||||
Self::deposit_event(Event::UnsupportedVersion { message_id });
|
||||
Ok(0)
|
||||
},
|
||||
Ok(Ok(x)) => {
|
||||
let outcome = T::XcmExecutor::execute_xcm(Parent, x, id, limit);
|
||||
match outcome {
|
||||
Outcome::Error(XcmError::WeightLimitReached(required)) =>
|
||||
Err((id, required)),
|
||||
Err((message_id, required)),
|
||||
outcome => {
|
||||
let weight_used = outcome.weight_used();
|
||||
Self::deposit_event(Event::ExecutedDownward(id, outcome));
|
||||
Self::deposit_event(Event::ExecutedDownward { message_id, outcome });
|
||||
Ok(weight_used)
|
||||
},
|
||||
}
|
||||
@@ -283,18 +281,22 @@ pub mod pallet {
|
||||
for (i, (sent_at, data)) in iter.enumerate() {
|
||||
if maybe_enqueue_page.is_none() {
|
||||
// We're not currently enqueuing - try to execute inline.
|
||||
let remaining = limit.saturating_sub(used);
|
||||
match Self::try_service_message(remaining, sent_at, &data[..]) {
|
||||
let remaining_weight = limit.saturating_sub(used);
|
||||
match Self::try_service_message(remaining_weight, sent_at, &data[..]) {
|
||||
Ok(consumed) => used += consumed,
|
||||
Err((id, required)) =>
|
||||
Err((message_id, required_weight)) =>
|
||||
// Too much weight required right now.
|
||||
{
|
||||
if required > config.max_individual {
|
||||
if required_weight > config.max_individual {
|
||||
// overweight - add to overweight queue and continue with
|
||||
// message execution.
|
||||
let index = page_index.overweight_count;
|
||||
Overweight::<T>::insert(index, (sent_at, data));
|
||||
Self::deposit_event(Event::OverweightEnqueued(id, index, required));
|
||||
let overweight_index = page_index.overweight_count;
|
||||
Overweight::<T>::insert(overweight_index, (sent_at, data));
|
||||
Self::deposit_event(Event::OverweightEnqueued {
|
||||
message_id,
|
||||
overweight_index,
|
||||
required_weight,
|
||||
});
|
||||
page_index.overweight_count += 1;
|
||||
// Not needed for control flow, but only to ensure that the compiler
|
||||
// understands that we won't attempt to re-use `data` later.
|
||||
@@ -304,9 +306,11 @@ pub mod pallet {
|
||||
// from here on.
|
||||
let item_count_left = item_count.saturating_sub(i);
|
||||
maybe_enqueue_page = Some(Vec::with_capacity(item_count_left));
|
||||
Self::deposit_event(Event::WeightExhausted(
|
||||
id, remaining, required,
|
||||
));
|
||||
Self::deposit_event(Event::WeightExhausted {
|
||||
message_id,
|
||||
remaining_weight,
|
||||
required_weight,
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -6,12 +6,13 @@ edition = "2021"
|
||||
description = "Base pallet for cumulus-based parachains"
|
||||
|
||||
[dependencies]
|
||||
bytes = { version = "1.2.1", 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.16", default-features = false }
|
||||
log = { version = "0.4.17", default-features = false }
|
||||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0.132", optional = true, features = ["derive"] }
|
||||
serde = { version = "1.0.143", optional = true, features = ["derive"] }
|
||||
|
||||
# Substrate
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
@@ -73,3 +74,7 @@ std = [
|
||||
"sp-trie/std",
|
||||
"xcm/std"
|
||||
]
|
||||
|
||||
runtime-benchmarks = [
|
||||
"sp-runtime/runtime-benchmarks"
|
||||
]
|
||||
|
||||
@@ -9,10 +9,10 @@ description = "Proc macros provided by the parachain-system pallet"
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
syn = "1.0.91"
|
||||
proc-macro2 = "1.0.37"
|
||||
quote = "1.0.18"
|
||||
proc-macro-crate = "1.1.3"
|
||||
syn = "1.0.99"
|
||||
proc-macro2 = "1.0.43"
|
||||
quote = "1.0.21"
|
||||
proc-macro-crate = "1.2.1"
|
||||
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
|
||||
@@ -88,6 +88,51 @@ pub use relay_state_snapshot::{MessagingStateSnapshot, RelayChainStateProof};
|
||||
|
||||
pub use pallet::*;
|
||||
|
||||
/// Something that can check the associated relay block number.
|
||||
///
|
||||
/// Each Parachain block is built in the context of a relay chain block, this trait allows us
|
||||
/// to validate the given relay chain block number. With async backing it is legal to build
|
||||
/// multiple Parachain blocks per relay chain parent. With this trait it is possible for the
|
||||
/// Parachain to ensure that still only one Parachain block is build per relay chain parent.
|
||||
///
|
||||
/// By default [`RelayNumberStrictlyIncreases`] and [`AnyRelayNumber`] are provided.
|
||||
pub trait CheckAssociatedRelayNumber {
|
||||
/// Check the current relay number versus the previous relay number.
|
||||
///
|
||||
/// The implementation should panic when there is something wrong.
|
||||
fn check_associated_relay_number(
|
||||
current: RelayChainBlockNumber,
|
||||
previous: RelayChainBlockNumber,
|
||||
);
|
||||
}
|
||||
|
||||
/// Provides an implementation of [`CheckAssociatedRelayNumber`].
|
||||
///
|
||||
/// It will ensure that the associated relay block number strictly increases between Parachain
|
||||
/// blocks. This should be used by production Parachains when in doubt.
|
||||
pub struct RelayNumberStrictlyIncreases;
|
||||
|
||||
impl CheckAssociatedRelayNumber for RelayNumberStrictlyIncreases {
|
||||
fn check_associated_relay_number(
|
||||
current: RelayChainBlockNumber,
|
||||
previous: RelayChainBlockNumber,
|
||||
) {
|
||||
if current <= previous {
|
||||
panic!("Relay chain block number needs to strictly increase between Parachain blocks!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Provides an implementation of [`CheckAssociatedRelayNumber`].
|
||||
///
|
||||
/// This will accept any relay chain block number combination. This is mainly useful for
|
||||
/// test parachains.
|
||||
pub struct AnyRelayNumber;
|
||||
|
||||
impl CheckAssociatedRelayNumber for AnyRelayNumber {
|
||||
fn check_associated_relay_number(_: RelayChainBlockNumber, _: RelayChainBlockNumber) {}
|
||||
}
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
@@ -128,6 +173,9 @@ pub mod pallet {
|
||||
|
||||
/// The weight we reserve at the beginning of the block for processing XCMP messages.
|
||||
type ReservedXcmpWeight: Get<Weight>;
|
||||
|
||||
/// Something that can check the associated relay parent block number.
|
||||
type CheckAssociatedRelayNumber: CheckAssociatedRelayNumber;
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
@@ -232,7 +280,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
// Remove the validation from the old block.
|
||||
<ValidationData<T>>::kill();
|
||||
ValidationData::<T>::kill();
|
||||
ProcessedDownwardMessages::<T>::kill();
|
||||
HrmpWatermark::<T>::kill();
|
||||
UpwardMessages::<T>::kill();
|
||||
@@ -307,6 +355,13 @@ pub mod pallet {
|
||||
|
||||
Self::validate_validation_data(&vfp);
|
||||
|
||||
// Check that the associated relay chain block number is as expected.
|
||||
T::CheckAssociatedRelayNumber::check_associated_relay_number(
|
||||
vfp.relay_parent_number,
|
||||
LastRelayChainBlockNumber::<T>::get(),
|
||||
);
|
||||
LastRelayChainBlockNumber::<T>::put(vfp.relay_parent_number);
|
||||
|
||||
let relay_state_proof = RelayChainStateProof::new(
|
||||
T::SelfParaId::get(),
|
||||
vfp.relay_parent_storage_root,
|
||||
@@ -330,7 +385,9 @@ pub mod pallet {
|
||||
|
||||
Self::put_parachain_code(&validation_code);
|
||||
<T::OnSystemEvent as OnSystemEvent>::on_validation_code_applied();
|
||||
Self::deposit_event(Event::ValidationFunctionApplied(vfp.relay_parent_number));
|
||||
Self::deposit_event(Event::ValidationFunctionApplied {
|
||||
relay_chain_block_num: vfp.relay_parent_number,
|
||||
});
|
||||
},
|
||||
Some(relay_chain::v2::UpgradeGoAhead::Abort) => {
|
||||
<PendingValidationCode<T>>::kill();
|
||||
@@ -389,7 +446,7 @@ pub mod pallet {
|
||||
|
||||
AuthorizedUpgrade::<T>::put(&code_hash);
|
||||
|
||||
Self::deposit_event(Event::UpgradeAuthorized(code_hash));
|
||||
Self::deposit_event(Event::UpgradeAuthorized { code_hash });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -411,17 +468,15 @@ pub mod pallet {
|
||||
/// The validation function has been scheduled to apply.
|
||||
ValidationFunctionStored,
|
||||
/// The validation function was applied as of the contained relay chain block number.
|
||||
ValidationFunctionApplied(RelayChainBlockNumber),
|
||||
ValidationFunctionApplied { relay_chain_block_num: RelayChainBlockNumber },
|
||||
/// The relay-chain aborted the upgrade process.
|
||||
ValidationFunctionDiscarded,
|
||||
/// An upgrade has been authorized.
|
||||
UpgradeAuthorized(T::Hash),
|
||||
UpgradeAuthorized { code_hash: T::Hash },
|
||||
/// Some downward messages have been received and will be processed.
|
||||
/// \[ count \]
|
||||
DownwardMessagesReceived(u32),
|
||||
DownwardMessagesReceived { count: u32 },
|
||||
/// Downward messages were processed using the given weight.
|
||||
/// \[ weight_used, result_mqc_head \]
|
||||
DownwardMessagesProcessed(Weight, relay_chain::Hash),
|
||||
DownwardMessagesProcessed { weight_used: Weight, dmq_head: relay_chain::Hash },
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
@@ -474,6 +529,11 @@ pub mod pallet {
|
||||
#[pallet::storage]
|
||||
pub(super) type DidSetValidationCode<T: Config> = StorageValue<_, bool, ValueQuery>;
|
||||
|
||||
/// The relay chain block number associated with the last parachain block.
|
||||
#[pallet::storage]
|
||||
pub(super) type LastRelayChainBlockNumber<T: Config> =
|
||||
StorageValue<_, RelayChainBlockNumber, ValueQuery>;
|
||||
|
||||
/// An option which indicates if the relay-chain restricts signalling a validation code upgrade.
|
||||
/// In other words, if this is `Some` and [`NewValidationCode`] is `Some` then the produced
|
||||
/// candidate will be invalid.
|
||||
@@ -750,7 +810,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
let mut weight_used = 0;
|
||||
if dm_count != 0 {
|
||||
Self::deposit_event(Event::DownwardMessagesReceived(dm_count));
|
||||
Self::deposit_event(Event::DownwardMessagesReceived { count: dm_count });
|
||||
let max_weight =
|
||||
<ReservedDmpWeightOverride<T>>::get().unwrap_or_else(T::ReservedDmpWeight::get);
|
||||
|
||||
@@ -763,7 +823,10 @@ impl<T: Config> Pallet<T> {
|
||||
weight_used += T::DmpMessageHandler::handle_dmp_messages(message_iter, max_weight);
|
||||
<LastDmqMqcHead<T>>::put(&dmq_head);
|
||||
|
||||
Self::deposit_event(Event::DownwardMessagesProcessed(weight_used, dmq_head.head()));
|
||||
Self::deposit_event(Event::DownwardMessagesProcessed {
|
||||
weight_used,
|
||||
dmq_head: dmq_head.head(),
|
||||
});
|
||||
}
|
||||
|
||||
// After hashing each message in the message queue chain submitted by the collator, we
|
||||
@@ -835,7 +898,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
running_mqc_heads
|
||||
.entry(sender)
|
||||
.or_insert_with(|| last_mqc_heads.get(&sender).cloned().unwrap_or_default())
|
||||
.or_insert_with(|| last_mqc_heads.get(sender).cloned().unwrap_or_default())
|
||||
.extend_hrmp(horizontal_message);
|
||||
}
|
||||
}
|
||||
@@ -1047,4 +1110,17 @@ impl<T: Config> BlockNumberProvider for RelaychainBlockNumberProvider<T> {
|
||||
.map(|d| d.relay_parent_number)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn set_block_number(block: Self::BlockNumber) {
|
||||
let mut validation_data = Pallet::<T>::validation_data().unwrap_or_else(||
|
||||
// PersistedValidationData does not impl default in non-std
|
||||
PersistedValidationData {
|
||||
parent_head: vec![].into(),
|
||||
relay_parent_number: Default::default(),
|
||||
max_pov_size: Default::default(),
|
||||
relay_parent_storage_root: Default::default(),
|
||||
});
|
||||
validation_data.relay_parent_number = block;
|
||||
ValidationData::<T>::put(validation_data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,9 +41,11 @@ pub fn on_runtime_upgrade<T: Config>() -> Weight {
|
||||
/// mechanism now uses signals instead of block offsets.
|
||||
mod v1 {
|
||||
use crate::{Config, Pallet};
|
||||
#[allow(deprecated)]
|
||||
use frame_support::{migration::remove_storage_prefix, pallet_prelude::*};
|
||||
|
||||
pub fn migrate<T: Config>() -> Weight {
|
||||
#[allow(deprecated)]
|
||||
remove_storage_prefix(<Pallet<T>>::name().as_bytes(), b"LastUpgrade", b"");
|
||||
T::DbWeight::get().writes(1)
|
||||
}
|
||||
|
||||
@@ -107,6 +107,7 @@ impl Config for Test {
|
||||
type ReservedDmpWeight = ReservedDmpWeight;
|
||||
type XcmpMessageHandler = SaveIntoThreadLocal;
|
||||
type ReservedXcmpWeight = ReservedXcmpWeight;
|
||||
type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases;
|
||||
}
|
||||
|
||||
pub struct FromThreadLocal;
|
||||
@@ -226,8 +227,7 @@ struct BlockTests {
|
||||
ran: bool,
|
||||
relay_sproof_builder_hook:
|
||||
Option<Box<dyn Fn(&BlockTests, RelayChainBlockNumber, &mut RelayStateSproofBuilder)>>,
|
||||
persisted_validation_data_hook:
|
||||
Option<Box<dyn Fn(&BlockTests, RelayChainBlockNumber, &mut PersistedValidationData)>>,
|
||||
persisted_validation_data_hook: Option<Box<dyn Fn(&BlockTests, &mut PersistedValidationData)>>,
|
||||
inherent_data_hook:
|
||||
Option<Box<dyn Fn(&BlockTests, RelayChainBlockNumber, &mut ParachainInherentData)>>,
|
||||
}
|
||||
@@ -274,10 +274,9 @@ impl BlockTests {
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(dead_code)] // might come in handy in future. If now is future and it still hasn't - feel free.
|
||||
fn with_validation_data<F>(mut self, f: F) -> Self
|
||||
where
|
||||
F: 'static + Fn(&BlockTests, RelayChainBlockNumber, &mut PersistedValidationData),
|
||||
F: 'static + Fn(&BlockTests, &mut PersistedValidationData),
|
||||
{
|
||||
self.persisted_validation_data_hook = Some(Box::new(f));
|
||||
self
|
||||
@@ -319,7 +318,7 @@ impl BlockTests {
|
||||
..Default::default()
|
||||
};
|
||||
if let Some(ref hook) = self.persisted_validation_data_hook {
|
||||
hook(self, *n as RelayChainBlockNumber, &mut vfp);
|
||||
hook(self, &mut vfp);
|
||||
}
|
||||
|
||||
<ValidationData<Test>>::put(&vfp);
|
||||
@@ -415,7 +414,10 @@ fn events() {
|
||||
let events = System::events();
|
||||
assert_eq!(
|
||||
events[0].event,
|
||||
Event::ParachainSystem(crate::Event::ValidationFunctionApplied(1234).into())
|
||||
Event::ParachainSystem(
|
||||
crate::Event::ValidationFunctionApplied { relay_chain_block_num: 1234 }
|
||||
.into()
|
||||
)
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -961,3 +963,14 @@ fn receive_hrmp_after_pause() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic = "Relay chain block number needs to strictly increase between Parachain blocks!"]
|
||||
fn test() {
|
||||
BlockTests::new()
|
||||
.with_validation_data(|_, data| {
|
||||
data.relay_parent_number = 1;
|
||||
})
|
||||
.add(1, || {})
|
||||
.add(2, || {});
|
||||
}
|
||||
|
||||
@@ -67,8 +67,8 @@ where
|
||||
assert!(parent_head.hash() == *block.header().parent_hash(), "Invalid parent hash",);
|
||||
|
||||
// Create the db
|
||||
let (db, _root) = match storage_proof.to_memory_db(Some(parent_head.state_root())) {
|
||||
Ok((db, root)) => (db, root),
|
||||
let db = match storage_proof.to_memory_db(Some(parent_head.state_root())) {
|
||||
Ok((db, _)) => db,
|
||||
Err(_) => panic!("Compact proof decoding failure."),
|
||||
};
|
||||
|
||||
@@ -205,8 +205,8 @@ fn host_storage_set(key: &[u8], value: &[u8]) {
|
||||
with_externalities(|ext| ext.place_storage(key.to_vec(), Some(value.to_vec())))
|
||||
}
|
||||
|
||||
fn host_storage_get(key: &[u8]) -> Option<Vec<u8>> {
|
||||
with_externalities(|ext| ext.storage(key).clone())
|
||||
fn host_storage_get(key: &[u8]) -> Option<bytes::Bytes> {
|
||||
with_externalities(|ext| ext.storage(key).map(|value| value.into()))
|
||||
}
|
||||
|
||||
fn host_storage_exists(key: &[u8]) -> bool {
|
||||
@@ -222,13 +222,7 @@ fn host_storage_root(version: StateVersion) -> Vec<u8> {
|
||||
}
|
||||
|
||||
fn host_storage_clear_prefix(prefix: &[u8], limit: Option<u32>) -> KillStorageResult {
|
||||
with_externalities(|ext| {
|
||||
let (all_removed, num_removed) = ext.clear_prefix(prefix, limit);
|
||||
match all_removed {
|
||||
true => KillStorageResult::AllRemoved(num_removed),
|
||||
false => KillStorageResult::SomeRemaining(num_removed),
|
||||
}
|
||||
})
|
||||
with_externalities(|ext| ext.clear_prefix(prefix, limit, None).into())
|
||||
}
|
||||
|
||||
fn host_storage_append(key: &[u8], value: Vec<u8>) {
|
||||
@@ -294,13 +288,7 @@ fn host_default_child_storage_storage_kill(
|
||||
limit: Option<u32>,
|
||||
) -> KillStorageResult {
|
||||
let child_info = ChildInfo::new_default(storage_key);
|
||||
with_externalities(|ext| {
|
||||
let (all_removed, num_removed) = ext.kill_child_storage(&child_info, limit);
|
||||
match all_removed {
|
||||
true => KillStorageResult::AllRemoved(num_removed),
|
||||
false => KillStorageResult::SomeRemaining(num_removed),
|
||||
}
|
||||
})
|
||||
with_externalities(|ext| ext.kill_child_storage(&child_info, limit, None).into())
|
||||
}
|
||||
|
||||
fn host_default_child_storage_exists(storage_key: &[u8], key: &[u8]) -> bool {
|
||||
@@ -314,13 +302,7 @@ fn host_default_child_storage_clear_prefix(
|
||||
limit: Option<u32>,
|
||||
) -> KillStorageResult {
|
||||
let child_info = ChildInfo::new_default(storage_key);
|
||||
with_externalities(|ext| {
|
||||
let (all_removed, num_removed) = ext.clear_child_prefix(&child_info, prefix, limit);
|
||||
match all_removed {
|
||||
true => KillStorageResult::AllRemoved(num_removed),
|
||||
false => KillStorageResult::SomeRemaining(num_removed),
|
||||
}
|
||||
})
|
||||
with_externalities(|ext| ext.clear_child_prefix(&child_info, prefix, limit, None).into())
|
||||
}
|
||||
|
||||
fn host_default_child_storage_root(storage_key: &[u8], version: StateVersion) -> Vec<u8> {
|
||||
|
||||
@@ -13,7 +13,7 @@ readme = "README.md"
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
parity-scale-codec = { version = "3.1.2", default-features = false }
|
||||
parity-scale-codec = { version = "3.1.5", 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" }
|
||||
|
||||
@@ -7,7 +7,7 @@ version = "0.1.0"
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
|
||||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0.132", optional = true, features = ["derive"] }
|
||||
serde = { version = "1.0.143", optional = true, features = ["derive"] }
|
||||
|
||||
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" }
|
||||
|
||||
@@ -27,7 +27,7 @@ use cumulus_primitives_core::{
|
||||
use frame_support::dispatch::Weight;
|
||||
pub use pallet::*;
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::traits::BadOrigin;
|
||||
use sp_runtime::{traits::BadOrigin, RuntimeDebug};
|
||||
use sp_std::{convert::TryFrom, prelude::*};
|
||||
use xcm::{
|
||||
latest::{ExecuteXcm, Outcome, Parent, Xcm},
|
||||
@@ -77,8 +77,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
/// Origin for the parachains module.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, TypeInfo)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, TypeInfo, RuntimeDebug, MaxEncodedLen)]
|
||||
#[pallet::origin]
|
||||
pub enum Origin {
|
||||
/// It comes from the (parent) relay chain.
|
||||
|
||||
@@ -6,7 +6,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", features = [ "derive" ], default-features = false }
|
||||
log = { version = "0.4.16", default-features = false }
|
||||
log = { version = "0.4.17", default-features = false }
|
||||
rand_chacha = { version = "0.3.0", default-features = false }
|
||||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ pub mod pallet {
|
||||
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));
|
||||
Self::deposit_event(Event::OverweightServiced { index, used });
|
||||
Ok(Some(used.saturating_add(1_000_000)).into())
|
||||
}
|
||||
|
||||
@@ -267,21 +267,26 @@ pub mod pallet {
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// Some XCM was executed ok.
|
||||
Success(Option<XcmHash>),
|
||||
Success { message_hash: Option<XcmHash>, weight: Weight },
|
||||
/// Some XCM failed.
|
||||
Fail(Option<XcmHash>, XcmError),
|
||||
Fail { message_hash: Option<XcmHash>, error: XcmError, weight: Weight },
|
||||
/// Bad XCM version used.
|
||||
BadVersion(Option<XcmHash>),
|
||||
BadVersion { message_hash: Option<XcmHash> },
|
||||
/// Bad XCM format used.
|
||||
BadFormat(Option<XcmHash>),
|
||||
BadFormat { message_hash: Option<XcmHash> },
|
||||
/// An upward message was sent to the relay chain.
|
||||
UpwardMessageSent(Option<XcmHash>),
|
||||
UpwardMessageSent { message_hash: Option<XcmHash> },
|
||||
/// An HRMP message was sent to a sibling parachain.
|
||||
XcmpMessageSent(Option<XcmHash>),
|
||||
XcmpMessageSent { message_hash: Option<XcmHash> },
|
||||
/// An XCM exceeded the individual message weight budget.
|
||||
OverweightEnqueued(ParaId, RelayBlockNumber, OverweightIndex, Weight),
|
||||
OverweightEnqueued {
|
||||
sender: ParaId,
|
||||
sent_at: RelayBlockNumber,
|
||||
index: OverweightIndex,
|
||||
required: Weight,
|
||||
},
|
||||
/// An XCM from the overweight queue was executed with the given actual weight used.
|
||||
OverweightServiced(OverweightIndex, Weight),
|
||||
OverweightServiced { index: OverweightIndex, used: Weight },
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
@@ -603,15 +608,20 @@ impl<T: Config> Pallet<T> {
|
||||
let (result, event) = match Xcm::<T::Call>::try_from(xcm) {
|
||||
Ok(xcm) => {
|
||||
let location = (Parent, Parachain(sender.into()));
|
||||
|
||||
match T::XcmExecutor::execute_xcm(location, xcm, hash, max_weight) {
|
||||
Outcome::Error(e) => (Err(e), Event::Fail(Some(hash), e)),
|
||||
Outcome::Complete(w) => (Ok(w), Event::Success(Some(hash))),
|
||||
Outcome::Error(e) =>
|
||||
(Err(e), Event::Fail { message_hash: Some(hash), error: e, weight: 0 }),
|
||||
Outcome::Complete(w) =>
|
||||
(Ok(w), Event::Success { message_hash: Some(hash), weight: w }),
|
||||
// As far as the caller is concerned, this was dispatched without error, so
|
||||
// we just report the weight used.
|
||||
Outcome::Incomplete(w, e) => (Ok(w), Event::Fail(Some(hash), e)),
|
||||
Outcome::Incomplete(w, e) =>
|
||||
(Ok(w), Event::Fail { message_hash: Some(hash), error: e, weight: w }),
|
||||
}
|
||||
},
|
||||
Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))),
|
||||
Err(()) =>
|
||||
(Err(XcmError::UnhandledXcmVersion), Event::BadVersion { message_hash: Some(hash) }),
|
||||
};
|
||||
Self::deposit_event(event);
|
||||
result
|
||||
@@ -648,7 +658,8 @@ impl<T: Config> Pallet<T> {
|
||||
.saturating_sub(remaining_fragments.len());
|
||||
let overweight_xcm = last_remaining_fragments[..msg_len].to_vec();
|
||||
let index = Self::stash_overweight(sender, sent_at, overweight_xcm);
|
||||
let e = Event::OverweightEnqueued(sender, sent_at, index, required);
|
||||
let e =
|
||||
Event::OverweightEnqueued { sender, sent_at, index, required };
|
||||
Self::deposit_event(e);
|
||||
},
|
||||
Err(XcmError::WeightLimitReached(required))
|
||||
@@ -1134,7 +1145,7 @@ impl<T: Config> SendXcm for Pallet<T> {
|
||||
|
||||
match Self::send_fragment(id, XcmpMessageFormat::ConcatenatedVersionedXcm, xcm) {
|
||||
Ok(_) => {
|
||||
Self::deposit_event(Event::XcmpMessageSent(Some(hash)));
|
||||
Self::deposit_event(Event::XcmpMessageSent { message_hash: Some(hash) });
|
||||
Ok(hash)
|
||||
},
|
||||
Err(e) => Err(SendError::Transport(<&'static str>::from(e))),
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
use super::*;
|
||||
use crate as xcmp_queue;
|
||||
use core::marker::PhantomData;
|
||||
use cumulus_pallet_parachain_system::AnyRelayNumber;
|
||||
use cumulus_primitives_core::{IsSystem, ParaId};
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
@@ -110,6 +111,7 @@ impl cumulus_pallet_parachain_system::Config for Test {
|
||||
type ReservedDmpWeight = ();
|
||||
type XcmpMessageHandler = XcmpQueue;
|
||||
type ReservedXcmpWeight = ();
|
||||
type CheckAssociatedRelayNumber = AnyRelayNumber;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
|
||||
Reference in New Issue
Block a user