Skip to content

Commit 567ca7d

Browse files
authored
Fix: deal with double transact msg (#1965)
* Update lib.rs * Update lib.rs * fix ci
1 parent a74cc6b commit 567ca7d

File tree

1 file changed

+61
-34
lines changed

1 file changed

+61
-34
lines changed

pallets/xcm-helper/src/lib.rs

+61-34
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,19 @@ impl<T: Config> Pallet<T> {
273273
query_id,
274274
max_weight,
275275
});
276-
// Prepend SetAppendix(Xcm(vec![ReportError])) wont be able to pass barrier check
277-
// so we need to insert it after Withdraw, BuyExecution
276+
// Before insertion is:
277+
// 0: WithdrawAsset
278+
// 1: BuyExecution
279+
// 2: Transact
280+
// 3: RefundSurplus
281+
// 4: DepositAsset
282+
// After insertion is:
283+
// 0: WithdrawAsset
284+
// 1: BuyExecution
285+
// 2: Transact
286+
// 3: ReportError
287+
// 4: RefundSurplus
288+
// 5: DepositAsset
278289
message.0.insert(3, report_error);
279290
Ok(query_id)
280291
}
@@ -288,9 +299,25 @@ impl<T: Config> Pallet<T> {
288299

289300
// Since xcm v3 doesn't support utility.batch_all
290301
// instead, here append one more transact msg
291-
//
292-
// NOTE: index here is 3,
293-
// must append before 'report_outcome_notify' that index is 2
302+
303+
// A new bug occurred due to XCM version incompatible,
304+
// here is a temp solutin which is ugly:
305+
// ***`append_transact` MUST invoke after `report_outcome_notify`***
306+
// Before insertion is:
307+
// 0: WithdrawAsset
308+
// 1: BuyExecution
309+
// 2: Transact
310+
// 3: ReportError
311+
// 4: RefundSurplus
312+
// 5: DepositAsset
313+
// After insertion is:
314+
// 0: WithdrawAsset
315+
// 1: BuyExecution
316+
// 2: Transact
317+
// 3: Transact
318+
// 4: ReportError
319+
// 5: RefundSurplus
320+
// 6: DepositAsset
294321
pub fn append_transact(message: &mut Xcm<()>, call: DoubleEncoded<()>, weight: Weight) {
295322
message.0.insert(
296323
3,
@@ -516,6 +543,13 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
516543
xcm_weight_fee_misc.fee,
517544
)?;
518545

546+
let query_id = Self::report_outcome_notify(
547+
&mut msg,
548+
MultiLocation::parent(),
549+
notify,
550+
T::NotifyTimeout::get(),
551+
)?;
552+
519553
let call = RelaychainCall::<T>::Proxy(Box::new(ProxyCall::Proxy(ProxyProxyCall {
520554
real,
521555
force_proxy_type: None,
@@ -529,13 +563,6 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
529563
})));
530564
Self::append_transact(&mut msg, call.encode().into(), xcm_weight_fee_misc.weight);
531565

532-
let query_id = Self::report_outcome_notify(
533-
&mut msg,
534-
MultiLocation::parent(),
535-
notify,
536-
T::NotifyTimeout::get(),
537-
)?;
538-
539566
if let Err(_e) = send_xcm::<T::XcmSender>(MultiLocation::parent(), msg) {
540567
return Err(Error::<T>::SendFailure.into());
541568
}
@@ -566,6 +593,14 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
566593
Self::refund_location(),
567594
xcm_weight_fee_misc.fee,
568595
)?;
596+
597+
let query_id = Self::report_outcome_notify(
598+
&mut msg,
599+
MultiLocation::parent(),
600+
notify,
601+
T::NotifyTimeout::get(),
602+
)?;
603+
569604
let call = RelaychainCall::<T>::Utility(Box::new(UtilityCall::AsDerivative(
570605
UtilityAsDerivativeCall {
571606
index,
@@ -576,16 +611,8 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
576611
})),
577612
},
578613
)));
579-
580614
Self::append_transact(&mut msg, call.encode().into(), xcm_weight_fee_misc.weight);
581615

582-
let query_id = Self::report_outcome_notify(
583-
&mut msg,
584-
MultiLocation::parent(),
585-
notify,
586-
T::NotifyTimeout::get(),
587-
)?;
588-
589616
if let Err(_err) = send_xcm::<T::XcmSender>(MultiLocation::parent(), msg) {
590617
return Err(Error::<T>::SendFailure.into());
591618
}
@@ -616,6 +643,13 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
616643
xcm_weight_fee_misc.fee,
617644
)?;
618645

646+
let query_id = Self::report_outcome_notify(
647+
&mut msg,
648+
MultiLocation::parent(),
649+
notify,
650+
T::NotifyTimeout::get(),
651+
)?;
652+
619653
let call = RelaychainCall::<T>::Utility(Box::new(UtilityCall::AsDerivative(
620654
UtilityAsDerivativeCall {
621655
index,
@@ -626,13 +660,6 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
626660
)));
627661
Self::append_transact(&mut msg, call.encode().into(), xcm_weight_fee_misc.weight);
628662

629-
let query_id = Self::report_outcome_notify(
630-
&mut msg,
631-
MultiLocation::parent(),
632-
notify,
633-
T::NotifyTimeout::get(),
634-
)?;
635-
636663
if let Err(_err) = send_xcm::<T::XcmSender>(MultiLocation::parent(), msg) {
637664
return Err(Error::<T>::SendFailure.into());
638665
}
@@ -741,6 +768,13 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
741768
xcm_weight_fee_misc.fee,
742769
)?;
743770

771+
let query_id = Self::report_outcome_notify(
772+
&mut msg,
773+
MultiLocation::parent(),
774+
notify,
775+
T::NotifyTimeout::get(),
776+
)?;
777+
744778
let call = RelaychainCall::Utility(Box::new(UtilityCall::AsDerivative(
745779
UtilityAsDerivativeCall {
746780
index,
@@ -754,13 +788,6 @@ impl<T: Config> XcmHelper<T, BalanceOf<T>, AccountIdOf<T>> for Pallet<T> {
754788
)));
755789
Self::append_transact(&mut msg, call.encode().into(), xcm_weight_fee_misc.weight);
756790

757-
let query_id = Self::report_outcome_notify(
758-
&mut msg,
759-
MultiLocation::parent(),
760-
notify,
761-
T::NotifyTimeout::get(),
762-
)?;
763-
764791
if let Err(_err) = send_xcm::<T::XcmSender>(MultiLocation::parent(), msg) {
765792
return Err(Error::<T>::SendFailure.into());
766793
}

0 commit comments

Comments
 (0)