From 22506915c831174198e2358f81741eff58ac03fc Mon Sep 17 00:00:00 2001 From: ron Date: Mon, 27 Nov 2023 19:44:10 +0800 Subject: [PATCH 1/8] Fix compile error --- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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 b6ba07f2d9820..71e5ce95c11f5 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 @@ -44,7 +44,9 @@ pub mod xcm_config; use codec::{Decode, Encode}; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use snowbridge_beacon_primitives::{Fork, ForkVersions}; -use snowbridge_core::{outbound::Message, AgentId, AllowSiblingsOnly}; +use snowbridge_core::{ + gwei, meth, outbound::Message, AgentId, AllowSiblingsOnly, PricingParameters, Rewards, +}; use snowbridge_router_primitives::inbound::MessageToXcm; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160}; @@ -52,7 +54,7 @@ use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, Keccak256}, transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, + ApplyExtrinsicResult, FixedU128, }; use sp_std::prelude::*; @@ -527,7 +529,12 @@ parameter_types! { pub const CreateAssetCall: [u8;2] = [53, 0]; pub const CreateAssetExecutionFee: u128 = 2_000_000_000; pub const CreateAssetDeposit: u128 = (UNITS / 10) + EXISTENTIAL_DEPOSIT; - pub const SendTokenExecutionFee: u128 = 2_000_000_000; + pub Parameters: PricingParameters = PricingParameters { + exchange_rate: FixedU128::from_rational(1, 400), + fee_per_gas: gwei(20), + rewards: Rewards { local: 1 * UNITS, remote: meth(1) } + }; + pub const InboundDeliveryCost: u128 = 1_000_000_000; } #[cfg(feature = "runtime-benchmarks")] @@ -541,7 +548,6 @@ impl snowbridge_inbound_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Verifier = snowbridge_ethereum_beacon_client::Pallet; type Token = Balances; - type Reward = Reward; #[cfg(not(feature = "runtime-benchmarks"))] type XcmSender = XcmRouter; #[cfg(feature = "runtime-benchmarks")] @@ -554,12 +560,12 @@ impl snowbridge_inbound_queue::Config for Runtime { CreateAssetCall, CreateAssetExecutionFee, CreateAssetDeposit, - SendTokenExecutionFee, AccountId, Balance, >; type WeightToFee = WeightToFee; type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo; + type PricingParameters = Parameters; } impl snowbridge_outbound_queue::Config for Runtime { @@ -573,6 +579,7 @@ impl snowbridge_outbound_queue::Config for Runtime { type Balance = Balance; type WeightToFee = WeightToFee; type WeightInfo = weights::snowbridge_outbound_queue::WeightInfo; + type PricingParameters = Parameters; } #[cfg(not(feature = "beacon-spec-mainnet"))] @@ -645,6 +652,8 @@ impl snowbridge_control::Config for Runtime { type WeightInfo = weights::snowbridge_control::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type Helper = (); + type DefaultPricingParameters = Parameters; + type InboundDeliveryCost = InboundDeliveryCost; } // Create the runtime by composing the FRAME pallets that were previously configured. From 51cae29967b2ad479e5721159797f1e5ddbb0433 Mon Sep 17 00:00:00 2001 From: ron Date: Tue, 28 Nov 2023 12:23:37 +0800 Subject: [PATCH 2/8] Load PricingParameters from control --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 8c5a12da642c9..e7ceaa47bc790 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 @@ -542,7 +542,7 @@ impl snowbridge_inbound_queue::Config for Runtime { >; type WeightToFee = WeightToFee; type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo; - type PricingParameters = Parameters; + type PricingParameters = EthereumControl; } impl snowbridge_outbound_queue::Config for Runtime { @@ -556,7 +556,7 @@ impl snowbridge_outbound_queue::Config for Runtime { type Balance = Balance; type WeightToFee = WeightToFee; type WeightInfo = weights::snowbridge_outbound_queue::WeightInfo; - type PricingParameters = Parameters; + type PricingParameters = EthereumControl; } #[cfg(not(feature = "beacon-spec-mainnet"))] From eec6f38c8fb14ea96f2630477b074ad381b92c2a Mon Sep 17 00:00:00 2001 From: ron Date: Tue, 28 Nov 2023 12:55:33 +0800 Subject: [PATCH 3/8] Load InboundDeliveryCost from EthereumInboundQueue --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 e7ceaa47bc790..f3d041ece1871 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 @@ -511,7 +511,6 @@ parameter_types! { fee_per_gas: gwei(20), rewards: Rewards { local: 1 * UNITS, remote: meth(1) } }; - pub const InboundDeliveryCost: u128 = 1_000_000_000; } #[cfg(feature = "runtime-benchmarks")] @@ -630,7 +629,7 @@ impl snowbridge_control::Config for Runtime { #[cfg(feature = "runtime-benchmarks")] type Helper = (); type DefaultPricingParameters = Parameters; - type InboundDeliveryCost = InboundDeliveryCost; + type InboundDeliveryCost = EthereumInboundQueue; } // Create the runtime by composing the FRAME pallets that were previously configured. From ec3368061c1e4a9a4b05da6202ef59516a75abd3 Mon Sep 17 00:00:00 2001 From: ron Date: Tue, 28 Nov 2023 18:11:11 +0800 Subject: [PATCH 4/8] Allow utility calls --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 32d9615b5c8d4..3161bec0d5c1c 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -173,6 +173,7 @@ impl Contains for SafeCallFilter { frame_system::Call::set_code_without_checks { .. } | frame_system::Call::kill_prefix { .. }, ) | RuntimeCall::ParachainSystem(..) | + RuntimeCall::Utility(..) | RuntimeCall::Timestamp(..) | RuntimeCall::Balances(..) | RuntimeCall::CollatorSelection( From e88d2b44124170c7dbcf9a003b9ffd0b6fedb001 Mon Sep 17 00:00:00 2001 From: ron Date: Tue, 28 Nov 2023 23:43:12 +0800 Subject: [PATCH 5/8] Fix integration tests --- .../bridge-hub-rococo/src/tests/snowbridge.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 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 2849ca6045caf..62fed0abf4abf 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 @@ -30,13 +30,14 @@ const TREASURY_ACCOUNT: [u8; 32] = hex!("6d6f646c70792f74727372790000000000000000000000000000000000000000"); const WETH: [u8; 20] = hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d"); const ETHEREUM_DESTINATION_ADDRESS: [u8; 20] = hex!("44a57ee2f2FCcb85FDa2B0B18EBD0D8D2333700e"); +const XCM_FEE: u128 = 4_000_000_000; #[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)] pub enum ControlCall { - #[codec(index = 2)] - CreateAgent, #[codec(index = 3)] - CreateChannel { mode: OperatingMode, outbound_fee: u128 }, + CreateAgent, + #[codec(index = 4)] + CreateChannel { mode: OperatingMode }, } #[allow(clippy::large_enum_variant)] @@ -133,10 +134,8 @@ fn create_channel() { }, ])); - let create_channel_call = SnowbridgeControl::Control(ControlCall::CreateChannel { - mode: OperatingMode::Normal, - outbound_fee: 1, - }); + let create_channel_call = + SnowbridgeControl::Control(ControlCall::CreateChannel { mode: OperatingMode::Normal }); let create_channel_xcm = VersionedXcm::from(Xcm(vec![ UnpaidExecution { weight_limit: Unlimited, check_origin: None }, @@ -294,8 +293,10 @@ fn send_token_to_penpal() { destination: Destination::ForeignAccountId32 { para_id: 2000, id: PenpalAReceiver::get().into(), + fee: XCM_FEE, }, amount: 1_000_000_000, + fee: XCM_FEE, }, }); let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap(); @@ -364,6 +365,7 @@ fn send_token() { token: WETH.into(), destination: Destination::AccountId32 { id: AssetHubRococoReceiver::get().into() }, amount: 1_000_000_000, + fee: XCM_FEE, }, }); let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap(); @@ -419,6 +421,7 @@ fn reserve_transfer_token() { token: WETH.into(), destination: Destination::AccountId32 { id: AssetHubRococoReceiver::get().into() }, amount: WETH_AMOUNT, + fee: XCM_FEE, }, }); let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap(); From e59a5b626045065f21176350efc2cc08f75379d6 Mon Sep 17 00:00:00 2001 From: ron Date: Wed, 29 Nov 2023 21:20:21 +0800 Subject: [PATCH 6/8] Remove createAssetExecutionFee --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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 7c0bd5db9e057..dab2b20d2b6d8 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 @@ -507,7 +507,6 @@ parameter_types! { pub const Reward: u128 = 10; pub const GatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39")); pub const CreateAssetCall: [u8;2] = [53, 0]; - pub const CreateAssetExecutionFee: u128 = 2_000_000_000; pub const CreateAssetDeposit: u128 = (UNITS / 10) + EXISTENTIAL_DEPOSIT; pub Parameters: PricingParameters = PricingParameters { exchange_rate: FixedU128::from_rational(1, 400), @@ -535,13 +534,7 @@ impl snowbridge_inbound_queue::Config for Runtime { type GatewayAddress = GatewayAddress; #[cfg(feature = "runtime-benchmarks")] type Helper = Runtime; - type MessageConverter = MessageToXcm< - CreateAssetCall, - CreateAssetExecutionFee, - CreateAssetDeposit, - AccountId, - Balance, - >; + type MessageConverter = MessageToXcm; type WeightToFee = WeightToFee; type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo; type PricingParameters = EthereumControl; From 21cf8340f5a4c233ad6e58373ac245c4766b737e Mon Sep 17 00:00:00 2001 From: ron Date: Wed, 29 Nov 2023 21:52:22 +0800 Subject: [PATCH 7/8] Fix breaking test --- .../tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 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 62fed0abf4abf..d8adfa3d933ea 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 @@ -204,7 +204,7 @@ fn register_token() { ::EthereumInboundQueue; let message = VersionedMessage::V1(MessageV1 { chain_id: CHAIN_ID, - command: Command::RegisterToken { token: WETH.into() }, + command: Command::RegisterToken { token: WETH.into(), fee: XCM_FEE }, }); let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap(); let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap(); @@ -355,7 +355,7 @@ fn send_token() { ::EthereumInboundQueue; let message = VersionedMessage::V1(MessageV1 { chain_id: CHAIN_ID, - command: Command::RegisterToken { token: WETH.into() }, + command: Command::RegisterToken { token: WETH.into(), fee: XCM_FEE }, }); let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap(); let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap(); @@ -411,7 +411,7 @@ fn reserve_transfer_token() { ::EthereumInboundQueue; let message = VersionedMessage::V1(MessageV1 { chain_id: CHAIN_ID, - command: Command::RegisterToken { token: WETH.into() }, + command: Command::RegisterToken { token: WETH.into(), fee: XCM_FEE }, }); let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap(); let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap(); From e01068d91b086455f4e21835ce7a0e95cdc89fd9 Mon Sep 17 00:00:00 2001 From: Vincent Geddes Date: Wed, 29 Nov 2023 21:31:08 +0200 Subject: [PATCH 8/8] fix benchmark weights --- .../src/weights/snowbridge_control.rs | 20 +++++++++++++++++++ .../runtimes/testing/penpal/src/lib.rs | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_control.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_control.rs index 23939297366e0..8176a929e3ba8 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_control.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_control.rs @@ -219,4 +219,24 @@ impl snowbridge_control::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } + + /// Storage: ParachainInfo ParachainId (r:1 w:0) + /// Proof: ParachainInfo ParachainId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + /// Storage: EthereumOutboundQueue PalletOperatingMode (r:1 w:0) + /// Proof: EthereumOutboundQueue PalletOperatingMode (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) + /// Storage: MessageQueue BookStateFor (r:1 w:1) + /// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: MessageQueue ServiceHead (r:1 w:1) + /// Proof: MessageQueue ServiceHead (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen) + /// Storage: MessageQueue Pages (r:0 w:1) + /// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen) + fn set_pricing_parameters() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3517` + // Minimum execution time: 31_000_000 picoseconds. + Weight::from_parts(42_000_000, 3517) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } } diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 09d236b717d7c..c39b0515dc141 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -490,7 +490,7 @@ impl pallet_assets::Config for Runtime { type AssetAccountDeposit = ForeignAssetsAssetAccountDeposit; type RemoveItemsLimit = frame_support::traits::ConstU32<1000>; #[cfg(feature = "runtime-benchmarks")] - type BenchmarkHelper = xcm_config::XcmBenchmarkHelper; + type BenchmarkHelper = (); } parameter_types! {