Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting Unlimited for BuyExecution in XCM Transactor #2553

Merged
merged 9 commits into from
Dec 11, 2023
74 changes: 49 additions & 25 deletions pallets/xcm-transactor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub mod pallet {
// the overall weight to be used for the whole XCM message execution. If None,
// then this amount will be tried to be derived from storage. If the storage item
// for the chain is not populated, then it fails
pub overall_weight: Option<Weight>,
pub overall_weight: Option<WeightLimit>,
}

/// Since we are using pallet-utility for account derivation (through AsDerivative),
Expand Down Expand Up @@ -524,22 +524,28 @@ pub mod pallet {
// Calculate the total weight that the xcm message is going to spend in the
// destination chain
let total_weight = weight_info.overall_weight.map_or_else(
|| {
Self::take_weight_from_transact_info(
|| -> Result<_, DispatchError> {
let weight_info = Self::take_weight_from_transact_info(
dest.clone(),
weight_info.transact_required_weight_at_most,
refund,
)
)?;
Ok(WeightLimit::from(Some(weight_info)))
},
|v| Ok(v),
)?;

let total_weight_fee_calculation = match total_weight {
Unlimited => Weight::from_parts(10_000_000_000, 100_000),
Limited(x) => x,
};

// Calculate fee based on FeePerSecond
let fee = Self::calculate_fee(
fee_location,
fee.fee_amount,
dest.clone(),
total_weight.clone(),
total_weight_fee_calculation,
)?;

// If refund is true, the appendix instruction will be a deposit back to the sovereign
Expand All @@ -566,9 +572,9 @@ pub mod pallet {
// Deposit event
Self::deposit_event(Event::<T>::TransactedDerivative {
account_id: who,
dest: dest,
dest,
call: call_bytes,
index: index,
index,
});

Ok(())
Expand Down Expand Up @@ -610,22 +616,28 @@ pub mod pallet {
// Calculate the total weight that the xcm message is going to spend in the
// destination chain
let total_weight = weight_info.overall_weight.map_or_else(
|| {
Self::take_weight_from_transact_info(
|| -> Result<_, DispatchError> {
let weight_info = Self::take_weight_from_transact_info(
dest.clone(),
weight_info.transact_required_weight_at_most,
refund,
)
)?;
Ok(WeightLimit::from(Some(weight_info)))
},
|v| Ok(v),
)?;

let total_weight_fee_calculation = match total_weight {
Unlimited => Weight::from_parts(10_000_000_000, 100_000),
Limited(x) => x,
};

// Calculate fee based on FeePerSecond and total_weight
let fee = Self::calculate_fee(
fee_location,
fee.fee_amount,
dest.clone(),
total_weight.clone(),
total_weight_fee_calculation,
)?;

// If refund is true, the appendix instruction will be a deposit back to the sovereign
Expand Down Expand Up @@ -736,22 +748,28 @@ pub mod pallet {
// Calculate the total weight that the xcm message is going to spend in the
// destination chain
let total_weight = weight_info.overall_weight.map_or_else(
|| {
Self::take_weight_from_transact_info_signed(
|| -> Result<_, DispatchError> {
let weight_info = Self::take_weight_from_transact_info_signed(
dest.clone(),
weight_info.transact_required_weight_at_most,
refund,
)
)?;
Ok(WeightLimit::from(Some(weight_info)))
},
|v| Ok(v),
)?;

let total_weight_fee_calculation = match total_weight {
Unlimited => Weight::from_parts(10_000_000_000, 100_000),
Limited(x) => x,
};

// Fee to be paid
let fee = Self::calculate_fee(
fee_location,
fee.fee_amount,
dest.clone(),
total_weight.clone(),
total_weight_fee_calculation,
)?;

// If refund is true, the appendix instruction will be a deposit back to the sender
Expand Down Expand Up @@ -877,21 +895,27 @@ pub mod pallet {
// Calculate the total weight that the xcm message is going to spend in the
// destination chain
let total_weight = weight_info.overall_weight.map_or_else(
|| {
Self::take_weight_from_transact_info(
|| -> Result<_, DispatchError> {
let weight_info = Self::take_weight_from_transact_info(
destination.clone(),
weight_info.transact_required_weight_at_most,
false,
)
)?;
Ok(WeightLimit::from(Some(weight_info)))
},
|v| Ok(v),
)?;

let total_weight_fee_calculation = match total_weight {
Unlimited => Weight::from_parts(10_000_000_000, 100_000),
Limited(x) => x,
};

let fee = Self::calculate_fee(
fee_location,
fee.fee_amount,
destination.clone(),
total_weight.clone(),
total_weight_fee_calculation,
)?;

ensure!(
Expand Down Expand Up @@ -927,7 +951,7 @@ pub mod pallet {
fee: MultiAsset,
call: Vec<u8>,
origin_kind: OriginKind,
total_weight: Weight,
total_weight: WeightLimit,
transact_required_weight_at_most: Weight,
with_appendix: Option<Vec<Instruction<()>>>,
) -> DispatchResult {
Expand Down Expand Up @@ -972,7 +996,7 @@ pub mod pallet {
fee: MultiAsset,
call: Vec<u8>,
origin_kind: OriginKind,
total_weight: Weight,
total_weight: WeightLimit,
transact_required_weight_at_most: Weight,
with_appendix: Option<Vec<Instruction<()>>>,
) -> DispatchResult {
Expand Down Expand Up @@ -1046,7 +1070,7 @@ pub mod pallet {
fn transact_message(
dest: MultiLocation,
asset: MultiAsset,
dest_weight: Weight,
dest_weight: WeightLimit,
call: Vec<u8>,
dispatch_weight: Weight,
origin_kind: OriginKind,
Expand All @@ -1060,7 +1084,7 @@ pub mod pallet {
instructions.push(Self::appendix_instruction(appendix)?);
}
instructions.push(Transact {
origin_kind: origin_kind,
origin_kind,
require_weight_at_most: dispatch_weight,
call: call.into(),
});
Expand All @@ -1071,7 +1095,7 @@ pub mod pallet {
fn buy_execution(
asset: MultiAsset,
at: &MultiLocation,
weight: Weight,
weight: WeightLimit,
) -> Result<Instruction<()>, DispatchError> {
let universal_location = T::UniversalLocation::get();
let fees = asset
Expand All @@ -1080,7 +1104,7 @@ pub mod pallet {

Ok(BuyExecution {
fees,
weight_limit: WeightLimit::Limited(weight),
weight_limit: weight,
})
}

Expand Down
26 changes: 13 additions & 13 deletions pallets/xcm-transactor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ fn test_send_through_derivative_with_custom_weight_and_fee() {
vec![1u8],
TransactWeights {
transact_required_weight_at_most: tx_weight,
overall_weight: Some(total_weight)
overall_weight: Some(Limited(total_weight))
},
false
));
Expand Down Expand Up @@ -999,7 +999,7 @@ fn test_send_through_sovereign_with_custom_weight_and_fee() {
OriginKind::SovereignAccount,
TransactWeights {
transact_required_weight_at_most: tx_weight,
overall_weight: Some(total_weight)
overall_weight: Some(Limited(total_weight))
},
false
));
Expand Down Expand Up @@ -1063,7 +1063,7 @@ fn test_send_through_signed_with_custom_weight_and_fee() {
vec![1u8],
TransactWeights {
transact_required_weight_at_most: tx_weight,
overall_weight: Some(total_weight)
overall_weight: Some(Limited(total_weight))
},
false
));
Expand Down Expand Up @@ -1119,7 +1119,7 @@ fn test_hrmp_manipulator_init() {
},
TransactWeights {
transact_required_weight_at_most: tx_weight,
overall_weight: Some(total_weight)
overall_weight: Some(Limited(total_weight))
}
));

Expand Down Expand Up @@ -1171,7 +1171,7 @@ fn test_hrmp_manipulator_init_v2_convert_works() {
},
TransactWeights {
transact_required_weight_at_most: tx_weight,
overall_weight: Some(total_weight)
overall_weight: Some(Limited(total_weight))
}
));

Expand Down Expand Up @@ -1235,7 +1235,7 @@ fn test_hrmp_manipulator_init_v3_convert_works() {
},
TransactWeights {
transact_required_weight_at_most: tx_weight,
overall_weight: Some(total_weight)
overall_weight: Some(Limited(total_weight))
}
));

Expand Down Expand Up @@ -1300,7 +1300,7 @@ fn test_hrmp_manipulator_init_v4_convert_fails() {
},
TransactWeights {
transact_required_weight_at_most: tx_weight,
overall_weight: Some(total_weight)
overall_weight: Some(Limited(total_weight))
}
),
Error::<Test>::ErrorValidating
Expand Down Expand Up @@ -1334,7 +1334,7 @@ fn test_hrmp_max_fee_errors() {
},
TransactWeights {
transact_required_weight_at_most: tx_weight,
overall_weight: Some(total_weight)
overall_weight: Some(Limited(total_weight))
}
),
Error::<Test>::TooMuchFeeUsed
Expand Down Expand Up @@ -1367,7 +1367,7 @@ fn test_hrmp_manipulator_accept() {
},
TransactWeights {
transact_required_weight_at_most: tx_weight,
overall_weight: Some(total_weight)
overall_weight: Some(Limited(total_weight))
}
));

Expand Down Expand Up @@ -1420,7 +1420,7 @@ fn test_hrmp_manipulator_cancel() {
},
TransactWeights {
transact_required_weight_at_most: tx_weight,
overall_weight: Some(total_weight)
overall_weight: Some(Limited(total_weight))
}
));

Expand Down Expand Up @@ -1468,7 +1468,7 @@ fn test_hrmp_manipulator_close() {
},
TransactWeights {
transact_required_weight_at_most: tx_weight,
overall_weight: Some(total_weight)
overall_weight: Some(Limited(total_weight))
}
));

Expand Down Expand Up @@ -1527,7 +1527,7 @@ fn test_transact_through_derivative_with_refund_works() {
vec![1u8],
TransactWeights {
transact_required_weight_at_most: 100u64.into(),
overall_weight: Some(1000.into())
overall_weight: Some(Limited(1000.into()))
},
true
));
Expand Down Expand Up @@ -1646,7 +1646,7 @@ fn test_transact_through_signed_with_refund_works() {
vec![1u8],
TransactWeights {
transact_required_weight_at_most: 100u64.into(),
overall_weight: Some(total_weight)
overall_weight: Some(Limited(total_weight))
},
true
));
Expand Down
Loading