diff --git a/pallets/xcm-helper/src/lib.rs b/pallets/xcm-helper/src/lib.rs index 906f26bf5..bcd2e4190 100644 --- a/pallets/xcm-helper/src/lib.rs +++ b/pallets/xcm-helper/src/lib.rs @@ -273,8 +273,19 @@ impl Pallet { 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) } @@ -288,9 +299,25 @@ impl Pallet { // 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, @@ -516,6 +543,13 @@ impl XcmHelper, AccountIdOf> for Pallet { xcm_weight_fee_misc.fee, )?; + let query_id = Self::report_outcome_notify( + &mut msg, + MultiLocation::parent(), + notify, + T::NotifyTimeout::get(), + )?; + let call = RelaychainCall::::Proxy(Box::new(ProxyCall::Proxy(ProxyProxyCall { real, force_proxy_type: None, @@ -529,13 +563,6 @@ impl XcmHelper, AccountIdOf> for Pallet { }))); 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::(MultiLocation::parent(), msg) { return Err(Error::::SendFailure.into()); } @@ -566,6 +593,14 @@ impl XcmHelper, AccountIdOf> for Pallet { 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::::Utility(Box::new(UtilityCall::AsDerivative( UtilityAsDerivativeCall { index, @@ -576,16 +611,8 @@ impl XcmHelper, AccountIdOf> for Pallet { })), }, ))); - 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::(MultiLocation::parent(), msg) { return Err(Error::::SendFailure.into()); } @@ -616,6 +643,13 @@ impl XcmHelper, AccountIdOf> for Pallet { 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, @@ -626,13 +660,6 @@ impl XcmHelper, AccountIdOf> for Pallet { ))); 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::(MultiLocation::parent(), msg) { return Err(Error::::SendFailure.into()); } @@ -741,6 +768,13 @@ impl XcmHelper, AccountIdOf> for Pallet { 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, @@ -754,13 +788,6 @@ impl XcmHelper, AccountIdOf> for Pallet { ))); 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::(MultiLocation::parent(), msg) { return Err(Error::::SendFailure.into()); }