From f732431b170d40508f26c5abdb3fd4e42cab1e16 Mon Sep 17 00:00:00 2001 From: ron Date: Fri, 4 Aug 2023 12:39:08 +0800 Subject: [PATCH 1/9] Update weight --- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 4 +- .../src/weights/snowbridge_control.rs | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 9c9e5797bda..89a0a314c88 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -691,10 +691,10 @@ impl snowbridge_control::Config for Runtime { type RelayLocation = RelayLocation; #[cfg(feature = "runtime-benchmarks")] - type CreateAgentOrigin = EnsureXcmOrigin; + type ControlOrigin = EnsureXcmOrigin; #[cfg(not(feature = "runtime-benchmarks"))] - type CreateAgentOrigin = EnsureXcm; + type ControlOrigin = EnsureXcm; } // Create the runtime by composing the FRAME pallets that were previously configured. diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_control.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_control.rs index ca0480834b3..5f679d24ddf 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_control.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_control.rs @@ -79,4 +79,49 @@ impl snowbridge_control::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(4)) } + + /// Todo: update with benchmarked + fn create_channel() -> Weight { + // Proof Size summary in bytes: + // Measured: `84` + // Estimated: `3517` + // Minimum execution time: 34_000_000 picoseconds. + Weight::from_parts(35_000_000, 0) + .saturating_add(Weight::from_parts(0, 3517)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + + fn update_channel() -> Weight { + // Proof Size summary in bytes: + // Measured: `84` + // Estimated: `3517` + // Minimum execution time: 34_000_000 picoseconds. + Weight::from_parts(35_000_000, 0) + .saturating_add(Weight::from_parts(0, 3517)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + + fn set_operating_mode() -> Weight { + // Proof Size summary in bytes: + // Measured: `84` + // Estimated: `3517` + // Minimum execution time: 34_000_000 picoseconds. + Weight::from_parts(35_000_000, 0) + .saturating_add(Weight::from_parts(0, 3517)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } + + fn transfer_native_from_agent() -> Weight { + // Proof Size summary in bytes: + // Measured: `84` + // Estimated: `3517` + // Minimum execution time: 34_000_000 picoseconds. + Weight::from_parts(35_000_000, 0) + .saturating_add(Weight::from_parts(0, 3517)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) + } } From 7e2efe0bba74e736383c643baf5ac4a334a9f598 Mon Sep 17 00:00:00 2001 From: ron Date: Sun, 6 Aug 2023 11:04:43 +0800 Subject: [PATCH 2/9] Update cumulus --- .../bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 9 +++------ polkadot-parachain/src/chain_spec/asset_hubs.rs | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index f99cafa9da7..623c7b1cffe 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -217,12 +217,9 @@ impl Contains for SafeCallFilter { | snowbridge_inbound_queue::Call::set_gateway { .. } | snowbridge_inbound_queue::Call::set_operating_mode { .. }, ) | RuntimeCall::EthereumOutboundQueue( - snowbridge_outbound_queue::Call::set_owner { .. } - | snowbridge_outbound_queue::Call::set_operating_mode { .. }, - ) | RuntimeCall::EthereumControl( - snowbridge_control::Call::upgrade { .. } - | snowbridge_control::Call::create_agent { .. }, - ) + snowbridge_outbound_queue::Call::set_owner { .. } | + snowbridge_outbound_queue::Call::set_operating_mode { .. }, + ) | RuntimeCall::EthereumControl(..) ) } } diff --git a/polkadot-parachain/src/chain_spec/asset_hubs.rs b/polkadot-parachain/src/chain_spec/asset_hubs.rs index 9188431bdf5..d79fbc1e839 100644 --- a/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -517,7 +517,7 @@ pub fn asset_hub_westend_local_config() -> AssetHubWestendChainSpec { get_account_id_from_seed::("Eve//stash"), get_account_id_from_seed::("Ferdie//stash"), ], - 1000.into(), + 1001.into(), ) }, Vec::new(), From e5b6f2e9a7f08e88521cebd34510b553e0fb4cd1 Mon Sep 17 00:00:00 2001 From: ron Date: Thu, 10 Aug 2023 20:36:12 +0800 Subject: [PATCH 3/9] Update chain spec --- parachain-template/node/src/chain_spec.rs | 2 +- polkadot-parachain/src/chain_spec/asset_hubs.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/parachain-template/node/src/chain_spec.rs b/parachain-template/node/src/chain_spec.rs index b37468f184e..811812fb0d7 100644 --- a/parachain-template/node/src/chain_spec.rs +++ b/parachain-template/node/src/chain_spec.rs @@ -172,7 +172,7 @@ pub fn local_testnet_config() -> ChainSpec { // Extensions Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: 1000, + para_id: 1001, }, ) } diff --git a/polkadot-parachain/src/chain_spec/asset_hubs.rs b/polkadot-parachain/src/chain_spec/asset_hubs.rs index d79fbc1e839..9188431bdf5 100644 --- a/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -517,7 +517,7 @@ pub fn asset_hub_westend_local_config() -> AssetHubWestendChainSpec { get_account_id_from_seed::("Eve//stash"), get_account_id_from_seed::("Ferdie//stash"), ], - 1001.into(), + 1000.into(), ) }, Vec::new(), From f6df91be55dbfc88d3a9be294f9099a082e167e1 Mon Sep 17 00:00:00 2001 From: ron Date: Thu, 10 Aug 2023 22:07:03 +0800 Subject: [PATCH 4/9] Add extrinsic for xcm test --- Cargo.lock | 3 ++ .../pallets/template/Cargo.toml | 9 ++++- .../pallets/template/src/lib.rs | 37 ++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71d6eab4a6e..ac7cba187b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8078,12 +8078,15 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "pallet-xcm", "parity-scale-codec", "scale-info", "serde", "sp-core", "sp-io", "sp-runtime", + "sp-std", + "xcm", ] [[package]] diff --git a/parachain-template/pallets/template/Cargo.toml b/parachain-template/pallets/template/Cargo.toml index 1ccdc6622ba..1abe5394c57 100644 --- a/parachain-template/pallets/template/Cargo.toml +++ b/parachain-template/pallets/template/Cargo.toml @@ -19,6 +19,10 @@ scale-info = { version = "2.2.0", default-features = false, features = ["derive" frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "master" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" } + +pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "master" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false , branch = "master" } [dev-dependencies] serde = { version = "1.0.163" } @@ -37,5 +41,8 @@ std = [ "frame-benchmarking/std", "frame-support/std", "frame-system/std", + "sp-std/std", + "pallet-xcm/std", + "xcm/std", ] -try-runtime = [ "frame-support/try-runtime" ] +try-runtime = [ "frame-support/try-runtime", "pallet-xcm/try-runtime" ] diff --git a/parachain-template/pallets/template/src/lib.rs b/parachain-template/pallets/template/src/lib.rs index 5f3252bfc3a..911896d15d4 100644 --- a/parachain-template/pallets/template/src/lib.rs +++ b/parachain-template/pallets/template/src/lib.rs @@ -18,10 +18,12 @@ 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 { + pub trait Config: frame_system::Config + pallet_xcm::Config { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; } @@ -45,6 +47,8 @@ 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. @@ -54,6 +58,15 @@ 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] @@ -102,5 +115,27 @@ 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 492e29534e00dbd5d20a64f3fa042985febb984f Mon Sep 17 00:00:00 2001 From: ron Date: Sat, 19 Aug 2023 01:00:44 +0800 Subject: [PATCH 5/9] ControlOrigin allow from sibling only --- parachain-template/node/src/chain_spec.rs | 2 +- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 14 ++------------ .../bridge-hub-rococo/src/xcm_config.rs | 11 +++++++++++ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/parachain-template/node/src/chain_spec.rs b/parachain-template/node/src/chain_spec.rs index 811812fb0d7..187186ef234 100644 --- a/parachain-template/node/src/chain_spec.rs +++ b/parachain-template/node/src/chain_spec.rs @@ -156,7 +156,7 @@ pub fn local_testnet_config() -> ChainSpec { get_account_id_from_seed::("Eve//stash"), get_account_id_from_seed::("Ferdie//stash"), ], - 1000.into(), + 1001.into(), ) }, // Bootnodes diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 89a0a314c88..69c117b075a 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -55,10 +55,6 @@ use snowbridge_inbound_queue::BenchmarkHelper; use snowbridge_beacon_primitives::CompactExecutionHeader; #[cfg(feature = "runtime-benchmarks")] use sp_core::H256; -#[cfg(feature = "runtime-benchmarks")] -use xcm_builder::EnsureXcmOrigin; -#[cfg(feature = "runtime-benchmarks")] -use crate::xcm_config::LocalOriginToLocation; use frame_support::{ construct_runtime, @@ -73,7 +69,6 @@ use frame_system::{ EnsureRoot, }; -#[cfg(not(feature = "runtime-benchmarks"))] use pallet_xcm::EnsureXcm; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; @@ -100,7 +95,7 @@ use crate::{ WithBridgeHubRococoMessageBridge, }, constants::fee::WeightToFee, - xcm_config::XcmRouter, + xcm_config::{AllowSiblingsOnly, XcmRouter}, }; use bridge_runtime_common::{ messages::{source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter}, @@ -689,12 +684,7 @@ impl snowbridge_control::Config for Runtime { type AgentHashedDescription = AgentHashedDescription; type UniversalLocation = UniversalLocation; type RelayLocation = RelayLocation; - - #[cfg(feature = "runtime-benchmarks")] - type ControlOrigin = EnsureXcmOrigin; - - #[cfg(not(feature = "runtime-benchmarks"))] - type ControlOrigin = EnsureXcm; + type ControlOrigin = EnsureXcm; } // Create the runtime by composing the FRAME pallets that were previously configured. diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 623c7b1cffe..287fe2965ef 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -408,3 +408,14 @@ impl ExportXcm for BridgeHubRococoOrBridgeHubWococoSwitchExporter { } } } + +/// [`Contains`] implementation that allows multiLocation from sibling chains only +pub struct AllowSiblingsOnly; +impl Contains for AllowSiblingsOnly { + fn contains(l: &MultiLocation) -> bool { + match l { + MultiLocation { parents: 1, interior: X1(Parachain(_)) } => true, + _ => false, + } + } +} From d57a27c8545b22895b80cfa3ae279a4809b29069 Mon Sep 17 00:00:00 2001 From: ron Date: Sat, 19 Aug 2023 07:43:29 +0800 Subject: [PATCH 6/9] Allow any origin for agent operation --- parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 69c117b075a..aaec18c20c2 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -684,7 +684,8 @@ impl snowbridge_control::Config for Runtime { type AgentHashedDescription = AgentHashedDescription; type UniversalLocation = UniversalLocation; type RelayLocation = RelayLocation; - type ControlOrigin = EnsureXcm; + type AgentOrigin = EnsureXcm; + type ChannelOrigin = EnsureXcm; } // Create the runtime by composing the FRAME pallets that were previously configured. From 292a4fd3755527cea757613640aeec7efc4d7a42 Mon Sep 17 00:00:00 2001 From: claravanstaden Date: Fri, 1 Sep 2023 15:06:47 +0200 Subject: [PATCH 7/9] Test bridge transfer without params. --- parachains/pallets/bridge-transfer/src/lib.rs | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/parachains/pallets/bridge-transfer/src/lib.rs b/parachains/pallets/bridge-transfer/src/lib.rs index 12a91faa44b..12e00b44bff 100644 --- a/parachains/pallets/bridge-transfer/src/lib.rs +++ b/parachains/pallets/bridge-transfer/src/lib.rs @@ -182,28 +182,29 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::transfer_asset_via_bridge())] pub fn transfer_asset_via_bridge( origin: OriginFor, - assets: Box, - destination: Box, + //assets: Box, + //destination: Box, ) -> DispatchResult { // Check origin let origin_location = T::AssetTransferOrigin::ensure_origin(origin)?; // Check if remote destination is reachable - let destination = Self::ensure_reachable_remote_destination( - (*destination).try_into().map_err(|()| Error::::InvalidRemoteDestination)?, - )?; + //let destination = Self::ensure_reachable_remote_destination( + // (*destination).try_into().map_err(|()| Error::::InvalidRemoteDestination)?, + //)?; // Check assets (lets leave others checks on `AssetTransactor`) - let assets: MultiAssets = - (*assets).try_into().map_err(|()| Error::::InvalidAssets)?; - ensure!(assets.len() <= T::AssetsLimit::get() as usize, Error::::AssetsLimitReached); + //let assets: MultiAssets = + // (*assets).try_into().map_err(|()| Error::::InvalidAssets)?; + //ensure!(assets.len() <= T::AssetsLimit::get() as usize, Error::::AssetsLimitReached); // Do this in transaction (explicitly), the rollback should occur in case of any error and no assets will be trapped or lost - Self::initiate_transfer_asset_via_bridge_in_transaction( - origin_location, - destination, - assets, - ) + //Self::initiate_transfer_asset_via_bridge_in_transaction( + // origin_location, + // destination, + // assets, + //) + Ok(()) } } } From ec8ff0c606cf567a657469003b73b1991468c4df Mon Sep 17 00:00:00 2001 From: claravanstaden Date: Mon, 4 Sep 2023 14:39:24 +0200 Subject: [PATCH 8/9] Trying to get test to work --- .../pallets/bridge-transfer/src/impls.rs | 56 ++++++++++++++++++- parachains/pallets/bridge-transfer/src/lib.rs | 29 +++++----- .../pallets/bridge-transfer/src/tests.rs | 17 ++++++ .../assets/asset-hub-kusama/src/xcm_config.rs | 4 +- .../bridge-hub-rococo/src/xcm_config.rs | 12 ++++ 5 files changed, 100 insertions(+), 18 deletions(-) diff --git a/parachains/pallets/bridge-transfer/src/impls.rs b/parachains/pallets/bridge-transfer/src/impls.rs index 9eb0e6cfcac..2a3fdc12ed9 100644 --- a/parachains/pallets/bridge-transfer/src/impls.rs +++ b/parachains/pallets/bridge-transfer/src/impls.rs @@ -43,14 +43,66 @@ impl Pallet { pub(crate) fn ensure_reachable_remote_destination( remote_destination: MultiLocation, ) -> Result> { - let devolved = ensure_is_remote(T::UniversalLocation::get(), remote_destination) - .map_err(|_| Error::::UnsupportedDestination)?; + log::info!(target: LOG_TARGET, "Checking destination"); + let devolved = Self::ensure_is_remote(T::UniversalLocation::get(), remote_destination) + //let devolved = ensure_is_remote(T::UniversalLocation::get(), remote_destination) + .map_err(|e| { + log::error!(target: LOG_TARGET, "Is not global consenus: {:?}", e); + Error::::UnsupportedDestination + })?; let (remote_network, _) = devolved; T::BridgedDestinationValidator::ensure_destination(remote_network, remote_destination) .map_err(Into::into) } + pub(crate) fn ensure_is_remote( + universal_local: impl Into, + dest: impl Into, + ) -> Result<(NetworkId, InteriorMultiLocation), MultiLocation> { + let dest = dest.into(); + let universal_local = universal_local.into(); + log::info!(target: LOG_TARGET, "Checking local net"); + let local_net = match universal_local.global_consensus() { + Ok(x) => x, + Err(e) => { + log::info!(target: LOG_TARGET, "Error for checking local net is {:?}", e); + return Err(dest) + }, + }; + log::info!(target: LOG_TARGET, "Checking universal location. Local net is {:?}", local_net); + println!("universal_local {:?}", universal_local); + let universal_destination: InteriorMultiLocation = universal_local + .into_location() + .appended_with(dest) + .map_err(|x| { + log::info!(target: LOG_TARGET, "universal location error is {:?}", x); + x.1 + })? + .try_into()?; + let first_dest = universal_destination.split_first(); + log::info!(target: LOG_TARGET, "first destination: {:?}", first_dest); + log::info!(target: LOG_TARGET, "universal_destination: {:?}", universal_destination); + println!("universal_destination {:?}", universal_destination); + println!("first destination {:?}", first_dest); + let (remote_dest, remote_net) = match universal_destination.split_first() { + (d, Some(GlobalConsensus(n))) => { + log::info!(target: LOG_TARGET, "Checking condition: n != local_net"); + if n != local_net { + (d, n) + } else { + log::info!(target: LOG_TARGET, "Condition not met: n {:?} local net {:?}", n, local_net); + return Err(dest); + } + }, + _ => return { + log::info!(target: LOG_TARGET, "another error "); + return Err(dest); + }, + }; + Ok((remote_net, remote_dest)) + } + /// Tries to initiate transfer assets over bridge. #[transactional] pub(crate) fn initiate_transfer_asset_via_bridge_in_transaction( diff --git a/parachains/pallets/bridge-transfer/src/lib.rs b/parachains/pallets/bridge-transfer/src/lib.rs index 12e00b44bff..478323b3e88 100644 --- a/parachains/pallets/bridge-transfer/src/lib.rs +++ b/parachains/pallets/bridge-transfer/src/lib.rs @@ -182,29 +182,30 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::transfer_asset_via_bridge())] pub fn transfer_asset_via_bridge( origin: OriginFor, - //assets: Box, - //destination: Box, + assets: Box, + destination: Box, ) -> DispatchResult { // Check origin let origin_location = T::AssetTransferOrigin::ensure_origin(origin)?; + //log::info!(target: LOG_TARGET, "transfer_asset_via_bridge destination: {:?}", destination); + // Check if remote destination is reachable - //let destination = Self::ensure_reachable_remote_destination( - // (*destination).try_into().map_err(|()| Error::::InvalidRemoteDestination)?, - //)?; + let destination = Self::ensure_reachable_remote_destination( + (*destination).try_into().map_err(|()| Error::::InvalidRemoteDestination)?, + )?; // Check assets (lets leave others checks on `AssetTransactor`) - //let assets: MultiAssets = - // (*assets).try_into().map_err(|()| Error::::InvalidAssets)?; - //ensure!(assets.len() <= T::AssetsLimit::get() as usize, Error::::AssetsLimitReached); + let assets: MultiAssets = + (*assets).try_into().map_err(|()| Error::::InvalidAssets)?; + ensure!(assets.len() <= T::AssetsLimit::get() as usize, Error::::AssetsLimitReached); // Do this in transaction (explicitly), the rollback should occur in case of any error and no assets will be trapped or lost - //Self::initiate_transfer_asset_via_bridge_in_transaction( - // origin_location, - // destination, - // assets, - //) - Ok(()) + Self::initiate_transfer_asset_via_bridge_in_transaction( + origin_location, + destination, + assets, + ) } } } diff --git a/parachains/pallets/bridge-transfer/src/tests.rs b/parachains/pallets/bridge-transfer/src/tests.rs index 33ef185cd3b..fd87b34f5cc 100644 --- a/parachains/pallets/bridge-transfer/src/tests.rs +++ b/parachains/pallets/bridge-transfer/src/tests.rs @@ -371,6 +371,23 @@ fn test_ensure_reachable_remote_destination() { }) } +#[test] +fn test_ensure_reachable_remote_destination_ethereum() { + new_test_ext().execute_with(|| { + let bridged_network = BridgedNetwork::get(); + + let location = BridgeTransfer::ensure_reachable_remote_destination(MultiLocation::new( + 2, + X3( + GlobalConsensus(bridged_network), + Parachain(1000), + consensus_account(bridged_network, 35) + ) + ) + ).unwrap(); + }) +} + #[test] fn test_transfer_asset_via_bridge_for_currency_works() { new_test_ext().execute_with(|| { diff --git a/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs b/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs index 12ad726a544..52dcfa3d253 100644 --- a/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs +++ b/parachains/runtimes/assets/asset-hub-kusama/src/xcm_config.rs @@ -542,8 +542,8 @@ pub mod bridging { // The Registry contract for the bridge which is also the origin for reserves and the prefix of all assets. pub EthereumGatewayLocation: MultiLocation = EthereumLocation::get() .pushed_with_interior( - AccountKey20 { - network: None, + AccountKey20 { + network: None, key: hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"), } ).unwrap(); diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 287fe2965ef..48b497465bd 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -49,6 +49,7 @@ use xcm_executor::{ traits::{ExportXcm, WithOriginFilter}, XcmExecutor, }; +use xcm_executor::traits::{FeeManager, FeeReason}; parameter_types! { pub const RelayLocation: MultiLocation = MultiLocation::parent(); @@ -252,6 +253,17 @@ pub type Barrier = TrailingSetTopicAsId< >; pub struct XcmConfig; + +impl FeeManager for XcmConfig { + fn is_waived(origin: Option<&MultiLocation>, r: FeeReason) -> bool { + todo!() + } + + fn handle_fee(fee: MultiAssets) { + todo!() + } +} + impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; type XcmSender = XcmRouter; From 0c7df0f497896d1a58d346cc2d76d5945e2ce382 Mon Sep 17 00:00:00 2001 From: claravanstaden Date: Mon, 4 Sep 2023 16:22:13 +0200 Subject: [PATCH 9/9] test nearly works --- .../pallets/bridge-transfer/src/impls.rs | 50 +------------------ parachains/pallets/bridge-transfer/src/lib.rs | 2 - .../pallets/bridge-transfer/src/tests.rs | 17 ------- 3 files changed, 1 insertion(+), 68 deletions(-) diff --git a/parachains/pallets/bridge-transfer/src/impls.rs b/parachains/pallets/bridge-transfer/src/impls.rs index 2a3fdc12ed9..8f993482ab9 100644 --- a/parachains/pallets/bridge-transfer/src/impls.rs +++ b/parachains/pallets/bridge-transfer/src/impls.rs @@ -44,8 +44,7 @@ impl Pallet { remote_destination: MultiLocation, ) -> Result> { log::info!(target: LOG_TARGET, "Checking destination"); - let devolved = Self::ensure_is_remote(T::UniversalLocation::get(), remote_destination) - //let devolved = ensure_is_remote(T::UniversalLocation::get(), remote_destination) + let devolved = ensure_is_remote(T::UniversalLocation::get(), remote_destination) .map_err(|e| { log::error!(target: LOG_TARGET, "Is not global consenus: {:?}", e); Error::::UnsupportedDestination @@ -56,53 +55,6 @@ impl Pallet { .map_err(Into::into) } - pub(crate) fn ensure_is_remote( - universal_local: impl Into, - dest: impl Into, - ) -> Result<(NetworkId, InteriorMultiLocation), MultiLocation> { - let dest = dest.into(); - let universal_local = universal_local.into(); - log::info!(target: LOG_TARGET, "Checking local net"); - let local_net = match universal_local.global_consensus() { - Ok(x) => x, - Err(e) => { - log::info!(target: LOG_TARGET, "Error for checking local net is {:?}", e); - return Err(dest) - }, - }; - log::info!(target: LOG_TARGET, "Checking universal location. Local net is {:?}", local_net); - println!("universal_local {:?}", universal_local); - let universal_destination: InteriorMultiLocation = universal_local - .into_location() - .appended_with(dest) - .map_err(|x| { - log::info!(target: LOG_TARGET, "universal location error is {:?}", x); - x.1 - })? - .try_into()?; - let first_dest = universal_destination.split_first(); - log::info!(target: LOG_TARGET, "first destination: {:?}", first_dest); - log::info!(target: LOG_TARGET, "universal_destination: {:?}", universal_destination); - println!("universal_destination {:?}", universal_destination); - println!("first destination {:?}", first_dest); - let (remote_dest, remote_net) = match universal_destination.split_first() { - (d, Some(GlobalConsensus(n))) => { - log::info!(target: LOG_TARGET, "Checking condition: n != local_net"); - if n != local_net { - (d, n) - } else { - log::info!(target: LOG_TARGET, "Condition not met: n {:?} local net {:?}", n, local_net); - return Err(dest); - } - }, - _ => return { - log::info!(target: LOG_TARGET, "another error "); - return Err(dest); - }, - }; - Ok((remote_net, remote_dest)) - } - /// Tries to initiate transfer assets over bridge. #[transactional] pub(crate) fn initiate_transfer_asset_via_bridge_in_transaction( diff --git a/parachains/pallets/bridge-transfer/src/lib.rs b/parachains/pallets/bridge-transfer/src/lib.rs index 478323b3e88..12a91faa44b 100644 --- a/parachains/pallets/bridge-transfer/src/lib.rs +++ b/parachains/pallets/bridge-transfer/src/lib.rs @@ -188,8 +188,6 @@ pub mod pallet { // Check origin let origin_location = T::AssetTransferOrigin::ensure_origin(origin)?; - //log::info!(target: LOG_TARGET, "transfer_asset_via_bridge destination: {:?}", destination); - // Check if remote destination is reachable let destination = Self::ensure_reachable_remote_destination( (*destination).try_into().map_err(|()| Error::::InvalidRemoteDestination)?, diff --git a/parachains/pallets/bridge-transfer/src/tests.rs b/parachains/pallets/bridge-transfer/src/tests.rs index fd87b34f5cc..33ef185cd3b 100644 --- a/parachains/pallets/bridge-transfer/src/tests.rs +++ b/parachains/pallets/bridge-transfer/src/tests.rs @@ -371,23 +371,6 @@ fn test_ensure_reachable_remote_destination() { }) } -#[test] -fn test_ensure_reachable_remote_destination_ethereum() { - new_test_ext().execute_with(|| { - let bridged_network = BridgedNetwork::get(); - - let location = BridgeTransfer::ensure_reachable_remote_destination(MultiLocation::new( - 2, - X3( - GlobalConsensus(bridged_network), - Parachain(1000), - consensus_account(bridged_network, 35) - ) - ) - ).unwrap(); - }) -} - #[test] fn test_transfer_asset_via_bridge_for_currency_works() { new_test_ext().execute_with(|| {