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

Fix: deal with double transact msg #1965

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading