diff --git a/Cargo.lock b/Cargo.lock index 1f0ec406ec..15f69416e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -956,7 +956,9 @@ dependencies = [ "bp-runtime", "ed25519-dalek", "frame-support", + "frame-system", "hash-db", + "pallet-balances", "pallet-bridge-dispatch", "pallet-bridge-grandpa", "pallet-bridge-messages", @@ -968,6 +970,7 @@ dependencies = [ "sp-state-machine", "sp-std", "sp-trie", + "sp-version", ] [[package]] diff --git a/bin/millau/runtime/src/lib.rs b/bin/millau/runtime/src/lib.rs index 4d6ecd8ba3..5734517f15 100644 --- a/bin/millau/runtime/src/lib.rs +++ b/bin/millau/runtime/src/lib.rs @@ -828,7 +828,7 @@ impl_runtime_apis! { let mut batches = Vec::::new(); let params = (&config, &whitelist); - use bp_runtime::messages::DispatchFeePayment; + use bridge_runtime_common::messages_benchmarking::{prepare_message_delivery_proof, prepare_message_proof, prepare_outbound_message}; use bridge_runtime_common::messages; use pallet_bridge_messages::benchmarking::{ Pallet as MessagesBench, @@ -836,9 +836,8 @@ impl_runtime_apis! { MessageDeliveryProofParams, MessageParams, MessageProofParams, - ProofSize as MessagesProofSize, }; - use rialto_messages::{ToRialtoMessagePayload, WithRialtoMessageBridge}; + use rialto_messages::WithRialtoMessageBridge; impl MessagesConfig for Runtime { fn maximal_message_size() -> u32 { @@ -863,120 +862,24 @@ impl_runtime_apis! { fn prepare_outbound_message( params: MessageParams, ) -> (rialto_messages::ToRialtoMessagePayload, Balance) { - let message_payload = vec![0; params.size as usize]; - let dispatch_origin = bp_message_dispatch::CallOrigin::SourceAccount( - params.sender_account, - ); - - let message = ToRialtoMessagePayload { - spec_version: 0, - weight: params.size as _, - origin: dispatch_origin, - call: message_payload, - dispatch_fee_payment: DispatchFeePayment::AtSourceChain, - }; - (message, pallet_bridge_messages::benchmarking::MESSAGE_FEE.into()) + prepare_outbound_message::(params) } fn prepare_message_proof( params: MessageProofParams, ) -> (rialto_messages::FromRialtoMessagesProof, Weight) { - use bp_messages::{MessageKey, storage_keys}; - use bridge_runtime_common::{ - messages::MessageBridge, - messages_benchmarking::{ed25519_sign, prepare_message_proof}, - }; - use codec::Encode; - use frame_support::weights::GetDispatchInfo; - use rialto_messages::WithRialtoMessageBridge; - use sp_runtime::traits::{Header, IdentifyAccount}; - - let remark = match params.size { - MessagesProofSize::Minimal(ref size) => vec![0u8; *size as _], - _ => vec![], - }; - let call = Call::System(SystemCall::remark { remark }); - let call_weight = call.get_dispatch_info().weight; - - let rialto_account_id: bp_rialto::AccountId = Default::default(); - let (millau_raw_public, millau_raw_signature) = ed25519_sign( - &call, - &rialto_account_id, - VERSION.spec_version, - bp_runtime::RIALTO_CHAIN_ID, - bp_runtime::MILLAU_CHAIN_ID, - ); - let millau_public = MultiSigner::Ed25519(sp_core::ed25519::Public::from_raw(millau_raw_public)); - let millau_signature = MultiSignature::Ed25519(sp_core::ed25519::Signature::from_raw( - millau_raw_signature, - )); - - if params.dispatch_fee_payment == DispatchFeePayment::AtTargetChain { - Self::endow_account(&millau_public.clone().into_account()); - } - - let make_rialto_message_key = |message_key: MessageKey| storage_keys::message_key( - ::BRIDGED_MESSAGES_PALLET_NAME, - &message_key.lane_id, message_key.nonce, - ).0; - let make_rialto_outbound_lane_data_key = |lane_id| storage_keys::outbound_lane_data_key( - ::BRIDGED_MESSAGES_PALLET_NAME, - &lane_id, - ).0; - - let make_rialto_header = |state_root| bp_rialto::Header::new( - 0, - Default::default(), - state_root, - Default::default(), - Default::default(), - ); - - let dispatch_fee_payment = params.dispatch_fee_payment.clone(); - prepare_message_proof::( + prepare_message_proof::( params, - make_rialto_message_key, - make_rialto_outbound_lane_data_key, - make_rialto_header, - call_weight, - bp_message_dispatch::MessagePayload { - spec_version: VERSION.spec_version, - weight: call_weight, - origin: bp_message_dispatch::CallOrigin::< - bp_rialto::AccountId, - MultiSigner, - Signature, - >::TargetAccount( - rialto_account_id, - millau_public, - millau_signature, - ), - dispatch_fee_payment, - call: call.encode(), - }.encode(), + &VERSION, + Balance::MAX / 100, ) } fn prepare_message_delivery_proof( params: MessageDeliveryProofParams, ) -> rialto_messages::ToRialtoMessagesDeliveryProof { - use bridge_runtime_common::messages_benchmarking::prepare_message_delivery_proof; - use rialto_messages::WithRialtoMessageBridge; - use sp_runtime::traits::Header; - - prepare_message_delivery_proof::( + prepare_message_delivery_proof::( params, - |lane_id| bp_messages::storage_keys::inbound_lane_data_key( - ::BRIDGED_MESSAGES_PALLET_NAME, - &lane_id, - ).0, - |state_root| bp_rialto::Header::new( - 0, - Default::default(), - state_root, - Default::default(), - Default::default(), - ), ) } diff --git a/bin/runtime-common/Cargo.toml b/bin/runtime-common/Cargo.toml index 0ae642ba55..ed3bb32d17 100644 --- a/bin/runtime-common/Cargo.toml +++ b/bin/runtime-common/Cargo.toml @@ -25,12 +25,15 @@ pallet-bridge-messages = { path = "../../modules/messages", default-features = f # Substrate dependencies frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } [features] default = ["std"] @@ -54,7 +57,10 @@ std = [ ] runtime-benchmarks = [ "ed25519-dalek/u64_backend", + "frame-system", + "pallet-balances", "pallet-bridge-grandpa/runtime-benchmarks", "pallet-bridge-messages/runtime-benchmarks", "sp-state-machine", + "sp-version", ] diff --git a/bin/runtime-common/src/messages.rs b/bin/runtime-common/src/messages.rs index dd03379ce5..47fb1c48f4 100644 --- a/bin/runtime-common/src/messages.rs +++ b/bin/runtime-common/src/messages.rs @@ -176,7 +176,7 @@ pub type BalanceOf = ::Balance; pub type CallOf = ::Call; /// Raw storage proof type (just raw trie nodes). -type RawStorageProof = Vec>; +pub type RawStorageProof = Vec>; /// Compute fee of transaction at runtime where regular transaction payment pallet is being used. /// diff --git a/bin/runtime-common/src/messages_benchmarking.rs b/bin/runtime-common/src/messages_benchmarking.rs index 217560e114..1b14ee30ae 100644 --- a/bin/runtime-common/src/messages_benchmarking.rs +++ b/bin/runtime-common/src/messages_benchmarking.rs @@ -20,162 +20,164 @@ #![cfg(feature = "runtime-benchmarks")] use crate::messages::{ - source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, - AccountIdOf, BalanceOf, BridgedChain, HashOf, MessageBridge, ThisChain, + source::{FromBridgedChainMessagesDeliveryProof, FromThisChainMessagePayload}, + target::FromBridgedChainMessagesProof, + AccountIdOf, BalanceOf, BridgedChain, CallOf, HashOf, MessageBridge, RawStorageProof, + SignatureOf, SignerOf, ThisChain, }; -use bp_messages::{LaneId, MessageData, MessageKey, MessagePayload}; -use bp_runtime::ChainId; +use bp_messages::{storage_keys, MessageData, MessageKey, MessagePayload}; +use bp_runtime::{messages::DispatchFeePayment, ChainId}; use codec::Encode; use ed25519_dalek::{PublicKey, SecretKey, Signer, KEYPAIR_LENGTH, SECRET_KEY_LENGTH}; -use frame_support::weights::Weight; +use frame_support::{ + traits::Currency, + weights::{GetDispatchInfo, Weight}, +}; use pallet_bridge_messages::benchmarking::{ - MessageDeliveryProofParams, MessageProofParams, ProofSize, + MessageDeliveryProofParams, MessageParams, MessageProofParams, ProofSize, }; use sp_core::Hasher; -use sp_runtime::traits::Header; -use sp_std::prelude::*; +use sp_runtime::traits::{Header, IdentifyAccount, MaybeSerializeDeserialize, Zero}; +use sp_std::{fmt::Debug, prelude::*}; use sp_trie::{record_all_keys, trie_types::TrieDBMut, Layout, MemoryDB, Recorder, TrieMut}; +use sp_version::RuntimeVersion; -/// Generate ed25519 signature to be used in -/// `pallet_brdige_call_dispatch::CallOrigin::TargetAccount`. -/// -/// Returns public key of the signer and the signature itself. -pub fn ed25519_sign( - target_call: &impl Encode, - source_account_id: &impl Encode, - target_spec_version: u32, - source_chain_id: ChainId, - target_chain_id: ChainId, -) -> ([u8; 32], [u8; 64]) { - // key from the repo example (https://docs.rs/ed25519-dalek/1.0.1/ed25519_dalek/struct.SecretKey.html) - let target_secret = SecretKey::from_bytes(&[ - 157, 097, 177, 157, 239, 253, 090, 096, 186, 132, 074, 244, 146, 236, 044, 196, 068, 073, - 197, 105, 123, 050, 105, 025, 112, 059, 172, 003, 028, 174, 127, 096, - ]) - .expect("harcoded key is valid"); - let target_public: PublicKey = (&target_secret).into(); - - let mut target_pair_bytes = [0u8; KEYPAIR_LENGTH]; - target_pair_bytes[..SECRET_KEY_LENGTH].copy_from_slice(&target_secret.to_bytes()); - target_pair_bytes[SECRET_KEY_LENGTH..].copy_from_slice(&target_public.to_bytes()); - let target_pair = - ed25519_dalek::Keypair::from_bytes(&target_pair_bytes).expect("hardcoded pair is valid"); - - let signature_message = pallet_bridge_dispatch::account_ownership_digest( - target_call, - source_account_id, - target_spec_version, - source_chain_id, - target_chain_id, - ); - let target_origin_signature = target_pair - .try_sign(&signature_message) - .expect("Ed25519 try_sign should not fail in benchmarks"); +/// Prepare outbound message for the `send_message` call. +pub fn prepare_outbound_message( + params: MessageParams>>, +) -> (FromThisChainMessagePayload, BalanceOf>) +where + B: MessageBridge, + BalanceOf>: From, +{ + let message_payload = vec![0; params.size as usize]; + let dispatch_origin = bp_message_dispatch::CallOrigin::SourceAccount(params.sender_account); - (target_public.to_bytes(), target_origin_signature.to_bytes()) + let message = FromThisChainMessagePayload:: { + spec_version: 0, + weight: params.size as _, + origin: dispatch_origin, + call: message_payload, + dispatch_fee_payment: DispatchFeePayment::AtSourceChain, + }; + (message, pallet_bridge_messages::benchmarking::MESSAGE_FEE.into()) } /// Prepare proof of messages for the `receive_messages_proof` call. -pub fn prepare_message_proof( +/// +/// In addition to returning valid messages proof, environment is prepared to verify this message +/// proof. +pub fn prepare_message_proof( params: MessageProofParams, - make_bridged_message_storage_key: MM, - make_bridged_outbound_lane_data_key: ML, - make_bridged_header: MH, - message_dispatch_weight: Weight, - message_payload: MessagePayload, + version: &RuntimeVersion, + endow_amount: BalanceOf>, ) -> (FromBridgedChainMessagesProof>>, Weight) where + R: frame_system::Config>> + + pallet_balances::Config>> + + pallet_bridge_grandpa::Config, + R::BridgedChain: bp_runtime::Chain
, B: MessageBridge, - H: Hasher, - R: pallet_bridge_grandpa::Config, + BI: 'static, FI: 'static, - ::Hash: Into>>, - MM: Fn(MessageKey) -> Vec, - ML: Fn(LaneId) -> Vec, - MH: Fn(H::Out) -> ::Header, + BH: Header>>, + BHH: Hasher>>, + AccountIdOf>: From<[u8; 32]>, + BalanceOf>: Debug + MaybeSerializeDeserialize, + CallOf>: From> + GetDispatchInfo, + HashOf>: Copy + Default, + SignatureOf>: From, + SignerOf>: Clone + + From + + IdentifyAccount>>, { - // prepare Bridged chain storage with messages and (optionally) outbound lane state - let message_count = - params.message_nonces.end().saturating_sub(*params.message_nonces.start()) + 1; - let mut storage_keys = Vec::with_capacity(message_count as usize + 1); - let mut root = Default::default(); - let mut mdb = MemoryDB::default(); - { - let mut trie = TrieDBMut::::new(&mut mdb, &mut root); + // we'll be dispatching the same call at This chain + let remark = match params.size { + ProofSize::Minimal(ref size) => vec![0u8; *size as _], + _ => vec![], + }; + let call: CallOf> = frame_system::Call::remark { remark }.into(); + let call_weight = call.get_dispatch_info().weight; - // insert messages - for nonce in params.message_nonces.clone() { - let message_key = MessageKey { lane_id: params.lane, nonce }; - let message_data = MessageData { - fee: BalanceOf::>::from(0), - payload: message_payload.clone(), - }; - let storage_key = make_bridged_message_storage_key(message_key); - trie.insert(&storage_key, &message_data.encode()) - .map_err(|_| "TrieMut::insert has failed") - .expect("TrieMut::insert should not fail in benchmarks"); - storage_keys.push(storage_key); - } + // message payload needs to be signed, because we use `TargetAccount` call origin + // (which is 'heaviest' to verify) + let bridged_account_id: AccountIdOf> = [0u8; 32].into(); + let (this_raw_public, this_raw_signature) = ed25519_sign( + &call, + &bridged_account_id, + version.spec_version, + B::BRIDGED_CHAIN_ID, + B::THIS_CHAIN_ID, + ); + let this_public: SignerOf> = + sp_core::ed25519::Public::from_raw(this_raw_public).into(); + let this_signature: SignatureOf> = + sp_core::ed25519::Signature::from_raw(this_raw_signature).into(); - // insert outbound lane state - if let Some(outbound_lane_data) = params.outbound_lane_data { - let storage_key = make_bridged_outbound_lane_data_key(params.lane); - trie.insert(&storage_key, &outbound_lane_data.encode()) - .map_err(|_| "TrieMut::insert has failed") - .expect("TrieMut::insert should not fail in benchmarks"); - storage_keys.push(storage_key); - } + // if dispatch fee is paid at this chain, endow relayer account + if params.dispatch_fee_payment == DispatchFeePayment::AtTargetChain { + pallet_balances::Pallet::::make_free_balance_be( + &this_public.clone().into_account(), + endow_amount, + ); } - root = grow_trie(root, &mut mdb, params.size); - // generate storage proof to be delivered to This chain - let mut proof_recorder = Recorder::::new(); - record_all_keys::, _>(&mdb, &root, &mut proof_recorder) - .map_err(|_| "record_all_keys has failed") - .expect("record_all_keys should not fail in benchmarks"); - let storage_proof = proof_recorder.drain().into_iter().map(|n| n.data.to_vec()).collect(); + // prepare message payload that is stored in the Bridged chain storage + let message_payload = bp_message_dispatch::MessagePayload { + spec_version: version.spec_version, + weight: call_weight, + origin: bp_message_dispatch::CallOrigin::< + AccountIdOf>, + SignerOf>, + SignatureOf>, + >::TargetAccount(bridged_account_id, this_public, this_signature), + dispatch_fee_payment: params.dispatch_fee_payment.clone(), + call: call.encode(), + } + .encode(); - // prepare Bridged chain header and insert it into the Substrate pallet - let bridged_header = make_bridged_header(root); - let bridged_header_hash = bridged_header.hash(); - pallet_bridge_grandpa::initialize_for_benchmarks::(bridged_header); + // finally - prepare storage proof and update environment + let (state_root, storage_proof) = + prepare_messages_storage_proof::(¶ms, message_payload); + let bridged_header_hash = insert_bridged_chain_header::(state_root); ( FromBridgedChainMessagesProof { - bridged_header_hash: bridged_header_hash.into(), + bridged_header_hash, storage_proof, lane: params.lane, nonces_start: *params.message_nonces.start(), nonces_end: *params.message_nonces.end(), }, - message_dispatch_weight - .checked_mul(message_count) + call_weight + .checked_mul( + params.message_nonces.end().saturating_sub(*params.message_nonces.start()) + 1, + ) .expect("too many messages requested by benchmark"), ) } /// Prepare proof of messages delivery for the `receive_messages_delivery_proof` call. -pub fn prepare_message_delivery_proof( +pub fn prepare_message_delivery_proof( params: MessageDeliveryProofParams>>, - make_bridged_inbound_lane_data_key: ML, - make_bridged_header: MH, ) -> FromBridgedChainMessagesDeliveryProof>> where - B: MessageBridge, - H: Hasher, R: pallet_bridge_grandpa::Config, + R::BridgedChain: bp_runtime::Chain
, FI: 'static, - ::Hash: Into>>, - ML: Fn(LaneId) -> Vec, - MH: Fn(H::Out) -> ::Header, + B: MessageBridge, + BH: Header>>, + BHH: Hasher>>, + HashOf>: Copy + Default, { // prepare Bridged chain storage with inbound lane state - let storage_key = make_bridged_inbound_lane_data_key(params.lane); + let storage_key = + storage_keys::inbound_lane_data_key(B::BRIDGED_MESSAGES_PALLET_NAME, ¶ms.lane).0; let mut root = Default::default(); let mut mdb = MemoryDB::default(); { - let mut trie = TrieDBMut::::new(&mut mdb, &mut root); + let mut trie = TrieDBMut::::new(&mut mdb, &mut root); trie.insert(&storage_key, ¶ms.inbound_lane_data.encode()) .map_err(|_| "TrieMut::insert has failed") .expect("TrieMut::insert should not fail in benchmarks"); @@ -183,16 +185,14 @@ where root = grow_trie(root, &mut mdb, params.size); // generate storage proof to be delivered to This chain - let mut proof_recorder = Recorder::::new(); - record_all_keys::, _>(&mdb, &root, &mut proof_recorder) + let mut proof_recorder = Recorder::::new(); + record_all_keys::, _>(&mdb, &root, &mut proof_recorder) .map_err(|_| "record_all_keys has failed") .expect("record_all_keys should not fail in benchmarks"); let storage_proof = proof_recorder.drain().into_iter().map(|n| n.data.to_vec()).collect(); - // prepare Bridged chain header and insert it into the Substrate pallet - let bridged_header = make_bridged_header(root); - let bridged_header_hash = bridged_header.hash(); - pallet_bridge_grandpa::initialize_for_benchmarks::(bridged_header); + // finally insert header with given state root to our storage + let bridged_header_hash = insert_bridged_chain_header::(root); FromBridgedChainMessagesDeliveryProof { bridged_header_hash: bridged_header_hash.into(), @@ -201,6 +201,132 @@ where } } +/// Prepare storage proof of given messages. +/// +/// Returns state trie root and nodes with prepared messages. +fn prepare_messages_storage_proof( + params: &MessageProofParams, + message_payload: MessagePayload, +) -> (HashOf>, RawStorageProof) +where + B: MessageBridge, + BHH: Hasher>>, + HashOf>: Copy + Default, +{ + // prepare Bridged chain storage with messages and (optionally) outbound lane state + let message_count = + params.message_nonces.end().saturating_sub(*params.message_nonces.start()) + 1; + let mut storage_keys = Vec::with_capacity(message_count as usize + 1); + let mut root = Default::default(); + let mut mdb = MemoryDB::default(); + { + let mut trie = TrieDBMut::::new(&mut mdb, &mut root); + + // insert messages + for nonce in params.message_nonces.clone() { + let message_key = MessageKey { lane_id: params.lane, nonce }; + let message_data = MessageData { + fee: BalanceOf::>::from(0), + payload: message_payload.clone(), + }; + let storage_key = storage_keys::message_key( + B::BRIDGED_MESSAGES_PALLET_NAME, + &message_key.lane_id, + message_key.nonce, + ) + .0; + trie.insert(&storage_key, &message_data.encode()) + .map_err(|_| "TrieMut::insert has failed") + .expect("TrieMut::insert should not fail in benchmarks"); + storage_keys.push(storage_key); + } + + // insert outbound lane state + if let Some(ref outbound_lane_data) = params.outbound_lane_data { + let storage_key = + storage_keys::outbound_lane_data_key(B::BRIDGED_MESSAGES_PALLET_NAME, ¶ms.lane) + .0; + trie.insert(&storage_key, &outbound_lane_data.encode()) + .map_err(|_| "TrieMut::insert has failed") + .expect("TrieMut::insert should not fail in benchmarks"); + storage_keys.push(storage_key); + } + } + root = grow_trie(root, &mut mdb, params.size); + + // generate storage proof to be delivered to This chain + let mut proof_recorder = Recorder::::new(); + record_all_keys::, _>(&mdb, &root, &mut proof_recorder) + .map_err(|_| "record_all_keys has failed") + .expect("record_all_keys should not fail in benchmarks"); + let storage_proof = proof_recorder.drain().into_iter().map(|n| n.data.to_vec()).collect(); + + (root, storage_proof) +} + +/// Insert Bridged chain header with given state root into storage of GRANDPA pallet at This chain. +fn insert_bridged_chain_header( + state_root: HashOf>, +) -> HashOf> +where + R: pallet_bridge_grandpa::Config, + R::BridgedChain: bp_runtime::Chain
, + FI: 'static, + B: MessageBridge, + BH: Header>>, + HashOf>: Default, +{ + let bridged_header = BH::new( + Zero::zero(), + Default::default(), + state_root, + Default::default(), + Default::default(), + ); + let bridged_header_hash = bridged_header.hash(); + pallet_bridge_grandpa::initialize_for_benchmarks::(bridged_header); + bridged_header_hash +} + +/// Generate ed25519 signature to be used in +/// `pallet_brdige_call_dispatch::CallOrigin::TargetAccount`. +/// +/// Returns public key of the signer and the signature itself. +fn ed25519_sign( + target_call: &impl Encode, + source_account_id: &impl Encode, + target_spec_version: u32, + source_chain_id: ChainId, + target_chain_id: ChainId, +) -> ([u8; 32], [u8; 64]) { + // key from the repo example (https://docs.rs/ed25519-dalek/1.0.1/ed25519_dalek/struct.SecretKey.html) + let target_secret = SecretKey::from_bytes(&[ + 157, 097, 177, 157, 239, 253, 090, 096, 186, 132, 074, 244, 146, 236, 044, 196, 068, 073, + 197, 105, 123, 050, 105, 025, 112, 059, 172, 003, 028, 174, 127, 096, + ]) + .expect("harcoded key is valid"); + let target_public: PublicKey = (&target_secret).into(); + + let mut target_pair_bytes = [0u8; KEYPAIR_LENGTH]; + target_pair_bytes[..SECRET_KEY_LENGTH].copy_from_slice(&target_secret.to_bytes()); + target_pair_bytes[SECRET_KEY_LENGTH..].copy_from_slice(&target_public.to_bytes()); + let target_pair = + ed25519_dalek::Keypair::from_bytes(&target_pair_bytes).expect("hardcoded pair is valid"); + + let signature_message = pallet_bridge_dispatch::account_ownership_digest( + target_call, + source_account_id, + target_spec_version, + source_chain_id, + target_chain_id, + ); + let target_origin_signature = target_pair + .try_sign(&signature_message) + .expect("Ed25519 try_sign should not fail in benchmarks"); + + (target_public.to_bytes(), target_origin_signature.to_bytes()) +} + /// Populate trie with dummy keys+values until trie has at least given size. fn grow_trie(mut root: H::Out, mdb: &mut MemoryDB, trie_size: ProofSize) -> H::Out { let (iterations, leaf_size, minimal_trie_size) = match trie_size { diff --git a/modules/messages/src/benchmarking.rs b/modules/messages/src/benchmarking.rs index f396365699..392e28176b 100644 --- a/modules/messages/src/benchmarking.rs +++ b/modules/messages/src/benchmarking.rs @@ -41,6 +41,7 @@ const SEED: u32 = 0; pub struct Pallet, I: 'static>(crate::Pallet); /// Proof size requirements. +#[derive(Clone, Copy, Debug)] pub enum ProofSize { /// The proof is expected to be minimal. If value size may be changed, then it is expected to /// have given size. @@ -54,6 +55,7 @@ pub enum ProofSize { } /// Benchmark-specific message parameters. +#[derive(Debug)] pub struct MessageParams { /// Size of the message payload. pub size: u32, @@ -62,6 +64,7 @@ pub struct MessageParams { } /// Benchmark-specific message proof parameters. +#[derive(Debug)] pub struct MessageProofParams { /// Id of the lane. pub lane: LaneId, @@ -76,6 +79,7 @@ pub struct MessageProofParams { } /// Benchmark-specific message delivery proof parameters. +#[derive(Debug)] pub struct MessageDeliveryProofParams { /// Id of the lane. pub lane: LaneId,