Skip to content

Commit

Permalink
Fix maximal message dispatch weight (#2219)
Browse files Browse the repository at this point in the history
* add test for maximal message dispatch weight

* fixed weight computations - use kb for both size-related benchmarks

* fix typo in weight formula

* decreased maximal message size to 64Kb
  • Loading branch information
svyatonik authored and bkontur committed May 20, 2024
1 parent 5915e27 commit 9ff9060
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 125 deletions.
6 changes: 6 additions & 0 deletions bridges/bin/runtime-common/src/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ pub fn check_message_lane_weights<
// check basic weight assumptions
pallet_bridge_messages::ensure_weights_are_correct::<Weights<T, MessagesPalletInstance>>();

// check that the maximal message dispatch weight is below hardcoded limit
pallet_bridge_messages::ensure_maximal_message_dispatch::<Weights<T, MessagesPalletInstance>>(
C::maximal_incoming_message_size(),
C::maximal_incoming_message_dispatch_weight(),
);

// check that weights allow us to receive messages
let max_incoming_message_proof_size =
bridged_chain_extra_storage_proof_size.saturating_add(C::maximal_incoming_message_size());
Expand Down
10 changes: 5 additions & 5 deletions bridges/modules/messages/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ mod benchmarks {
// * message is dispatched (reminder: dispatch weight should be minimal);
// * message requires all heavy checks done by dispatcher.
#[benchmark]
fn receive_single_message_n_kb_proof(
fn receive_single_message_n_bytes_proof(
/// Proof size in KB
n: Linear<1, 16>,
n: Linear<1, { 16 * 1024 }>,
) {
// setup code
let setup = ReceiveMessagesProofSetup::<T, I>::new(1);
Expand All @@ -313,7 +313,7 @@ mod benchmarks {
message_nonces: setup.nonces(),
outbound_lane_data: None,
is_successful_dispatch_expected: false,
size: StorageProofSize::Minimal(n * 1024),
size: StorageProofSize::Minimal(n),
});

#[extrinsic_call]
Expand Down Expand Up @@ -491,8 +491,8 @@ mod benchmarks {
// #[benchmark(extra)]
#[benchmark]
fn receive_single_message_n_bytes_proof_with_dispatch(
/// Proof size in bytes
n: Linear<EXPECTED_DEFAULT_MESSAGE_LENGTH, { EXPECTED_DEFAULT_MESSAGE_LENGTH * 16 }>,
/// Proof size in KB
n: Linear<1, { 16 * 1024 }>,
) {
// setup code
let setup = ReceiveMessagesProofSetup::<T, I>::new(1);
Expand Down
4 changes: 2 additions & 2 deletions bridges/modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub use outbound_lane::StoredMessagePayload;
pub use weights::WeightInfo;
pub use weights_ext::{
ensure_able_to_receive_confirmation, ensure_able_to_receive_message,
ensure_weights_are_correct, WeightInfoExt, EXPECTED_DEFAULT_MESSAGE_LENGTH,
EXTRA_STORAGE_PROOF_SIZE,
ensure_maximal_message_dispatch, ensure_weights_are_correct, WeightInfoExt,
EXPECTED_DEFAULT_MESSAGE_LENGTH, EXTRA_STORAGE_PROOF_SIZE,
};

use crate::{
Expand Down
Loading

0 comments on commit 9ff9060

Please sign in to comment.