Skip to content

Commit 74b597f

Browse files
authored
[cumulus] Improved check for sane bridge fees calculations (#3175)
## TODO - [x] change constants when CI fails (should fail :) ) ## Result On the AssetHubRococo: 1701175800126 -> 1700929825257 = 0.15 % decreased. ``` # Before ( [xcm] Fix `SovereignPaidRemoteExporter` and `DepositAsset` handling (#3157)) Feb 02 12:59:05.520 ERROR bridges::estimate: `bridging::XcmBridgeHubRouterBaseFee` actual value: 1701175800126 for runtime: statemine-1006000 (statemine-0.tx14.au1) # After Feb 02 13:02:40.647 ERROR bridges::estimate: `bridging::XcmBridgeHubRouterBaseFee` actual value: 1700929825257 for runtime: statemine-1006000 (statemine-0.tx14.au1) ``` On the AssetHubWestend: 2116038876326 -> 1641718372993 = 22.4 % decreased. ``` # Before ( [xcm] Fix `SovereignPaidRemoteExporter` and `DepositAsset` handling (#3157)) Feb 02 12:56:00.880 ERROR bridges::estimate: `bridging::XcmBridgeHubRouterBaseFee` actual value: 2116038876326 for runtime: westmint-1006000 (westmint-0.tx14.au1) # After Feb 02 13:04:42.515 ERROR bridges::estimate: `bridging::XcmBridgeHubRouterBaseFee` actual value: 1641718372993 for runtime: westmint-1006000 (westmint-0.tx14.au1) ```
1 parent 5ba8921 commit 74b597f

File tree

10 files changed

+235
-169
lines changed

10 files changed

+235
-169
lines changed

bridges/primitives/chain-bridge-hub-rococo/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ frame_support::parameter_types! {
9999
/// The XCM fee that is paid for executing XCM program (with `ExportMessage` instruction) at the Rococo
100100
/// BridgeHub.
101101
/// (initially was calculated by test `BridgeHubRococo::can_calculate_weight_for_paid_export_message_with_reserve_transfer` + `33%`)
102-
pub const BridgeHubRococoBaseXcmFeeInRocs: u128 = 1_640_102_205;
102+
pub const BridgeHubRococoBaseXcmFeeInRocs: u128 = 59_034_266;
103103

104104
/// Transaction fee that is paid at the Rococo BridgeHub for delivering single inbound message.
105105
/// (initially was calculated by test `BridgeHubRococo::can_calculate_fee_for_complex_message_delivery_transaction` + `33%`)
106106
pub const BridgeHubRococoBaseDeliveryFeeInRocs: u128 = 5_651_581_649;
107107

108108
/// Transaction fee that is paid at the Rococo BridgeHub for delivering single outbound message confirmation.
109109
/// (initially was calculated by test `BridgeHubRococo::can_calculate_fee_for_complex_message_confirmation_transaction` + `33%`)
110-
pub const BridgeHubRococoBaseConfirmationFeeInRocs: u128 = 4_045_736_577;
110+
pub const BridgeHubRococoBaseConfirmationFeeInRocs: u128 = 5_380_829_647;
111111
}

bridges/primitives/chain-bridge-hub-westend/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ frame_support::parameter_types! {
9090
/// The XCM fee that is paid for executing XCM program (with `ExportMessage` instruction) at the Westend
9191
/// BridgeHub.
9292
/// (initially was calculated by test `BridgeHubWestend::can_calculate_weight_for_paid_export_message_with_reserve_transfer` + `33%`)
93-
pub const BridgeHubWestendBaseXcmFeeInWnds: u128 = 492_077_333_333;
93+
pub const BridgeHubWestendBaseXcmFeeInWnds: u128 = 17_756_830_000;
9494

9595
/// Transaction fee that is paid at the Westend BridgeHub for delivering single inbound message.
9696
/// (initially was calculated by test `BridgeHubWestend::can_calculate_fee_for_complex_message_delivery_transaction` + `33%`)

cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,12 @@ fn change_xcm_bridge_hub_router_base_fee_by_governance_works() {
12631263
1000,
12641264
Box::new(|call| RuntimeCall::System(call).encode()),
12651265
|| {
1266+
log::error!(
1267+
target: "bridges::estimate",
1268+
"`bridging::XcmBridgeHubRouterBaseFee` actual value: {} for runtime: {}",
1269+
bridging::XcmBridgeHubRouterBaseFee::get(),
1270+
<Runtime as frame_system::Config>::Version::get(),
1271+
);
12661272
(
12671273
bridging::XcmBridgeHubRouterBaseFee::key().to_vec(),
12681274
bridging::XcmBridgeHubRouterBaseFee::get(),
@@ -1289,6 +1295,12 @@ fn change_xcm_bridge_hub_ethereum_base_fee_by_governance_works() {
12891295
1000,
12901296
Box::new(|call| RuntimeCall::System(call).encode()),
12911297
|| {
1298+
log::error!(
1299+
target: "bridges::estimate",
1300+
"`bridging::BridgeHubEthereumBaseFee` actual value: {} for runtime: {}",
1301+
bridging::to_ethereum::BridgeHubEthereumBaseFee::get(),
1302+
<Runtime as frame_system::Config>::Version::get(),
1303+
);
12921304
(
12931305
bridging::to_ethereum::BridgeHubEthereumBaseFee::key().to_vec(),
12941306
bridging::to_ethereum::BridgeHubEthereumBaseFee::get(),

cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,38 @@ fn change_xcm_bridge_hub_router_byte_fee_by_governance_works() {
12091209
)
12101210
}
12111211

1212+
#[test]
1213+
fn change_xcm_bridge_hub_router_base_fee_by_governance_works() {
1214+
asset_test_utils::test_cases::change_storage_constant_by_governance_works::<
1215+
Runtime,
1216+
bridging::XcmBridgeHubRouterBaseFee,
1217+
Balance,
1218+
>(
1219+
collator_session_keys(),
1220+
1000,
1221+
Box::new(|call| RuntimeCall::System(call).encode()),
1222+
|| {
1223+
log::error!(
1224+
target: "bridges::estimate",
1225+
"`bridging::XcmBridgeHubRouterBaseFee` actual value: {} for runtime: {}",
1226+
bridging::XcmBridgeHubRouterBaseFee::get(),
1227+
<Runtime as frame_system::Config>::Version::get(),
1228+
);
1229+
(
1230+
bridging::XcmBridgeHubRouterBaseFee::key().to_vec(),
1231+
bridging::XcmBridgeHubRouterBaseFee::get(),
1232+
)
1233+
},
1234+
|old_value| {
1235+
if let Some(new_value) = old_value.checked_add(1) {
1236+
new_value
1237+
} else {
1238+
old_value.checked_sub(1).unwrap()
1239+
}
1240+
},
1241+
)
1242+
}
1243+
12121244
#[test]
12131245
fn reserve_transfer_native_asset_to_non_teleport_para_works() {
12141246
asset_test_utils::test_cases::reserve_transfer_native_asset_to_non_teleport_para_works::<

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs

Lines changed: 80 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use sp_core::H160;
3434
use sp_keyring::AccountKeyring::Alice;
3535
use sp_runtime::{
3636
generic::{Era, SignedPayload},
37-
AccountId32,
37+
AccountId32, Perbill,
3838
};
3939
use testnet_parachains_constants::rococo::{
4040
consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, fee::WeightToFee,
@@ -400,53 +400,61 @@ mod bridge_hub_westend_tests {
400400

401401
#[test]
402402
pub fn can_calculate_weight_for_paid_export_message_with_reserve_transfer() {
403-
let estimated = bridge_hub_test_utils::test_cases::can_calculate_weight_for_paid_export_message_with_reserve_transfer::<
404-
Runtime,
405-
XcmConfig,
406-
WeightToFee,
407-
>();
408-
409-
// check if estimated value is sane
410-
let max_expected = bp_bridge_hub_rococo::BridgeHubRococoBaseXcmFeeInRocs::get();
411-
assert!(
412-
estimated <= max_expected,
413-
"calculated: {:?}, max_expected: {:?}, please adjust `bp_bridge_hub_rococo::BridgeHubRococoBaseXcmFeeInRocs` value",
414-
estimated,
415-
max_expected
416-
);
403+
bridge_hub_test_utils::check_sane_fees_values(
404+
"bp_bridge_hub_rococo::BridgeHubRococoBaseXcmFeeInRocs",
405+
bp_bridge_hub_rococo::BridgeHubRococoBaseXcmFeeInRocs::get(),
406+
|| {
407+
bridge_hub_test_utils::test_cases::can_calculate_weight_for_paid_export_message_with_reserve_transfer::<
408+
Runtime,
409+
XcmConfig,
410+
WeightToFee,
411+
>()
412+
},
413+
Perbill::from_percent(33),
414+
Some(-33),
415+
&format!(
416+
"Estimate fee for `ExportMessage` for runtime: {:?}",
417+
<Runtime as frame_system::Config>::Version::get()
418+
),
419+
)
417420
}
418421

419422
#[test]
420423
pub fn can_calculate_fee_for_complex_message_delivery_transaction() {
421-
let estimated = from_parachain::can_calculate_fee_for_complex_message_delivery_transaction::<
422-
RuntimeTestsAdapter,
423-
>(collator_session_keys(), construct_and_estimate_extrinsic_fee);
424-
425-
// check if estimated value is sane
426-
let max_expected = bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs::get();
427-
assert!(
428-
estimated <= max_expected,
429-
"calculated: {:?}, max_expected: {:?}, please adjust `bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs` value",
430-
estimated,
431-
max_expected
432-
);
424+
bridge_hub_test_utils::check_sane_fees_values(
425+
"bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs",
426+
bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs::get(),
427+
|| {
428+
from_parachain::can_calculate_fee_for_complex_message_delivery_transaction::<
429+
RuntimeTestsAdapter,
430+
>(collator_session_keys(), construct_and_estimate_extrinsic_fee)
431+
},
432+
Perbill::from_percent(33),
433+
Some(-33),
434+
&format!(
435+
"Estimate fee for `single message delivery` for runtime: {:?}",
436+
<Runtime as frame_system::Config>::Version::get()
437+
),
438+
)
433439
}
434440

435441
#[test]
436442
pub fn can_calculate_fee_for_complex_message_confirmation_transaction() {
437-
let estimated =
438-
from_parachain::can_calculate_fee_for_complex_message_confirmation_transaction::<
439-
RuntimeTestsAdapter,
440-
>(collator_session_keys(), construct_and_estimate_extrinsic_fee);
441-
442-
// check if estimated value is sane
443-
let max_expected = bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs::get();
444-
assert!(
445-
estimated <= max_expected,
446-
"calculated: {:?}, max_expected: {:?}, please adjust `bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs` value",
447-
estimated,
448-
max_expected
449-
);
443+
bridge_hub_test_utils::check_sane_fees_values(
444+
"bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs",
445+
bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs::get(),
446+
|| {
447+
from_parachain::can_calculate_fee_for_complex_message_confirmation_transaction::<
448+
RuntimeTestsAdapter,
449+
>(collator_session_keys(), construct_and_estimate_extrinsic_fee)
450+
},
451+
Perbill::from_percent(33),
452+
Some(-33),
453+
&format!(
454+
"Estimate fee for `single message confirmation` for runtime: {:?}",
455+
<Runtime as frame_system::Config>::Version::get()
456+
),
457+
)
450458
}
451459
}
452460

@@ -594,55 +602,43 @@ mod bridge_hub_bulletin_tests {
594602
);
595603
}
596604

597-
#[test]
598-
pub fn can_calculate_weight_for_paid_export_message_with_reserve_transfer() {
599-
let estimated = bridge_hub_test_utils::test_cases::can_calculate_weight_for_paid_export_message_with_reserve_transfer::<
600-
Runtime,
601-
XcmConfig,
602-
WeightToFee,
603-
>();
604-
605-
// check if estimated value is sane
606-
let max_expected = bp_bridge_hub_rococo::BridgeHubRococoBaseXcmFeeInRocs::get();
607-
assert!(
608-
estimated <= max_expected,
609-
"calculated: {:?}, max_expected: {:?}, please adjust `bp_bridge_hub_rococo::BridgeHubRococoBaseXcmFeeInRocs` value",
610-
estimated,
611-
max_expected
612-
);
613-
}
614-
615605
#[test]
616606
pub fn can_calculate_fee_for_complex_message_delivery_transaction() {
617-
let estimated =
618-
from_grandpa_chain::can_calculate_fee_for_complex_message_delivery_transaction::<
619-
RuntimeTestsAdapter,
620-
>(collator_session_keys(), construct_and_estimate_extrinsic_fee);
621-
622-
// check if estimated value is sane
623-
let max_expected = bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs::get();
624-
assert!(
625-
estimated <= max_expected,
626-
"calculated: {:?}, max_expected: {:?}, please adjust `bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs` value",
627-
estimated,
628-
max_expected
629-
);
607+
bridge_hub_test_utils::check_sane_fees_values(
608+
"bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs",
609+
bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs::get(),
610+
|| {
611+
from_grandpa_chain::can_calculate_fee_for_complex_message_delivery_transaction::<
612+
RuntimeTestsAdapter,
613+
>(collator_session_keys(), construct_and_estimate_extrinsic_fee)
614+
},
615+
Perbill::from_percent(33),
616+
None, /* we don't want lowering according to the Bulletin setup, because
617+
* `from_grandpa_chain` is cheaper then `from_parachain_chain` */
618+
&format!(
619+
"Estimate fee for `single message delivery` for runtime: {:?}",
620+
<Runtime as frame_system::Config>::Version::get()
621+
),
622+
)
630623
}
631624

632625
#[test]
633626
pub fn can_calculate_fee_for_complex_message_confirmation_transaction() {
634-
let estimated =
635-
from_grandpa_chain::can_calculate_fee_for_complex_message_confirmation_transaction::<
636-
RuntimeTestsAdapter,
637-
>(collator_session_keys(), construct_and_estimate_extrinsic_fee);
638-
639-
// check if estimated value is sane
640-
let max_expected = bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs::get();
641-
assert!(
642-
estimated <= max_expected,
643-
"calculated: {:?}, max_expected: {:?}, please adjust `bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs` value",
644-
estimated,
645-
max_expected
646-
);
627+
bridge_hub_test_utils::check_sane_fees_values(
628+
"bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs",
629+
bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs::get(),
630+
|| {
631+
from_grandpa_chain::can_calculate_fee_for_complex_message_confirmation_transaction::<
632+
RuntimeTestsAdapter,
633+
>(collator_session_keys(), construct_and_estimate_extrinsic_fee)
634+
},
635+
Perbill::from_percent(33),
636+
None, /* we don't want lowering according to the Bulletin setup, because
637+
* `from_grandpa_chain` is cheaper then `from_parachain_chain` */
638+
&format!(
639+
"Estimate fee for `single message confirmation` for runtime: {:?}",
640+
<Runtime as frame_system::Config>::Version::get()
641+
),
642+
)
647643
}
648644
}

cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/tests.rs

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use sp_consensus_aura::SlotDuration;
3838
use sp_keyring::AccountKeyring::Alice;
3939
use sp_runtime::{
4040
generic::{Era, SignedPayload},
41-
AccountId32,
41+
AccountId32, Perbill,
4242
};
4343
use testnet_parachains_constants::westend::{
4444
consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, fee::WeightToFee,
@@ -295,50 +295,59 @@ pub fn complex_relay_extrinsic_works() {
295295

296296
#[test]
297297
pub fn can_calculate_weight_for_paid_export_message_with_reserve_transfer() {
298-
let estimated = bridge_hub_test_utils::test_cases::can_calculate_weight_for_paid_export_message_with_reserve_transfer::<
298+
bridge_hub_test_utils::check_sane_fees_values(
299+
"bp_bridge_hub_westend::BridgeHubWestendBaseXcmFeeInWnds",
300+
bp_bridge_hub_westend::BridgeHubWestendBaseXcmFeeInWnds::get(),
301+
|| {
302+
bridge_hub_test_utils::test_cases::can_calculate_weight_for_paid_export_message_with_reserve_transfer::<
299303
Runtime,
300304
XcmConfig,
301305
WeightToFee,
302-
>();
303-
304-
// check if estimated value is sane
305-
let max_expected = bp_bridge_hub_westend::BridgeHubWestendBaseXcmFeeInWnds::get();
306-
assert!(
307-
estimated <= max_expected,
308-
"calculated: {:?}, max_expected: {:?}, please adjust `bp_bridge_hub_westend::BridgeHubWestendBaseXcmFeeInWnds` value",
309-
estimated,
310-
max_expected
311-
);
306+
>()
307+
},
308+
Perbill::from_percent(33),
309+
Some(-33),
310+
&format!(
311+
"Estimate fee for `ExportMessage` for runtime: {:?}",
312+
<Runtime as frame_system::Config>::Version::get()
313+
),
314+
)
312315
}
313316

314317
#[test]
315318
pub fn can_calculate_fee_for_complex_message_delivery_transaction() {
316-
let estimated = from_parachain::can_calculate_fee_for_complex_message_delivery_transaction::<
317-
RuntimeTestsAdapter,
318-
>(collator_session_keys(), construct_and_estimate_extrinsic_fee);
319-
320-
// check if estimated value is sane
321-
let max_expected = bp_bridge_hub_westend::BridgeHubWestendBaseDeliveryFeeInWnds::get();
322-
assert!(
323-
estimated <= max_expected,
324-
"calculated: {:?}, max_expected: {:?}, please adjust `bp_bridge_hub_westend::BridgeHubWestendBaseDeliveryFeeInWnds` value",
325-
estimated,
326-
max_expected
327-
);
319+
bridge_hub_test_utils::check_sane_fees_values(
320+
"bp_bridge_hub_westend::BridgeHubWestendBaseDeliveryFeeInWnds",
321+
bp_bridge_hub_westend::BridgeHubWestendBaseDeliveryFeeInWnds::get(),
322+
|| {
323+
from_parachain::can_calculate_fee_for_complex_message_delivery_transaction::<
324+
RuntimeTestsAdapter,
325+
>(collator_session_keys(), construct_and_estimate_extrinsic_fee)
326+
},
327+
Perbill::from_percent(33),
328+
Some(-33),
329+
&format!(
330+
"Estimate fee for `single message delivery` for runtime: {:?}",
331+
<Runtime as frame_system::Config>::Version::get()
332+
),
333+
)
328334
}
329335

330336
#[test]
331337
pub fn can_calculate_fee_for_complex_message_confirmation_transaction() {
332-
let estimated = from_parachain::can_calculate_fee_for_complex_message_confirmation_transaction::<
333-
RuntimeTestsAdapter,
334-
>(collator_session_keys(), construct_and_estimate_extrinsic_fee);
335-
336-
// check if estimated value is sane
337-
let max_expected = bp_bridge_hub_westend::BridgeHubWestendBaseConfirmationFeeInWnds::get();
338-
assert!(
339-
estimated <= max_expected,
340-
"calculated: {:?}, max_expected: {:?}, please adjust `bp_bridge_hub_westend::BridgeHubWestendBaseConfirmationFeeInWnds` value",
341-
estimated,
342-
max_expected
343-
);
338+
bridge_hub_test_utils::check_sane_fees_values(
339+
"bp_bridge_hub_westend::BridgeHubWestendBaseConfirmationFeeInWnds",
340+
bp_bridge_hub_westend::BridgeHubWestendBaseConfirmationFeeInWnds::get(),
341+
|| {
342+
from_parachain::can_calculate_fee_for_complex_message_confirmation_transaction::<
343+
RuntimeTestsAdapter,
344+
>(collator_session_keys(), construct_and_estimate_extrinsic_fee)
345+
},
346+
Perbill::from_percent(33),
347+
Some(-33),
348+
&format!(
349+
"Estimate fee for `single message confirmation` for runtime: {:?}",
350+
<Runtime as frame_system::Config>::Version::get()
351+
),
352+
)
344353
}

0 commit comments

Comments
 (0)