Skip to content

Commit

Permalink
verify ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT constant value (parity…
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored and serban300 committed Apr 8, 2024
1 parent f80d8f8 commit 371e35d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 20 deletions.
3 changes: 2 additions & 1 deletion bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ mod tests {
type Weights = pallet_message_lane::weights::RialtoWeight<Runtime>;

pallet_message_lane::ensure_weights_are_correct::<Weights>(
bp_millau::MAX_SINGLE_MESSAGE_DELIVERY_TX_WEIGHT,
bp_millau::DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT,
bp_millau::ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT,
bp_millau::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT,
);

Expand Down
2 changes: 1 addition & 1 deletion bridges/bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl MessageBridge for WithRialtoMessageBridge {
message_payload_len.saturating_add(bp_millau::EXTRA_STORAGE_PROOF_SIZE as _),
extra_bytes_in_payload
.saturating_mul(bp_rialto::ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT)
.saturating_add(bp_rialto::MAX_SINGLE_MESSAGE_DELIVERY_TX_WEIGHT),
.saturating_add(bp_rialto::DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT),
)
}

Expand Down
3 changes: 2 additions & 1 deletion bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,8 @@ mod tests {
type Weights = pallet_message_lane::weights::RialtoWeight<Runtime>;

pallet_message_lane::ensure_weights_are_correct::<Weights>(
bp_rialto::MAX_SINGLE_MESSAGE_DELIVERY_TX_WEIGHT,
bp_rialto::DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT,
bp_rialto::ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT,
bp_rialto::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT,
);

Expand Down
2 changes: 1 addition & 1 deletion bridges/bin/rialto/runtime/src/millau_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl MessageBridge for WithMillauMessageBridge {
message_payload_len.saturating_add(bp_rialto::EXTRA_STORAGE_PROOF_SIZE as _),
extra_bytes_in_payload
.saturating_mul(bp_millau::ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT)
.saturating_add(bp_millau::MAX_SINGLE_MESSAGE_DELIVERY_TX_WEIGHT),
.saturating_add(bp_millau::DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT),
)
}

Expand Down
18 changes: 14 additions & 4 deletions bridges/modules/message-lane/src/weights_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const SIGNED_EXTENSIONS_SIZE: u32 = 1024;

/// Ensure that weights from `WeightInfoExt` implementation are looking correct.
pub fn ensure_weights_are_correct<W: WeightInfoExt>(
expected_single_regular_message_delivery_tx_weight: Weight,
expected_default_message_delivery_tx_weight: Weight,
expected_additional_byte_delivery_weight: Weight,
expected_messages_delivery_confirmation_tx_weight: Weight,
) {
// verify `send_message` weight components
Expand All @@ -51,10 +52,19 @@ pub fn ensure_weights_are_correct<W: WeightInfoExt>(
0,
);
assert!(
actual_single_regular_message_delivery_tx_weight <= expected_single_regular_message_delivery_tx_weight,
"Single message delivery transaction weight {} is larger than expected weight {}",
actual_single_regular_message_delivery_tx_weight <= expected_default_message_delivery_tx_weight,
"Default message delivery transaction weight {} is larger than expected weight {}",
actual_single_regular_message_delivery_tx_weight,
expected_single_regular_message_delivery_tx_weight,
expected_default_message_delivery_tx_weight,
);

// verify that hardcoded value covers additional byte length of `receive_messages_proof` weight
let actual_additional_byte_delivery_weight = W::storage_proof_size_overhead(1);
assert!(
actual_additional_byte_delivery_weight <= expected_additional_byte_delivery_weight,
"Single additional byte delivery weight {} is larger than expected weight {}",
actual_additional_byte_delivery_weight,
expected_additional_byte_delivery_weight,
);

// verify `receive_messages_delivery_proof` weight components
Expand Down
16 changes: 10 additions & 6 deletions bridges/primitives/millau/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,19 @@ pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 1024;
/// Maximal number of unconfirmed messages at inbound lane.
pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 1024;

/// Maximal weight of single regular message delivery transaction on Millau chain.
/// Weight of single regular message delivery transaction on Millau chain.
///
/// This value is a result of `pallet_message_lane::Module::receive_messages_proof` weight formula computation
/// for the case when single message is delivered. The result then must be rounded up to account possible future
/// runtime upgrades.
pub const MAX_SINGLE_MESSAGE_DELIVERY_TX_WEIGHT: Weight = 1_000_000_000;
/// This value is a result of `pallet_message_lane::Module::receive_messages_proof_weight()` call
/// for the case when single message of `pallet_message_lane::EXPECTED_DEFAULT_MESSAGE_LENGTH` bytes is delivered.
/// The message must have dispatch weight set to zero. The result then must be rounded up to account
/// possible future runtime upgrades.
pub const DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT: Weight = 1_000_000_000;

/// Increase of delivery transaction weight on Millau chain with every additional message byte.
pub const ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT: Weight = 3_000;
///
/// This value is a result of `pallet_message_lane::WeightInfoExt::storage_proof_size_overhead(1)` call. The
/// result then must be rounded up to account possible future runtime upgrades.
pub const ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT: Weight = 25_000;

/// Maximal weight of single message delivery confirmation transaction on Millau chain.
///
Expand Down
16 changes: 10 additions & 6 deletions bridges/primitives/rialto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,19 @@ pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 128;
/// Maximal number of unconfirmed messages at inbound lane.
pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 128;

/// Maximal weight of single regular message delivery transaction on Rialto chain.
/// Weight of single regular message delivery transaction on Rialto chain.
///
/// This value is a result of `pallet_message_lane::Module::receive_messages_proof` weight formula computation
/// for the case when single message is delivered. The result then must be rounded up to account possible future
/// runtime upgrades.
pub const MAX_SINGLE_MESSAGE_DELIVERY_TX_WEIGHT: Weight = 1_000_000_000;
/// This value is a result of `pallet_message_lane::Module::receive_messages_proof_weight()` call
/// for the case when single message of `pallet_message_lane::EXPECTED_DEFAULT_MESSAGE_LENGTH` bytes is delivered.
/// The message must have dispatch weight set to zero. The result then must be rounded up to account
/// possible future runtime upgrades.
pub const DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT: Weight = 1_000_000_000;

/// Increase of delivery transaction weight on Rialto chain with every additional message byte.
pub const ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT: Weight = 3_000;
///
/// This value is a result of `pallet_message_lane::WeightInfoExt::storage_proof_size_overhead(1)` call. The
/// result then must be rounded up to account possible future runtime upgrades.
pub const ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT: Weight = 25_000;

/// Maximal weight of single message delivery confirmation transaction on Rialto chain.
///
Expand Down

0 comments on commit 371e35d

Please sign in to comment.