Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Rename original_origin and origin in XcmExecutor #7136

Closed
wants to merge 10 commits into from
6 changes: 4 additions & 2 deletions xcm/src/v3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ impl TryFrom<OldWeightLimit> for WeightLimit {
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)]
pub struct XcmContext {
/// The `MultiLocation` origin of the corresponding XCM.
pub origin: Option<MultiLocation>,
/// 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<MultiLocation>,
/// The hash of the XCM.
pub message_hash: XcmHash,
/// The topic of the XCM.
Expand All @@ -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 }
}
}

Expand Down
20 changes: 10 additions & 10 deletions xcm/src/v3/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,38 +257,38 @@ pub trait ExecuteXcm<Call> {
type Prepared: PreparedMessage;
fn prepare(message: Xcm<Call>) -> result::Result<Self::Prepared, Xcm<Call>>;
fn execute(
origin: impl Into<MultiLocation>,
physical_origin: impl Into<MultiLocation>,
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<MultiLocation>,
physical_origin: impl Into<MultiLocation>,
message: Xcm<Call>,
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<MultiLocation>,
physical_origin: impl Into<MultiLocation>,
message: Xcm<Call>,
hash: XcmHash,
weight_limit: Weight,
Expand All @@ -302,7 +302,7 @@ pub trait ExecuteXcm<Call> {
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
Expand Down
56 changes: 29 additions & 27 deletions xcm/xcm-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ pub struct XcmExecutor<Config: config::Config> {
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.
Expand Down Expand Up @@ -94,16 +95,16 @@ impl<Config: config::Config> XcmExecutor<Config> {
self.holding_limit = v
}
pub fn origin(&self) -> &Option<MultiLocation> {
&self.context.origin
&self.context.computed_origin
}
pub fn set_origin(&mut self, v: Option<MultiLocation>) {
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
Expand Down Expand Up @@ -191,21 +192,21 @@ impl<Config: config::Config> ExecuteXcm<Config::RuntimeCall> for XcmExecutor<Con
}
}
fn execute(
origin: impl Into<MultiLocation>,
physical_origin: impl Into<MultiLocation>,
WeighedMessage(xcm_weight, mut message): WeighedMessage<Config::RuntimeCall>,
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,
Expand All @@ -214,14 +215,14 @@ impl<Config: config::Config> ExecuteXcm<Config::RuntimeCall> for XcmExecutor<Con
target: "xcm::execute_xcm_in_credit",
"Barrier blocked execution! Error: {:?}. (origin: {:?}, message: {:?}, weight_credit: {:?})",
e,
origin,
physical_origin,
message,
weight_credit,
);
return Outcome::Error(XcmError::Barrier)
}

let mut vm = Self::new(origin, message_hash);
let mut vm = Self::new(physical_origin, message_hash);

while !message.0.is_empty() {
let result = vm.process(message);
Expand Down Expand Up @@ -277,8 +278,8 @@ impl<Config: config::Config> XcmExecutor<Config> {
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(),
Expand Down Expand Up @@ -365,10 +366,11 @@ impl<Config: config::Config> XcmExecutor<Config> {
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);
Expand All @@ -379,18 +381,18 @@ impl<Config: config::Config> XcmExecutor<Config> {
// 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<MultiLocation> {
self.context.origin
self.context.computed_origin
}

/// Send an XCM, charging fees from Holding as needed.
Expand Down Expand Up @@ -590,13 +592,13 @@ impl<Config: config::Config> XcmExecutor<Config> {
},
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) => {
Expand Down Expand Up @@ -726,7 +728,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
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,
Expand All @@ -736,7 +738,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
},
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) => {
Expand All @@ -746,7 +748,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
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) => {
Expand Down Expand Up @@ -816,7 +818,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
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 } => {
Expand All @@ -827,7 +829,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
//
// 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)?;
Expand Down Expand Up @@ -912,7 +914,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
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(())
Expand Down