From fc72d08b1b593c890303d7e658cd6ee4da8d158d Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Wed, 18 Jan 2023 14:12:05 +0300 Subject: [PATCH] fix benchmarks compilation and add bridges benchmarks (prototype) to RBH/WBH --- Cargo.lock | 1 + .../bridge-hubs/bridge-hub-rococo/Cargo.toml | 10 +- .../src/bridge_hub_rococo_config.rs | 13 +- .../src/bridge_hub_wococo_config.rs | 16 +- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 139 +++++++++++++++++- 5 files changed, 164 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b052902709..756808417f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -962,6 +962,7 @@ dependencies = [ "bp-bridge-hub-rococo", "bp-bridge-hub-wococo", "bp-messages", + "bp-polkadot-core", "bp-rococo", "bp-runtime", "bp-wococo", diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index ab2a920e4c1..469ff873022 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -72,6 +72,7 @@ parachains-common = { path = "../../../../parachains/common", default-features = bp-bridge-hub-rococo = { path = "../../../../bridges/primitives/chain-bridge-hub-rococo", default-features = false } bp-bridge-hub-wococo = { path = "../../../../bridges/primitives/chain-bridge-hub-wococo", default-features = false } bp-messages = { path = "../../../../bridges/primitives/messages", default-features = false } +bp-polkadot-core = { path = "../../../../bridges/primitives/polkadot-core", default-features = false } bp-runtime = { path = "../../../../bridges/primitives/runtime", default-features = false } bp-rococo = { path = "../../../../bridges/primitives/chain-rococo", default-features = false } bp-wococo = { path = "../../../../bridges/primitives/chain-wococo", default-features = false } @@ -92,6 +93,7 @@ std = [ "bp-bridge-hub-rococo/std", "bp-bridge-hub-wococo/std", "bp-messages/std", + "bp-polkadot-core/std", "bp-runtime/std", "bp-rococo/std", "bp-wococo/std", @@ -149,14 +151,20 @@ std = [ ] runtime-benchmarks = [ + "bridge-runtime-common/runtime-benchmarks", "hex-literal", "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", - "frame-system-benchmarking", + "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", + "pallet-bridge-grandpa/runtime-benchmarks", + "pallet-bridge-messages/runtime-benchmarks", + "pallet-bridge-parachains/runtime-benchmarks", + "pallet-bridge-relayers/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_rococo_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_rococo_config.rs index c7506e6d74a..d273854a8ea 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_rococo_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_rococo_config.rs @@ -27,8 +27,8 @@ use bp_runtime::ChainId; use bridge_runtime_common::{ messages, messages::{ - target::FromBridgedChainMessagesProof, MessageBridge, ThisChainWithMessages, - UnderlyingChainProvider, + source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, + MessageBridge, ThisChainWithMessages, UnderlyingChainProvider, }, }; use frame_support::{parameter_types, RuntimeDebug}; @@ -50,6 +50,13 @@ parameter_types! { pub ActiveOutboundLanesToBridgeHubWococo: &'static [bp_messages::LaneId] = &[DEFAULT_XCM_LANE_TO_BRIDGE_HUB_WOCOCO]; } +/// Proof of messages, coming from Wococo. +pub type FromWococoBridgeHubMessagesProof = + FromBridgedChainMessagesProof; +/// Messages delivery proof for Rococo Bridge Hub -> Wococo Bridge Hub messages. +pub type ToWococoBridgeHubMessagesDeliveryProof = + FromBridgedChainMessagesDeliveryProof; + /// Dispatches received XCM messages from other bridge pub type OnBridgeHubRococoBlobDispatcher = BridgeBlobDispatcher; @@ -109,7 +116,7 @@ impl UnderlyingChainProvider for BridgeHubWococo { impl SourceHeaderChain for BridgeHubWococo { type Error = &'static str; - type MessagesProof = FromBridgedChainMessagesProof; + type MessagesProof = FromWococoBridgeHubMessagesProof; fn verify_messages_proof( proof: Self::MessagesProof, diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_wococo_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_wococo_config.rs index 01759671382..6b589ac86b0 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_wococo_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_hub_wococo_config.rs @@ -27,8 +27,8 @@ use bp_runtime::ChainId; use bridge_runtime_common::{ messages, messages::{ - target::FromBridgedChainMessagesProof, MessageBridge, ThisChainWithMessages, - UnderlyingChainProvider, + source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, + MessageBridge, ThisChainWithMessages, UnderlyingChainProvider, }, }; use frame_support::{parameter_types, RuntimeDebug}; @@ -50,6 +50,13 @@ parameter_types! { pub ActiveOutboundLanesToBridgeHubRococo: &'static [bp_messages::LaneId] = &[DEFAULT_XCM_LANE_TO_BRIDGE_HUB_ROCOCO]; } +/// Proof of messages, coming from Rococo. +pub type FromRococoBridgeHubMessagesProof = + FromBridgedChainMessagesProof; +/// Messages delivery proof for Rococo Bridge Hub -> Wococo Bridge Hub messages. +pub type ToRococoBridgeHubMessagesDeliveryProof = + FromBridgedChainMessagesDeliveryProof; + /// Dispatches received XCM messages from other bridge pub type OnBridgeHubWococoBlobDispatcher = BridgeBlobDispatcher; @@ -109,7 +116,7 @@ impl UnderlyingChainProvider for BridgeHubRococo { impl SourceHeaderChain for BridgeHubRococo { type Error = &'static str; - type MessagesProof = FromBridgedChainMessagesProof; + type MessagesProof = FromRococoBridgeHubMessagesProof; fn verify_messages_proof( proof: Self::MessagesProof, @@ -124,8 +131,7 @@ impl SourceHeaderChain for BridgeHubRococo { impl TargetHeaderChain for BridgeHubRococo { type Error = &'static str; - type MessagesDeliveryProof = - messages::source::FromBridgedChainMessagesDeliveryProof; + type MessagesDeliveryProof = ToRococoBridgeHubMessagesDeliveryProof; fn verify_message(payload: &XcmAsPlainPayload) -> Result<(), Self::Error> { messages::source::verify_chain_message::(payload) diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 3ac42e94580..d26ede92b8b 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -589,12 +589,16 @@ construct_runtime!( CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin} = 32, DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 33, - // Wococo bridge modules + // Rococo and Wococo Bridge Hubs are sharing the runtime, so this runtime has two sets of + // bridge pallets. Both are deployed at both runtimes, but only one set is actually used + // at particular runtime. + + // With-Wococo bridge modules that are active (used) at Rococo Bridge Hub runtime. BridgeWococoGrandpa: pallet_bridge_grandpa::::{Pallet, Call, Storage, Config} = 41, BridgeWococoParachain: pallet_bridge_parachains::::{Pallet, Call, Storage, Event} = 42, BridgeWococoMessages: pallet_bridge_messages::::{Pallet, Call, Storage, Event, Config} = 46, - // Rococo bridge modules + // With-Rococo bridge modules that are active (used) at Wococo Bridge Hub runtime. BridgeRococoGrandpa: pallet_bridge_grandpa::::{Pallet, Call, Storage, Config} = 43, BridgeRococoParachain: pallet_bridge_parachains::::{Pallet, Call, Storage, Event} = 44, BridgeRococoMessages: pallet_bridge_messages::::{Pallet, Call, Storage, Event, Config} = 45, @@ -624,10 +628,14 @@ mod benches { [pallet_timestamp, Timestamp] [pallet_collator_selection, CollatorSelection] [cumulus_pallet_xcmp_queue, XcmpQueue] - // XCM - // NOTE: Make sure you point to the individual modules below. - [pallet_xcm_benchmarks::fungible, XcmBalances] - [pallet_xcm_benchmarks::generic, XcmGeneric] + // Bridge pallets at Rococo + [pallet_bridge_grandpa, BridgeWococoGrandpa] + [pallet_bridge_parachains, BridgeParachainsBench::] + [pallet_bridge_messages, BridgeMessagesBench::] + // Bridge pallets at Wococo + [pallet_bridge_grandpa, BridgeRococoGrandpa] + [pallet_bridge_parachains, BridgeParachainsBench::] + [pallet_bridge_messages, BridgeMessagesBench::] ); } @@ -843,6 +851,9 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + use pallet_bridge_parachains::benchmarking::Pallet as BridgeParachainsBench; + use pallet_bridge_messages::benchmarking::Pallet as BridgeMessagesBench; + let mut list = Vec::::new(); list_benchmarks!(list, extra); @@ -861,6 +872,122 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; impl cumulus_pallet_session_benchmarking::Config for Runtime {} + use bridge_runtime_common::messages_benchmarking::{prepare_message_delivery_proof, prepare_message_proof}; + use pallet_bridge_messages::benchmarking::{ + Config as BridgeMessagesConfig, + Pallet as BridgeMessagesBench, + MessageDeliveryProofParams, + MessageProofParams, + }; + + impl BridgeMessagesConfig for Runtime { + // TODO: remove me after bridges subtree update + fn bridged_relayer_id() -> AccountId { [0u8; 32].into() } + fn endow_account(_: &AccountId) {} + fn is_message_dispatched(_: bp_messages::MessageNonce) -> bool { true } + + fn prepare_message_proof( + params: MessageProofParams, + ) -> (bridge_hub_rococo_config::FromWococoBridgeHubMessagesProof, Weight) { + prepare_message_proof::< + Runtime, + (), + BridgeGrandpaWococoInstance, + bridge_hub_rococo_config::WithBridgeHubWococoMessageBridge, + bp_bridge_hub_wococo::Header, + bp_bridge_hub_wococo::Hasher, + >(params) + } + + fn prepare_message_delivery_proof( + params: MessageDeliveryProofParams, + ) -> bridge_hub_rococo_config::ToWococoBridgeHubMessagesDeliveryProof { + prepare_message_delivery_proof::< + Runtime, + BridgeGrandpaWococoInstance, + bridge_hub_rococo_config::WithBridgeHubWococoMessageBridge, + bp_bridge_hub_wococo::Header, + bp_bridge_hub_wococo::Hasher, + >(params) + } + } + + impl BridgeMessagesConfig for Runtime { + // TODO: remove me after bridges subtree update + fn bridged_relayer_id() -> AccountId { [0u8; 32].into() } + fn endow_account(_: &AccountId) {} + fn is_message_dispatched(_: bp_messages::MessageNonce) -> bool { true } + + fn prepare_message_proof( + params: MessageProofParams, + ) -> (bridge_hub_wococo_config::FromRococoBridgeHubMessagesProof, Weight) { + prepare_message_proof::< + Runtime, + (), + BridgeGrandpaRococoInstance, + bridge_hub_wococo_config::WithBridgeHubRococoMessageBridge, + bp_bridge_hub_rococo::Header, + bp_bridge_hub_rococo::Hasher, + >(params) + } + + fn prepare_message_delivery_proof( + params: MessageDeliveryProofParams, + ) -> bridge_hub_wococo_config::ToRococoBridgeHubMessagesDeliveryProof { + prepare_message_delivery_proof::< + Runtime, + BridgeGrandpaRococoInstance, + bridge_hub_wococo_config::WithBridgeHubRococoMessageBridge, + bp_bridge_hub_rococo::Header, + bp_bridge_hub_rococo::Hasher, + >(params) + } + } + + use bridge_runtime_common::parachains_benchmarking::prepare_parachain_heads_proof; + use pallet_bridge_parachains::benchmarking::{ + Config as BridgeParachainsConfig, + Pallet as BridgeParachainsBench, + }; + + impl BridgeParachainsConfig for Runtime { + fn prepare_parachain_heads_proof( + parachains: &[bp_polkadot_core::parachains::ParaId], + parachain_head_size: u32, + proof_size: bp_runtime::StorageProofSize, + ) -> ( + pallet_bridge_parachains::RelayBlockNumber, + pallet_bridge_parachains::RelayBlockHash, + bp_polkadot_core::parachains::ParaHeadsProof, + Vec<(bp_polkadot_core::parachains::ParaId, bp_polkadot_core::parachains::ParaHash)>, + ) { + prepare_parachain_heads_proof::( + parachains, + parachain_head_size, + proof_size, + ) + } + } + + impl BridgeParachainsConfig for Runtime { + fn prepare_parachain_heads_proof( + parachains: &[bp_polkadot_core::parachains::ParaId], + parachain_head_size: u32, + proof_size: bp_runtime::StorageProofSize, + ) -> ( + pallet_bridge_parachains::RelayBlockNumber, + pallet_bridge_parachains::RelayBlockHash, + bp_polkadot_core::parachains::ParaHeadsProof, + Vec<(bp_polkadot_core::parachains::ParaId, bp_polkadot_core::parachains::ParaHash)>, + ) { + prepare_parachain_heads_proof::( + parachains, + parachain_head_size, + proof_size, + ) + } + } + let whitelist: Vec = vec![ // Block Number hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),