Remove BuyExecution::orders (#3640)

* Remove BuyExecution::orders

* Fixes

* Fixes

* Fixes

* Formatting
This commit is contained in:
Gavin Wood
2021-08-16 12:51:56 +02:00
committed by GitHub
parent 1c039fda48
commit e16c8d9902
8 changed files with 7 additions and 43 deletions
-2
View File
@@ -190,7 +190,6 @@ pub mod pallet {
weight: 0, weight: 0,
debt: dest_weight, debt: dest_weight,
halt_on_error: false, halt_on_error: false,
orders: vec![],
instructions: vec![], instructions: vec![],
}, },
DepositAsset { assets: Wild(All), max_assets, beneficiary: *beneficiary }, DepositAsset { assets: Wild(All), max_assets, beneficiary: *beneficiary },
@@ -259,7 +258,6 @@ pub mod pallet {
weight: 0, weight: 0,
debt: dest_weight, // covers this, `TransferReserveAsset` xcm, and `DepositAsset` order. debt: dest_weight, // covers this, `TransferReserveAsset` xcm, and `DepositAsset` order.
halt_on_error: false, halt_on_error: false,
orders: vec![],
instructions: vec![], instructions: vec![],
}, },
DepositAsset { assets: Wild(All), max_assets, beneficiary: *beneficiary }, DepositAsset { assets: Wild(All), max_assets, beneficiary: *beneficiary },
-1
View File
@@ -198,7 +198,6 @@ pub(crate) fn buy_execution<C>(fees: impl Into<MultiAsset>, debt: Weight) -> Ord
weight: 0, weight: 0,
debt, debt,
halt_on_error: false, halt_on_error: false,
orders: vec![],
instructions: vec![], instructions: vec![],
} }
} }
+1 -4
View File
@@ -194,10 +194,7 @@ impl<Call> TryFrom<Order1<Call>> for Order<Call> {
}, },
Order1::QueryHolding { query_id, dest, assets } => Order1::QueryHolding { query_id, dest, assets } =>
QueryHolding { query_id, dest: dest.try_into()?, assets: assets.try_into()? }, QueryHolding { query_id, dest: dest.try_into()?, assets: assets.try_into()? },
Order1::BuyExecution { fees, weight, debt, halt_on_error, orders, instructions } => { Order1::BuyExecution { fees, weight, debt, halt_on_error, instructions } => {
if !orders.is_empty() {
return Err(())
}
let xcm = instructions let xcm = instructions
.into_iter() .into_iter()
.map(Xcm::<Call>::try_from) .map(Xcm::<Call>::try_from)
+4 -15
View File
@@ -19,7 +19,7 @@
use super::{ use super::{
super::v0::Order as Order0, MultiAsset, MultiAssetFilter, MultiAssets, MultiLocation, Xcm, super::v0::Order as Order0, MultiAsset, MultiAssetFilter, MultiAssets, MultiLocation, Xcm,
}; };
use alloc::{vec, vec::Vec}; use alloc::vec::Vec;
use core::{ use core::{
convert::{TryFrom, TryInto}, convert::{TryFrom, TryInto},
result, result,
@@ -140,8 +140,6 @@ pub enum Order<Call> {
/// any surrounding operations/orders. /// any surrounding operations/orders.
/// - `halt_on_error`: If `true`, the execution of the `orders` and `operations` will halt on the first failure. If /// - `halt_on_error`: If `true`, the execution of the `orders` and `operations` will halt on the first failure. If
/// `false`, then execution will continue regardless. /// `false`, then execution will continue regardless.
/// - `orders`: Orders to be executed with the existing Holding Register; execution of these orders happens PRIOR to
/// execution of the `operations`. The (shallow) weight for these must be paid for with the `weight` purchased.
/// - `instructions`: XCM instructions to be executed outside of the context of the current Holding Register; /// - `instructions`: XCM instructions to be executed outside of the context of the current Holding Register;
/// execution of these instructions happens AFTER the execution of the `orders`. The (shallow) weight for these /// execution of these instructions happens AFTER the execution of the `orders`. The (shallow) weight for these
/// must be paid for with the `weight` purchased. /// must be paid for with the `weight` purchased.
@@ -152,7 +150,6 @@ pub enum Order<Call> {
weight: u64, weight: u64,
debt: u64, debt: u64,
halt_on_error: bool, halt_on_error: bool,
orders: Vec<Order<Call>>,
instructions: Vec<Xcm<Call>>, instructions: Vec<Xcm<Call>>,
}, },
} }
@@ -179,10 +176,9 @@ impl<Call> Order<Call> {
InitiateTeleport { assets, dest, effects } => InitiateTeleport { assets, dest, effects } =>
InitiateTeleport { assets, dest, effects }, InitiateTeleport { assets, dest, effects },
QueryHolding { query_id, dest, assets } => QueryHolding { query_id, dest, assets }, QueryHolding { query_id, dest, assets } => QueryHolding { query_id, dest, assets },
BuyExecution { fees, weight, debt, halt_on_error, orders, instructions } => { BuyExecution { fees, weight, debt, halt_on_error, instructions } => {
let orders = orders.into_iter().map(Order::from).collect();
let instructions = instructions.into_iter().map(Xcm::from).collect(); let instructions = instructions.into_iter().map(Xcm::from).collect();
BuyExecution { fees, weight, debt, halt_on_error, orders, instructions } BuyExecution { fees, weight, debt, halt_on_error, instructions }
}, },
} }
} }
@@ -232,14 +228,7 @@ impl<Call> TryFrom<Order0<Call>> for Order<Call> {
Order0::BuyExecution { fees, weight, debt, halt_on_error, xcm } => { Order0::BuyExecution { fees, weight, debt, halt_on_error, xcm } => {
let instructions = let instructions =
xcm.into_iter().map(Xcm::<Call>::try_from).collect::<result::Result<_, _>>()?; xcm.into_iter().map(Xcm::<Call>::try_from).collect::<result::Result<_, _>>()?;
BuyExecution { BuyExecution { fees: fees.try_into()?, weight, debt, halt_on_error, instructions }
fees: fees.try_into()?,
weight,
debt,
halt_on_error,
orders: vec![],
instructions,
}
}, },
}) })
} }
-5
View File
@@ -51,7 +51,6 @@ fn weigher_should_work() {
weight: 0, weight: 0,
debt: 30, debt: 30,
halt_on_error: true, halt_on_error: true,
orders: vec![],
instructions: vec![], instructions: vec![],
}, },
Order::DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() }, Order::DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() },
@@ -139,7 +138,6 @@ fn allow_paid_should_work() {
weight: 0, weight: 0,
debt: 20, debt: 20,
halt_on_error: true, halt_on_error: true,
orders: vec![],
instructions: vec![], instructions: vec![],
}, },
Order::DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() }, Order::DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() },
@@ -164,7 +162,6 @@ fn allow_paid_should_work() {
weight: 0, weight: 0,
debt: 30, debt: 30,
halt_on_error: true, halt_on_error: true,
orders: vec![],
instructions: vec![], instructions: vec![],
}, },
Order::DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() }, Order::DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here.into() },
@@ -206,7 +203,6 @@ fn paying_reserve_deposit_should_work() {
weight: 0, weight: 0,
debt: 30, debt: 30,
halt_on_error: true, halt_on_error: true,
orders: vec![],
instructions: vec![], instructions: vec![],
}, },
Order::<TestCall>::DepositAsset { Order::<TestCall>::DepositAsset {
@@ -347,7 +343,6 @@ fn paid_transacting_should_refund_payment_for_unused_weight() {
weight: 70, weight: 70,
debt: 30, debt: 30,
halt_on_error: true, halt_on_error: true,
orders: vec![],
instructions: vec![Xcm::<TestCall>::Transact { instructions: vec![Xcm::<TestCall>::Transact {
origin_type: OriginKind::Native, origin_type: OriginKind::Native,
require_weight_at_most: 60, require_weight_at_most: 60,
+1 -6
View File
@@ -80,18 +80,13 @@ impl<T: Get<Weight>, C: Decode + GetDispatchInfo> FixedWeightBounds<T, C> {
} }
fn deep_order(order: &mut Order<C>) -> Result<Weight, ()> { fn deep_order(order: &mut Order<C>) -> Result<Weight, ()> {
Ok(match order { Ok(match order {
Order::BuyExecution { orders, instructions, .. } => { Order::BuyExecution { instructions, .. } => {
let mut extra = 0; let mut extra = 0;
for instruction in instructions.iter_mut() { for instruction in instructions.iter_mut() {
extra.saturating_accrue( extra.saturating_accrue(
Self::shallow(instruction)?.saturating_add(Self::deep(instruction)?), Self::shallow(instruction)?.saturating_add(Self::deep(instruction)?),
); );
} }
for order in orders.iter_mut() {
extra.saturating_accrue(
Self::shallow_order(order)?.saturating_add(Self::deep_order(order)?),
);
}
extra extra
}, },
_ => 0, _ => 0,
@@ -46,7 +46,6 @@ fn execute_within_recursion_limit() {
weight: 0, weight: 0,
debt: 0, debt: 0,
halt_on_error: true, halt_on_error: true,
orders: vec![],
// nest `msg` into itself on each iteration. // nest `msg` into itself on each iteration.
instructions: vec![msg], instructions: vec![msg],
}], }],
@@ -101,7 +100,6 @@ fn exceed_recursion_limit() {
weight: 0, weight: 0,
debt: 0, debt: 0,
halt_on_error: true, halt_on_error: true,
orders: vec![],
// nest `msg` into itself on each iteration. // nest `msg` into itself on each iteration.
instructions: vec![msg], instructions: vec![msg],
}], }],
+1 -8
View File
@@ -332,7 +332,7 @@ impl<Config: config::Config> XcmExecutor<Config> {
Xcm::QueryResponse { query_id, response: Response::Assets(assets) }, Xcm::QueryResponse { query_id, response: Response::Assets(assets) },
)?; )?;
}, },
Order::BuyExecution { fees, weight, debt, halt_on_error, orders, instructions } => { Order::BuyExecution { fees, weight, debt, halt_on_error, instructions } => {
// pay for `weight` using up to `fees` of the holding register. // pay for `weight` using up to `fees` of the holding register.
let purchasing_weight = let purchasing_weight =
Weight::from(weight.checked_add(debt).ok_or(XcmError::Overflow)?); Weight::from(weight.checked_add(debt).ok_or(XcmError::Overflow)?);
@@ -342,13 +342,6 @@ impl<Config: config::Config> XcmExecutor<Config> {
holding.subsume_assets(unspent); holding.subsume_assets(unspent);
let mut remaining_weight = weight; let mut remaining_weight = weight;
for order in orders.into_iter() {
match Self::execute_orders(origin, holding, order, trader, num_recursions + 1) {
Err(e) if halt_on_error => return Err(e),
Err(_) => {},
Ok(surplus) => total_surplus += surplus,
}
}
for instruction in instructions.into_iter() { for instruction in instructions.into_iter() {
match Self::do_execute_xcm( match Self::do_execute_xcm(
origin.clone(), origin.clone(),