diff --git a/xcm/src/v3/mod.rs b/xcm/src/v3/mod.rs index c49b74c3903a..83c40545a7f5 100644 --- a/xcm/src/v3/mod.rs +++ b/xcm/src/v3/mod.rs @@ -340,7 +340,9 @@ impl TryFrom for WeightLimit { #[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)] pub struct XcmContext { /// The `MultiLocation` origin of the corresponding XCM. - pub origin: Option, + /// The computed origin is the author of the message, as opposed to the physical + /// origin, which represents the location of the message deliverer + pub computed_origin: Option, /// The hash of the XCM. pub message_hash: XcmHash, /// The topic of the XCM. @@ -351,7 +353,7 @@ impl XcmContext { /// Constructor which sets the message hash to the supplied parameter and leaves the origin and /// topic unset. pub fn with_message_hash(message_hash: XcmHash) -> XcmContext { - XcmContext { origin: None, message_hash, topic: None } + XcmContext { computed_origin: None, message_hash, topic: None } } } diff --git a/xcm/src/v3/traits.rs b/xcm/src/v3/traits.rs index b752647b0819..7f5465bba896 100644 --- a/xcm/src/v3/traits.rs +++ b/xcm/src/v3/traits.rs @@ -257,38 +257,38 @@ pub trait ExecuteXcm { type Prepared: PreparedMessage; fn prepare(message: Xcm) -> result::Result>; fn execute( - origin: impl Into, + physical_origin: impl Into, pre: Self::Prepared, hash: XcmHash, weight_credit: Weight, ) -> Outcome; - /// Execute some XCM `message` with the message `hash` from `origin` using no more than `weight_limit` weight. + /// Execute some XCM `message` with the message `hash` from `physical_origin` using no more than `weight_limit` weight. /// The weight limit is a basic hard-limit and the implementation may place further restrictions or requirements /// on weight and other aspects. fn execute_xcm( - origin: impl Into, + physical_origin: impl Into, message: Xcm, hash: XcmHash, weight_limit: Weight, ) -> Outcome { - let origin = origin.into(); + let physical_origin = physical_origin.into(); log::debug!( target: "xcm::execute_xcm", - "origin: {:?}, message: {:?}, weight_limit: {:?}", - origin, + "physical_origin: {:?}, message: {:?}, weight_limit: {:?}", + physical_origin, message, weight_limit, ); - Self::execute_xcm_in_credit(origin, message, hash, weight_limit, Weight::zero()) + Self::execute_xcm_in_credit(physical_origin, message, hash, weight_limit, Weight::zero()) } - /// Execute some XCM `message` with the message `hash` from `origin` using no more than `weight_limit` weight. + /// Execute some XCM `message` with the message `hash` from `physical_origin` using no more than `weight_limit` weight. /// /// Some amount of `weight_credit` may be provided which, depending on the implementation, may allow /// execution without associated payment. fn execute_xcm_in_credit( - origin: impl Into, + physical_origin: impl Into, message: Xcm, hash: XcmHash, weight_limit: Weight, @@ -302,7 +302,7 @@ pub trait ExecuteXcm { if xcm_weight.any_gt(weight_limit) { return Outcome::Error(Error::WeightLimitReached(xcm_weight)) } - Self::execute(origin, pre, hash, weight_credit) + Self::execute(physical_origin, pre, hash, weight_credit) } /// Deduct some `fees` to the sovereign account of the given `location` and place them as per diff --git a/xcm/xcm-executor/src/lib.rs b/xcm/xcm-executor/src/lib.rs index 749a63114d95..7a84b59483b4 100644 --- a/xcm/xcm-executor/src/lib.rs +++ b/xcm/xcm-executor/src/lib.rs @@ -59,7 +59,8 @@ pub struct XcmExecutor { holding: Assets, holding_limit: usize, context: XcmContext, - original_origin: MultiLocation, + /// The physical origin (chain, etc) which the instructions originated from. + physical_origin: MultiLocation, trader: Config::Trader, /// The most recent error result and instruction index into the fragment in which it occurred, /// if any. @@ -94,16 +95,16 @@ impl XcmExecutor { self.holding_limit = v } pub fn origin(&self) -> &Option { - &self.context.origin + &self.context.computed_origin } pub fn set_origin(&mut self, v: Option) { - self.context.origin = v + self.context.computed_origin = v } pub fn original_origin(&self) -> &MultiLocation { - &self.original_origin + &self.physical_origin } pub fn set_original_origin(&mut self, v: MultiLocation) { - self.original_origin = v + self.physical_origin = v } pub fn trader(&self) -> &Config::Trader { &self.trader @@ -191,21 +192,21 @@ impl ExecuteXcm for XcmExecutor, + physical_origin: impl Into, WeighedMessage(xcm_weight, mut message): WeighedMessage, message_hash: XcmHash, mut weight_credit: Weight, ) -> Outcome { - let origin = origin.into(); + let physical_origin = physical_origin.into(); log::trace!( target: "xcm::execute_xcm_in_credit", "origin: {:?}, message: {:?}, weight_credit: {:?}", - origin, + physical_origin, message, weight_credit, ); if let Err(e) = Config::Barrier::should_execute( - &origin, + &physical_origin, message.inner_mut(), xcm_weight, &mut weight_credit, @@ -214,14 +215,14 @@ impl ExecuteXcm for XcmExecutor XcmExecutor { Self { holding: Assets::new(), holding_limit: Config::MaxAssetsIntoHolding::get() as usize, - context: XcmContext { origin: Some(origin), message_hash, topic: None }, - original_origin: origin, + context: XcmContext { computed_origin: Some(origin), message_hash, topic: None }, + physical_origin: origin, trader: Config::Trader::new(), error: None, total_surplus: Weight::zero(), @@ -365,10 +366,11 @@ impl XcmExecutor { if !self.holding.is_empty() { log::trace!( target: "xcm::execute_xcm_in_credit", - "Trapping assets in holding register: {:?}, context: {:?} (original_origin: {:?})", - self.holding, self.context, self.original_origin, + "Trapping assets in holding register: {:?}, context: {:?} (physical_origin: {:?})", + self.holding, self.context, self.physical_origin, ); - let effective_origin = self.context.origin.as_ref().unwrap_or(&self.original_origin); + let effective_origin = + self.context.computed_origin.as_ref().unwrap_or(&self.physical_origin); let trap_weight = Config::AssetTrap::drop_assets(effective_origin, self.holding, &self.context); weight_used.saturating_accrue(trap_weight); @@ -379,18 +381,18 @@ impl XcmExecutor { // TODO: #2841 #REALWEIGHT We should deduct the cost of any instructions following // the error which didn't end up being executed. Some((_i, e)) => { - log::trace!(target: "xcm::execute_xcm_in_credit", "Execution errored at {:?}: {:?} (original_origin: {:?})", _i, e, self.original_origin); + log::trace!(target: "xcm::execute_xcm_in_credit", "Execution errored at {:?}: {:?} (physical_origin: {:?})", _i, e, self.physical_origin); Outcome::Incomplete(weight_used, e) }, } } fn origin_ref(&self) -> Option<&MultiLocation> { - self.context.origin.as_ref() + self.context.computed_origin.as_ref() } fn cloned_origin(&self) -> Option { - self.context.origin + self.context.computed_origin } /// Send an XCM, charging fees from Holding as needed. @@ -590,13 +592,13 @@ impl XcmExecutor { }, DescendOrigin(who) => self .context - .origin + .computed_origin .as_mut() .ok_or(XcmError::BadOrigin)? .append_with(who) .map_err(|_| XcmError::LocationFull), ClearOrigin => { - self.context.origin = None; + self.context.computed_origin = None; Ok(()) }, ReportError(response_info) => { @@ -726,7 +728,7 @@ impl XcmExecutor { let origin = self.origin_ref().ok_or(XcmError::BadOrigin)?; // We don't allow derivative origins to subscribe since it would otherwise pose a // DoS risk. - ensure!(&self.original_origin == origin, XcmError::BadOrigin); + ensure!(&self.physical_origin == origin, XcmError::BadOrigin); Config::SubscriptionService::start( origin, query_id, @@ -736,7 +738,7 @@ impl XcmExecutor { }, UnsubscribeVersion => { let origin = self.origin_ref().ok_or(XcmError::BadOrigin)?; - ensure!(&self.original_origin == origin, XcmError::BadOrigin); + ensure!(&self.physical_origin == origin, XcmError::BadOrigin); Config::SubscriptionService::stop(origin, &self.context) }, BurnAsset(assets) => { @@ -746,7 +748,7 @@ impl XcmExecutor { ExpectAsset(assets) => self.holding.ensure_contains(&assets).map_err(|_| XcmError::ExpectationFalse), ExpectOrigin(origin) => { - ensure!(self.context.origin == origin, XcmError::ExpectationFalse); + ensure!(self.context.computed_origin == origin, XcmError::ExpectationFalse); Ok(()) }, ExpectError(error) => { @@ -816,7 +818,7 @@ impl XcmExecutor { ensure!(ok, XcmError::InvalidLocation); let (_, new_global) = origin_xform; let new_origin = X1(new_global).relative_to(&universal_location); - self.context.origin = Some(new_origin); + self.context.computed_origin = Some(new_origin); Ok(()) }, ExportMessage { network, destination, xcm } => { @@ -827,7 +829,7 @@ impl XcmExecutor { // // This only works because the remote chain empowers the bridge // to speak for the local network. - let origin = self.context.origin.ok_or(XcmError::BadOrigin)?; + let origin = self.context.computed_origin.ok_or(XcmError::BadOrigin)?; let universal_source = Config::UniversalLocation::get() .within_global(origin) .map_err(|()| XcmError::Unanchored)?; @@ -912,7 +914,7 @@ impl XcmExecutor { AliasOrigin(_) => Err(XcmError::NoPermission), UnpaidExecution { check_origin, .. } => { ensure!( - check_origin.is_none() || self.context.origin == check_origin, + check_origin.is_none() || self.context.computed_origin == check_origin, XcmError::BadOrigin ); Ok(())