Skip to content

Commit

Permalink
Fix: deal with double transact msg (#1965)
Browse files Browse the repository at this point in the history
* Update lib.rs

* Update lib.rs

* fix ci
  • Loading branch information
mclyk authored Mar 21, 2024
1 parent a74cc6b commit 567ca7d
Showing 1 changed file with 61 additions and 34 deletions.
95 changes: 61 additions & 34 deletions pallets/xcm-helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,19 @@ impl<T: Config> Pallet<T> {
query_id,
max_weight,
});
// Prepend SetAppendix(Xcm(vec![ReportError])) wont be able to pass barrier check
// so we need to insert it after Withdraw, BuyExecution
// Before insertion is:
// 0: WithdrawAsset
// 1: BuyExecution
// 2: Transact
// 3: RefundSurplus
// 4: DepositAsset
// After insertion is:
// 0: WithdrawAsset
// 1: BuyExecution
// 2: Transact
// 3: ReportError
// 4: RefundSurplus
// 5: DepositAsset
message.0.insert(3, report_error);
Ok(query_id)
}
Expand All @@ -288,9 +299,25 @@ impl<T: Config> Pallet<T> {

// Since xcm v3 doesn't support utility.batch_all
// instead, here append one more transact msg
//
// NOTE: index here is 3,
// must append before 'report_outcome_notify' that index is 2

// A new bug occurred due to XCM version incompatible,
// here is a temp solutin which is ugly:
// ***`append_transact` MUST invoke after `report_outcome_notify`***
// Before insertion is:
// 0: WithdrawAsset
// 1: BuyExecution
// 2: Transact
// 3: ReportError
// 4: RefundSurplus
// 5: DepositAsset
// After insertion is:
// 0: WithdrawAsset
// 1: BuyExecution
// 2: Transact
// 3: Transact
// 4: ReportError
// 5: RefundSurplus
// 6: DepositAsset
pub fn append_transact(message: &mut Xcm<()>, call: DoubleEncoded<()>, weight: Weight) {
message.0.insert(
3,
Expand Down Expand Up @@ -516,6 +543,13 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
xcm_weight_fee_misc.fee,
)?;

let query_id = Self::report_outcome_notify(
&mut msg,
MultiLocation::parent(),
notify,
T::NotifyTimeout::get(),
)?;

let call = RelaychainCall::<T>::Proxy(Box::new(ProxyCall::Proxy(ProxyProxyCall {
real,
force_proxy_type: None,
Expand All @@ -529,13 +563,6 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
})));
Self::append_transact(&mut msg, call.encode().into(), xcm_weight_fee_misc.weight);

let query_id = Self::report_outcome_notify(
&mut msg,
MultiLocation::parent(),
notify,
T::NotifyTimeout::get(),
)?;

if let Err(_e) = send_xcm::<T::XcmSender>(MultiLocation::parent(), msg) {
return Err(Error::<T>::SendFailure.into());
}
Expand Down Expand Up @@ -566,6 +593,14 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
Self::refund_location(),
xcm_weight_fee_misc.fee,
)?;

let query_id = Self::report_outcome_notify(
&mut msg,
MultiLocation::parent(),
notify,
T::NotifyTimeout::get(),
)?;

let call = RelaychainCall::<T>::Utility(Box::new(UtilityCall::AsDerivative(
UtilityAsDerivativeCall {
index,
Expand All @@ -576,16 +611,8 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
})),
},
)));

Self::append_transact(&mut msg, call.encode().into(), xcm_weight_fee_misc.weight);

let query_id = Self::report_outcome_notify(
&mut msg,
MultiLocation::parent(),
notify,
T::NotifyTimeout::get(),
)?;

if let Err(_err) = send_xcm::<T::XcmSender>(MultiLocation::parent(), msg) {
return Err(Error::<T>::SendFailure.into());
}
Expand Down Expand Up @@ -616,6 +643,13 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
xcm_weight_fee_misc.fee,
)?;

let query_id = Self::report_outcome_notify(
&mut msg,
MultiLocation::parent(),
notify,
T::NotifyTimeout::get(),
)?;

let call = RelaychainCall::<T>::Utility(Box::new(UtilityCall::AsDerivative(
UtilityAsDerivativeCall {
index,
Expand All @@ -626,13 +660,6 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
)));
Self::append_transact(&mut msg, call.encode().into(), xcm_weight_fee_misc.weight);

let query_id = Self::report_outcome_notify(
&mut msg,
MultiLocation::parent(),
notify,
T::NotifyTimeout::get(),
)?;

if let Err(_err) = send_xcm::<T::XcmSender>(MultiLocation::parent(), msg) {
return Err(Error::<T>::SendFailure.into());
}
Expand Down Expand Up @@ -741,6 +768,13 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
xcm_weight_fee_misc.fee,
)?;

let query_id = Self::report_outcome_notify(
&mut msg,
MultiLocation::parent(),
notify,
T::NotifyTimeout::get(),
)?;

let call = RelaychainCall::Utility(Box::new(UtilityCall::AsDerivative(
UtilityAsDerivativeCall {
index,
Expand All @@ -754,13 +788,6 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
)));
Self::append_transact(&mut msg, call.encode().into(), xcm_weight_fee_misc.weight);

let query_id = Self::report_outcome_notify(
&mut msg,
MultiLocation::parent(),
notify,
T::NotifyTimeout::get(),
)?;

if let Err(_err) = send_xcm::<T::XcmSender>(MultiLocation::parent(), msg) {
return Err(Error::<T>::SendFailure.into());
}
Expand Down

0 comments on commit 567ca7d

Please sign in to comment.