Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
fix benchmarks compilation and add bridges benchmarks (prototype) to …
Browse files Browse the repository at this point in the history
…RBH/WBH
  • Loading branch information
svyatonik committed Jan 19, 2023
1 parent 6419dad commit fc72d08
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<bp_bridge_hub_wococo::Hash>;
/// Messages delivery proof for Rococo Bridge Hub -> Wococo Bridge Hub messages.
pub type ToWococoBridgeHubMessagesDeliveryProof =
FromBridgedChainMessagesDeliveryProof<bp_bridge_hub_wococo::Hash>;

/// Dispatches received XCM messages from other bridge
pub type OnBridgeHubRococoBlobDispatcher =
BridgeBlobDispatcher<XcmRouter, BridgeHubRococoUniversalLocation>;
Expand Down Expand Up @@ -109,7 +116,7 @@ impl UnderlyingChainProvider for BridgeHubWococo {

impl SourceHeaderChain for BridgeHubWococo {
type Error = &'static str;
type MessagesProof = FromBridgedChainMessagesProof<crate::Hash>;
type MessagesProof = FromWococoBridgeHubMessagesProof;

fn verify_messages_proof(
proof: Self::MessagesProof,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<bp_bridge_hub_rococo::Hash>;
/// Messages delivery proof for Rococo Bridge Hub -> Wococo Bridge Hub messages.
pub type ToRococoBridgeHubMessagesDeliveryProof =
FromBridgedChainMessagesDeliveryProof<bp_bridge_hub_rococo::Hash>;

/// Dispatches received XCM messages from other bridge
pub type OnBridgeHubWococoBlobDispatcher =
BridgeBlobDispatcher<XcmRouter, BridgeHubWococoUniversalLocation>;
Expand Down Expand Up @@ -109,7 +116,7 @@ impl UnderlyingChainProvider for BridgeHubRococo {

impl SourceHeaderChain for BridgeHubRococo {
type Error = &'static str;
type MessagesProof = FromBridgedChainMessagesProof<crate::Hash>;
type MessagesProof = FromRococoBridgeHubMessagesProof;

fn verify_messages_proof(
proof: Self::MessagesProof,
Expand All @@ -124,8 +131,7 @@ impl SourceHeaderChain for BridgeHubRococo {

impl TargetHeaderChain<XcmAsPlainPayload, crate::AccountId> for BridgeHubRococo {
type Error = &'static str;
type MessagesDeliveryProof =
messages::source::FromBridgedChainMessagesDeliveryProof<bp_bridge_hub_rococo::Hash>;
type MessagesDeliveryProof = ToRococoBridgeHubMessagesDeliveryProof;

fn verify_message(payload: &XcmAsPlainPayload) -> Result<(), Self::Error> {
messages::source::verify_chain_message::<WithBridgeHubRococoMessageBridge>(payload)
Expand Down
139 changes: 133 additions & 6 deletions parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,16 @@ construct_runtime!(
CumulusXcm: cumulus_pallet_xcm::{Pallet, Event<T>, Origin} = 32,
DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 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::<Instance1>::{Pallet, Call, Storage, Config<T>} = 41,
BridgeWococoParachain: pallet_bridge_parachains::<Instance1>::{Pallet, Call, Storage, Event<T>} = 42,
BridgeWococoMessages: pallet_bridge_messages::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>} = 46,

// Rococo bridge modules
// With-Rococo bridge modules that are active (used) at Wococo Bridge Hub runtime.
BridgeRococoGrandpa: pallet_bridge_grandpa::<Instance2>::{Pallet, Call, Storage, Config<T>} = 43,
BridgeRococoParachain: pallet_bridge_parachains::<Instance2>::{Pallet, Call, Storage, Event<T>} = 44,
BridgeRococoMessages: pallet_bridge_messages::<Instance2>::{Pallet, Call, Storage, Event<T>, Config<T>} = 45,
Expand Down Expand Up @@ -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::<Runtime, BridgeParachainWococoInstance>]
[pallet_bridge_messages, BridgeMessagesBench::<Runtime, WithBridgeHubWococoMessagesInstance>]
// Bridge pallets at Wococo
[pallet_bridge_grandpa, BridgeRococoGrandpa]
[pallet_bridge_parachains, BridgeParachainsBench::<Runtime, BridgeParachainRococoInstance>]
[pallet_bridge_messages, BridgeMessagesBench::<Runtime, WithBridgeHubRococoMessagesInstance>]
);
}

Expand Down Expand Up @@ -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::<BenchmarkList>::new();
list_benchmarks!(list, extra);

Expand All @@ -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<WithBridgeHubWococoMessagesInstance> 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<AccountId>,
) -> 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<WithBridgeHubRococoMessagesInstance> 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<AccountId>,
) -> 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<BridgeParachainWococoInstance> 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::<Runtime, BridgeParachainWococoInstance>(
parachains,
parachain_head_size,
proof_size,
)
}
}

impl BridgeParachainsConfig<BridgeParachainRococoInstance> 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::<Runtime, BridgeParachainRococoInstance>(
parachains,
parachain_head_size,
proof_size,
)
}
}

let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
Expand Down

0 comments on commit fc72d08

Please sign in to comment.