Unverified Commit 6663dee8 authored by Gavin Wood's avatar Gavin Wood Committed by GitHub
Browse files

Required weight is returned in case it exceeds limit. (#2952)

parent efbc5a07
Pipeline #136144 passed with stages
in 38 minutes and 52 seconds
...@@ -73,7 +73,7 @@ impl<XcmExecutor: xcm::v0::ExecuteXcm<Call>, Call> UmpSink for XcmSink<XcmExecut ...@@ -73,7 +73,7 @@ impl<XcmExecutor: xcm::v0::ExecuteXcm<Call>, Call> UmpSink for XcmSink<XcmExecut
let xcm_location: MultiLocation = xcm_junction.into(); let xcm_location: MultiLocation = xcm_junction.into();
match XcmExecutor::execute_xcm(xcm_location, xcm_message, max_weight) { match XcmExecutor::execute_xcm(xcm_location, xcm_message, max_weight) {
Outcome::Complete(w) | Outcome::Incomplete(w, _) => Some(w), Outcome::Complete(w) | Outcome::Incomplete(w, _) => Some(w),
Outcome::Error(XcmError::WeightLimitReached) => None, Outcome::Error(XcmError::WeightLimitReached(..)) => None,
Outcome::Error(_) => Some(0), Outcome::Error(_) => Some(0),
} }
} }
......
...@@ -578,7 +578,7 @@ impl MultiLocation { ...@@ -578,7 +578,7 @@ impl MultiLocation {
let self_parents = self.parent_count(); let self_parents = self.parent_count();
let prefix_rest = prefix.len() - prefix.parent_count(); let prefix_rest = prefix.len() - prefix.parent_count();
let skipped = self_parents.min(prefix_rest); let skipped = self_parents.min(prefix_rest);
if self.len() + prefix.len() - 2 * skipped > 4 { if self.len() + prefix.len() - 2 * skipped > 8 {
return Err(prefix); return Err(prefix);
} }
......
...@@ -43,7 +43,9 @@ pub enum Error { ...@@ -43,7 +43,9 @@ pub enum Error {
BadOrigin, BadOrigin,
ExceedsMaxMessageSize, ExceedsMaxMessageSize,
FailedToTransactAsset(#[codec(skip)] &'static str), FailedToTransactAsset(#[codec(skip)] &'static str),
WeightLimitReached, /// Execution of the XCM would potentially result in a greater weight used than the pre-specified
/// weight limit. The amount that is potentially required is the parameter.
WeightLimitReached(Weight),
Wildcard, Wildcard,
/// The case where an XCM message has specified a optional weight limit and the weight required for /// The case where an XCM message has specified a optional weight limit and the weight required for
/// processing is too great. /// processing is too great.
......
...@@ -54,10 +54,10 @@ impl<Config: config::Config> ExecuteXcm<Config::Call> for XcmExecutor<Config> { ...@@ -54,10 +54,10 @@ impl<Config: config::Config> ExecuteXcm<Config::Call> for XcmExecutor<Config> {
}; };
let maximum_weight = match shallow_weight.checked_add(deep_weight) { let maximum_weight = match shallow_weight.checked_add(deep_weight) {
Some(x) => x, Some(x) => x,
None => return Outcome::Error(XcmError::WeightLimitReached), None => return Outcome::Error(XcmError::Overflow),
}; };
if maximum_weight > weight_limit { if maximum_weight > weight_limit {
return Outcome::Error(XcmError::WeightLimitReached); return Outcome::Error(XcmError::WeightLimitReached(maximum_weight));
} }
let mut trader = Config::Trader::new(); let mut trader = Config::Trader::new();
let result = Self::do_execute_xcm(origin, true, message, &mut 0, Some(shallow_weight), &mut trader); let result = Self::do_execute_xcm(origin, true, message, &mut 0, Some(shallow_weight), &mut trader);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment