Skip to content

Commit d41d01f

Browse files
yrongbkonturacatangiu
authored
Snowbridge: Remove snowbridge-pallet-system::NativeToForeignId (#730)
Co-authored-by: Branislav Kontur <[email protected]> Co-authored-by: Adrian Catangiu <[email protected]>
1 parent 356837c commit d41d01f

File tree

3 files changed

+128
-7
lines changed

3 files changed

+128
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1010

1111
- Slash and disable lazy and spammy validators as part of the new validator disabling strategy ([SDK #6827](https://github.com/paritytech/polkadot-sdk/pull/6827), [polkadot-fellows/runtimes/pull/782](https://github.com/polkadot-fellows/runtimes/pull/782))
1212
- Switch to UpToLimitWithReEnablingDisablingStrategy (Polkadot & Kusama) which always prioritises highest offenders for disabling instead of stopping when limit is reached ([polkadot-fellows/runtimes/pull/781](https://github.com/polkadot-fellows/runtimes/pull/781))
13+
- Snowbridge: Remove `snowbridge-pallet-system::NativeToForeignId` which is unused. ([#730](https://github.com/polkadot-fellows/runtimes/pull/730))
1314

1415
## [1.6.0] 19.06.2025
1516

@@ -24,7 +25,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2425
- [[#711](https://github.com/polkadot-fellows/runtimes/pull/711)] Pallet-broker: add extrinsic to remove a lease ([SDK stable2503 #7026](https://github.com/paritytech/polkadot-sdk/pull/7026)).
2526
- [[#711](https://github.com/polkadot-fellows/runtimes/pull/711)] Pallet-broker: add extrinsic to remove an assignment ([SDK stable2503 #7080](https://github.com/paritytech/polkadot-sdk/pull/7080)).
2627
- [[#711](https://github.com/polkadot-fellows/runtimes/pull/711)] Pallet-broker: add extrinsic to reserve a system core without having to wait two sale boundaries ([SDK stable2503 #4273](https://github.com/paritytech/polkadot-sdk/pull/4273)).
27-
2828
- [[#755](https://github.com/polkadot-fellows/runtimes/pull/755)] Added `pallet_revive` to Kusama AssetHub.
2929

3030
### Changed

system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ pub type UncheckedExtrinsic =
143143
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
144144

145145
parameter_types! {
146-
pub const BridgeKusamaMessagesPalletName: &'static str = "BridgeKusamaMessages";
147-
pub const OutboundLanesCongestedSignalsKey: &'static str = "OutboundLanesCongestedSignals";
146+
pub const EthereumSystemPalletName: &'static str = "EthereumSystem";
147+
pub const NativeToForeignIdKey: &'static str = "NativeToForeignId";
148148
}
149149

150150
/// Migrations to apply on runtime upgrade.
@@ -154,7 +154,11 @@ pub type Migrations = (
154154
Runtime,
155155
bridge_to_kusama_config::XcmOverBridgeHubKusamaInstance,
156156
>,
157-
snowbridge_pallet_system::migration::FeePerGasMigrationV0ToV1<Runtime>,
157+
frame_support::migrations::RemoveStorage<
158+
EthereumSystemPalletName,
159+
NativeToForeignIdKey,
160+
RocksDbWeight,
161+
>,
158162
pallet_session::migrations::v1::MigrateV0ToV1<
159163
Runtime,
160164
pallet_session::migrations::v1::InitOffenceSeverity<Runtime>,

system-parachains/bridge-hubs/bridge-hub-polkadot/tests/snowbridge.rs

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,35 @@
1616

1717
#![cfg(test)]
1818

19+
use bp_bridge_hub_polkadot::{snowbridge::EthereumLocation, BRIDGE_HUB_POLKADOT_PARACHAIN_ID};
1920
use bp_polkadot_core::Signature;
2021
use bridge_hub_polkadot_runtime::{
2122
bridge_to_ethereum_config::{EthereumGatewayAddress, EthereumNetwork},
2223
bridge_to_kusama_config::OnBridgeHubPolkadotRefundBridgeHubKusamaMessages,
23-
xcm_config::{GovernanceLocation, XcmConfig, XcmFeeManagerFromComponentsBridgeHub},
24+
xcm_config::{
25+
GovernanceLocation, UniversalLocation, XcmConfig, XcmFeeManagerFromComponentsBridgeHub,
26+
},
2427
AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages, Executive,
2528
MessageQueueServiceWeight, Runtime, RuntimeCall, RuntimeEvent, SessionKeys, TxExtension,
2629
UncheckedExtrinsic,
2730
};
2831
use bridge_hub_test_utils::GovernanceOrigin;
2932
use codec::{Decode, Encode};
30-
use cumulus_primitives_core::XcmError::{FailedToTransactAsset, TooExpensive};
33+
use cumulus_primitives_core::{
34+
ParaId,
35+
XcmError::{FailedToTransactAsset, TooExpensive},
36+
};
3137
use frame_support::{
3238
assert_err, assert_ok, parameter_types,
3339
traits::{fungible::Mutate, Contains},
3440
};
41+
use hex_literal::hex;
3542
use parachains_common::{AccountId, AuraId, Balance};
3643
pub use parachains_runtimes_test_utils::test_cases::change_storage_constant_by_governance_works;
3744
use parachains_runtimes_test_utils::{
3845
AccountIdOf, BalanceOf, CollatorSessionKeys, ExtBuilder, ValidatorIdOf,
3946
};
47+
use snowbridge_core::{TokenId, TokenIdOf};
4048
use snowbridge_pallet_ethereum_client::WeightInfo;
4149
use snowbridge_pallet_ethereum_client_fixtures::*;
4250
use sp_core::{Get, H160};
@@ -47,7 +55,8 @@ use sp_runtime::{
4755
};
4856
use xcm::latest::prelude::*;
4957
use xcm_builder::HandleFee;
50-
use xcm_executor::traits::{FeeManager, FeeReason};
58+
use xcm_executor::traits::{ConvertLocation, FeeManager, FeeReason};
59+
5160
parameter_types! {
5261
pub const DefaultBridgeHubEthereumBaseFee: Balance = 3_833_568_200_000;
5362
}
@@ -416,3 +425,111 @@ fn construct_and_apply_extrinsic(
416425
let r = Executive::apply_extrinsic(xt);
417426
r.unwrap()
418427
}
428+
429+
// Check compatibility for `token_id` stored on ethereum. If this test starts to fail, the [TokenIdOf](https://github.com/paritytech/polkadot-sdk/blob/20510c488198e8ee72b241fd2d0f6d1784982734/bridges/snowbridge/primitives/core/src/location.rs#L38-L43)
430+
// converter should be updated to ensure the generated token ID remains consistent and unchanged.
431+
#[test]
432+
fn check_compatibility_for_token_id_stored_on_ethereum() {
433+
pub struct RegisterTokenTestCase {
434+
/// Input: Location of Polkadot-native token relative to BH
435+
pub native: Location,
436+
/// Output: Reanchored, canonicalized location
437+
pub reanchored: Location,
438+
/// Output: Stable hash of reanchored location
439+
pub foreign: TokenId,
440+
}
441+
let test_cases = vec![
442+
// DOT
443+
RegisterTokenTestCase {
444+
native: Location::parent(),
445+
reanchored: Location::new(1, GlobalConsensus(Polkadot)),
446+
foreign: hex!("4e241583d94b5d48a27a22064cd49b2ed6f5231d2d950e432f9b7c2e0ade52b2")
447+
.into(),
448+
},
449+
// KSM
450+
RegisterTokenTestCase {
451+
native: Location::new(2, [GlobalConsensus(Kusama)]),
452+
reanchored: Location::new(1, [GlobalConsensus(Kusama)]),
453+
foreign: hex!("03b6054d0c576dd8391e34e1609cf398f68050c23009d19ce93c000922bcd852")
454+
.into(),
455+
},
456+
// PINK
457+
RegisterTokenTestCase {
458+
native: Location::new(1, [Parachain(1000), PalletInstance(50), GeneralIndex(23)]),
459+
reanchored: Location::new(
460+
1,
461+
[GlobalConsensus(Polkadot), Parachain(1000), PalletInstance(50), GeneralIndex(23)],
462+
),
463+
foreign: hex!("bc8785969587ef3d22739d3385cb519a9e0133dd5da8d320c376772468c19be6")
464+
.into(),
465+
},
466+
// TEER
467+
RegisterTokenTestCase {
468+
native: Location::new(1, [Parachain(2039)]),
469+
reanchored: Location::new(1, [GlobalConsensus(Polkadot), Parachain(2039)]),
470+
foreign: hex!("3b7f577715347bdcde4739a1bf1a7f1dec71e8ff4dbe23a6a49348ebf920c658")
471+
.into(),
472+
},
473+
// Hydration
474+
RegisterTokenTestCase {
475+
native: Location::new(1, [Parachain(2034), GeneralIndex(0)]),
476+
reanchored: Location::new(
477+
1,
478+
[GlobalConsensus(Polkadot), Parachain(2034), GeneralIndex(0)],
479+
),
480+
foreign: hex!("d5678e3bb6486c4fef73dc109cf23d5648654edd4b41fb32e1ce9f9a984a3d59")
481+
.into(),
482+
},
483+
// Voucher DOT
484+
RegisterTokenTestCase {
485+
native: Location::new(
486+
1,
487+
[
488+
Parachain(2030),
489+
GeneralKey {
490+
length: 2,
491+
data: hex!(
492+
"0900000000000000000000000000000000000000000000000000000000000000"
493+
),
494+
},
495+
],
496+
),
497+
reanchored: Location::new(
498+
1,
499+
[
500+
GlobalConsensus(Polkadot),
501+
Parachain(2030),
502+
GeneralKey {
503+
length: 2,
504+
data: hex!(
505+
"0900000000000000000000000000000000000000000000000000000000000000"
506+
),
507+
},
508+
],
509+
),
510+
foreign: hex!("2a8080362874bbfeb585d676eba3f06e3b878d7c5d5f98d2a092ebb375bd484c")
511+
.into(),
512+
},
513+
];
514+
for tc in test_cases.iter() {
515+
ExtBuilder::<Runtime>::default()
516+
.with_collators(collator_session_keys().collators())
517+
.with_session_keys(collator_session_keys().session_keys())
518+
.with_para_id(ParaId::from(BRIDGE_HUB_POLKADOT_PARACHAIN_ID))
519+
.with_tracing()
520+
.build()
521+
.execute_with(|| {
522+
let ethereum_location = EthereumLocation::get();
523+
// reanchor to Ethereum context
524+
let location = tc
525+
.native
526+
.clone()
527+
.reanchored(&ethereum_location, &UniversalLocation::get())
528+
.unwrap();
529+
assert_eq!(location, tc.reanchored);
530+
531+
let token_id = TokenIdOf::convert_location(&location).unwrap();
532+
assert_eq!(token_id, tc.foreign);
533+
})
534+
}
535+
}

0 commit comments

Comments
 (0)