Skip to content

Commit 27999c3

Browse files
Merge pull request #1396 from galacticcouncil/xcm_egress
fix: Account for egress on partially executed xcm
2 parents 9ddea80 + 5417026 commit 27999c3

6 files changed

Lines changed: 76 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "runtime-integration-tests"
3-
version = "1.75.0"
3+
version = "1.75.1"
44
description = "Integration tests"
55
authors = ["GalacticCouncil"]
66
edition = "2021"

integration-tests/src/global_withdraw_limit.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,3 +1460,71 @@ fn inbound_xcm_buffer_is_clean_between_messages() {
14601460
);
14611461
});
14621462
}
1463+
1464+
#[test]
1465+
fn inbound_xcm_incomplete_message_still_accounts_egress() {
1466+
TestNet::reset();
1467+
1468+
let sovereign = parachain_reserve_account();
1469+
1470+
Hydra::execute_with(|| {
1471+
init_global_withdraw_limit_params();
1472+
1473+
assert_ok!(CircuitBreaker::set_asset_category(
1474+
hydradx_runtime::RuntimeOrigin::root(),
1475+
HDX,
1476+
Some(GlobalAssetCategory::Local)
1477+
));
1478+
1479+
assert_ok!(hydradx_runtime::Balances::transfer_allow_death(
1480+
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()),
1481+
sovereign.clone(),
1482+
500 * UNITS,
1483+
));
1484+
1485+
assert_eq!(CircuitBreaker::withdraw_limit_accumulator().0, 0);
1486+
assert_eq!(Currencies::free_balance(HDX, &sovereign), 500 * UNITS);
1487+
});
1488+
1489+
Acala::execute_with(|| {
1490+
let hdx_loc = Location::new(
1491+
1,
1492+
[
1493+
cumulus_primitives_core::Junction::Parachain(HYDRA_PARA_ID),
1494+
cumulus_primitives_core::Junction::GeneralIndex(0),
1495+
],
1496+
);
1497+
let amount = 100 * UNITS;
1498+
let asset: Asset = Asset {
1499+
id: cumulus_primitives_core::AssetId(hdx_loc),
1500+
fun: Fungible(amount),
1501+
};
1502+
1503+
let message = Xcm(vec![
1504+
WithdrawAsset(asset.clone().into()),
1505+
BuyExecution {
1506+
fees: asset,
1507+
weight_limit: Unlimited,
1508+
},
1509+
Trap(1),
1510+
]);
1511+
1512+
assert_ok!(hydradx_runtime::PolkadotXcm::send_xcm(
1513+
Here,
1514+
Location::new(1, [cumulus_primitives_core::Junction::Parachain(HYDRA_PARA_ID)]),
1515+
message
1516+
));
1517+
});
1518+
1519+
Hydra::execute_with(|| {
1520+
assert_xcm_message_processing_failed();
1521+
assert!(
1522+
Currencies::free_balance(HDX, &sovereign) < 500 * UNITS,
1523+
"Incomplete inbound XCM must have withdrawn funds from the sovereign account"
1524+
);
1525+
assert!(
1526+
CircuitBreaker::withdraw_limit_accumulator().0 > 0,
1527+
"Incomplete inbound XCM with real egress must still increment the accumulator"
1528+
);
1529+
});
1530+
}

runtime/hydradx/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hydradx-runtime"
3-
version = "404.0.0"
3+
version = "405.0.0"
44
authors = ["GalacticCouncil"]
55
edition = "2021"
66
license = "Apache 2.0"

runtime/hydradx/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
129129
spec_name: Cow::Borrowed("hydradx"),
130130
impl_name: Cow::Borrowed("hydradx"),
131131
authoring_version: 1,
132-
spec_version: 404,
132+
spec_version: 405,
133133
impl_version: 0,
134134
apis: RUNTIME_API_VERSIONS,
135135
transaction_version: 1,

runtime/hydradx/src/xcm.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,9 @@ where
482482
let result = MessageProcessor::process_message(message, origin, meter, id);
483483

484484
if let Some((withdrawn, deposited)) = pallet_circuit_breaker::XcmEgressBuffer::<Runtime>::take() {
485-
if matches!(result, Ok(true)) {
486-
let net = withdrawn.saturating_sub(deposited);
487-
if !net.is_zero() {
488-
let _ = pallet_circuit_breaker::Pallet::<Runtime>::note_egress(net);
489-
}
485+
let net = withdrawn.saturating_sub(deposited);
486+
if !net.is_zero() {
487+
let _ = pallet_circuit_breaker::Pallet::<Runtime>::note_egress(net);
490488
}
491489
}
492490
result

0 commit comments

Comments
 (0)