Skip to content

Commit

Permalink
fix send_message_worst_case (paritytech#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored and serban300 committed Apr 10, 2024
1 parent 86e0563 commit a4e8da6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ impl_runtime_apis! {
}

fn prepare_message(
params: MessageLaneMessageParams,
params: MessageLaneMessageParams<Self::AccountId>,
) -> (millau_messages::ToMillauMessagePayload, Balance) {
use crate::millau_messages::{ToMillauMessagePayload, WithMillauMessageBridge};
use bridge_runtime_common::messages;
Expand All @@ -843,7 +843,9 @@ impl_runtime_apis! {
* sp_std::cmp::min(factor, WORST_MESSAGE_SIZE_FACTOR),
};
let message_payload = vec![0; message_size as usize];
let dispatch_origin = pallet_bridge_call_dispatch::CallOrigin::SourceAccount(Default::default());
let dispatch_origin = pallet_bridge_call_dispatch::CallOrigin::SourceAccount(
params.sender_account,
);

let message = ToMillauMessagePayload {
spec_version: 0,
Expand Down
11 changes: 8 additions & 3 deletions bridges/modules/message-lane/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@ const SEED: u32 = 0;
pub struct Module<T: Trait<I>, I: crate::Instance>(crate::Module<T, I>);

/// Benchmark-specific message parameters.
pub struct MessageParams {
pub struct MessageParams<ThisAccountId> {
/// Size factor of the message payload. Message payload grows with every factor
/// increment. Zero is the smallest possible message and the `WORST_MESSAGE_SIZE_FACTOR` is
/// largest possible message.
pub size_factor: u32,
/// Message sender account.
pub sender_account: ThisAccountId,
}

/// Trait that must be implemented by runtime.
pub trait Trait<I: Instance>: crate::Trait<I> {
/// Create given account and give it enough balance for test purposes.
fn endow_account(account: &Self::AccountId);
/// Prepare message to send over lane.
fn prepare_message(params: MessageParams) -> (Self::OutboundPayload, Self::OutboundMessageFee);
fn prepare_message(params: MessageParams<Self::AccountId>) -> (Self::OutboundPayload, Self::OutboundMessageFee);
}

benchmarks_instance! {
Expand All @@ -70,7 +72,10 @@ benchmarks_instance! {
}
confirm_message_delivery::<T, I>(T::MaxMessagesToPruneAtOnce::get());

let (payload, fee) = T::prepare_message(MessageParams { size_factor: WORST_MESSAGE_SIZE_FACTOR });
let (payload, fee) = T::prepare_message(MessageParams {
size_factor: WORST_MESSAGE_SIZE_FACTOR,
sender_account: sender.clone(),
});
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
}

Expand Down

0 comments on commit a4e8da6

Please sign in to comment.