Skip to content

Commit

Permalink
ensure xcm outcome is always complete
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Nov 20, 2023
1 parent b585893 commit 69541e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
16 changes: 13 additions & 3 deletions polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,10 @@ pub mod pallet {
max_weight: Weight,
) -> DispatchResultWithPostInfo {
let outcome = <Self as ExecuteController<_, _>>::execute(origin, message, max_weight)?;
outcome.clone().ensure_complete().map_err(|error| {
log::error!(target: "runtime::xcm", "XCM execution failed with error {:?}", error);
Error::<T>::LocalExecutionIncomplete
})?;
Ok(Some(outcome.weight_used().saturating_add(T::WeightInfo::execute())).into())
}

Expand Down Expand Up @@ -1495,13 +1499,19 @@ impl<T: Config> Pallet<T> {
let outcome =
T::XcmExecutor::execute_xcm_in_credit(origin, local_xcm, hash, weight, weight);
Self::deposit_event(Event::Attempted { outcome: outcome.clone() });
if let Some(remote_xcm) = remote_xcm {
outcome.ensure_complete().map_err(|_| Error::<T>::LocalExecutionIncomplete)?;
outcome.ensure_complete().map_err(|error| {
log::error!(target: "runtime::xcm", "XCM execution failed with error {:?}", error);
Error::<T>::LocalExecutionIncomplete
})?;

if let Some(remote_xcm) = remote_xcm {
let (ticket, price) = validate_send::<T::XcmRouter>(dest, remote_xcm.clone())
.map_err(Error::<T>::from)?;
if origin != Here.into_location() {
Self::charge_fees(origin, price).map_err(|_| Error::<T>::FeesNotMet)?;
Self::charge_fees(origin, price).map_err(|error| {
log::error!(target: "runtime::xcm", "Unable to charge fee with error {:?}", error);
Error::<T>::FeesNotMet
})?;
}
let message_id = T::XcmRouter::deliver(ticket).map_err(Error::<T>::from)?;

Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/pallet-xcm/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ fn trapped_assets_can_be_claimed() {
assert_eq!(AssetTraps::<Test>::iter().collect::<Vec<_>>(), vec![]);

let weight = BaseXcmWeight::get() * 3;
assert_ok!(XcmPallet::execute(
assert_ok!(<XcmPallet as xcm_builder::ExecuteController<_, _>>::execute(
RuntimeOrigin::signed(ALICE),
Box::new(VersionedXcm::from(Xcm(vec![
ClaimAsset { assets: (Here, SEND_AMOUNT).into(), ticket: Here.into() },
Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/src/v3/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ pub enum Outcome {
}

impl Outcome {
pub fn ensure_complete(self) -> Result {
pub fn ensure_complete(self) -> result::Result<Weight, Error> {
match self {
Outcome::Complete(_) => Ok(()),
Outcome::Complete(weight) => Ok(weight),
Outcome::Incomplete(_, e) => Err(e),
Outcome::Error(e) => Err(e),
}
Expand Down

0 comments on commit 69541e1

Please sign in to comment.