Skip to content

Commit

Permalink
[XCMv5]Remove XCM testnet NetworkIds (#5390)
Browse files Browse the repository at this point in the history
# Context
Close #5241, for more detail, please refer to
[RFC0108](polkadot-fellows/RFCs#108)
# Changes
- Remove `Rococo` and `Westend` from `NetworkId`
* Add `Rococo Genesis Hash` and `Westend Genesis Hash`

---------

Co-authored-by: Nazar Mokrynskyi <nazar@mokrynskyi.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
  • Loading branch information
6 people authored Nov 1, 2024
1 parent 0eb726d commit e21773a
Show file tree
Hide file tree
Showing 62 changed files with 304 additions and 143 deletions.
4 changes: 2 additions & 2 deletions bridges/modules/xcm-bridge-hub/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use sp_runtime::{
AccountId32, BuildStorage, StateVersion,
};
use sp_std::cell::RefCell;
use xcm::prelude::*;
use xcm::{latest::ROCOCO_GENESIS_HASH, prelude::*};
use xcm_builder::{
AllowUnpaidExecutionFrom, DispatchBlob, DispatchBlobError, FixedWeightBounds,
InspectMessageQueues, NetworkExportTable, NetworkExportTableItem, ParentIsPreset,
Expand Down Expand Up @@ -160,7 +160,7 @@ parameter_types! {
pub BridgedRelayNetworkLocation: Location = (Parent, GlobalConsensus(BridgedRelayNetwork::get())).into();
pub BridgedRelativeDestination: InteriorLocation = [Parachain(BRIDGED_ASSET_HUB_ID)].into();
pub BridgedUniversalDestination: InteriorLocation = [GlobalConsensus(BridgedRelayNetwork::get()), Parachain(BRIDGED_ASSET_HUB_ID)].into();
pub const NonBridgedRelayNetwork: NetworkId = NetworkId::Rococo;
pub const NonBridgedRelayNetwork: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);

pub const BridgeDeposit: Balance = 100_000;

Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/messages/src/lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl TypeId for LegacyLaneId {
/// concatenation (separated by some binary data). I.e.:
///
/// ```nocompile
/// let endpoint1 = X2(GlobalConsensus(NetworkId::Rococo), Parachain(42));
/// let endpoint1 = X2(GlobalConsensus(NetworkId::ByGenesis(ROCOCO_GENESIS_HASH)), Parachain(42));
/// let endpoint2 = X2(GlobalConsensus(NetworkId::Wococo), Parachain(777));
///
/// let final_lane_key = if endpoint1 < endpoint2 {
Expand Down
3 changes: 2 additions & 1 deletion bridges/primitives/xcm-bridge-hub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,11 @@ impl BridgeLocations {
#[cfg(test)]
mod tests {
use super::*;
use xcm::latest::ROCOCO_GENESIS_HASH;

const LOCAL_NETWORK: NetworkId = Kusama;
const REMOTE_NETWORK: NetworkId = Polkadot;
const UNREACHABLE_NETWORK: NetworkId = Rococo;
const UNREACHABLE_NETWORK: NetworkId = NetworkId::ByGenesis(ROCOCO_GENESIS_HASH);
const SIBLING_PARACHAIN: u32 = 1000;
const LOCAL_BRIDGE_HUB: u32 = 1001;
const REMOTE_PARACHAIN: u32 = 2000;
Expand Down
2 changes: 1 addition & 1 deletion bridges/snowbridge/pallets/system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use sp_runtime::{
traits::{AccountIdConversion, BlakeTwo256, IdentityLookup, Keccak256},
AccountId32, BuildStorage, FixedU128,
};
use xcm::prelude::*;
use xcm::{latest::ROCOCO_GENESIS_HASH, prelude::*};

#[cfg(feature = "runtime-benchmarks")]
use crate::BenchmarkHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use emulated_integration_tests_common::{
};
use parachains_common::Balance;
use xcm::latest::prelude::*;
use xcm::latest::ROCOCO_GENESIS_HASH;

pub const PARA_ID: u32 = 1002;
pub const ASSETHUB_PARA_ID: u32 = 1000;
Expand Down Expand Up @@ -73,7 +74,7 @@ pub fn genesis() -> Storage {
// open AHW -> AHR bridge
(
Location::new(1, [Parachain(1000)]),
Junctions::from([Rococo.into(), Parachain(1000)]),
Junctions::from([NetworkId::ByGenesis(ROCOCO_GENESIS_HASH).into(), Parachain(1000)]),
Some(bp_messages::LegacyLaneId([0, 0, 0, 2])),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ use emulated_integration_tests_common::{
xcm_emulator::decl_test_parachains,
};

// Polkadot
use xcm::latest::{ROCOCO_GENESIS_HASH, WESTEND_GENESIS_HASH};

// Penpal Parachain declaration
decl_test_parachains! {
pub struct PenpalA {
Expand All @@ -39,7 +42,7 @@ decl_test_parachains! {
penpal_runtime::AuraExt::on_initialize(1);
frame_support::assert_ok!(penpal_runtime::System::set_storage(
penpal_runtime::RuntimeOrigin::root(),
vec![(PenpalRelayNetworkId::key().to_vec(), NetworkId::Rococo.encode())],
vec![(PenpalRelayNetworkId::key().to_vec(), NetworkId::ByGenesis(ROCOCO_GENESIS_HASH).encode())],
));
},
runtime = penpal_runtime,
Expand All @@ -63,7 +66,7 @@ decl_test_parachains! {
penpal_runtime::AuraExt::on_initialize(1);
frame_support::assert_ok!(penpal_runtime::System::set_storage(
penpal_runtime::RuntimeOrigin::root(),
vec![(PenpalRelayNetworkId::key().to_vec(), NetworkId::Westend.encode())],
vec![(PenpalRelayNetworkId::key().to_vec(), NetworkId::ByGenesis(WESTEND_GENESIS_HASH).encode())],
));
},
runtime = penpal_runtime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ mod imports {
};

// Polkadot
pub use xcm::prelude::{AccountId32 as AccountId32Junction, *};
pub use xcm::{
latest::{ROCOCO_GENESIS_HASH, WESTEND_GENESIS_HASH},
prelude::{AccountId32 as AccountId32Junction, *},
};
pub use xcm_executor::traits::TransferType;

// Cumulus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ fn assets_can_be_claimed() {
let amount = AssetHubRococoExistentialDeposit::get();
let assets: Assets = (Parent, amount).into();

test_chain_can_claim_assets!(AssetHubRococo, RuntimeCall, NetworkId::Rococo, assets, amount);
test_chain_can_claim_assets!(
AssetHubRococo,
RuntimeCall,
NetworkId::ByGenesis(ROCOCO_GENESIS_HASH),
assets,
amount
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
// Foreign asset used: bridged WND
let foreign_amount_to_send = ASSET_HUB_ROCOCO_ED * 10_000_000;
let wnd_at_rococo_parachains =
Location::new(2, [Junction::GlobalConsensus(NetworkId::Westend)]);
Location::new(2, [Junction::GlobalConsensus(NetworkId::ByGenesis(WESTEND_GENESIS_HASH))]);

// Configure destination chain to trust AH as reserve of WND
PenpalA::execute_with(|| {
assert_ok!(<PenpalA as Chain>::System::set_storage(
<PenpalA as Chain>::RuntimeOrigin::root(),
vec![(
PenpalCustomizableAssetFromSystemAssetHub::key().to_vec(),
Location::new(2, [GlobalConsensus(Westend)]).encode(),
Location::new(2, [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH))]).encode(),
)],
));
});
Expand Down Expand Up @@ -293,15 +293,15 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
// Foreign asset used: bridged WND
let foreign_amount_to_send = ASSET_HUB_ROCOCO_ED * 10_000_000;
let wnd_at_rococo_parachains =
Location::new(2, [Junction::GlobalConsensus(NetworkId::Westend)]);
Location::new(2, [Junction::GlobalConsensus(NetworkId::ByGenesis(WESTEND_GENESIS_HASH))]);

// Configure destination chain to trust AH as reserve of WND
PenpalA::execute_with(|| {
assert_ok!(<PenpalA as Chain>::System::set_storage(
<PenpalA as Chain>::RuntimeOrigin::root(),
vec![(
PenpalCustomizableAssetFromSystemAssetHub::key().to_vec(),
Location::new(2, [GlobalConsensus(Westend)]).encode(),
Location::new(2, [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH))]).encode(),
)],
));
});
Expand Down Expand Up @@ -464,14 +464,14 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
<PenpalB as Chain>::RuntimeOrigin::root(),
vec![(
PenpalCustomizableAssetFromSystemAssetHub::key().to_vec(),
Location::new(2, [GlobalConsensus(Westend)]).encode(),
Location::new(2, [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH))]).encode(),
)],
));
});

// Register WND as foreign asset and transfer it around the Rococo ecosystem
let wnd_at_rococo_parachains =
Location::new(2, [Junction::GlobalConsensus(NetworkId::Westend)]);
Location::new(2, [Junction::GlobalConsensus(NetworkId::ByGenesis(WESTEND_GENESIS_HASH))]);
AssetHubRococo::force_create_foreign_asset(
wnd_at_rococo_parachains.clone().try_into().unwrap(),
assets_owner.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod imports {

// Polkadot
pub use xcm::{
latest::AssetTransferFilter,
latest::{AssetTransferFilter, ROCOCO_GENESIS_HASH, WESTEND_GENESIS_HASH},
prelude::{AccountId32 as AccountId32Junction, *},
};
pub use xcm_executor::traits::TransferType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ fn assets_can_be_claimed() {
let amount = AssetHubWestendExistentialDeposit::get();
let assets: Assets = (Parent, amount).into();

test_chain_can_claim_assets!(AssetHubWestend, RuntimeCall, NetworkId::Westend, assets, amount);
test_chain_can_claim_assets!(
AssetHubWestend,
RuntimeCall,
NetworkId::ByGenesis(WESTEND_GENESIS_HASH),
assets,
amount
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ fn transfer_foreign_assets_from_asset_hub_to_para() {
// Foreign asset used: bridged ROC
let foreign_amount_to_send = ASSET_HUB_WESTEND_ED * 10_000_000;
let roc_at_westend_parachains =
Location::new(2, [Junction::GlobalConsensus(NetworkId::Rococo)]);
Location::new(2, [Junction::GlobalConsensus(NetworkId::ByGenesis(ROCOCO_GENESIS_HASH))]);

// Configure destination chain to trust AH as reserve of ROC
PenpalA::execute_with(|| {
assert_ok!(<PenpalA as Chain>::System::set_storage(
<PenpalA as Chain>::RuntimeOrigin::root(),
vec![(
PenpalCustomizableAssetFromSystemAssetHub::key().to_vec(),
Location::new(2, [GlobalConsensus(Rococo)]).encode(),
Location::new(2, [GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH))]).encode(),
)],
));
});
Expand Down Expand Up @@ -293,15 +293,15 @@ fn transfer_foreign_assets_from_para_to_asset_hub() {
// Foreign asset used: bridged ROC
let foreign_amount_to_send = ASSET_HUB_WESTEND_ED * 10_000_000;
let roc_at_westend_parachains =
Location::new(2, [Junction::GlobalConsensus(NetworkId::Rococo)]);
Location::new(2, [Junction::GlobalConsensus(NetworkId::ByGenesis(ROCOCO_GENESIS_HASH))]);

// Configure destination chain to trust AH as reserve of ROC
PenpalA::execute_with(|| {
assert_ok!(<PenpalA as Chain>::System::set_storage(
<PenpalA as Chain>::RuntimeOrigin::root(),
vec![(
PenpalCustomizableAssetFromSystemAssetHub::key().to_vec(),
Location::new(2, [GlobalConsensus(Rococo)]).encode(),
Location::new(2, [GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH))]).encode(),
)],
));
});
Expand Down Expand Up @@ -456,7 +456,7 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
<PenpalA as Chain>::RuntimeOrigin::root(),
vec![(
PenpalCustomizableAssetFromSystemAssetHub::key().to_vec(),
Location::new(2, [GlobalConsensus(Rococo)]).encode(),
Location::new(2, [GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH))]).encode(),
)],
));
});
Expand All @@ -465,14 +465,14 @@ fn transfer_foreign_assets_from_para_to_para_through_asset_hub() {
<PenpalB as Chain>::RuntimeOrigin::root(),
vec![(
PenpalCustomizableAssetFromSystemAssetHub::key().to_vec(),
Location::new(2, [GlobalConsensus(Rococo)]).encode(),
Location::new(2, [GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH))]).encode(),
)],
));
});

// Register ROC as foreign asset and transfer it around the Westend ecosystem
let roc_at_westend_parachains =
Location::new(2, [Junction::GlobalConsensus(NetworkId::Rococo)]);
Location::new(2, [Junction::GlobalConsensus(NetworkId::ByGenesis(ROCOCO_GENESIS_HASH))]);
AssetHubWestend::force_create_foreign_asset(
roc_at_westend_parachains.clone().try_into().unwrap(),
assets_owner.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn account_and_location(account: &str) -> (AccountId32, Location) {
let account_id = AssetHubWestend::account_id_of(account);
let account_clone = account_id.clone();
let location: Location =
[Junction::AccountId32 { network: Some(Westend), id: account_id.into() }].into();
[Junction::AccountId32 { network: Some(ByGenesis(WESTEND_GENESIS_HASH)), id: account_id.into() }].into();
(account_clone, location)
}

Expand All @@ -99,7 +99,7 @@ fn test_set_asset_claimer_between_the_chains() {
1,
[
Parachain(AssetHubWestend::para_id().into()),
Junction::AccountId32 { network: Some(Westend), id: alice.clone().into() },
Junction::AccountId32 { network: Some(ByGenesis(WESTEND_GENESIS_HASH)), id: alice.clone().into() },
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ mod imports {

// Polkadot
pub use xcm::{
latest::ParentThen,
latest::{ParentThen, ROCOCO_GENESIS_HASH, WESTEND_GENESIS_HASH},
prelude::{AccountId32 as AccountId32Junction, *},
v5::NetworkId::Westend as WestendId,
v5,
};
pub use xcm_executor::traits::TransferType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn send_assets_from_penpal_rococo_through_rococo_ah_to_westend_ah(
);
let sov_ahw_on_ahr =
AssetHubRococo::sovereign_account_of_parachain_on_other_global_consensus(
Westend,
ByGenesis(WESTEND_GENESIS_HASH),
AssetHubWestend::para_id(),
);
// send message over bridge
Expand Down Expand Up @@ -125,7 +125,7 @@ fn send_roc_from_asset_hub_rococo_to_asset_hub_westend() {
set_up_pool_with_wnd_on_ah_westend(bridged_roc_at_asset_hub_westend.clone(), true);

let sov_ahw_on_ahr = AssetHubRococo::sovereign_account_of_parachain_on_other_global_consensus(
Westend,
ByGenesis(WESTEND_GENESIS_HASH),
AssetHubWestend::para_id(),
);
let rocs_in_reserve_on_ahr_before =
Expand Down Expand Up @@ -199,7 +199,7 @@ fn send_back_wnds_usdt_and_weth_from_asset_hub_rococo_to_asset_hub_westend() {

// fund the AHR's SA on AHW with the WND tokens held in reserve
let sov_ahr_on_ahw = AssetHubWestend::sovereign_account_of_parachain_on_other_global_consensus(
Rococo,
ByGenesis(ROCOCO_GENESIS_HASH),
AssetHubRococo::para_id(),
);
AssetHubWestend::fund_accounts(vec![(sov_ahr_on_ahw.clone(), prefund_amount)]);
Expand Down Expand Up @@ -357,7 +357,7 @@ fn send_rocs_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_westend()
set_up_rocs_for_penpal_rococo_through_ahr_to_ahw(&sender, amount);

let sov_ahw_on_ahr = AssetHubRococo::sovereign_account_of_parachain_on_other_global_consensus(
Westend,
ByGenesis(WESTEND_GENESIS_HASH),
AssetHubWestend::para_id(),
);
let rocs_in_reserve_on_ahr_before =
Expand Down Expand Up @@ -463,7 +463,7 @@ fn send_back_wnds_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_weste

// fund the AHR's SA on AHW with the WND tokens held in reserve
let sov_ahr_on_ahw = AssetHubWestend::sovereign_account_of_parachain_on_other_global_consensus(
NetworkId::Rococo,
NetworkId::ByGenesis(ROCOCO_GENESIS_HASH),
AssetHubRococo::para_id(),
);
AssetHubWestend::fund_accounts(vec![(sov_ahr_on_ahw.clone(), amount * 2)]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ fn assets_can_be_claimed() {
let amount = BridgeHubRococoExistentialDeposit::get();
let assets: Assets = (Parent, amount).into();

test_chain_can_claim_assets!(AssetHubRococo, RuntimeCall, NetworkId::Rococo, assets, amount);
test_chain_can_claim_assets!(
AssetHubRococo,
RuntimeCall,
NetworkId::ByGenesis(ROCOCO_GENESIS_HASH),
assets,
amount
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,38 @@ mod snowbridge;
mod teleport;

pub(crate) fn asset_hub_westend_location() -> Location {
Location::new(2, [GlobalConsensus(Westend), Parachain(AssetHubWestend::para_id().into())])
Location::new(
2,
[
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(AssetHubWestend::para_id().into()),
],
)
}
pub(crate) fn bridge_hub_westend_location() -> Location {
Location::new(2, [GlobalConsensus(Westend), Parachain(BridgeHubWestend::para_id().into())])
Location::new(
2,
[
GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)),
Parachain(BridgeHubWestend::para_id().into()),
],
)
}

// ROC and wROC
pub(crate) fn roc_at_ah_rococo() -> Location {
Parent.into()
}
pub(crate) fn bridged_roc_at_ah_westend() -> Location {
Location::new(2, [GlobalConsensus(Rococo)])
Location::new(2, [GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH))])
}

// WND and wWND
pub(crate) fn wnd_at_ah_westend() -> Location {
Parent.into()
}
pub(crate) fn bridged_wnd_at_ah_rococo() -> Location {
Location::new(2, [GlobalConsensus(Westend)])
Location::new(2, [GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH))])
}

// USDT and wUSDT
Expand All @@ -54,8 +66,8 @@ pub(crate) fn bridged_usdt_at_ah_rococo() -> Location {
Location::new(
2,
[
GlobalConsensus(Westend),
Parachain(AssetHubWestend::para_id().into()),
GlobalConsensus(ByGenesis(ROCOCO_GENESIS_HASH)),
Parachain(AssetHubRococo::para_id().into()),
PalletInstance(ASSETS_PALLET_ID),
GeneralIndex(USDT_ID.into()),
],
Expand Down
Loading

0 comments on commit e21773a

Please sign in to comment.