From 668b8913f6437d82d84d23969ae3559ad43c5eef Mon Sep 17 00:00:00 2001 From: Clara van Staden Date: Tue, 28 Nov 2023 07:46:46 +0200 Subject: [PATCH 1/6] Revert template parachain changes (#43) * use penpal parachain instead of template parachain * update smoke tests * removes log --------- Co-authored-by: claravanstaden --- Cargo.lock | 3 -- .../parachain-template/node/src/chain_spec.rs | 8 ++-- .../pallets/template/Cargo.toml | 7 ---- .../pallets/template/src/lib.rs | 37 +------------------ 4 files changed, 5 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 680b246480e8..44629722defd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10899,15 +10899,12 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "pallet-xcm", "parity-scale-codec", "scale-info", "serde", "sp-core", "sp-io", "sp-runtime", - "sp-std 8.0.0", - "staging-xcm", ] [[package]] diff --git a/cumulus/parachain-template/node/src/chain_spec.rs b/cumulus/parachain-template/node/src/chain_spec.rs index da0660506850..a79c78699c07 100644 --- a/cumulus/parachain-template/node/src/chain_spec.rs +++ b/cumulus/parachain-template/node/src/chain_spec.rs @@ -73,7 +73,7 @@ pub fn development_config() -> ChainSpec { Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: 1001, + para_id: 1000, }, ) .with_name("Development") @@ -106,7 +106,7 @@ pub fn development_config() -> ChainSpec { get_account_id_from_seed::("Ferdie//stash"), ], get_account_id_from_seed::("Alice"), - 1001.into(), + 1000.into(), )) .build() } @@ -125,7 +125,7 @@ pub fn local_testnet_config() -> ChainSpec { Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: 1001, + para_id: 1000, }, ) .with_name("Local Testnet") @@ -158,7 +158,7 @@ pub fn local_testnet_config() -> ChainSpec { get_account_id_from_seed::("Ferdie//stash"), ], get_account_id_from_seed::("Alice"), - 1001.into(), + 1000.into(), )) .with_protocol_id("template-local") .with_properties(properties) diff --git a/cumulus/parachain-template/pallets/template/Cargo.toml b/cumulus/parachain-template/pallets/template/Cargo.toml index 1f53ff50e81a..925457839348 100644 --- a/cumulus/parachain-template/pallets/template/Cargo.toml +++ b/cumulus/parachain-template/pallets/template/Cargo.toml @@ -19,10 +19,6 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive frame-benchmarking = { path = "../../../../substrate/frame/benchmarking", default-features = false, optional = true} frame-support = { path = "../../../../substrate/frame/support", default-features = false} frame-system = { path = "../../../../substrate/frame/system", default-features = false} -sp-std = { path = "../../../../substrate/primitives/std", default-features = false} - -pallet-xcm = { path = "../../../../polkadot/xcm/pallet-xcm", default-features = false} -xcm = { package = "staging-xcm", path = "../../../../polkadot/xcm", default-features = false} [dev-dependencies] serde = { version = "1.0.188" } @@ -49,9 +45,6 @@ std = [ "sp-core/std", "sp-io/std", "sp-runtime/std", - "sp-std/std", - "pallet-xcm/std", - "xcm/std", ] try-runtime = [ "frame-support/try-runtime", diff --git a/cumulus/parachain-template/pallets/template/src/lib.rs b/cumulus/parachain-template/pallets/template/src/lib.rs index 911896d15d40..5f3252bfc3a7 100644 --- a/cumulus/parachain-template/pallets/template/src/lib.rs +++ b/cumulus/parachain-template/pallets/template/src/lib.rs @@ -18,12 +18,10 @@ mod benchmarking; pub mod pallet { use frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::*}; use frame_system::pallet_prelude::*; - use sp_std::boxed::Box; - use xcm::{v3::prelude::*, VersionedMultiLocation, VersionedXcm}; /// Configure the pallet by specifying the parameters and types on which it depends. #[pallet::config] - pub trait Config: frame_system::Config + pallet_xcm::Config { + pub trait Config: frame_system::Config { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; } @@ -47,8 +45,6 @@ pub mod pallet { /// Event documentation should end with an array that provides descriptive names for event /// parameters. [something, who] SomethingStored(u32, T::AccountId), - /// XCM message sent. \[to, message\] - Sent { from: T::AccountId, to: MultiLocation, message: Xcm<()> }, } // Errors inform users that something went wrong. @@ -58,15 +54,6 @@ pub mod pallet { NoneValue, /// Errors should have helpful documentation associated with them. StorageOverflow, - /// The message and destination combination was not recognized as being - /// reachable. - Unreachable, - /// The message and destination was recognized as being reachable but - /// the operation could not be completed. - SendFailure, - /// The version of the `Versioned` value used is not able to be - /// interpreted. - BadVersion, } #[pallet::hooks] @@ -115,27 +102,5 @@ pub mod pallet { }, } } - - /// Send an XCM message as parachain sovereign. - #[pallet::call_index(2)] - #[pallet::weight(Weight::from_parts(100_000_000, 0))] - pub fn send_xcm( - origin: OriginFor, - dest: Box, - message: Box>, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - let dest = MultiLocation::try_from(*dest).map_err(|()| Error::::BadVersion)?; - let message: Xcm<()> = (*message).try_into().map_err(|()| Error::::BadVersion)?; - - pallet_xcm::Pallet::::send_xcm(Here, dest, message.clone()).map_err( - |e| match e { - SendError::Unroutable => Error::::Unreachable, - _ => Error::::SendFailure, - }, - )?; - Self::deposit_event(Event::Sent { from: who, to: dest, message }); - Ok(()) - } } } From aa29476ec3abb8c6e6f01f0a4d8b22bbc0333f95 Mon Sep 17 00:00:00 2001 From: Clara van Staden Date: Tue, 28 Nov 2023 08:51:50 +0200 Subject: [PATCH 2/6] Updates pallet indices in integration tests (#45) * updates pallet indices in integration tests * fix test * fmt --------- Co-authored-by: claravanstaden --- .../bridge-hub-rococo/src/tests/snowbridge.rs | 93 +++++++++---------- 1 file changed, 42 insertions(+), 51 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index 5fdd7db17e69..21e63e81eb8b 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -31,6 +31,21 @@ const TREASURY_ACCOUNT: [u8; 32] = const WETH: [u8; 20] = hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d"); const ETHEREUM_DESTINATION_ADDRESS: [u8; 20] = hex!("44a57ee2f2FCcb85FDa2B0B18EBD0D8D2333700e"); +#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] +pub enum ControlCall { + #[codec(index = 2)] + CreateAgent, + #[codec(index = 3)] + CreateChannel { mode: OperatingMode, outbound_fee: u128 }, +} + +#[allow(clippy::large_enum_variant)] +#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] +pub enum SnowbridgeControl { + #[codec(index = 83)] + Control(ControlCall), +} + #[test] fn create_agent() { let origin_para: u32 = 1001; @@ -46,13 +61,15 @@ fn create_agent() { let sudo_origin = ::RuntimeOrigin::root(); let destination = Rococo::child_location_of(BridgeHubRococo::para_id()).into(); + let create_agent_call = SnowbridgeControl::Control(ControlCall::CreateAgent {}); + let remote_xcm = VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit: Unlimited, check_origin: None }, DescendOrigin(X1(Parachain(origin_para))), Transact { require_weight_at_most: 3000000000.into(), origin_kind: OriginKind::Xcm, - call: vec![63, 2].into(), + call: create_agent_call.encode().into(), }, ])); @@ -89,19 +106,6 @@ fn create_agent() { }); } -#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] -pub enum CreateChannelCall { - #[codec(index = 3)] - CreateChannel { mode: OperatingMode, outbound_fee: u128 }, -} - -#[allow(clippy::large_enum_variant)] -#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] -pub enum SnowbridgeControl { - #[codec(index = 63)] - Control(CreateChannelCall), -} - #[test] fn create_channel() { let origin_para: u32 = 1001; @@ -117,17 +121,19 @@ fn create_channel() { let destination: VersionedMultiLocation = Rococo::child_location_of(BridgeHubRococo::para_id()).into(); + let create_agent_call = SnowbridgeControl::Control(ControlCall::CreateAgent {}); + let create_agent_xcm = VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit: Unlimited, check_origin: None }, DescendOrigin(X1(Parachain(origin_para))), Transact { require_weight_at_most: 3000000000.into(), origin_kind: OriginKind::Xcm, - call: vec![63, 2].into(), + call: create_agent_call.encode().into(), }, ])); - let create_channel_call = SnowbridgeControl::Control(CreateChannelCall::CreateChannel { + let create_channel_call = SnowbridgeControl::Control(ControlCall::CreateChannel { mode: OperatingMode::Normal, outbound_fee: 1, }); @@ -226,33 +232,23 @@ fn register_token() { #[test] fn send_token_to_penpal() { - let asset_hub_sovereign = BridgeHubRococo::sovereign_account_id_of( - MultiLocation { - parents: 1, - interior: X1(Parachain(ASSETHUB_PARA_ID)), - } - ); - BridgeHubRococo::fund_accounts(vec![( - asset_hub_sovereign.clone(), - INITIAL_FUND, - )]); + let asset_hub_sovereign = BridgeHubRococo::sovereign_account_id_of(MultiLocation { + parents: 1, + interior: X1(Parachain(ASSETHUB_PARA_ID)), + }); + BridgeHubRococo::fund_accounts(vec![(asset_hub_sovereign.clone(), INITIAL_FUND)]); // Fund ethereum sovereign in asset hub - AssetHubRococo::fund_accounts(vec![ - (AssetHubRococoReceiver::get(), INITIAL_FUND), - ]); + AssetHubRococo::fund_accounts(vec![(AssetHubRococoReceiver::get(), INITIAL_FUND)]); PenpalA::fund_accounts(vec![ (PenpalAReceiver::get(), INITIAL_FUND), (PenpalASender::get(), INITIAL_FUND), ]); - let weth_asset_id: MultiLocation = ( - Parent, - Parent, - Ethereum { chain_id: 15 }, - AccountKey20 { network: None, key: WETH } - ).into(); + let weth_asset_id: MultiLocation = + (Parent, Parent, Ethereum { chain_id: 15 }, AccountKey20 { network: None, key: WETH }) + .into(); // Create asset on penpal. PenpalA::execute_with(|| { @@ -282,7 +278,10 @@ fn send_token_to_penpal() { chain_id: CHAIN_ID, command: Command::SendToken { token: WETH.into(), - destination: Destination::ForeignAccountId32 { para_id: 2000, id: PenpalAReceiver::get().into() }, + destination: Destination::ForeignAccountId32 { + para_id: 2000, + id: PenpalAReceiver::get().into(), + }, amount: 1_000_000_000, }, }); @@ -332,9 +331,7 @@ fn send_token() { )]); // Fund ethereum sovereign in asset hub - AssetHubRococo::fund_accounts(vec![ - (AssetHubRococoReceiver::get(), INITIAL_FUND), - ]); + AssetHubRococo::fund_accounts(vec![(AssetHubRococoReceiver::get(), INITIAL_FUND)]); let message_id_: H256 = [1; 32].into(); @@ -381,20 +378,14 @@ fn send_token() { #[test] fn reserve_transfer_token() { - let assethub_sovereign = BridgeHubRococo::sovereign_account_id_of( - MultiLocation { - parents: 1, - interior: X1(Parachain(ASSETHUB_PARA_ID)), - } - ); + let assethub_sovereign = BridgeHubRococo::sovereign_account_id_of(MultiLocation { + parents: 1, + interior: X1(Parachain(ASSETHUB_PARA_ID)), + }); - BridgeHubRococo::fund_accounts(vec![ - (assethub_sovereign.clone(), INITIAL_FUND) - ]); + BridgeHubRococo::fund_accounts(vec![(assethub_sovereign.clone(), INITIAL_FUND)]); - AssetHubRococo::fund_accounts(vec![ - (AssetHubRococoReceiver::get(), INITIAL_FUND), - ]); + AssetHubRococo::fund_accounts(vec![(AssetHubRococoReceiver::get(), INITIAL_FUND)]); const WETH_AMOUNT: u128 = 1_000_000_000; let message_id_: H256 = [1; 32].into(); From 771e43cbf117ab21814300246e9fb9e2cf4baa99 Mon Sep 17 00:00:00 2001 From: Clara van Staden Date: Tue, 28 Nov 2023 09:01:35 +0200 Subject: [PATCH 3/6] move asset hub fee config to xcm config (#41) Co-authored-by: claravanstaden --- cumulus/parachains/common/src/snowbridge_config.rs | 9 --------- .../runtimes/assets/asset-hub-rococo/src/xcm_config.rs | 7 ++++++- 2 files changed, 6 insertions(+), 10 deletions(-) delete mode 100644 cumulus/parachains/common/src/snowbridge_config.rs diff --git a/cumulus/parachains/common/src/snowbridge_config.rs b/cumulus/parachains/common/src/snowbridge_config.rs deleted file mode 100644 index 1e957d4cd291..000000000000 --- a/cumulus/parachains/common/src/snowbridge_config.rs +++ /dev/null @@ -1,9 +0,0 @@ -frame_support::parameter_types! { - /// User fee for ERC20 token transfer back to Ethereum. - /// (initially was calculated by test `OutboundQueue::calculate_fees` - ETH/ROC 1/400 and fee_per_gas 20 GWEI = 2200698000000 + *25%) - /// Needs to be more than fee calculated from DefaultFeeConfig FeeConfigRecord in snowbridge:parachain/pallets/outbound-queue/src/lib.rs - /// Polkadot uses 12 decimals, Kusama and Rococo 10 decimals. - pub const BridgeHubEthereumBaseFeeInDOT: u128 = 27_508_725_000; - pub const BridgeHubEthereumBaseFeeInKSM: u128 = 2_750_872_500_000; - pub const BridgeHubEthereumBaseFeeInRocs: u128 = 2_750_872_500_000; -} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index dc4651882c50..2ce8dbe9871c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -851,6 +851,11 @@ pub mod bridging { parameter_types! { pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 }; pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get()))); + /// User fee for ERC20 token transfer back to Ethereum. + /// (initially was calculated by test `OutboundQueue::calculate_fees` - ETH/ROC 1/400 and fee_per_gas 20 GWEI = 2200698000000 + *25%) + /// Needs to be more than fee calculated from DefaultFeeConfig FeeConfigRecord in snowbridge:parachain/pallets/outbound-queue/src/lib.rs + /// Polkadot uses 12 decimals, Kusama and Rococo 10 decimals. + pub const BridgeHubEthereumBaseFeeInROC: u128 = 2_750_872_500_000; /// Set up exporters configuration. /// `Option` represents static "base fee" which is used for total delivery fee calculation. @@ -863,7 +868,7 @@ pub mod bridging { SiblingBridgeHub::get(), Some(( XcmBridgeHubRouterFeeAssetId::get(), - BridgeHubEthereumBaseFeeInRocs::get(), + BridgeHubEthereumBaseFeeInROC::get(), ).into()) ), ]; From 91d6e274b9f2aefe90a0bc2ff9287fb3d75f2b9a Mon Sep 17 00:00:00 2001 From: Clara van Staden Date: Tue, 28 Nov 2023 10:26:42 +0200 Subject: [PATCH 4/6] Update aggregate message origin (#38) * update aggregate message origin * fix imports * fmt * revert non-rococo changes * adds log * Fix compile error & breaking tests (#39) * westend needs the same config * revert log * add test back in * revert fmt * Fix breaking test --------- Co-authored-by: claravanstaden Co-authored-by: Ron --- Cargo.lock | 8 +- .../bridges/bridge-hub-rococo/Cargo.toml | 1 + .../bridges/bridge-hub-rococo/src/lib.rs | 2 +- .../bridges/bridge-hub-westend/Cargo.toml | 1 + .../bridges/bridge-hub-westend/src/lib.rs | 2 +- .../bridges/bridge-hub-rococo/Cargo.toml | 2 + .../bridges/bridge-hub-rococo/src/lib.rs | 12 ++- .../bridge-hub-rococo/src/tests/snowbridge.rs | 35 ++++-- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 7 +- .../bridge-hubs/bridge-hub-westend/Cargo.toml | 3 + .../bridge-hubs/bridge-hub-westend/src/lib.rs | 7 +- .../runtimes/bridge-hubs/common/Cargo.toml | 7 +- .../runtimes/bridge-hubs/common/src/lib.rs | 2 +- .../bridge-hubs/common/src/message_queue.rs | 101 +++++++++++++++++- .../runtimes/testing/penpal/src/lib.rs | 1 - cumulus/primitives/core/src/lib.rs | 7 -- cumulus/xcm/xcm-emulator/src/lib.rs | 18 ++-- 17 files changed, 170 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 44629722defd..c9b2265c1923 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2153,6 +2153,7 @@ dependencies = [ "pallet-message-queue", "parity-scale-codec", "scale-info", + "snowbridge-core", "sp-runtime", "sp-std 8.0.0", "staging-xcm", @@ -2292,6 +2293,7 @@ dependencies = [ name = "bridge-hub-rococo-emulated-chain" version = "0.0.0" dependencies = [ + "bridge-hub-common", "bridge-hub-rococo-runtime", "cumulus-primitives-core", "emulated-integration-tests-common", @@ -2330,6 +2332,8 @@ dependencies = [ "parachains-common", "parity-scale-codec", "penpal-emulated-chain", + "penpal-runtime", + "rococo-system-emulated-network", "rococo-westend-system-emulated-network", "scale-info", "snowbridge-control", @@ -2485,6 +2489,7 @@ dependencies = [ name = "bridge-hub-westend-emulated-chain" version = "0.0.0" dependencies = [ + "bridge-hub-common", "bridge-hub-westend-runtime", "cumulus-primitives-core", "emulated-integration-tests-common", @@ -2533,6 +2538,7 @@ dependencies = [ "bp-rococo", "bp-runtime", "bp-westend", + "bridge-hub-common", "bridge-hub-test-utils", "bridge-runtime-common", "cumulus-pallet-aura-ext", @@ -17708,7 +17714,7 @@ dependencies = [ name = "snowbridge-outbound-queue" version = "0.1.1" dependencies = [ - "cumulus-primitives-core", + "bridge-hub-common", "ethabi-decode", "frame-benchmarking", "frame-support", diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/Cargo.toml index 0efb2b199c1c..9ccc6b5ec335 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/Cargo.toml @@ -22,6 +22,7 @@ parachains-common = { path = "../../../../../../../parachains/common" } cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false } emulated-integration-tests-common = { path = "../../../../common", default-features = false } bridge-hub-rococo-runtime = { path = "../../../../../../runtimes/bridge-hubs/bridge-hub-rococo" } +bridge-hub-common = { path = "../../../../../../runtimes/bridge-hubs/common", default-features = false } # Snowbridge snowbridge-core = { path = "../../../../../../../../../parachain/primitives/core", default-features = false } diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/lib.rs index 595329e85bb6..6eb14969eda9 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/lib.rs @@ -36,7 +36,7 @@ decl_test_parachains! { XcmpMessageHandler: bridge_hub_rococo_runtime::XcmpQueue, LocationToAccountId: bridge_hub_rococo_runtime::xcm_config::LocationToAccountId, ParachainInfo: bridge_hub_rococo_runtime::ParachainInfo, - MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin, + MessageOrigin: bridge_hub_common::AggregateMessageOrigin, }, pallets = { PolkadotXcm: bridge_hub_rococo_runtime::PolkadotXcm, diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/Cargo.toml b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/Cargo.toml index e5e6fd707393..191388e5f6df 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/Cargo.toml @@ -22,3 +22,4 @@ parachains-common = { path = "../../../../../../../parachains/common" } cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false } emulated-integration-tests-common = { path = "../../../../common", default-features = false } bridge-hub-westend-runtime = { path = "../../../../../../runtimes/bridge-hubs/bridge-hub-westend" } +bridge-hub-common = { path = "../../../../../../runtimes/bridge-hubs/common", default-features = false } diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs index bb3536154f2e..dd1a2d835641 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs @@ -36,7 +36,7 @@ decl_test_parachains! { XcmpMessageHandler: bridge_hub_westend_runtime::XcmpQueue, LocationToAccountId: bridge_hub_westend_runtime::xcm_config::LocationToAccountId, ParachainInfo: bridge_hub_westend_runtime::ParachainInfo, - MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin, + MessageOrigin: bridge_hub_common::AggregateMessageOrigin, }, pallets = { PolkadotXcm: bridge_hub_westend_runtime::PolkadotXcm, diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml index 4866f2c3188c..24d1f1308b42 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml @@ -40,6 +40,8 @@ rococo-westend-system-emulated-network = { path = "../../../networks/rococo-west bridge-hub-rococo-emulated-chain = { path = "../../../chains/parachains/bridges/bridge-hub-rococo"} asset-hub-rococo-emulated-chain = { path = "../../../chains/parachains/assets/asset-hub-rococo"} penpal-emulated-chain = { path = "../../../chains/parachains/testing/penpal" } +penpal-runtime = { path = "../../../../../runtimes/testing/penpal" } +rococo-system-emulated-network ={ path = "../../../networks/rococo-system" } # Snowbridge snowbridge-core = { path = "../../../../../../../../parachain/primitives/core", default-features = false } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs index 86cf8e68d40d..b78cb140c3d6 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs @@ -41,6 +41,11 @@ pub use emulated_integration_tests_common::{ PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, }; pub use parachains_common::{AccountId, Balance}; +pub use rococo_system_emulated_network::{ + penpal_emulated_chain::PenpalAParaPallet as PenpalAPallet, + BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, PenpalAPara as PenpalA, + PenpalAParaReceiver as PenpalAReceiver, PenpalAParaSender as PenpalASender, +}; pub use rococo_westend_system_emulated_network::{ asset_hub_rococo_emulated_chain::{ genesis::ED as ASSET_HUB_ROCOCO_ED, AssetHubRococoParaPallet as AssetHubRococoPallet, @@ -51,16 +56,13 @@ pub use rococo_westend_system_emulated_network::{ bridge_hub_rococo_emulated_chain::{ genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubRococoParaPallet as BridgeHubRococoPallet, }, - penpal_emulated_chain::PenpalAParaPallet as PenpalAPallet, rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet}, AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver, AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWestendPara as AssetHubWestend, AssetHubWestendParaReceiver as AssetHubWestendReceiver, BridgeHubRococoPara as BridgeHubRococo, - BridgeHubRococoParaReceiver as BridgeHubRococoReceiver, BridgeHubRococoParaSender as BridgeHubRococoSender, BridgeHubWestendPara as BridgeHubWestend, - PenpalAPara as PenpalA, PenpalAParaReceiver as PenpalAReceiver, - PenpalAParaSender as PenpalASender, RococoRelay as Rococo, - RococoRelayReceiver as RococoReceiver, RococoRelaySender as RococoSender, + RococoRelay as Rococo, RococoRelayReceiver as RococoReceiver, + RococoRelaySender as RococoSender, }; pub const ASSET_ID: u32 = 1; diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs index 21e63e81eb8b..2849ca6045ca 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs @@ -238,17 +238,36 @@ fn send_token_to_penpal() { }); BridgeHubRococo::fund_accounts(vec![(asset_hub_sovereign.clone(), INITIAL_FUND)]); - // Fund ethereum sovereign in asset hub - AssetHubRococo::fund_accounts(vec![(AssetHubRococoReceiver::get(), INITIAL_FUND)]); - PenpalA::fund_accounts(vec![ (PenpalAReceiver::get(), INITIAL_FUND), (PenpalASender::get(), INITIAL_FUND), ]); - let weth_asset_id: MultiLocation = + let weth_asset_location: MultiLocation = (Parent, Parent, Ethereum { chain_id: 15 }, AccountKey20 { network: None, key: WETH }) .into(); + let weth_asset_id = weth_asset_location.into(); + + let origin_location = + MultiLocation { parents: 2, interior: weth_asset_location.interior.split_last().0 }; + + // Fund ethereum sovereign in asset hub + let ethereum_sovereign: AccountId = + hex!("da4d66c3651dc151264eee5460493210338e41a7bbfca91a520e438daf180bf5").into(); + AssetHubRococo::fund_accounts(vec![(ethereum_sovereign.clone(), INITIAL_FUND)]); + // Create asset on assethub. + AssetHubRococo::execute_with(|| { + assert_ok!(::ForeignAssets::create( + pallet_xcm::Origin::Xcm(origin_location).into(), + weth_asset_id, + asset_hub_sovereign.clone().into(), + 1000, + )); + + assert!(::ForeignAssets::asset_exists( + weth_asset_id + )); + }); // Create asset on penpal. PenpalA::execute_with(|| { @@ -259,7 +278,7 @@ fn send_token_to_penpal() { 1000, )); - //assert!(::Assets::asset_exists(weth_asset_id)); + assert!(::ForeignAssets::asset_exists(weth_asset_id)); }); let message_id_: H256 = [1; 32].into(); @@ -268,12 +287,6 @@ fn send_token_to_penpal() { type RuntimeEvent = ::RuntimeEvent; type EthereumInboundQueue = ::EthereumInboundQueue; - let message = VersionedMessage::V1(MessageV1 { - chain_id: CHAIN_ID, - command: Command::RegisterToken { token: WETH.into() }, - }); - let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap(); - let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap(); let message = VersionedMessage::V1(MessageV1 { chain_id: CHAIN_ID, command: Command::SendToken { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 38d009359aed..0cb2ae9a307f 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -50,7 +50,7 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use cumulus_primitives_core::ParaId; use frame_support::{ construct_runtime, dispatch::DispatchClass, @@ -65,8 +65,11 @@ use frame_system::{ EnsureRoot, }; +use bridge_hub_common::{ + message_queue::{NarrowOriginToSibling, ParaIdToSibling}, + AggregateMessageOrigin, +}; use pallet_xcm::EnsureXcm; -use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm::VersionedMultiLocation; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml index 7e384126ab67..297fa2d7b038 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml @@ -91,6 +91,7 @@ pallet-bridge-messages = { path = "../../../../../bridges/modules/messages", def pallet-bridge-parachains = { path = "../../../../../bridges/modules/parachains", default-features = false } pallet-bridge-relayers = { path = "../../../../../bridges/modules/relayers", default-features = false } bridge-runtime-common = { path = "../../../../../bridges/bin/runtime-common", default-features = false } +bridge-hub-common = { path = "../../bridge-hubs/common", default-features = false } [dev-dependencies] static_assertions = "1.1" @@ -173,6 +174,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "bridge-hub-common/std", ] runtime-benchmarks = [ @@ -205,6 +207,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", + "bridge-hub-common/runtime-benchmarks", ] try-runtime = [ diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 9e8fd84e7125..90702e95533e 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -33,8 +33,7 @@ mod weights; pub mod xcm_config; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; -use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; -use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; +use cumulus_primitives_core::ParaId; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -49,6 +48,10 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; +use bridge_hub_common::{ + message_queue::{NarrowOriginToSibling, ParaIdToSibling}, + AggregateMessageOrigin, +}; use frame_support::{ construct_runtime, dispatch::DispatchClass, diff --git a/cumulus/parachains/runtimes/bridge-hubs/common/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/common/Cargo.toml index 46405f16dd5a..cb45735bbdcd 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/common/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/common/Cargo.toml @@ -15,6 +15,7 @@ sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-fea cumulus-primitives-core = { path = "../../../../primitives/core", default-features = false } xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false} pallet-message-queue = { path = "../../../../../substrate/frame/message-queue", default-features = false} +snowbridge-core = { path = "../../../../../../parachain/primitives/core", default-features = false } [features] default = [ "std" ] @@ -26,12 +27,14 @@ std = [ "sp-runtime/std", "cumulus-primitives-core/std", "xcm/std", - "pallet-message-queue/std" + "pallet-message-queue/std", + "snowbridge-core/std" ] runtime-benchmarks = [ "frame-support/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "sp-runtime/runtime-benchmarks", - "pallet-message-queue/runtime-benchmarks" + "pallet-message-queue/runtime-benchmarks", + "snowbridge-core/runtime-benchmarks" ] diff --git a/cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs index 58e6264d1b70..eb02498448a1 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs @@ -16,4 +16,4 @@ pub mod message_queue; -pub use message_queue::BridgeHubMessageRouter; +pub use message_queue::{AggregateMessageOrigin, BridgeHubMessageRouter}; diff --git a/cumulus/parachains/runtimes/bridge-hubs/common/src/message_queue.rs b/cumulus/parachains/runtimes/bridge-hubs/common/src/message_queue.rs index 3d53d985af1d..15b12ee785b8 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/common/src/message_queue.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/common/src/message_queue.rs @@ -13,17 +13,78 @@ // See the License for the specific language governing permissions and // limitations under the License. //! Runtime configuration for MessageQueue pallet -use cumulus_primitives_core::AggregateMessageOrigin; +use codec::{Decode, Encode, MaxEncodedLen}; +use cumulus_primitives_core::{AggregateMessageOrigin as CumulusAggregateMessageOrigin, ParaId}; use frame_support::{ - traits::{ProcessMessage, ProcessMessageError}, + traits::{ProcessMessage, ProcessMessageError, QueueFootprint, QueuePausedQuery}, weights::WeightMeter, }; -use sp_std::marker::PhantomData; +use pallet_message_queue::OnQueueChanged; +use scale_info::TypeInfo; +use snowbridge_core::ChannelId; +use sp_std::{marker::PhantomData, prelude::*}; +use xcm::v3::{Junction, MultiLocation}; + +/// The aggregate origin of an inbound message. +/// This is specialized for BridgeHub, as the snowbridge-outbound-queue pallet is also using +/// the shared MessageQueue pallet. +#[derive(Encode, Decode, Copy, MaxEncodedLen, Clone, Eq, PartialEq, TypeInfo, Debug)] +pub enum AggregateMessageOrigin { + /// The message came from the para-chain itself. + Here, + /// The message came from the relay-chain. + /// + /// This is used by the DMP queue. + Parent, + /// The message came from a sibling para-chain. + /// + /// This is used by the HRMP queue. + Sibling(ParaId), + Snowbridge(ChannelId), +} + +impl From for MultiLocation { + fn from(origin: AggregateMessageOrigin) -> Self { + use AggregateMessageOrigin::*; + match origin { + Here => MultiLocation::here(), + Parent => MultiLocation::parent(), + Sibling(id) => MultiLocation::new(1, Junction::Parachain(id.into())), + // NOTE: We don't need this conversion for Snowbridge. However we have to + // implement it anyway as xcm_builder::ProcessXcmMessage requires it. + Snowbridge(_) => MultiLocation::default(), + } + } +} + +impl From for AggregateMessageOrigin { + fn from(origin: CumulusAggregateMessageOrigin) -> Self { + match origin { + CumulusAggregateMessageOrigin::Here => Self::Here, + CumulusAggregateMessageOrigin::Parent => Self::Parent, + CumulusAggregateMessageOrigin::Sibling(id) => Self::Sibling(id), + } + } +} + +#[cfg(feature = "runtime-benchmarks")] +impl From for AggregateMessageOrigin { + fn from(x: u32) -> Self { + match x { + 0 => Self::Here, + 1 => Self::Parent, + p => Self::Sibling(ParaId::from(p)), + } + } +} /// Routes messages to either the XCMP or Snowbridge processor. pub struct BridgeHubMessageRouter( PhantomData<(XcmpProcessor, SnowbridgeProcessor)>, -); +) +where + XcmpProcessor: ProcessMessage, + SnowbridgeProcessor: ProcessMessage; impl ProcessMessage for BridgeHubMessageRouter @@ -43,7 +104,37 @@ where match origin { Here | Parent | Sibling(_) => XcmpProcessor::process_message(message, origin, meter, id), - GeneralKey(_) => SnowbridgeProcessor::process_message(message, origin, meter, id), + Snowbridge(_) => SnowbridgeProcessor::process_message(message, origin, meter, id), + } + } +} + +pub struct NarrowOriginToSibling(PhantomData); +impl> QueuePausedQuery + for NarrowOriginToSibling +{ + fn is_paused(origin: &AggregateMessageOrigin) -> bool { + match origin { + AggregateMessageOrigin::Sibling(id) => Inner::is_paused(id), + _ => false, } } } + +impl> OnQueueChanged + for NarrowOriginToSibling +{ + fn on_queue_changed(origin: AggregateMessageOrigin, fp: QueueFootprint) { + if let AggregateMessageOrigin::Sibling(id) = origin { + Inner::on_queue_changed(id, fp) + } + } +} + +/// Convert a sibling `ParaId` to an `AggregateMessageOrigin`. +pub struct ParaIdToSibling; +impl sp_runtime::traits::Convert for ParaIdToSibling { + fn convert(para_id: ParaId) -> AggregateMessageOrigin { + AggregateMessageOrigin::Sibling(para_id) + } +} diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 7e2992d832c0..09d236b717d7 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -458,7 +458,6 @@ impl pallet_assets::Config for Runtime { type BenchmarkHelper = (); } - parameter_types! { // we just reuse the same deposits pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get(); diff --git a/cumulus/primitives/core/src/lib.rs b/cumulus/primitives/core/src/lib.rs index 2f972203ab54..835c9de649ea 100644 --- a/cumulus/primitives/core/src/lib.rs +++ b/cumulus/primitives/core/src/lib.rs @@ -91,11 +91,6 @@ pub enum AggregateMessageOrigin { /// /// This is used by the HRMP queue. Sibling(ParaId), - /// The message came from some origin identified by a 32-byte ID. - /// - /// Due to its generality, this is can be used by pallets - /// other than the DMP and HRMP queue. - GeneralKey([u8; 32]), } impl From for xcm::v3::MultiLocation { @@ -105,8 +100,6 @@ impl From for xcm::v3::MultiLocation { AggregateMessageOrigin::Parent => MultiLocation::parent(), AggregateMessageOrigin::Sibling(id) => MultiLocation::new(1, Junction::Parachain(id.into())), - AggregateMessageOrigin::GeneralKey(id) => - MultiLocation::new(0, Junction::GeneralKey { length: 32, data: id }), } } } diff --git a/cumulus/xcm/xcm-emulator/src/lib.rs b/cumulus/xcm/xcm-emulator/src/lib.rs index 1ad4cd05b74e..f5c6b88adce5 100644 --- a/cumulus/xcm/xcm-emulator/src/lib.rs +++ b/cumulus/xcm/xcm-emulator/src/lib.rs @@ -245,7 +245,7 @@ pub trait Parachain: Chain { type LocationToAccountId: ConvertLocation>; type ParachainInfo: Get; type ParachainSystem; - type MessageProcessor: ProcessMessage + ServiceQueues; + type MessageProcessor: ProcessMessage + ServiceQueues; fn init(); @@ -1007,7 +1007,7 @@ macro_rules! decl_test_networks { <$parachain>::ext_wrapper(|| { let _ = <$parachain as Parachain>::MessageProcessor::process_message( &msg[..], - $crate::CumulusAggregateMessageOrigin::Parent, + $crate::CumulusAggregateMessageOrigin::Parent.into(), &mut weight_meter, &mut msg.using_encoded($crate::blake2_256), ); @@ -1317,11 +1317,16 @@ pub struct DefaultParaMessageProcessor(PhantomData<(T, M)>); // Process HRMP messages from sibling paraids impl ProcessMessage for DefaultParaMessageProcessor where - M: codec::FullCodec + MaxEncodedLen + Clone + Eq + PartialEq + frame_support::pallet_prelude::TypeInfo + Debug, + M: codec::FullCodec + + MaxEncodedLen + + Clone + + Eq + + PartialEq + + frame_support::pallet_prelude::TypeInfo + + Debug, T: Parachain, T::Runtime: MessageQueueConfig, - <::MessageProcessor as ProcessMessage>::Origin: - PartialEq, + <::MessageProcessor as ProcessMessage>::Origin: PartialEq, MessageQueuePallet: EnqueueMessage + ServiceQueues, { type Origin = M; @@ -1346,8 +1351,7 @@ where M: MaxEncodedLen, T: Parachain, T::Runtime: MessageQueueConfig, - <::MessageProcessor as ProcessMessage>::Origin: - PartialEq, + <::MessageProcessor as ProcessMessage>::Origin: PartialEq, MessageQueuePallet: EnqueueMessage + ServiceQueues, { type OverweightMessageAddress = (); From 1b09ac88f8e2c42893451cdd5a2c5e436d894d04 Mon Sep 17 00:00:00 2001 From: Clara van Staden Date: Tue, 28 Nov 2023 10:45:37 +0200 Subject: [PATCH 5/6] remove old mod (#46) Co-authored-by: claravanstaden --- cumulus/parachains/common/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cumulus/parachains/common/src/lib.rs b/cumulus/parachains/common/src/lib.rs index db5ca402f62f..68425a00b358 100644 --- a/cumulus/parachains/common/src/lib.rs +++ b/cumulus/parachains/common/src/lib.rs @@ -20,7 +20,6 @@ pub mod kusama; pub mod message_queue; pub mod polkadot; pub mod rococo; -pub mod snowbridge_config; pub mod westend; pub mod wococo; pub mod xcm_config; From 42537e8239fbfc06be1511c211d9c0393fbd6d27 Mon Sep 17 00:00:00 2001 From: Clara van Staden Date: Tue, 28 Nov 2023 11:50:27 +0200 Subject: [PATCH 6/6] removes old config (#47) Co-authored-by: claravanstaden --- .../runtimes/assets/asset-hub-rococo/src/xcm_config.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs index 2ce8dbe9871c..8be6b7517da3 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs @@ -31,7 +31,6 @@ use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use parachains_common::{ impls::ToStakingPot, - snowbridge_config::BridgeHubEthereumBaseFeeInRocs, xcm_config::{ AssetFeeAsExistentialDepositMultiplier, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,