From 87e28a29db3c8be49d10a7fd910949de34ba8120 Mon Sep 17 00:00:00 2001 From: Ron Date: Thu, 30 Nov 2023 17:17:55 +0800 Subject: [PATCH] Remove redundant address (#49) * Fix compile error * Load PricingParameters from control * Load InboundDeliveryCost from EthereumInboundQueue * Allow utility calls * Fix integration tests * Remove createAssetExecutionFee * Fix breaking test * fix benchmark weights --------- Co-authored-by: Vincent Geddes --- .../bridge-hub-rococo/src/tests/snowbridge.rs | 23 +++++++++------- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 27 ++++++++++--------- .../src/weights/snowbridge_system.rs | 20 ++++++++++++++ .../bridge-hub-rococo/src/xcm_config.rs | 1 + .../runtimes/testing/penpal/src/lib.rs | 2 +- 5 files changed, 49 insertions(+), 24 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 ebba932c1af2..dd136b935f01 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 }, @@ -205,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(); @@ -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(); @@ -354,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(); @@ -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(); @@ -409,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(); @@ -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(); 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 356c04f09151..bcdcc8d64f26 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 @@ -34,7 +34,9 @@ pub mod xcm_config; 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}; @@ -42,7 +44,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::*; @@ -505,9 +507,12 @@ 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 const SendTokenExecutionFee: u128 = 4_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) } + }; } #[cfg(feature = "runtime-benchmarks")] @@ -521,7 +526,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")] @@ -530,16 +534,10 @@ impl snowbridge_inbound_queue::Config for Runtime { type GatewayAddress = GatewayAddress; #[cfg(feature = "runtime-benchmarks")] type Helper = Runtime; - type MessageConverter = MessageToXcm< - CreateAssetCall, - CreateAssetExecutionFee, - CreateAssetDeposit, - SendTokenExecutionFee, - AccountId, - Balance, - >; + type MessageConverter = MessageToXcm; type WeightToFee = WeightToFee; type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo; + type PricingParameters = EthereumControl; } impl snowbridge_outbound_queue::Config for Runtime { @@ -553,6 +551,7 @@ impl snowbridge_outbound_queue::Config for Runtime { type Balance = Balance; type WeightToFee = WeightToFee; type WeightInfo = weights::snowbridge_outbound_queue::WeightInfo; + type PricingParameters = EthereumControl; } #[cfg(not(feature = "beacon-spec-mainnet"))] @@ -625,6 +624,8 @@ impl snowbridge_system::Config for Runtime { type WeightInfo = weights::snowbridge_system::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type Helper = (); + type DefaultPricingParameters = Parameters; + type InboundDeliveryCost = EthereumInboundQueue; } // Create the runtime by composing the FRAME pallets that were previously configured. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_system.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_system.rs index 8b710ef03180..abd8d3cbfb98 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_system.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_system.rs @@ -219,4 +219,24 @@ impl snowbridge_system::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/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index c5a03eb86a20..ce20759a5914 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( diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 09d236b717d7..c39b0515dc14 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! {