Use named events in cumulus pallets (#1260)

* Use named events

* For now standardise on message_id

* cargo fmt

* reverting xcm changes

* remove superfluous comments

* renaming

* updating benches
This commit is contained in:
Squirrel
2022-05-23 09:23:27 +01:00
committed by GitHub
parent 12221cb534
commit c7ef5f6a6b
5 changed files with 68 additions and 58 deletions
+34 -30
View File
@@ -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, 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,
});
}
},
}