From 4bc29ca149583cf2b931d8f82ee070a728cab529 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 15 Nov 2024 15:51:55 +0100 Subject: [PATCH] Setup permissionless lanes for AssetHubRococo tmp --- Cargo.lock | 23 ++ .../chains/chain-asset-hub-rococo/Cargo.toml | 16 + .../chains/chain-asset-hub-rococo/src/lib.rs | 102 +++++- .../chains/chain-asset-hub-westend/Cargo.toml | 16 + .../chains/chain-asset-hub-westend/src/lib.rs | 103 +++++- .../assets/asset-hub-rococo/Cargo.toml | 26 +- .../src/bridge_common_config.rs | 48 +++ .../src/bridge_to_westend_config.rs | 298 +++++++++++++++++ .../assets/asset-hub-rococo/src/lib.rs | 203 +++++++++++- .../asset-hub-rococo/src/weights/mod.rs | 27 +- .../src/weights/pallet_bridge_messages.rs | 273 +++++++++++++++ .../src/weights/pallet_bridge_relayers.rs | 123 +++++++ .../src/weights/pallet_xcm_bridge.rs | 110 +++++++ ...uter_to_westend_over_asset_hub_westend.rs} | 1 + ...ridge_router_to_westend_over_bridge_hub.rs | 64 ++++ .../asset-hub-rococo/src/weights/xcm/mod.rs | 6 +- .../xcm/pallet_xcm_benchmarks_generic.rs | 23 ++ .../assets/asset-hub-rococo/src/xcm_config.rs | 25 +- .../assets/asset-hub-rococo/tests/tests.rs | 311 +++++++++++++++++- 19 files changed, 1768 insertions(+), 30 deletions(-) create mode 100644 cumulus/parachains/runtimes/assets/asset-hub-rococo/src/bridge_common_config.rs create mode 100644 cumulus/parachains/runtimes/assets/asset-hub-rococo/src/bridge_to_westend_config.rs create mode 100644 cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_bridge_messages.rs create mode 100644 cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_bridge_relayers.rs create mode 100644 cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge.rs rename cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/{pallet_xcm_bridge_router.rs => pallet_xcm_bridge_router_to_westend_over_asset_hub_westend.rs} (98%) create mode 100644 cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge_router_to_westend_over_bridge_hub.rs diff --git a/Cargo.lock b/Cargo.lock index 485614bcaa5fb..90252ebf44e4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -958,7 +958,13 @@ dependencies = [ "bp-asset-hub-westend", "bp-bridge-hub-rococo", "bp-bridge-hub-westend", + "bp-header-chain 0.7.0", + "bp-messages 0.7.0", + "bp-runtime 0.7.0", "bp-xcm-bridge", + "bridge-hub-common 0.1.0", + "bridge-hub-test-utils 0.7.0", + "bridge-runtime-common 0.7.0", "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", "cumulus-pallet-session-benchmarking 9.0.0", @@ -987,6 +993,8 @@ dependencies = [ "pallet-aura 27.0.0", "pallet-authorship 28.0.0", "pallet-balances 28.0.0", + "pallet-bridge-messages 0.7.0", + "pallet-bridge-relayers 0.7.0", "pallet-collator-selection 9.0.0", "pallet-message-queue 31.0.0", "pallet-multisig 28.0.0", @@ -1001,6 +1009,7 @@ dependencies = [ "pallet-utility 28.0.0", "pallet-xcm 7.0.0", "pallet-xcm-benchmarks 7.0.0", + "pallet-xcm-bridge", "pallet-xcm-bridge-router", "parachains-common 7.0.0", "parachains-runtimes-test-utils 7.0.0", @@ -2067,11 +2076,18 @@ dependencies = [ name = "bp-asset-hub-rococo" version = "0.4.0" dependencies = [ + "bp-bridge-hub-cumulus", + "bp-messages 0.7.0", + "bp-runtime 0.7.0", + "bp-xcm-bridge", "bp-xcm-bridge-router", "frame-support 28.0.0", "parity-scale-codec", "scale-info", + "sp-api 26.0.0", "sp-core 28.0.0", + "sp-runtime 31.0.1", + "sp-std 14.0.0", "staging-xcm 7.0.0", ] @@ -2079,11 +2095,18 @@ dependencies = [ name = "bp-asset-hub-westend" version = "0.3.0" dependencies = [ + "bp-bridge-hub-cumulus", + "bp-messages 0.7.0", + "bp-runtime 0.7.0", + "bp-xcm-bridge", "bp-xcm-bridge-router", "frame-support 28.0.0", "parity-scale-codec", "scale-info", + "sp-api 26.0.0", "sp-core 28.0.0", + "sp-runtime 31.0.1", + "sp-std 14.0.0", "staging-xcm 7.0.0", ] diff --git a/bridges/chains/chain-asset-hub-rococo/Cargo.toml b/bridges/chains/chain-asset-hub-rococo/Cargo.toml index 994621e018912..143961c025ee8 100644 --- a/bridges/chains/chain-asset-hub-rococo/Cargo.toml +++ b/bridges/chains/chain-asset-hub-rococo/Cargo.toml @@ -19,10 +19,17 @@ scale-info = { features = ["derive"], workspace = true } # Substrate Dependencies frame-support = { workspace = true } +sp-api = { workspace = true } sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } # Bridge Dependencies bp-xcm-bridge-router = { workspace = true } +bp-bridge-hub-cumulus = { workspace = true } +bp-runtime = { workspace = true } +bp-messages = { workspace = true } +bp-xcm-bridge = { workspace = true } # Polkadot dependencies xcm = { workspace = true } @@ -36,4 +43,13 @@ std = [ "scale-info/std", "sp-core/std", "xcm/std", + "bp-bridge-hub-cumulus/std", + "bp-messages/std", + "bp-runtime/std", + "bp-xcm-bridge/std", + "codec/std", + "frame-support/std", + "sp-api/std", + "sp-runtime/std", + "sp-std/std", ] diff --git a/bridges/chains/chain-asset-hub-rococo/src/lib.rs b/bridges/chains/chain-asset-hub-rococo/src/lib.rs index bde8b1265935f..f840eab4b8199 100644 --- a/bridges/chains/chain-asset-hub-rococo/src/lib.rs +++ b/bridges/chains/chain-asset-hub-rococo/src/lib.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity Bridges Common. If not, see . -//! Module with configuration which reflects AssetHubRococo runtime setup. +//! Module with configuration which reflects AssetHubRococo runtime setup (AccountId, Headers, +//! Hashes...) #![cfg_attr(not(feature = "std"), no_std)] @@ -23,6 +24,15 @@ extern crate alloc; use codec::{Decode, Encode}; use scale_info::TypeInfo; +pub use bp_bridge_hub_cumulus::*; +use bp_messages::*; +use bp_runtime::{ + decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, ChainId, Parachain, +}; +use frame_support::{ + dispatch::DispatchClass, + sp_runtime::{MultiAddress, MultiSigner, RuntimeDebug, StateVersion}, +}; pub use bp_xcm_bridge_router::XcmBridgeHubCall; use xcm::latest::prelude::*; @@ -71,3 +81,93 @@ pub fn build_congestion_message( /// Identifier of AssetHubRococo in the Rococo relay chain. pub const ASSET_HUB_ROCOCO_PARACHAIN_ID: u32 = 1000; + +/// AssetHubRococo parachain. +#[derive(RuntimeDebug)] +pub struct AssetHubRococo; + +impl Chain for AssetHubRococo { + const ID: ChainId = *b"ahro"; + + type BlockNumber = BlockNumber; + type Hash = Hash; + type Hasher = Hasher; + type Header = Header; + + type AccountId = AccountId; + type Balance = Balance; + type Nonce = Nonce; + type Signature = Signature; + + const STATE_VERSION: StateVersion = StateVersion::V1; + + fn max_extrinsic_size() -> u32 { + *BlockLength::get().max.get(DispatchClass::Normal) + } + + fn max_extrinsic_weight() -> Weight { + BlockWeightsForAsyncBacking::get() + .get(DispatchClass::Normal) + .max_extrinsic + .unwrap_or(Weight::MAX) + } +} + +impl Parachain for AssetHubRococo { + const PARACHAIN_ID: u32 = ASSET_HUB_ROCOCO_PARACHAIN_ID; + const MAX_HEADER_SIZE: u32 = MAX_BRIDGE_HUB_HEADER_SIZE; +} + +/// Describing permissionless lanes instance +impl ChainWithMessages for AssetHubRococo { + const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str = + WITH_ASSET_HUB_ROCOCO_MESSAGES_PALLET_NAME; + + const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = + MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX; + const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = + MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX; +} + +/// Public key of the chain account that may be used to verify signatures. +pub type AccountSigner = MultiSigner; + +/// The address format for describing accounts. +pub type Address = MultiAddress; + +/// Name of the With-AssetHubRococo messages pallet instance that is deployed at bridged chains. +pub const WITH_ASSET_HUB_ROCOCO_MESSAGES_PALLET_NAME: &str = "BridgeRococoMessages"; + +/// Name of the With-AssetHubRococo bridge-relayers pallet instance that is deployed at bridged +/// chains. +pub const WITH_ASSET_HUB_ROCOCO_RELAYERS_PALLET_NAME: &str = "BridgeRelayers"; + +/// Pallet index of `BridgeWestendMessages: pallet_bridge_messages::`. +pub const WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX: u8 = 62; + +decl_bridge_finality_runtime_apis!(asset_hub_rococo); +decl_bridge_messages_runtime_apis!(asset_hub_rococo, HashedLaneId); + +frame_support::parameter_types! { + /// TODO: FAIL-CI - probably not needed or ise for MessageExporterPrice + /// The XCM fee that is paid for executing XCM program (with `ExportMessage` instruction) at the Rococo + /// BridgeHub. + /// (initially was calculated by test `AssetHubRococo::can_calculate_weight_for_paid_export_message_with_reserve_transfer` + `33%`) + pub const AssetHubRococoBaseXcmFeeInRocs: u128 = 57_325_000; + + /// Transaction fee that is paid at the Rococo BridgeHub for delivering single inbound message. + /// (initially was calculated by test `AssetHubRococo::can_calculate_fee_for_standalone_message_delivery_transaction` + `33%`) + pub const AssetHubRococoBaseDeliveryFeeInRocs: u128 = 297_685_840; + + /// Transaction fee that is paid at the Rococo BridgeHub for delivering single outbound message confirmation. + /// (initially was calculated by test `AssetHubRococo::can_calculate_fee_for_standalone_message_confirmation_transaction` + `33%`) + pub const AssetHubRococoBaseConfirmationFeeInRocs: u128 = 56_782_099; +} + +/// Wrapper over `AssetHubRococo`'s `RuntimeCall` that can be used without a runtime. +#[derive(Decode, Encode)] +pub enum RuntimeCall { + /// Points to the `pallet_xcm_bridge` pallet instance for `AssetHubWestend`. + #[codec(index = 61)] + XcmOverAssetHubWestend(bp_xcm_bridge::XcmBridgeCall), +} diff --git a/bridges/chains/chain-asset-hub-westend/Cargo.toml b/bridges/chains/chain-asset-hub-westend/Cargo.toml index 2fd2b00983355..ef6dc67371825 100644 --- a/bridges/chains/chain-asset-hub-westend/Cargo.toml +++ b/bridges/chains/chain-asset-hub-westend/Cargo.toml @@ -19,10 +19,17 @@ scale-info = { features = ["derive"], workspace = true } # Substrate Dependencies frame-support = { workspace = true } +sp-api = { workspace = true } sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } # Bridge Dependencies bp-xcm-bridge-router = { workspace = true } +bp-bridge-hub-cumulus = { workspace = true } +bp-runtime = { workspace = true } +bp-messages = { workspace = true } +bp-xcm-bridge = { workspace = true } # Polkadot dependencies xcm = { workspace = true } @@ -36,4 +43,13 @@ std = [ "scale-info/std", "sp-core/std", "xcm/std", + "bp-bridge-hub-cumulus/std", + "bp-messages/std", + "bp-runtime/std", + "bp-xcm-bridge/std", + "codec/std", + "frame-support/std", + "sp-api/std", + "sp-runtime/std", + "sp-std/std", ] diff --git a/bridges/chains/chain-asset-hub-westend/src/lib.rs b/bridges/chains/chain-asset-hub-westend/src/lib.rs index 6c75566e3301e..57965fa111b63 100644 --- a/bridges/chains/chain-asset-hub-westend/src/lib.rs +++ b/bridges/chains/chain-asset-hub-westend/src/lib.rs @@ -14,12 +14,23 @@ // You should have received a copy of the GNU General Public License // along with Parity Bridges Common. If not, see . -//! Module with configuration which reflects AssetHubWestend runtime setup. +//! Module with configuration which reflects AssetHubWestend runtime setup (AccountId, Headers, +//! Hashes...) #![cfg_attr(not(feature = "std"), no_std)] extern crate alloc; +pub use bp_bridge_hub_cumulus::*; +use bp_messages::*; +use bp_runtime::{ + decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, ChainId, Parachain, +}; +use frame_support::{ + dispatch::DispatchClass, + sp_runtime::{MultiAddress, MultiSigner, RuntimeDebug, StateVersion}, +}; + use codec::{Decode, Encode}; use scale_info::TypeInfo; @@ -71,3 +82,93 @@ pub fn build_congestion_message( /// Identifier of AssetHubWestend in the Westend relay chain. pub const ASSET_HUB_WESTEND_PARACHAIN_ID: u32 = 1000; + +/// Westend parachain. +#[derive(RuntimeDebug)] +pub struct AssetHubWestend; + +impl Chain for AssetHubWestend { + const ID: ChainId = *b"ahwd"; + + type BlockNumber = BlockNumber; + type Hash = Hash; + type Hasher = Hasher; + type Header = Header; + + type AccountId = AccountId; + type Balance = Balance; + type Nonce = Nonce; + type Signature = Signature; + + const STATE_VERSION: StateVersion = StateVersion::V1; + + fn max_extrinsic_size() -> u32 { + *BlockLength::get().max.get(DispatchClass::Normal) + } + + fn max_extrinsic_weight() -> Weight { + BlockWeightsForAsyncBacking::get() + .get(DispatchClass::Normal) + .max_extrinsic + .unwrap_or(Weight::MAX) + } +} + +impl Parachain for AssetHubWestend { + const PARACHAIN_ID: u32 = ASSET_HUB_WESTEND_PARACHAIN_ID; + const MAX_HEADER_SIZE: u32 = MAX_BRIDGE_HUB_HEADER_SIZE; // TODO: FAIL-CI - MAX_ASSET_HUB_HEADER_SIZE +} + +/// Describing permissionless lanes instance +impl ChainWithMessages for AssetHubWestend { + const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str = + WITH_ASSET_HUB_WESTEND_MESSAGES_PALLET_NAME; + + const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = + MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX; + const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = + MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX; +} + +/// Public key of the chain account that may be used to verify signatures. +pub type AccountSigner = MultiSigner; + +/// The address format for describing accounts. +pub type Address = MultiAddress; + +/// Name of the With-AssetHubWestend messages pallet instance that is deployed at bridged chains. +pub const WITH_ASSET_HUB_WESTEND_MESSAGES_PALLET_NAME: &str = "BridgeWestendMessages"; + +/// Name of the With-AssetHubWestend bridge-relayers pallet instance that is deployed at bridged +/// chains. +pub const WITH_ASSET_HUB_WESTEND_RELAYERS_PALLET_NAME: &str = "BridgeRelayers"; + +/// Pallet index of `BridgeRococoMessages: pallet_bridge_messages::`. +pub const WITH_BRIDGE_WESTEND_TO_ROCOCO_MESSAGES_PALLET_INDEX: u8 = 60; // TODO: FAIL-CI - correct index when AssetHubWestend + +decl_bridge_finality_runtime_apis!(asset_hub_westend); +decl_bridge_messages_runtime_apis!(asset_hub_westend, HashedLaneId); + +frame_support::parameter_types! { + /// TODO: FAIL-CI - probably not needed + /// The XCM fee that is paid for executing XCM program (with `ExportMessage` instruction) at the Westend + /// AssetHub. + /// (initially was calculated by test `AssetHubWestend::can_calculate_weight_for_paid_export_message_with_reserve_transfer` + `33%`) + pub const AssetHubWestendBaseXcmFeeInWnds: u128 = 57_325_000; + + /// Transaction fee that is paid at the Westend AssetHub for delivering single inbound message. + /// (initially was calculated by test `AssetHubWestend::can_calculate_fee_for_standalone_message_delivery_transaction` + `33%`) + pub const AssetHubWestendBaseDeliveryFeeInWnds: u128 = 297_685_840; + + /// Transaction fee that is paid at the Westend AssetHub for delivering single outbound message confirmation. + /// (initially was calculated by test `AssetHubWestend::can_calculate_fee_for_standalone_message_confirmation_transaction` + `33%`) + pub const AssetHubWestendBaseConfirmationFeeInWnds: u128 = 56_782_099; +} + +/// Wrapper over `AssetHubWestend`'s `RuntimeCall` that can be used without a runtime. +#[derive(Decode, Encode)] +pub enum RuntimeCall { + /// Points to the `pallet_xcm_bridge_hub` pallet instance for `AssetHubRococo`. + #[codec(index = 62)] // TODO: FAIL-CI - corect index when AssetHubWestend + XcmOverAssetHubRococo(bp_xcm_bridge::XcmBridgeCall), +} \ No newline at end of file diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index 9b41bba349b25..cbcf2e0bd8937 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -93,17 +93,27 @@ parachains-common = { workspace = true } testnet-parachains-constants = { features = ["rococo"], workspace = true } # Bridges +pallet-bridge-messages = { workspace = true } +pallet-bridge-relayers = { workspace = true } +pallet-xcm-bridge = { workspace = true } +pallet-xcm-bridge-router = { workspace = true } bp-asset-hub-rococo = { workspace = true } bp-asset-hub-westend = { workspace = true } bp-bridge-hub-rococo = { workspace = true } bp-bridge-hub-westend = { workspace = true } -pallet-xcm-bridge-router = { workspace = true } +bp-header-chain = { workspace = true } +bp-messages = { workspace = true } +bp-runtime = { workspace = true } +bridge-hub-common = { workspace = true } snowbridge-router-primitives = { workspace = true } [dev-dependencies] asset-test-utils = { workspace = true, default-features = true } bp-xcm-bridge = { workspace = true } parachains-runtimes-test-utils = { workspace = true, default-features = true } +bridge-hub-test-utils = { workspace = true, default-features = true } +bridge-runtime-common = { features = ["integrity-test"], workspace = true } +pallet-bridge-relayers = { features = ["integrity-test"], workspace = true } [build-dependencies] substrate-wasm-builder = { optional = true, workspace = true, default-features = true } @@ -112,6 +122,7 @@ substrate-wasm-builder = { optional = true, workspace = true, default-features = default = ["std"] runtime-benchmarks = [ "assets-common/runtime-benchmarks", + "bridge-hub-common/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-weight-reclaim/runtime-benchmarks", @@ -129,6 +140,8 @@ runtime-benchmarks = [ "pallet-assets-freezer/runtime-benchmarks", "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", + "pallet-bridge-messages/runtime-benchmarks", + "pallet-bridge-relayers/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", @@ -141,6 +154,7 @@ runtime-benchmarks = [ "pallet-utility/runtime-benchmarks", "pallet-xcm-benchmarks/runtime-benchmarks", "pallet-xcm-bridge-router/runtime-benchmarks", + "pallet-xcm-bridge/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", @@ -171,6 +185,8 @@ try-runtime = [ "pallet-aura/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", + "pallet-bridge-messages/try-runtime", + "pallet-bridge-relayers/try-runtime", "pallet-collator-selection/try-runtime", "pallet-message-queue/try-runtime", "pallet-multisig/try-runtime", @@ -183,6 +199,7 @@ try-runtime = [ "pallet-uniques/try-runtime", "pallet-utility/try-runtime", "pallet-xcm-bridge-router/try-runtime", + "pallet-xcm-bridge/try-runtime", "pallet-xcm/try-runtime", "parachain-info/try-runtime", "polkadot-runtime-common/try-runtime", @@ -194,7 +211,11 @@ std = [ "bp-asset-hub-westend/std", "bp-bridge-hub-rococo/std", "bp-bridge-hub-westend/std", + "bp-header-chain/std", + "bp-messages/std", + "bp-runtime/std", "bp-xcm-bridge/std", + "bridge-hub-common/std", "codec/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", @@ -223,6 +244,8 @@ std = [ "pallet-aura/std", "pallet-authorship/std", "pallet-balances/std", + "pallet-bridge-messages/std", + "pallet-bridge-relayers/std", "pallet-collator-selection/std", "pallet-message-queue/std", "pallet-multisig/std", @@ -237,6 +260,7 @@ std = [ "pallet-utility/std", "pallet-xcm-benchmarks?/std", "pallet-xcm-bridge-router/std", + "pallet-xcm-bridge/std", "pallet-xcm/std", "parachain-info/std", "parachains-common/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/bridge_common_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/bridge_common_config.rs new file mode 100644 index 0000000000000..bcd139fbe9cbf --- /dev/null +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/bridge_common_config.rs @@ -0,0 +1,48 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Bridge definitions that can be used by multiple bridges. + +use super::{weights, AccountId, Balance, Balances, BlockNumber, Runtime, RuntimeEvent}; + +frame_support::parameter_types! { + pub storage RequiredStakeForStakeAndSlash: Balance = 1_000_000; + pub const RelayerStakeLease: u32 = 8; + pub const RelayerStakeReserveId: [u8; 8] = *b"brdgrlrs"; + pub storage DeliveryRewardInBalance: u64 = 1_000_000; +} + +/// Allows collect and claim rewards for the relayers +pub type BridgeRelayersInstance = pallet_bridge_relayers::Instance1; +impl pallet_bridge_relayers::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Reward = Balance; + type PaymentProcedure = pallet_bridge_relayers::PayRewardFromAccount< + Balances, + AccountId, + Self::LaneId, + >; + type StakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed< + AccountId, + BlockNumber, + Balances, + RelayerStakeReserveId, + RequiredStakeForStakeAndSlash, + RelayerStakeLease, + >; + type WeightInfo = weights::pallet_bridge_relayers::WeightInfo; + type LaneId = bp_messages::HashedLaneId; +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/bridge_to_westend_config.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/bridge_to_westend_config.rs new file mode 100644 index 0000000000000..780045e9cd2ca --- /dev/null +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/bridge_to_westend_config.rs @@ -0,0 +1,298 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Bridge definitions used on BridgeHubRococo for bridging to BridgeHubWestend. + +use crate::{bridge_common_config::{ + DeliveryRewardInBalance, + BridgeRelayersInstance, +}, weights, xcm_config, xcm_config::UniversalLocation, AccountId, Balance, Balances, PolkadotXcm, Runtime, RuntimeEvent, RuntimeHoldReason, XcmOverAssetHubWestend, ToWestendOverAssetHubWestendXcmRouter}; +use alloc::{vec, vec::Vec}; +use bp_messages::HashedLaneId; +use bp_runtime::HashOf; +use bridge_hub_common::xcm_version::XcmVersionOfDestAndRemoteBridge; +use pallet_xcm_bridge::XcmAsPlainPayload; + +use frame_support::parameter_types; +use frame_support::traits::{EitherOf, Equals}; +use frame_system::{EnsureRoot, EnsureRootWithSuccess}; +use pallet_bridge_messages::LaneIdOf; +use pallet_bridge_relayers::extension::{ + BridgeRelayersTransactionExtension, WithMessagesExtensionConfig, +}; +use pallet_xcm::EnsureXcm; +use pallet_xcm_bridge::congestion::{ + BlobDispatcherWithChannelStatus, UpdateBridgeStatusXcmChannelManager, HereOrLocalConsensusXcmChannelManager, +}; +use parachains_common::xcm_config::{AllSiblingSystemParachains, ParentRelayOrSiblingParachains, RelayOrOtherSystemParachains}; +use polkadot_parachain_primitives::primitives::Sibling; +use sp_runtime::traits::Convert; +use testnet_parachains_constants::rococo::currency::UNITS as ROC; +use xcm::{ + latest::{prelude::*, WESTEND_GENESIS_HASH}, + prelude::{NetworkId}, +}; +use xcm_builder::{BridgeBlobDispatcher, ParentIsPreset, SiblingParachainConvertsVia, LocalExporter}; + +parameter_types! { + pub const HereLocation: Location = Location::here(); + pub WestendGlobalConsensusNetwork: NetworkId = NetworkId::ByGenesis(WESTEND_GENESIS_HASH); + pub WestendGlobalConsensusNetworkLocation: Location = Location::new( + 2, + [GlobalConsensus(WestendGlobalConsensusNetwork::get())] + ); + // see the `FEE_BOOST_PER_MESSAGE` constant to get the meaning of this value + pub PriorityBoostPerMessage: u64 = 182_044_444_444_444; + + // The other side of the bridge + pub AssetHubWestendLocation: Location = Location::new( + 2, + [ + GlobalConsensus(WestendGlobalConsensusNetwork::get()), + Parachain(::PARACHAIN_ID) + ] + ); + + pub storage BridgeDeposit: Balance = 5 * ROC; +} + +/// Transaction extension that refunds relayers that are delivering messages from the Westend +/// parachain. +pub type OnAssetHubRococoRefundAssetHubWestendMessages = BridgeRelayersTransactionExtension< + Runtime, + WithMessagesExtensionConfig< + StrOnAssetHubRococoRefundAssetHubWestendMessages, + Runtime, + WithAssetHubWestendMessagesInstance, + BridgeRelayersInstance, + PriorityBoostPerMessage, + >, + LaneIdOf, +>; +bp_runtime::generate_static_str_provider!(OnAssetHubRococoRefundAssetHubWestendMessages); + +/// Add XCM messages support for AssetHubRococo to support Rococo->Westend XCM messages +pub type WithAssetHubWestendMessagesInstance = pallet_bridge_messages::Instance1; +impl pallet_bridge_messages::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = weights::pallet_bridge_messages::WeightInfo; + + type ThisChain = bp_asset_hub_rococo::AssetHubRococo; + type BridgedChain = bp_asset_hub_westend::AssetHubWestend; + type BridgedHeaderChain = ParachainHeaderProofs; + + type OutboundPayload = XcmAsPlainPayload; + type InboundPayload = XcmAsPlainPayload; + type LaneId = HashedLaneId; + + type DeliveryPayments = (); + type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter< + Runtime, + WithAssetHubWestendMessagesInstance, + BridgeRelayersInstance, + DeliveryRewardInBalance, + >; + + type MessageDispatch = XcmOverAssetHubWestend; + type OnMessagesDelivered = XcmOverAssetHubWestend; +} + +/// TODO: doc + FAIL-CI - implement storage for synced proofs from BridgeHub +pub struct ParachainHeaderProofs(core::marker::PhantomData); +impl bp_header_chain::HeaderChain for ParachainHeaderProofs { + fn finalized_header_state_root( + _header_hash: HashOf, + ) -> Option> { + todo!("TODO: FAIL-CI - implement storage for synced proofs from BridgeHub") + } +} + +/// Converts encoded call to the unpaid XCM `Transact`. +pub struct UpdateBridgeStatusXcmProvider; +impl Convert, Xcm<()>> for UpdateBridgeStatusXcmProvider { + fn convert(encoded_call: Vec) -> Xcm<()> { + Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::Xcm, + call: encoded_call.into(), + // TODO: FAIL-CI - add some test for this or remove TODO + fallback_max_weight: Some(Weight::from_parts(200_000_000, 6144)) + }, + ExpectTransactStatus(MaybeErrorCode::Success), + ]) + } +} + +/// Add support for the export and dispatch of XCM programs withing +/// `WithAssetHubWestendMessagesInstance`. +pub type XcmOverAssetHubWestendInstance = pallet_xcm_bridge::Instance1; +impl pallet_xcm_bridge::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = weights::pallet_xcm_bridge::WeightInfo; + + type UniversalLocation = UniversalLocation; + type BridgedNetwork = WestendGlobalConsensusNetworkLocation; + type BridgeMessagesPalletInstance = WithAssetHubWestendMessagesInstance; + + // TODO: FAIL-CI: we need to setup some price or configure per location? + type MessageExportPrice = (); + type DestinationVersion = + XcmVersionOfDestAndRemoteBridge; + + type ForceOrigin = EnsureRoot; + // We allow creating bridges for the runtime itself and for other local consensus chains (relay, paras). + type OpenBridgeOrigin = EitherOf< + // We want to translate `RuntimeOrigin::root()` to the `Location::here()`, e.g. for governance calls. + EnsureRootWithSuccess, + // For relay or sibling chains + EnsureXcm, + >; + // Converter aligned with `OpenBridgeOrigin`. + type BridgeOriginAccountIdConverter = + (ParentIsPreset, SiblingParachainConvertsVia); + + type BridgeDeposit = BridgeDeposit; + type Currency = Balances; + type RuntimeHoldReason = RuntimeHoldReason; + // Do not require deposit from system parachains (including itself) or relay chain + type AllowWithoutBridgeDeposit = (RelayOrOtherSystemParachains, Equals); + + // This pallet is deployed on AH, so we expect a remote router with `ExportMessage`. We handle + // congestion with XCM using `udpate_bridge_status` sent to the sending chain. (congestion with + // local sending chain) + type LocalXcmChannelManager = HereOrLocalConsensusXcmChannelManager< + pallet_xcm_bridge::BridgeId, + // handles congestion for local chain router for local AH's bridges + ToWestendOverAssetHubWestendXcmRouter, + // handles congestion for other local chains with XCM using `update_bridge_status` sent to the sending chain. + UpdateBridgeStatusXcmChannelManager< + Runtime, + XcmOverAssetHubWestendInstance, + UpdateBridgeStatusXcmProvider, + xcm_config::LocalXcmRouter, + >, + >; + // Dispatching inbound messages from the bridge and managing congestion with the local + // receiving/destination chain + type BlobDispatcher = BlobDispatcherWithChannelStatus< + // Dispatches received XCM messages from other bridge + BridgeBlobDispatcher< + // TODO: FAIL-CI wait for https://github.com/paritytech/polkadot-sdk/pull/6002#issuecomment-2469892343 + xcm_config::LocalXcmRouter, + UniversalLocation, + (), + >, + // Provides the status of the XCMP queue's outbound queue, indicating whether messages can + // be dispatched to the sibling. + cumulus_pallet_xcmp_queue::bridging::OutXcmpChannelStatusProvider, + >; + type CongestionLimits = (); +} + +/// XCM router instance to the local `pallet_xcm_bridge_hub::` with direct bridging capabilities for `Westend` global +/// consensus with dynamic fees and back-pressure. +pub type ToWestendOverAssetHubWestendXcmRouterInstance = pallet_xcm_bridge_router::Instance4; +impl pallet_xcm_bridge_router::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = weights::pallet_xcm_bridge_router_to_westend_over_asset_hub_westend::WeightInfo; + + type DestinationVersion = PolkadotXcm; + + // We use `LocalExporter` with `ViaLocalBridgeHubExporter` ensures that + // `pallet_xcm_bridge_router` can trigger directly `pallet_xcm_bridge` as exporter. + type MessageExporter = pallet_xcm_bridge_router::impls::ViaLocalBridgeHubExporter< + Runtime, + ToWestendOverAssetHubWestendXcmRouterInstance, + LocalExporter, + >; + + // For congestion - resolves `BridgeId` using the same algorithm as `pallet_xcm_bridge_hub` on + // the BH. + type BridgeIdResolver = pallet_xcm_bridge_router::impls::EnsureIsRemoteBridgeIdResolver; + // We don't expect here `update_bridge_status` calls, but let's allow just for root (governance, ...). + type UpdateBridgeStatusOrigin = EnsureRoot; + + // TODO: FAIL-CI - fix/add new constants + // For adding message size fees + type ByteFee = xcm_config::bridging::XcmBridgeHubRouterByteFee; + // For adding message size fees + type FeeAsset = xcm_config::bridging::XcmBridgeHubRouterFeeAssetId; +} + +#[cfg(test)] +mod tests { + use super::*; + use bridge_runtime_common::{ + assert_complete_bridge_types, + integrity::{ + assert_standalone_messages_bridge_constants, check_message_lane_weights, + AssertChainConstants, AssertCompleteBridgeConstants, + }, + }; + + /// Every additional message in the message delivery transaction boosts its priority. + /// So the priority of transaction with `N+1` messages is larger than priority of + /// transaction with `N` messages by the `PriorityBoostPerMessage`. + /// + /// Economically, it is an equivalent of adding tip to the transaction with `N` messages. + /// The `FEE_BOOST_PER_MESSAGE` constant is the value of this tip. + /// + /// We want this tip to be large enough (delivery transactions with more messages = less + /// operational costs and a faster bridge), so this value should be significant. + const FEE_BOOST_PER_MESSAGE: Balance = 2 * ROC; + + #[test] + fn ensure_bridge_hub_rococo_message_lane_weights_are_correct() { + check_message_lane_weights::< + bp_asset_hub_rococo::AssetHubRococo, + Runtime, + WithAssetHubWestendMessagesInstance, + >( + bp_asset_hub_westend::EXTRA_STORAGE_PROOF_SIZE, + bp_asset_hub_rococo::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX, + bp_asset_hub_rococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX, + true, + ); + } + + #[test] + fn ensure_bridge_integrity() { + assert_complete_bridge_types!( + runtime: Runtime, + with_bridged_chain_messages_instance: WithAssetHubWestendMessagesInstance, + this_chain: bp_asset_hub_rococo::AssetHubRococo, + bridged_chain: bp_asset_hub_westend::AssetHubWestend, + expected_payload_type: XcmAsPlainPayload, + ); + + assert_standalone_messages_bridge_constants::< + Runtime, + WithAssetHubWestendMessagesInstance, + >(AssertCompleteBridgeConstants { + this_chain_constants: AssertChainConstants { + block_length: bp_bridge_hub_rococo::BlockLength::get(), + block_weights: bp_bridge_hub_rococo::BlockWeightsForAsyncBacking::get(), + }, + }); + + pallet_bridge_relayers::extension::per_message::ensure_priority_boost_is_sane::< + Runtime, + WithAssetHubWestendMessagesInstance, + PriorityBoostPerMessage, + >(FEE_BOOST_PER_MESSAGE); + } +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index d60f00f946a66..b886a245d538b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -26,6 +26,8 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod genesis_config_presets; mod weights; +pub mod bridge_common_config; +pub mod bridge_to_westend_config; pub mod xcm_config; extern crate alloc; @@ -100,7 +102,7 @@ use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; #[cfg(feature = "runtime-benchmarks")] use xcm::latest::prelude::{ Asset, Assets as XcmAssets, Fungible, Here, InteriorLocation, Junction, Junction::*, Location, - NetworkId, NonFungible, Parent, ParentThen, Response, + NetworkId, NonFungible, Parent, ParentThen, Response, XCM_VERSION, }; use xcm::{ latest::prelude::{AssetId, BodyId}, @@ -985,11 +987,12 @@ impl pallet_nfts::Config for Runtime { } /// XCM router instance to BridgeHub with bridging capabilities for `Westend` global -/// consensus with dynamic fees and back-pressure. +/// consensus with dynamic fees and back-pressure +/// (legacy routing with `ExportMessage` over BridgeHub). pub type ToWestendXcmRouterInstance = pallet_xcm_bridge_router::Instance3; impl pallet_xcm_bridge_router::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type WeightInfo = weights::pallet_xcm_bridge_router::WeightInfo; + type WeightInfo = weights::pallet_xcm_bridge_router_to_westend_over_bridge_hub::WeightInfo; type DestinationVersion = PolkadotXcm; @@ -1124,6 +1127,12 @@ construct_runtime!( AssetRewards: pallet_asset_rewards = 60, + // Bridges permissionless lanes. + XcmOverAssetHubWestend: pallet_xcm_bridge:: = 61, + BridgeWestendMessages: pallet_bridge_messages:: = 62, + BridgeRelayers: pallet_bridge_relayers:: = 63, + ToWestendOverAssetHubWestendXcmRouter: pallet_xcm_bridge_router:: = 64, + // TODO: the pallet instance should be removed once all pools have migrated // to the new account IDs. AssetConversionMigration: pallet_asset_conversion_ops = 200, @@ -1151,6 +1160,7 @@ pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< frame_system::CheckWeight, pallet_asset_conversion_tx_payment::ChargeAssetTxPayment, frame_metadata_hash_extension::CheckMetadataHash, + (bridge_to_westend_config::OnAssetHubRococoRefundAssetHubWestendMessages, ), ), >; /// Unchecked extrinsic type as expected by this runtime. @@ -1331,8 +1341,13 @@ mod benches { [pallet_collator_selection, CollatorSelection] [cumulus_pallet_parachain_system, ParachainSystem] [cumulus_pallet_xcmp_queue, XcmpQueue] - [pallet_xcm_bridge_router, ToWestend] [pallet_asset_conversion_ops, AssetConversionMigration] + // Bridge pallets + [pallet_xcm_bridge_router, ToWestendOverBridgeHub] + [pallet_xcm_bridge_router, ToWestendOverAssetHubWestend] + [pallet_bridge_messages, RococoToWestend] + [pallet_bridge_relayers, BridgeRelayersBench::] + [pallet_xcm_bridge, OverWestend] // XCM [pallet_xcm, PalletXcmExtrinsicsBenchmark::] // NOTE: Make sure you point to the individual modules below. @@ -1669,7 +1684,8 @@ impl_runtime_apis! { use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark; - use pallet_xcm_bridge_router::benchmarking::Pallet as XcmBridgeHubRouterBench; + use pallet_xcm_bridge_router::benchmarking::Pallet as XcmBridgeHubRouterBench; // TODO: FAIL-CI - rename XcmBridgeHubRouterBench -> XcmBridgeRouterBench + use pallet_bridge_relayers::benchmarking::Pallet as BridgeRelayersBench; // This is defined once again in dispatch_benchmark, because list_benchmarks! // and add_benchmarks! are macros exported by define_benchmarks! macros and those types @@ -1685,7 +1701,10 @@ impl_runtime_apis! { type Foreign = pallet_assets::Pallet::; type Pool = pallet_assets::Pallet::; - type ToWestend = XcmBridgeHubRouterBench; + type ToWestendOverBridgeHub = XcmBridgeHubRouterBench; + type ToWestendOverAssetHubWestend = XcmBridgeHubRouterBench; + type OverWestend = pallet_xcm_bridge::benchmarking::Pallet::; + type RococoToWestend = pallet_bridge_messages::benchmarking::Pallet::; let mut list = Vec::::new(); list_benchmarks!(list, extra); @@ -1837,6 +1856,14 @@ impl_runtime_apis! { Some(pallet_xcm::Origin::Xcm(xcm_config::bridging::SiblingBridgeHub::get()).into()) } } + impl XcmBridgeHubRouterConfig for Runtime { + fn ensure_bridged_target_destination() -> Result { + Ok(xcm_config::bridging::to_westend::AssetHubWestend::get()) + } + fn update_bridge_status_origin() -> Option { + None + } + } use xcm_config::{TokenLocation, MaxAssetsIntoHolding}; use pallet_xcm_benchmarks::asset_instance_from; @@ -1950,7 +1977,50 @@ impl_runtime_apis! { fn export_message_origin_and_destination( ) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError> { - Err(BenchmarkError::Skip) + // save XCM version for remote permissionless lanes on bridged asset hub + let _ = PolkadotXcm::force_xcm_version( + RuntimeOrigin::root(), + alloc::boxed::Box::new(bridge_to_westend_config::AssetHubWestendLocation::get()), + XCM_VERSION, + ).map_err(|e| { + log::error!( + "Failed to dispatch `force_xcm_version({:?}, {:?}, {:?})`, error: {:?}", + RuntimeOrigin::root(), + bridge_to_westend_config::AssetHubWestendLocation::get(), + XCM_VERSION, + e + ); + BenchmarkError::Stop("XcmVersion was not stored!") + })?; + + // open bridge + let westend = bridge_to_westend_config::WestendGlobalConsensusNetwork::get(); + let sibling_parachain_location = Location::new(1, [Parachain(5678)]); + let bridge_destination_universal_location: InteriorLocation = [GlobalConsensus(westend), Parachain(8765)].into(); + let _ = XcmOverAssetHubWestend::open_bridge_for_benchmarks( + ::try_new(1, 2).unwrap(), + sibling_parachain_location.clone(), + bridge_destination_universal_location.clone(), + true, + None, + || ExistentialDeposit::get(), + ).map_err(|e| { + log::error!( + "Failed to `XcmOverAssetHubWestend::open_bridge`({:?}, {:?})`, error: {:?}", + sibling_parachain_location, + bridge_destination_universal_location, + e + ); + BenchmarkError::Stop("Bridge was not opened!") + })?; + + Ok( + ( + sibling_parachain_location, + westend, + [Parachain(8765)].into() + ) + ) } fn alias_origin() -> Result<(Location, Location), BenchmarkError> { @@ -1970,7 +2040,124 @@ impl_runtime_apis! { type Foreign = pallet_assets::Pallet::; type Pool = pallet_assets::Pallet::; - type ToWestend = XcmBridgeHubRouterBench; + type ToWestendOverBridgeHub = XcmBridgeHubRouterBench; + type ToWestendOverAssetHubWestend = XcmBridgeHubRouterBench; + type OverWestend = pallet_xcm_bridge::benchmarking::Pallet::; + type RococoToWestend = pallet_bridge_messages::benchmarking::Pallet::; + + use pallet_bridge_relayers::benchmarking::{ + Config as BridgeRelayersConfig, + Pallet as BridgeRelayersBench + }; + + impl BridgeRelayersConfig for Runtime { + fn prepare_rewards_account( + account_params: pallet_bridge_relayers::RewardsAccountParams<>::LaneId>, + reward: Balance, + ) { + let rewards_account = pallet_bridge_relayers::PayRewardFromAccount::< + Balances, + AccountId, + >::LaneId, + >::rewards_account(account_params); + >::deposit_account(rewards_account, reward); + } + + fn deposit_account(account: AccountId, balance: Balance) { + use frame_support::traits::fungible::Mutate; + Balances::mint_into(&account, balance.saturating_add(ExistentialDeposit::get())).unwrap(); + } + } + + impl pallet_xcm_bridge::benchmarking::Config for Runtime { + fn open_bridge_origin() -> Option<(RuntimeOrigin, Balance)> { + // We allow bridges to be opened for sibling parachains. + Some(( + pallet_xcm::Origin::Xcm(Location::new(1, [Parachain(42)])).into(), + ExistentialDeposit::get(), + )) + } + } + + use pallet_bridge_messages::{BridgedChainOf, LaneIdOf}; + use pallet_bridge_messages::benchmarking::{ + Config as BridgeMessagesConfig, + MessageDeliveryProofParams, + MessageProofParams, + }; + + impl BridgeMessagesConfig for Runtime { + fn is_relayer_rewarded(relayer: &Self::AccountId) -> bool { + let bench_lane_id = >::bench_lane_id(); + use bp_runtime::Chain; + let bridged_chain_id =>::BridgedChain::ID; + pallet_bridge_relayers::Pallet::::relayer_reward( + relayer, + pallet_bridge_relayers::RewardsAccountParams::new( + bench_lane_id, + bridged_chain_id, + pallet_bridge_relayers::RewardsAccountOwner::BridgedChain + ) + ).is_some() + } + + fn prepare_message_proof( + params: MessageProofParams>, + ) -> ( + bp_messages::target_chain::FromBridgedChainMessagesProof< + bp_runtime::HashOf>, + LaneIdOf + >, + Weight + ) { + use cumulus_primitives_core::XcmpMessageSource; + assert!(XcmpQueue::take_outbound_messages(usize::MAX).is_empty()); + ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(42.into()); + let _bridge_locations = XcmOverAssetHubWestend::open_bridge_for_benchmarks( + params.lane, + Location::new(1, [Parachain(42)]), + [GlobalConsensus(bridge_to_westend_config::WestendGlobalConsensusNetwork::get()), Parachain(2075)].into(), + // do not create lanes, because they are already created `params.lane` + false, + None, + || ExistentialDeposit::get(), + ).expect("valid bridge opened"); + todo!("TODO: FAIL-CI - prepare storage proof for synced proof") + // prepare_message_proof_from_parachain::< + // Runtime, + // bridge_common_config::BridgeGrandpaWestendInstance, + // bridge_to_westend_config::WithAssetHubWestendMessagesInstance, + // >(params, generate_xcm_builder_bridge_message_sample(bridge_locations.bridge_origin_universal_location().clone())) + } + + fn prepare_message_delivery_proof( + params: MessageDeliveryProofParams>, + ) -> bp_messages::source_chain::FromBridgedChainMessagesDeliveryProof< + bp_runtime::HashOf>, + LaneIdOf + > { + let _ = XcmOverAssetHubWestend::open_bridge_for_benchmarks( + params.lane, + Location::new(1, [Parachain(42)]), + [GlobalConsensus(bridge_to_westend_config::WestendGlobalConsensusNetwork::get()), Parachain(2075)].into(), + // do not create lanes, because they are already created `params.lane` + false, + None, + || ExistentialDeposit::get(), + ); + todo!("TODO: FAIL-CI - prepare storage proof for synced proof") + // prepare_message_delivery_proof_from_parachain::< + // Runtime, + // bridge_common_config::BridgeGrandpaWestendInstance, + // bridge_to_westend_config::WithAssetHubWestendMessagesInstance, + // >(params) + } + + fn is_message_successfully_dispatched(_nonce: bp_messages::MessageNonce) -> bool { + use cumulus_primitives_core::XcmpMessageSource; + !XcmpQueue::take_outbound_messages(usize::MAX).is_empty() + } + } use frame_support::traits::WhitelistedStorageKeys; let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs index c3d4e1974bc24..23c6e5b4097b2 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs @@ -29,6 +29,8 @@ pub mod pallet_assets_foreign; pub mod pallet_assets_local; pub mod pallet_assets_pool; pub mod pallet_balances; +pub mod pallet_bridge_messages; +pub mod pallet_bridge_relayers; pub mod pallet_collator_selection; pub mod pallet_message_queue; pub mod pallet_multisig; @@ -41,7 +43,9 @@ pub mod pallet_transaction_payment; pub mod pallet_uniques; pub mod pallet_utility; pub mod pallet_xcm; -pub mod pallet_xcm_bridge_router; +pub mod pallet_xcm_bridge; +pub mod pallet_xcm_bridge_router_to_westend_over_asset_hub_westend; +pub mod pallet_xcm_bridge_router_to_westend_over_bridge_hub; pub mod paritydb_weights; pub mod rocksdb_weights; pub mod xcm; @@ -49,3 +53,24 @@ pub mod xcm; pub use block_weights::constants::BlockExecutionWeight; pub use extrinsic_weights::constants::ExtrinsicBaseWeight; pub use rocksdb_weights::constants::RocksDbWeight; + +use ::pallet_bridge_messages::WeightInfoExt as MessagesWeightInfoExt; +use ::pallet_bridge_relayers::WeightInfoExt as _; + +use crate::{Runtime, Weight}; + +impl MessagesWeightInfoExt +for pallet_bridge_messages::WeightInfo +{ + fn expected_extra_storage_proof_size() -> u32 { + bp_bridge_hub_westend::EXTRA_STORAGE_PROOF_SIZE + } + + fn receive_messages_proof_overhead_from_runtime() -> Weight { + pallet_bridge_relayers::WeightInfo::::receive_messages_proof_overhead_from_runtime() + } + + fn receive_messages_delivery_proof_overhead_from_runtime() -> Weight { + pallet_bridge_relayers::WeightInfo::::receive_messages_delivery_proof_overhead_from_runtime() + } +} \ No newline at end of file diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_bridge_messages.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_bridge_messages.rs new file mode 100644 index 0000000000000..dbe2465342379 --- /dev/null +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_bridge_messages.rs @@ -0,0 +1,273 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Autogenerated weights for `pallet_bridge_messages` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-11-09, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-wiukf8gn-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("bridge-hub-rococo-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=pallet_bridge_messages +// --chain=bridge-hub-rococo-dev TODO: FAIL-CI regenerate +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_bridge_messages`. +pub struct WeightInfo(PhantomData); +impl pallet_bridge_messages::WeightInfo for WeightInfo { + /// Storage: `BridgeWestendMessages::PalletOperatingMode` (r:1 w:0) + /// Proof: `BridgeWestendMessages::PalletOperatingMode` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendParachains::ImportedParaHeads` (r:1 w:0) + /// Proof: `BridgeWestendParachains::ImportedParaHeads` (`max_values`: Some(64), `max_size`: Some(196), added: 1186, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::InboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::InboundLanes` (`max_values`: None, `max_size`: Some(49180), added: 51655, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::LaneToBridge` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::LaneToBridge` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::Bridges` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::Bridges` (`max_values`: None, `max_size`: Some(1893), added: 4368, mode: `MaxEncodedLen`) + /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:0) + /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: Some(1282), added: 1777, mode: `MaxEncodedLen`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn receive_single_message_proof() -> Weight { + // Proof Size summary in bytes: + // Measured: `940` + // Estimated: `52645` + // Minimum execution time: 62_868_000 picoseconds. + Weight::from_parts(65_210_000, 0) + .saturating_add(Weight::from_parts(0, 52645)) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `BridgeWestendMessages::PalletOperatingMode` (r:1 w:0) + /// Proof: `BridgeWestendMessages::PalletOperatingMode` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendParachains::ImportedParaHeads` (r:1 w:0) + /// Proof: `BridgeWestendParachains::ImportedParaHeads` (`max_values`: Some(64), `max_size`: Some(196), added: 1186, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::InboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::InboundLanes` (`max_values`: None, `max_size`: Some(49180), added: 51655, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::LaneToBridge` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::LaneToBridge` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::Bridges` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::Bridges` (`max_values`: None, `max_size`: Some(1893), added: 4368, mode: `MaxEncodedLen`) + /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:0) + /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: Some(1282), added: 1777, mode: `MaxEncodedLen`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// The range of component `n` is `[1, 4076]`. + /// The range of component `n` is `[1, 4076]`. + fn receive_n_messages_proof(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `940` + // Estimated: `52645` + // Minimum execution time: 62_893_000 picoseconds. + Weight::from_parts(63_992_000, 0) + .saturating_add(Weight::from_parts(0, 52645)) + // Standard Error: 13_856 + .saturating_add(Weight::from_parts(12_332_627, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `BridgeWestendMessages::PalletOperatingMode` (r:1 w:0) + /// Proof: `BridgeWestendMessages::PalletOperatingMode` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendParachains::ImportedParaHeads` (r:1 w:0) + /// Proof: `BridgeWestendParachains::ImportedParaHeads` (`max_values`: Some(64), `max_size`: Some(196), added: 1186, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::InboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::InboundLanes` (`max_values`: None, `max_size`: Some(49180), added: 51655, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::LaneToBridge` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::LaneToBridge` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::Bridges` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::Bridges` (`max_values`: None, `max_size`: Some(1893), added: 4368, mode: `MaxEncodedLen`) + /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:0) + /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: Some(1282), added: 1777, mode: `MaxEncodedLen`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn receive_single_message_proof_with_outbound_lane_state() -> Weight { + // Proof Size summary in bytes: + // Measured: `940` + // Estimated: `52645` + // Minimum execution time: 68_193_000 picoseconds. + Weight::from_parts(70_799_000, 0) + .saturating_add(Weight::from_parts(0, 52645)) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `BridgeWestendMessages::PalletOperatingMode` (r:1 w:0) + /// Proof: `BridgeWestendMessages::PalletOperatingMode` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendParachains::ImportedParaHeads` (r:1 w:0) + /// Proof: `BridgeWestendParachains::ImportedParaHeads` (`max_values`: Some(64), `max_size`: Some(196), added: 1186, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::InboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::InboundLanes` (`max_values`: None, `max_size`: Some(49180), added: 51655, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::LaneToBridge` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::LaneToBridge` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::Bridges` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::Bridges` (`max_values`: None, `max_size`: Some(1893), added: 4368, mode: `MaxEncodedLen`) + /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:0) + /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: Some(1282), added: 1777, mode: `MaxEncodedLen`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// The range of component `n` is `[1, 16384]`. + /// The range of component `n` is `[1, 16384]`. + fn receive_single_n_bytes_message_proof(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `940` + // Estimated: `52645` + // Minimum execution time: 61_230_000 picoseconds. + Weight::from_parts(65_437_770, 0) + .saturating_add(Weight::from_parts(0, 52645)) + // Standard Error: 9 + .saturating_add(Weight::from_parts(2_168, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `BridgeWestendMessages::PalletOperatingMode` (r:1 w:0) + /// Proof: `BridgeWestendMessages::PalletOperatingMode` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendParachains::ImportedParaHeads` (r:1 w:0) + /// Proof: `BridgeWestendParachains::ImportedParaHeads` (`max_values`: Some(64), `max_size`: Some(196), added: 1186, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::OutboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::OutboundLanes` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0x6e0a18b62a1de81c5f519181cc611e18` (r:1 w:0) + /// Proof: UNKNOWN KEY `0x6e0a18b62a1de81c5f519181cc611e18` (r:1 w:0) + /// Storage: `BridgeRelayers::RelayerRewards` (r:1 w:1) + /// Proof: `BridgeRelayers::RelayerRewards` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::LaneToBridge` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::LaneToBridge` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::Bridges` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::Bridges` (`max_values`: None, `max_size`: Some(1893), added: 4368, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::OutboundMessages` (r:0 w:1) + /// Proof: `BridgeWestendMessages::OutboundMessages` (`max_values`: None, `max_size`: Some(65568), added: 68043, mode: `MaxEncodedLen`) + fn receive_delivery_proof_for_single_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `711` + // Estimated: `5358` + // Minimum execution time: 51_650_000 picoseconds. + Weight::from_parts(53_190_000, 0) + .saturating_add(Weight::from_parts(0, 5358)) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `BridgeWestendMessages::PalletOperatingMode` (r:1 w:0) + /// Proof: `BridgeWestendMessages::PalletOperatingMode` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendParachains::ImportedParaHeads` (r:1 w:0) + /// Proof: `BridgeWestendParachains::ImportedParaHeads` (`max_values`: Some(64), `max_size`: Some(196), added: 1186, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::OutboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::OutboundLanes` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0x6e0a18b62a1de81c5f519181cc611e18` (r:1 w:0) + /// Proof: UNKNOWN KEY `0x6e0a18b62a1de81c5f519181cc611e18` (r:1 w:0) + /// Storage: `BridgeRelayers::RelayerRewards` (r:1 w:1) + /// Proof: `BridgeRelayers::RelayerRewards` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::LaneToBridge` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::LaneToBridge` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::Bridges` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::Bridges` (`max_values`: None, `max_size`: Some(1893), added: 4368, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::OutboundMessages` (r:0 w:2) + /// Proof: `BridgeWestendMessages::OutboundMessages` (`max_values`: None, `max_size`: Some(65568), added: 68043, mode: `MaxEncodedLen`) + fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight { + // Proof Size summary in bytes: + // Measured: `711` + // Estimated: `5358` + // Minimum execution time: 51_836_000 picoseconds. + Weight::from_parts(53_960_000, 0) + .saturating_add(Weight::from_parts(0, 5358)) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `BridgeWestendMessages::PalletOperatingMode` (r:1 w:0) + /// Proof: `BridgeWestendMessages::PalletOperatingMode` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendParachains::ImportedParaHeads` (r:1 w:0) + /// Proof: `BridgeWestendParachains::ImportedParaHeads` (`max_values`: Some(64), `max_size`: Some(196), added: 1186, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::OutboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::OutboundLanes` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0x6e0a18b62a1de81c5f519181cc611e18` (r:1 w:0) + /// Proof: UNKNOWN KEY `0x6e0a18b62a1de81c5f519181cc611e18` (r:1 w:0) + /// Storage: `BridgeRelayers::RelayerRewards` (r:2 w:2) + /// Proof: `BridgeRelayers::RelayerRewards` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::LaneToBridge` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::LaneToBridge` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::Bridges` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::Bridges` (`max_values`: None, `max_size`: Some(1893), added: 4368, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::OutboundMessages` (r:0 w:2) + /// Proof: `BridgeWestendMessages::OutboundMessages` (`max_values`: None, `max_size`: Some(65568), added: 68043, mode: `MaxEncodedLen`) + fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight { + // Proof Size summary in bytes: + // Measured: `711` + // Estimated: `6086` + // Minimum execution time: 56_606_000 picoseconds. + Weight::from_parts(58_528_000, 0) + .saturating_add(Weight::from_parts(0, 6086)) + .saturating_add(T::DbWeight::get().reads(8)) + .saturating_add(T::DbWeight::get().writes(5)) + } + /// Storage: `BridgeWestendMessages::PalletOperatingMode` (r:1 w:0) + /// Proof: `BridgeWestendMessages::PalletOperatingMode` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendParachains::ImportedParaHeads` (r:1 w:0) + /// Proof: `BridgeWestendParachains::ImportedParaHeads` (`max_values`: Some(64), `max_size`: Some(196), added: 1186, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::InboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::InboundLanes` (`max_values`: None, `max_size`: Some(49180), added: 51655, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::LaneToBridge` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::LaneToBridge` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) + /// Storage: `XcmOverBridgeHubWestend::Bridges` (r:1 w:0) + /// Proof: `XcmOverBridgeHubWestend::Bridges` (`max_values`: None, `max_size`: Some(1893), added: 4368, mode: `MaxEncodedLen`) + /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:1) + /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: Some(1282), added: 1777, mode: `MaxEncodedLen`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `XcmpQueue::DeliveryFeeFactor` (r:1 w:0) + /// Proof: `XcmpQueue::DeliveryFeeFactor` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::RelevantMessagingState` (r:1 w:0) + /// Proof: `ParachainSystem::RelevantMessagingState` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `XcmpQueue::OutboundXcmpMessages` (r:0 w:1) + /// Proof: `XcmpQueue::OutboundXcmpMessages` (`max_values`: None, `max_size`: Some(105506), added: 107981, mode: `MaxEncodedLen`) + /// The range of component `n` is `[1, 16384]`. + /// The range of component `n` is `[1, 16384]`. + fn receive_single_n_bytes_message_proof_with_dispatch(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1071` + // Estimated: `52645` + // Minimum execution time: 85_179_000 picoseconds. + Weight::from_parts(91_600_892, 0) + .saturating_add(Weight::from_parts(0, 52645)) + // Standard Error: 11 + .saturating_add(Weight::from_parts(7_210, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(12)) + .saturating_add(T::DbWeight::get().writes(4)) + } +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_bridge_relayers.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_bridge_relayers.rs new file mode 100644 index 0000000000000..913bb3ab24871 --- /dev/null +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_bridge_relayers.rs @@ -0,0 +1,123 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Autogenerated weights for `pallet_bridge_relayers` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-08-15, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-696hpswk-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("bridge-hub-rococo-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=pallet_bridge_relayers +// --chain=bridge-hub-rococo-dev TODO: FAIL-CI regenerate +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_bridge_relayers`. +pub struct WeightInfo(PhantomData); +impl pallet_bridge_relayers::WeightInfo for WeightInfo { + /// Storage: `BridgeRelayers::RelayerRewards` (r:1 w:1) + /// Proof: `BridgeRelayers::RelayerRewards` (`max_values`: None, `max_size`: Some(102), added: 2577, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn claim_rewards() -> Weight { + // Proof Size summary in bytes: + // Measured: `306` + // Estimated: `3593` + // Minimum execution time: 53_924_000 picoseconds. + Weight::from_parts(54_736_000, 0) + .saturating_add(Weight::from_parts(0, 3593)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `BridgeRelayers::RegisteredRelayers` (r:1 w:1) + /// Proof: `BridgeRelayers::RegisteredRelayers` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0x1e8445dc201eeb8560e5579a5dd54655` (r:1 w:0) + /// Proof: UNKNOWN KEY `0x1e8445dc201eeb8560e5579a5dd54655` (r:1 w:0) + /// Storage: `Balances::Reserves` (r:1 w:1) + /// Proof: `Balances::Reserves` (`max_values`: None, `max_size`: Some(1249), added: 3724, mode: `MaxEncodedLen`) + fn register() -> Weight { + // Proof Size summary in bytes: + // Measured: `131` + // Estimated: `4714` + // Minimum execution time: 28_608_000 picoseconds. + Weight::from_parts(29_081_000, 0) + .saturating_add(Weight::from_parts(0, 4714)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `BridgeRelayers::RegisteredRelayers` (r:1 w:1) + /// Proof: `BridgeRelayers::RegisteredRelayers` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`) + /// Storage: `Balances::Reserves` (r:1 w:1) + /// Proof: `Balances::Reserves` (`max_values`: None, `max_size`: Some(1249), added: 3724, mode: `MaxEncodedLen`) + fn deregister() -> Weight { + // Proof Size summary in bytes: + // Measured: `231` + // Estimated: `4714` + // Minimum execution time: 29_738_000 picoseconds. + Weight::from_parts(30_242_000, 0) + .saturating_add(Weight::from_parts(0, 4714)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `BridgeRelayers::RegisteredRelayers` (r:1 w:1) + /// Proof: `BridgeRelayers::RegisteredRelayers` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`) + /// Storage: `Balances::Reserves` (r:1 w:1) + /// Proof: `Balances::Reserves` (`max_values`: None, `max_size`: Some(1249), added: 3724, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn slash_and_deregister() -> Weight { + // Proof Size summary in bytes: + // Measured: `334` + // Estimated: `4714` + // Minimum execution time: 33_174_000 picoseconds. + Weight::from_parts(33_992_000, 0) + .saturating_add(Weight::from_parts(0, 4714)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `BridgeRelayers::RelayerRewards` (r:1 w:1) + /// Proof: `BridgeRelayers::RelayerRewards` (`max_values`: None, `max_size`: Some(102), added: 2577, mode: `MaxEncodedLen`) + fn register_relayer_reward() -> Weight { + // Proof Size summary in bytes: + // Measured: `76` + // Estimated: `3567` + // Minimum execution time: 7_950_000 picoseconds. + Weight::from_parts(8_123_000, 0) + .saturating_add(Weight::from_parts(0, 3567)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge.rs new file mode 100644 index 0000000000000..76ebd021ce2df --- /dev/null +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge.rs @@ -0,0 +1,110 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Autogenerated weights for `pallet_xcm_bridge_hub` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-11-18, STEPS: `2`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `toaster1`, CPU: `AMD Ryzen Threadripper 7980X 64-Cores` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 + +// Executed Command: +// ./target/release/frame-omni-bencher +// v1 +// benchmark +// pallet +// --runtime +// ./target/debug/wbuild/asset-hub-rococo-runtime/asset_hub_rococo_runtime.wasm +// --pallet +// pallet_xcm_bridge_hub +// --extrinsic +// * +// --steps +// 2 +// --repeat +// 1 +// --output +// ./remote-builds -- TODO: FAIL-CI new weights + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_xcm_bridge_hub`. +pub struct WeightInfo(PhantomData); +impl pallet_xcm_bridge::WeightInfo for WeightInfo { + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `XcmOverAssetHubWestend::Bridges` (r:1 w:1) + /// Proof: `XcmOverAssetHubWestend::Bridges` (`max_values`: None, `max_size`: Some(1922), added: 4397, mode: `MaxEncodedLen`) + /// Storage: `XcmOverAssetHubWestend::LaneToBridge` (r:1 w:1) + /// Proof: `XcmOverAssetHubWestend::LaneToBridge` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::InboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::InboundLanes` (`max_values`: None, `max_size`: Some(49208), added: 51683, mode: `MaxEncodedLen`) + /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:0) + /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: Some(1282), added: 1777, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::OutboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::OutboundLanes` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) + fn open_bridge() -> Weight { + // Proof Size summary in bytes: + // Measured: `214` + // Estimated: `52673` + // Minimum execution time: 40_171_000 picoseconds. + Weight::from_parts(40_171_000, 0) + .saturating_add(Weight::from_parts(0, 52673)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `XcmOverAssetHubWestend::Bridges` (r:1 w:1) + /// Proof: `XcmOverAssetHubWestend::Bridges` (`max_values`: None, `max_size`: Some(1922), added: 4397, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::InboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::InboundLanes` (`max_values`: None, `max_size`: Some(49208), added: 51683, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::OutboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::OutboundLanes` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) + /// Storage: `XcmOverAssetHubWestend::LaneToBridge` (r:0 w:1) + /// Proof: `XcmOverAssetHubWestend::LaneToBridge` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`) + fn close_bridge() -> Weight { + // Proof Size summary in bytes: + // Measured: `488` + // Estimated: `52673` + // Minimum execution time: 30_096_000 picoseconds. + Weight::from_parts(30_096_000, 0) + .saturating_add(Weight::from_parts(0, 52673)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `XcmOverAssetHubWestend::Bridges` (r:1 w:1) + /// Proof: `XcmOverAssetHubWestend::Bridges` (`max_values`: None, `max_size`: Some(1922), added: 4397, mode: `MaxEncodedLen`) + fn update_notification_receiver() -> Weight { + // Proof Size summary in bytes: + // Measured: `212` + // Estimated: `5387` + // Minimum execution time: 15_994_000 picoseconds. + Weight::from_parts(15_994_000, 0) + .saturating_add(Weight::from_parts(0, 5387)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge_router.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge_router_to_westend_over_asset_hub_westend.rs similarity index 98% rename from cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge_router.rs rename to cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge_router_to_westend_over_asset_hub_westend.rs index e053a2ceba017..227b70336971c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge_router.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge_router_to_westend_over_asset_hub_westend.rs @@ -51,6 +51,7 @@ impl pallet_xcm_bridge_router::WeightInfo for WeightInf /// Storage: `ToWestendXcmRouter::Bridges` (r:1 w:1) /// Proof: `ToWestendXcmRouter::Bridges` (`max_values`: None, `max_size`: Some(65), added: 2540, mode: `MaxEncodedLen`) fn update_bridge_status() -> Weight { + // TODO: FAIL-CI new weights // Proof Size summary in bytes: // Measured: `109` // Estimated: `3530` diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge_router_to_westend_over_bridge_hub.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge_router_to_westend_over_bridge_hub.rs new file mode 100644 index 0000000000000..bf1a6fcd4eb70 --- /dev/null +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_xcm_bridge_router_to_westend_over_bridge_hub.rs @@ -0,0 +1,64 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Autogenerated weights for `pallet_xcm_bridge_hub_router` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-11-09, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-wiukf8gn-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("asset-hub-rococo-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=pallet_xcm_bridge_hub_router +// --chain=asset-hub-rococo-dev +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_xcm_bridge_hub_router`. +pub struct WeightInfo(PhantomData); +impl pallet_xcm_bridge_router::WeightInfo for WeightInfo { + /// Storage: `ToWestendXcmRouter::Bridges` (r:1 w:1) + /// Proof: `ToWestendXcmRouter::Bridges` (`max_values`: None, `max_size`: Some(65), added: 2540, mode: `MaxEncodedLen`) + fn update_bridge_status() -> Weight { + // TODO: FAIL-CI fresh weights + // Proof Size summary in bytes: + // Measured: `109` + // Estimated: `3530` + // Minimum execution time: 12_193_000 picoseconds. + Weight::from_parts(12_658_000, 0) + .saturating_add(Weight::from_parts(0, 3530)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/xcm/mod.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/xcm/mod.rs index ccf473484cad0..7dd6cc1354dd3 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/xcm/mod.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/xcm/mod.rs @@ -19,6 +19,7 @@ mod pallet_xcm_benchmarks_generic; use crate::{xcm_config::MaxAssetsIntoHolding, Runtime}; use alloc::vec::Vec; +use codec::Encode; use frame_support::weights::Weight; use pallet_xcm_benchmarks_fungible::WeightInfo as XcmFungibleWeight; use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric; @@ -236,8 +237,9 @@ impl XcmWeightInfo for AssetHubRococoXcmWeight { fn universal_origin(_: &Junction) -> Weight { XcmGeneric::::universal_origin() } - fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight { - Weight::MAX + fn export_message(_: &NetworkId, _: &Junctions, inner: &Xcm<()>) -> Weight { + let inner_encoded_len = inner.encode().len() as u32; + XcmGeneric::::export_message(inner_encoded_len) } fn lock_asset(_: &Asset, _: &Location) -> Weight { Weight::MAX diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/xcm/pallet_xcm_benchmarks_generic.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/xcm/pallet_xcm_benchmarks_generic.rs index d48debef94c88..65fb8b380efc7 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/xcm/pallet_xcm_benchmarks_generic.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/xcm/pallet_xcm_benchmarks_generic.rs @@ -352,6 +352,29 @@ impl WeightInfo { Weight::from_parts(2_715_000, 1489) .saturating_add(T::DbWeight::get().reads(1)) } + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `XcmOverAssetHubWestend::Bridges` (r:1 w:0) + /// Proof: `XcmOverAssetHubWestend::Bridges` (`max_values`: None, `max_size`: Some(1922), added: 4397, mode: `MaxEncodedLen`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:2 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `BridgeWestendMessages::PalletOperatingMode` (r:1 w:0) + /// Proof: `BridgeWestendMessages::PalletOperatingMode` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::OutboundLanes` (r:1 w:1) + /// Proof: `BridgeWestendMessages::OutboundLanes` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) + /// Storage: `BridgeWestendMessages::OutboundMessages` (r:0 w:1) + /// Proof: `BridgeWestendMessages::OutboundMessages` (`max_values`: None, `max_size`: Some(65596), added: 68071, mode: `MaxEncodedLen`) + /// The range of component `x` is `[1, 1000]`. + pub fn export_message(_x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `692` + // Estimated: `6632` + // Minimum execution time: 64_317_000 picoseconds. + Weight::from_parts(115_635_000, 0) + .saturating_add(Weight::from_parts(0, 6632)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(2)) + } pub fn set_fees_mode() -> Weight { // Proof Size summary in bytes: // Measured: `0` 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 00a9043348b72..2dead5edfe342 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 @@ -14,11 +14,11 @@ // limitations under the License. use super::{ - AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, BaseDeliveryFee, - CollatorSelection, FeeAssetId, ForeignAssets, ForeignAssetsInstance, ParachainInfo, - ParachainSystem, PolkadotXcm, PoolAssets, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - ToWestendXcmRouter, TransactionByteFee, TrustBackedAssetsInstance, Uniques, WeightToFee, - XcmpQueue, + AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, BaseDeliveryFee, CollatorSelection, + FeeAssetId, ForeignAssets, ForeignAssetsInstance, ParachainInfo, ParachainSystem, PolkadotXcm, + PoolAssets, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, ToWestendOverAssetHubWestendXcmRouter, + ToWestendXcmRouter, TransactionByteFee, TrustBackedAssetsInstance, Uniques, WeightToFee, XcmpQueue, + XcmOverAssetHubWestend, }; use assets_common::{ matching::{FromNetwork, FromSiblingParachain, IsForeignConcreteAsset, ParentLocation}, @@ -442,7 +442,10 @@ impl xcm_executor::Config for XcmConfig { WaivedLocations, SendXcmFeeToAccount, >; - type MessageExporter = (); + type MessageExporter = ( + // AH's permissionless lanes support exporting to Westend. + XcmOverAssetHubWestend, + ); type UniversalAliases = (bridging::to_westend::UniversalAliases, bridging::to_ethereum::UniversalAliases); type CallDispatcher = RuntimeCall; @@ -464,7 +467,7 @@ pub type PriceForParentDelivery = ExponentialPrice; /// For routing XCM messages which do not cross local consensus boundary. -type LocalXcmRouter = ( +pub(crate) type LocalXcmRouter = ( // Two routers - use UMP to communicate with the relay chain: cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. @@ -475,7 +478,13 @@ type LocalXcmRouter = ( /// queues. pub type XcmRouter = WithUniqueTopic<( LocalXcmRouter, - // Router which wraps and sends xcm to BridgeHub to be delivered to the Westend + // Router that exports messages to be delivered to the Westend GlobalConsensus, + // when a permissionless lane is created between the origin and destination. + // + // Note: `ToWestendOverAssetHubWestendXcmRouter` must come before `ToWestendXcmRouter` + // because it checks if the lane is created dynamically, whereas `ToWestendXcmRouter` has a static configuration. + ToWestendOverAssetHubWestendXcmRouter, + // Router which wraps (`ExportMessage`) and sends xcm to BridgeHub to be delivered to the Westend // GlobalConsensus ToWestendXcmRouter, // Router which wraps and sends xcm to BridgeHub to be delivered to the Ethereum diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs index 57d5d9d47db79..cfa099c7c62e9 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/tests/tests.rs @@ -27,8 +27,7 @@ use asset_hub_rococo_runtime::{ AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, Block, CollatorSelection, ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase, MetadataDepositPerByte, ParachainSystem, Runtime, RuntimeCall, - RuntimeEvent, RuntimeOrigin, SessionKeys, ToWestendXcmRouterInstance, - TrustBackedAssetsInstance, XcmpQueue, + RuntimeEvent, RuntimeOrigin, SessionKeys, TrustBackedAssetsInstance, XcmpQueue, }; use asset_test_utils::{ test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, @@ -1078,8 +1077,8 @@ fn limited_reserve_transfer_assets_for_native_asset_over_bridge_works( mod asset_hub_rococo_tests { use super::*; - use asset_hub_rococo_runtime::PolkadotXcm; - use xcm::latest::WESTEND_GENESIS_HASH; + use asset_hub_rococo_runtime::{PolkadotXcm, ToWestendXcmRouterInstance}; + use asset_hub_rococo_runtime::bridge_to_westend_config::WestendGlobalConsensusNetwork; use xcm_executor::traits::ConvertLocation; fn bridging_to_asset_hub_westend() -> TestBridgingConfig { @@ -1112,7 +1111,7 @@ mod asset_hub_rococo_tests { let foreign_asset_id_location = Location::new( 2, - [Junction::GlobalConsensus(NetworkId::ByGenesis(WESTEND_GENESIS_HASH))], + [GlobalConsensus(WestendGlobalConsensusNetwork::get())], ); let foreign_asset_id_minimum_balance = 1_000_000_000; // sovereign account as foreign asset owner (can be whoever for this scenario) @@ -1147,7 +1146,7 @@ mod asset_hub_rococo_tests { }, ( [PalletInstance(bp_bridge_hub_rococo::WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX)].into(), - GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)), + GlobalConsensus(WestendGlobalConsensusNetwork::get()), [Parachain(1000)].into() ), || { @@ -1188,7 +1187,7 @@ mod asset_hub_rococo_tests { let foreign_asset_id_location = Location::new( 2, - [Junction::GlobalConsensus(NetworkId::ByGenesis(WESTEND_GENESIS_HASH))], + [Junction::GlobalConsensus(WestendGlobalConsensusNetwork::get())], ); let foreign_asset_id_minimum_balance = 1_000_000_000; // sovereign account as foreign asset owner (can be whoever for this scenario) @@ -1216,7 +1215,7 @@ mod asset_hub_rococo_tests { bridging_to_asset_hub_westend, ( [PalletInstance(bp_bridge_hub_rococo::WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX)].into(), - GlobalConsensus(ByGenesis(WESTEND_GENESIS_HASH)), + GlobalConsensus(WestendGlobalConsensusNetwork::get()), [Parachain(1000)].into() ), || { @@ -1540,3 +1539,299 @@ fn xcm_payment_api_works() { Block, >(); } + +mod bridge_to_westend_tests { + use super::{collator_session_keys, slot_durations, ExtBuilder, AccountId, RuntimeHelper}; + use asset_hub_rococo_runtime::{Runtime, RuntimeOrigin, RuntimeCall, RuntimeEvent, PolkadotXcm, ParachainSystem, AllPalletsWithoutSystem, ExistentialDeposit}; + use asset_hub_rococo_runtime::xcm_config::{TokenLocation, LocationToAccountId, RelayNetwork, XcmConfig, bridging}; + use asset_hub_rococo_runtime::bridge_common_config::DeliveryRewardInBalance; + use asset_hub_rococo_runtime::bridge_to_westend_config::{WithAssetHubWestendMessagesInstance, WestendGlobalConsensusNetwork, XcmOverAssetHubWestendInstance, AssetHubWestendLocation}; + use codec::{Decode, Encode}; + use bp_runtime::RangeInclusiveExt; + use bridge_hub_test_utils::mock_open_hrmp_channel; + use frame_support::traits::{ConstU8, ProcessMessageError}; + use xcm::latest::prelude::*; + use xcm_builder::{CreateMatcher, MatchXcm}; + + // Random para id of sibling chain used in tests. + pub const SIBLING_PARACHAIN_ID: u32 = 2053; + // Random para id of bridged chain from different global consensus used in tests. + pub const BRIDGED_LOCATION_PARACHAIN_ID: u32 = 1075; + const RUNTIME_PARA_ID: u32 = bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID; + + frame_support::parameter_types! { + pub SiblingParachainLocation: Location = Location::new(1, [Parachain(SIBLING_PARACHAIN_ID)]); + pub BridgedUniversalLocation: InteriorLocation = [GlobalConsensus(WestendGlobalConsensusNetwork::get()), Parachain(BRIDGED_LOCATION_PARACHAIN_ID)].into(); + } + + #[test] + fn change_bridge_messages_pallet_mode_by_governance_works() { + bridge_hub_test_utils::test_cases::change_bridge_messages_pallet_mode_by_governance_works::< + Runtime, + WithAssetHubWestendMessagesInstance, + >(collator_session_keys(), bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID) + } + + #[test] + fn change_delivery_reward_by_governance_works() { + bridge_hub_test_utils::test_cases::change_storage_constant_by_governance_works::< + Runtime, + DeliveryRewardInBalance, + u64, + >( + collator_session_keys(), + RUNTIME_PARA_ID, + Box::new(|call| RuntimeCall::System(call).encode()), + || (DeliveryRewardInBalance::key().to_vec(), DeliveryRewardInBalance::get()), + |old_value| old_value.checked_mul(2).unwrap(), + ) + } + + #[test] + fn handle_export_message_from_sibling_parachain_and_add_to_outbound_queue_works() { + // for Westend + bridge_hub_test_utils::test_cases::handle_export_message_from_system_parachain_to_outbound_queue_works::< + Runtime, + XcmConfig, + WithAssetHubWestendMessagesInstance, + >( + collator_session_keys(), + RUNTIME_PARA_ID, + SIBLING_PARACHAIN_ID, + Box::new(|runtime_event_encoded: Vec| { + match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) { + Ok(RuntimeEvent::BridgeWestendMessages(event)) => Some(event), + _ => None, + } + }), + || ExportMessage { network: WestendGlobalConsensusNetwork::get(), destination: [Parachain(BRIDGED_LOCATION_PARACHAIN_ID)].into(), xcm: Xcm(vec![]) }, + Some((TokenLocation::get(), ExistentialDeposit::get()).into()), + // value should be >= than value generated by `can_calculate_weight_for_paid_export_message_with_reserve_transfer` + Some((TokenLocation::get(), bp_bridge_hub_rococo::BridgeHubRococoBaseXcmFeeInRocs::get()).into()), + || { + PolkadotXcm::force_xcm_version(RuntimeOrigin::root(), Box::new(AssetHubWestendLocation::get()), XCM_VERSION).expect("version saved!"); + + // we need to create lane between sibling parachain and remote destination + bridge_hub_test_utils::ensure_opened_xcm_bridge::< + Runtime, + XcmOverAssetHubWestendInstance, + LocationToAccountId, + TokenLocation, + >( + SiblingParachainLocation::get(), + BridgedUniversalLocation::get(), + true, + |locations, fee| { + bridge_hub_test_utils::open_xcm_bridge_with_extrinsic::< + Runtime, + XcmOverAssetHubWestendInstance + >((locations.bridge_origin_relative_location().clone(), OriginKind::Xcm), locations.bridge_destination_universal_location().clone(), fee) + } + ).1 + }, + ) + } + + #[test] + fn message_dispatch_routing_works() { + // from Westend + bridge_hub_test_utils::test_cases::message_dispatch_routing_works::< + Runtime, + AllPalletsWithoutSystem, + XcmConfig, + ParachainSystem, + WithAssetHubWestendMessagesInstance, + RelayNetwork, + WestendGlobalConsensusNetwork, + ConstU8<2>, + >( + collator_session_keys(), + slot_durations(), + RUNTIME_PARA_ID, + SIBLING_PARACHAIN_ID, + Box::new(|runtime_event_encoded: Vec| { + match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) { + Ok(RuntimeEvent::ParachainSystem(event)) => Some(event), + _ => None, + } + }), + Box::new(|runtime_event_encoded: Vec| { + match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) { + Ok(RuntimeEvent::XcmpQueue(event)) => Some(event), + _ => None, + } + }), + || (), + ) + } + + #[test] + fn open_and_close_bridge_for_sibling_parachain_works() { + bridge_hub_test_utils::test_cases::open_and_close_xcm_bridge_works::< + Runtime, + XcmOverAssetHubWestendInstance, + LocationToAccountId, + TokenLocation, + >( + collator_session_keys(), + RUNTIME_PARA_ID, + SiblingParachainLocation::get(), + BridgedUniversalLocation::get(), + (SiblingParachainLocation::get(), OriginKind::Xcm), + true, + ) + } + + #[test] + fn open_and_close_bridge_for_relay_works() { + bridge_hub_test_utils::test_cases::open_and_close_xcm_bridge_works::< + Runtime, + XcmOverAssetHubWestendInstance, + LocationToAccountId, + TokenLocation, + >( + collator_session_keys(), + RUNTIME_PARA_ID, + Location::parent(), + BridgedUniversalLocation::get(), + (Location::parent(), OriginKind::Xcm), + false, + ) + } + + #[test] + fn open_and_close_bridge_for_local_works() { + bridge_hub_test_utils::test_cases::open_and_close_xcm_bridge_works::< + Runtime, + XcmOverAssetHubWestendInstance, + LocationToAccountId, + TokenLocation, + >( + collator_session_keys(), + RUNTIME_PARA_ID, + // The source is `here` as the local chain, e.g., AssetHub itself can open its lanes. + Location::here(), + BridgedUniversalLocation::get(), + // This should represent `RuntimeOrigin::root()` which represents `Location::here()` for `OpenBridgeOrigin` + (Location::parent(), OriginKind::Superuser), + false, + ) + } + + #[test] + fn westend_xcm_routing_works() { + let runtime_para_id = 1000; + ExtBuilder::::default() + .with_collators(collator_session_keys().collators()) + .with_session_keys(collator_session_keys().session_keys()) + .with_para_id(runtime_para_id.into()) + .build() + .execute_with(|| { + frame_support::__private::sp_tracing::try_init_simple(); + let sibling_bridge_hub_para_id = bridging::SiblingBridgeHubParaId::get(); + let bridged_destination = bridging::to_westend::AssetHubWestend::get(); + let bridged_universal_destination = bridged_destination.interior().clone(); + + // Common setup + frame_support::assert_ok!( + PolkadotXcm::force_xcm_version( + RuntimeOrigin::root(), + Box::new(bridging::to_westend::AssetHubWestend::get()), + XCM_VERSION, + ) + ); + + // Setup for `ExportMessage` to the `BridgeHub` + let mut alice = [0u8; 32]; + alice[0] = 1; + let included_head = RuntimeHelper::run_to_block( + 2, + AccountId::from(alice), + ); + mock_open_hrmp_channel::( + runtime_para_id.into(), + sibling_bridge_hub_para_id.into(), + included_head, + &alice, + &slot_durations(), + ); + frame_support::assert_ok!( + PolkadotXcm::force_xcm_version( + RuntimeOrigin::root(), + Box::new(bridging::SiblingBridgeHub::get()), + XCM_VERSION, + ) + ); + + // check no bridge/lane exists + assert_eq!(0, pallet_bridge_messages::OutboundLanes::::iter().count()); + + // send to the `bridged_destination` + frame_support::assert_ok!( + PolkadotXcm::send_xcm( + Here, + bridged_destination.clone(), + Xcm::<()>::default() + ) + ); + + // check HRMP message contains `ExportMessage`. + assert!( + asset_test_utils::RuntimeHelper::, AllPalletsWithoutSystem>::take_xcm(sibling_bridge_hub_para_id.into()) + .map(|m| { + let mut m: Xcm<()> = m.try_into().expect("valid XCM version"); + m.0.matcher() + .skip_inst_while(|inst| !matches!(inst, ExportMessage { .. })) + .expect("no instruction ExportMessage?") + .match_next_inst(|instr| match instr { + ExportMessage { ref network, ..} => { + assert_eq!(network, &bridged_destination.interior.global_consensus().expect("valid NetworkId")); + Ok(()) + }, + _ => Err(ProcessMessageError::BadFormat), + }).is_ok() + }).unwrap_or(false) + ); + + // open permissionless lane between this AH and bridged AH + let (_, lane_id) = bridge_hub_test_utils::ensure_opened_xcm_bridge::< + Runtime, + XcmOverAssetHubWestendInstance, + LocationToAccountId, + TokenLocation, + >( + Here.into(), + bridged_universal_destination, + false, + |locations, maybe_paid_execution| bridge_hub_test_utils::open_xcm_bridge_with_extrinsic::< + Runtime, + XcmOverAssetHubWestendInstance, + >( + // This should represent `RuntimeOrigin::root()` which represents `Location::here()` for `OpenBridgeOrigin` + (Location::parent(), OriginKind::Superuser), + locations.bridge_destination_universal_location().clone(), + maybe_paid_execution + ) + ); + // lane created + assert_eq!(1, pallet_bridge_messages::OutboundLanes::::iter().count()); + + // send to the `bridged_destination` again + frame_support::assert_ok!( + PolkadotXcm::send_xcm( + Here, + bridged_destination.clone(), + Xcm::<()>::default() + ) + ); + + // messages pallet holds outbound message for expected lane_id + assert_eq!(1, pallet_bridge_messages::OutboundLanes::::get(lane_id).map(|d| d.queued_messages().saturating_len()).unwrap_or(0)); + + // no hrmp message was fired + assert!( + asset_test_utils::RuntimeHelper::, AllPalletsWithoutSystem>::take_xcm(sibling_bridge_hub_para_id.into()).is_none() + ); + }); + } +}