weights v1.5: iteration 2 (#1613)

This commit is contained in:
Svyatoslav Nikolsky
2022-10-21 13:43:07 +03:00
committed by Bastian Köcher
parent 829b23c7cf
commit e97bb57564
15 changed files with 81 additions and 70 deletions
+10 -5
View File
@@ -407,7 +407,7 @@ pub mod source {
let delivery_transaction = BridgedChain::<B>::estimate_delivery_transaction( let delivery_transaction = BridgedChain::<B>::estimate_delivery_transaction(
&payload.encode(), &payload.encode(),
true, true,
Weight::from_ref_time(0), Weight::zero(),
); );
let delivery_transaction_fee = BridgedChain::<B>::transaction_payment(delivery_transaction); let delivery_transaction_fee = BridgedChain::<B>::transaction_payment(delivery_transaction);
@@ -733,7 +733,7 @@ pub mod target {
payload.weight = Some(weight); payload.weight = Some(weight);
weight weight
}, },
_ => Weight::from_ref_time(0), _ => Weight::zero(),
} }
} }
@@ -762,17 +762,22 @@ pub mod target {
location, location,
xcm, xcm,
hash, hash,
weight_limit.unwrap_or(Weight::from_ref_time(0)).ref_time(), weight_limit.unwrap_or_else(Weight::zero).ref_time(),
weight_credit.ref_time(), weight_credit.ref_time(),
); );
Ok(xcm_outcome) Ok(xcm_outcome)
}; };
let xcm_outcome = do_dispatch(); let xcm_outcome = do_dispatch();
log::trace!(target: "runtime::bridge-dispatch", "Incoming message {:?} dispatched with result: {:?}", message_id, xcm_outcome); log::trace!(
target: "runtime::bridge-dispatch",
"Incoming message {:?} dispatched with result: {:?}",
message_id,
xcm_outcome,
);
MessageDispatchResult { MessageDispatchResult {
dispatch_result: true, dispatch_result: true,
unspent_weight: Weight::from_ref_time(0), unspent_weight: Weight::zero(),
dispatch_fee_paid_during_dispatch: false, dispatch_fee_paid_during_dispatch: false,
} }
} }
@@ -39,7 +39,7 @@ where
nonce, nonce,
// dispatch message weight is always zero at the source chain, since we're paying for // dispatch message weight is always zero at the source chain, since we're paying for
// dispatch at the target chain // dispatch at the target chain
dispatch_weight: frame_support::weights::Weight::from_ref_time(0), dispatch_weight: frame_support::weights::Weight::zero(),
size: message_data.payload.len() as _, size: message_data.payload.len() as _,
delivery_and_dispatch_fee: message_data.fee, delivery_and_dispatch_fee: message_data.fee,
// we're delivering XCM messages here, so fee is always paid at the target chain // we're delivering XCM messages here, so fee is always paid at the target chain
@@ -94,7 +94,7 @@ where
nonces_start: *params.message_nonces.start(), nonces_start: *params.message_nonces.start(),
nonces_end: *params.message_nonces.end(), nonces_end: *params.message_nonces.end(),
}, },
Weight::from_ref_time(0), Weight::zero(),
) )
} }
@@ -125,7 +125,7 @@ mod tests {
pallet_bridge_messages::Call::<Runtime, ()>::receive_messages_proof { pallet_bridge_messages::Call::<Runtime, ()>::receive_messages_proof {
relayer_id_at_bridged_chain: [0u8; 32].into(), relayer_id_at_bridged_chain: [0u8; 32].into(),
messages_count: (nonces_end - nonces_start + 1) as u32, messages_count: (nonces_end - nonces_start + 1) as u32,
dispatch_weight: frame_support::weights::Weight::from_ref_time(0), dispatch_weight: frame_support::weights::Weight::zero(),
proof: FromBridgedChainMessagesProof { proof: FromBridgedChainMessagesProof {
bridged_header_hash: Default::default(), bridged_header_hash: Default::default(),
storage_proof: vec![], storage_proof: vec![],
+1 -3
View File
@@ -135,9 +135,7 @@ pub mod pallet {
fn on_initialize(_n: T::BlockNumber) -> frame_support::weights::Weight { fn on_initialize(_n: T::BlockNumber) -> frame_support::weights::Weight {
<RequestCount<T, I>>::mutate(|count| *count = count.saturating_sub(1)); <RequestCount<T, I>>::mutate(|count| *count = count.saturating_sub(1));
Weight::from_ref_time(0) T::DbWeight::get().reads_writes(1, 1)
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
} }
} }
+7 -13
View File
@@ -330,11 +330,8 @@ pub mod pallet {
}); });
// compute actual dispatch weight that depends on the stored message size // compute actual dispatch weight that depends on the stored message size
let actual_weight = sp_std::cmp::min_by( let actual_weight = T::WeightInfo::maximal_increase_message_fee()
T::WeightInfo::maximal_increase_message_fee(), .min(T::WeightInfo::increase_message_fee(message_size as _));
T::WeightInfo::increase_message_fee(message_size as _),
|w1, w2| w1.ref_time().cmp(&w2.ref_time()),
);
Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes }) Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes })
} }
@@ -416,7 +413,7 @@ pub mod pallet {
// on this lane. We can't dispatch lane messages out-of-order, so if declared // on this lane. We can't dispatch lane messages out-of-order, so if declared
// weight is not enough, let's move to next lane // weight is not enough, let's move to next lane
let dispatch_weight = T::MessageDispatch::dispatch_weight(&mut message); let dispatch_weight = T::MessageDispatch::dispatch_weight(&mut message);
if dispatch_weight.ref_time() > dispatch_weight_left.ref_time() { if dispatch_weight.any_gt(dispatch_weight_left) {
log::trace!( log::trace!(
target: LOG_TARGET, target: LOG_TARGET,
"Cannot dispatch any more messages on lane {:?}. Weight: declared={}, left={}", "Cannot dispatch any more messages on lane {:?}. Weight: declared={}, left={}",
@@ -454,10 +451,7 @@ pub mod pallet {
ReceivalResult::TooManyUnconfirmedMessages => (dispatch_weight, true), ReceivalResult::TooManyUnconfirmedMessages => (dispatch_weight, true),
}; };
let unspent_weight = let unspent_weight = unspent_weight.min(dispatch_weight);
sp_std::cmp::min_by(unspent_weight, dispatch_weight, |w1, w2| {
w1.ref_time().cmp(&w2.ref_time())
});
dispatch_weight_left -= dispatch_weight - unspent_weight; dispatch_weight_left -= dispatch_weight - unspent_weight;
actual_weight = actual_weight.saturating_sub(unspent_weight).saturating_sub( actual_weight = actual_weight.saturating_sub(unspent_weight).saturating_sub(
// delivery call weight formula assumes that the fee is paid at // delivery call weight formula assumes that the fee is paid at
@@ -466,7 +460,7 @@ pub mod pallet {
if refund_pay_dispatch_fee { if refund_pay_dispatch_fee {
T::WeightInfo::pay_inbound_dispatch_fee_overhead() T::WeightInfo::pay_inbound_dispatch_fee_overhead()
} else { } else {
Weight::from_ref_time(0) Weight::zero()
}, },
); );
} }
@@ -585,7 +579,7 @@ pub mod pallet {
let actual_callback_weight = let actual_callback_weight =
T::OnDeliveryConfirmed::on_messages_delivered(&lane_id, &confirmed_messages); T::OnDeliveryConfirmed::on_messages_delivered(&lane_id, &confirmed_messages);
match preliminary_callback_overhead.checked_sub(&actual_callback_weight) { match preliminary_callback_overhead.checked_sub(&actual_callback_weight) {
Some(difference) if difference.ref_time() == 0 => (), Some(difference) if difference.is_zero() => (),
Some(difference) => { Some(difference) => {
log::trace!( log::trace!(
target: LOG_TARGET, target: LOG_TARGET,
@@ -880,7 +874,7 @@ fn send_message<T: Config<I>, I: 'static>(
T::WeightInfo::single_message_callback_overhead(T::DbWeight::get()); T::WeightInfo::single_message_callback_overhead(T::DbWeight::get());
let actual_callback_weight = T::OnMessageAccepted::on_messages_accepted(&lane_id, &nonce); let actual_callback_weight = T::OnMessageAccepted::on_messages_accepted(&lane_id, &nonce);
match single_message_callback_overhead.checked_sub(&actual_callback_weight) { match single_message_callback_overhead.checked_sub(&actual_callback_weight) {
Some(difference) if difference.ref_time() == 0 => (), Some(difference) if difference.is_zero() => (),
Some(difference) => { Some(difference) => {
log::trace!( log::trace!(
target: LOG_TARGET, target: LOG_TARGET,
+20 -22
View File
@@ -43,14 +43,14 @@ pub fn ensure_weights_are_correct<W: WeightInfoExt>(
db_weight: RuntimeDbWeight, db_weight: RuntimeDbWeight,
) { ) {
// verify `send_message` weight components // verify `send_message` weight components
assert_ne!(W::send_message_overhead(), Weight::from_ref_time(0)); assert_ne!(W::send_message_overhead(), Weight::zero());
assert_ne!(W::send_message_size_overhead(0), Weight::from_ref_time(0)); assert_ne!(W::send_message_size_overhead(0), Weight::zero());
// verify `receive_messages_proof` weight components // verify `receive_messages_proof` weight components
assert_ne!(W::receive_messages_proof_overhead(), Weight::from_ref_time(0)); assert_ne!(W::receive_messages_proof_overhead(), Weight::zero());
assert_ne!(W::receive_messages_proof_messages_overhead(1), Weight::from_ref_time(0)); assert_ne!(W::receive_messages_proof_messages_overhead(1), Weight::zero());
assert_ne!(W::receive_messages_proof_outbound_lane_state_overhead(), Weight::from_ref_time(0)); assert_ne!(W::receive_messages_proof_outbound_lane_state_overhead(), Weight::zero());
assert_ne!(W::storage_proof_size_overhead(1), Weight::from_ref_time(0)); assert_ne!(W::storage_proof_size_overhead(1), Weight::zero());
// verify that the hardcoded value covers `receive_messages_proof` weight // verify that the hardcoded value covers `receive_messages_proof` weight
let actual_single_regular_message_delivery_tx_weight = W::receive_messages_proof_weight( let actual_single_regular_message_delivery_tx_weight = W::receive_messages_proof_weight(
@@ -58,11 +58,11 @@ pub fn ensure_weights_are_correct<W: WeightInfoExt>(
(EXPECTED_DEFAULT_MESSAGE_LENGTH + W::expected_extra_storage_proof_size()) as usize, (EXPECTED_DEFAULT_MESSAGE_LENGTH + W::expected_extra_storage_proof_size()) as usize,
), ),
1, 1,
Weight::from_ref_time(0), Weight::zero(),
); );
assert!( assert!(
actual_single_regular_message_delivery_tx_weight.ref_time() <= actual_single_regular_message_delivery_tx_weight
expected_default_message_delivery_tx_weight.ref_time(), .all_lte(expected_default_message_delivery_tx_weight),
"Default message delivery transaction weight {} is larger than expected weight {}", "Default message delivery transaction weight {} is larger than expected weight {}",
actual_single_regular_message_delivery_tx_weight, actual_single_regular_message_delivery_tx_weight,
expected_default_message_delivery_tx_weight, expected_default_message_delivery_tx_weight,
@@ -71,16 +71,15 @@ pub fn ensure_weights_are_correct<W: WeightInfoExt>(
// verify that hardcoded value covers additional byte length of `receive_messages_proof` 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); let actual_additional_byte_delivery_weight = W::storage_proof_size_overhead(1);
assert!( assert!(
actual_additional_byte_delivery_weight.ref_time() <= actual_additional_byte_delivery_weight.all_lte(expected_additional_byte_delivery_weight),
expected_additional_byte_delivery_weight.ref_time(),
"Single additional byte delivery weight {} is larger than expected weight {}", "Single additional byte delivery weight {} is larger than expected weight {}",
actual_additional_byte_delivery_weight, actual_additional_byte_delivery_weight,
expected_additional_byte_delivery_weight, expected_additional_byte_delivery_weight,
); );
// verify `receive_messages_delivery_proof` weight components // verify `receive_messages_delivery_proof` weight components
assert_ne!(W::receive_messages_delivery_proof_overhead(), Weight::from_ref_time(0)); assert_ne!(W::receive_messages_delivery_proof_overhead(), Weight::zero());
assert_ne!(W::storage_proof_size_overhead(1), Weight::from_ref_time(0)); assert_ne!(W::storage_proof_size_overhead(1), Weight::zero());
// `receive_messages_delivery_proof_messages_overhead` and // `receive_messages_delivery_proof_messages_overhead` and
// `receive_messages_delivery_proof_relayers_overhead` may return zero if rewards are not paid // `receive_messages_delivery_proof_relayers_overhead` may return zero if rewards are not paid
@@ -97,8 +96,8 @@ pub fn ensure_weights_are_correct<W: WeightInfoExt>(
db_weight, db_weight,
); );
assert!( assert!(
actual_messages_delivery_confirmation_tx_weight.ref_time() <= actual_messages_delivery_confirmation_tx_weight
expected_messages_delivery_confirmation_tx_weight.ref_time(), .all_lte(expected_messages_delivery_confirmation_tx_weight),
"Messages delivery confirmation transaction weight {} is larger than expected weight {}", "Messages delivery confirmation transaction weight {} is larger than expected weight {}",
actual_messages_delivery_confirmation_tx_weight, actual_messages_delivery_confirmation_tx_weight,
expected_messages_delivery_confirmation_tx_weight, expected_messages_delivery_confirmation_tx_weight,
@@ -107,7 +106,7 @@ pub fn ensure_weights_are_correct<W: WeightInfoExt>(
// verify pay-dispatch-fee overhead for inbound messages // verify pay-dispatch-fee overhead for inbound messages
let actual_pay_inbound_dispatch_fee_weight = W::pay_inbound_dispatch_fee_overhead(); let actual_pay_inbound_dispatch_fee_weight = W::pay_inbound_dispatch_fee_overhead();
assert!( assert!(
actual_pay_inbound_dispatch_fee_weight.ref_time() <= expected_pay_inbound_dispatch_fee_weight.ref_time(), actual_pay_inbound_dispatch_fee_weight.all_lte(expected_pay_inbound_dispatch_fee_weight),
"Weight {} of pay-dispatch-fee overhead for inbound messages is larger than expected weight {}", "Weight {} of pay-dispatch-fee overhead for inbound messages is larger than expected weight {}",
actual_pay_inbound_dispatch_fee_weight, actual_pay_inbound_dispatch_fee_weight,
expected_pay_inbound_dispatch_fee_weight, expected_pay_inbound_dispatch_fee_weight,
@@ -141,7 +140,7 @@ pub fn ensure_able_to_receive_message<W: WeightInfoExt>(
max_incoming_message_dispatch_weight, max_incoming_message_dispatch_weight,
); );
assert!( assert!(
max_delivery_transaction_dispatch_weight.ref_time() <= max_extrinsic_weight.ref_time(), max_delivery_transaction_dispatch_weight.all_lte(max_extrinsic_weight),
"Weight of maximal message delivery transaction + {} is larger than maximal possible transaction weight {}", "Weight of maximal message delivery transaction + {} is larger than maximal possible transaction weight {}",
max_delivery_transaction_dispatch_weight, max_delivery_transaction_dispatch_weight,
max_extrinsic_weight, max_extrinsic_weight,
@@ -180,7 +179,7 @@ pub fn ensure_able_to_receive_confirmation<W: WeightInfoExt>(
db_weight, db_weight,
); );
assert!( assert!(
max_confirmation_transaction_dispatch_weight.ref_time() <= max_extrinsic_weight.ref_time(), max_confirmation_transaction_dispatch_weight.all_lte(max_extrinsic_weight),
"Weight of maximal confirmation transaction {} is larger than maximal possible transaction weight {}", "Weight of maximal confirmation transaction {} is larger than maximal possible transaction weight {}",
max_confirmation_transaction_dispatch_weight, max_confirmation_transaction_dispatch_weight,
max_extrinsic_weight, max_extrinsic_weight,
@@ -263,15 +262,14 @@ pub trait WeightInfoExt: WeightInfo {
// and cost of calling `OnDeliveryConfirmed::on_messages_delivered()` for every confirmed // and cost of calling `OnDeliveryConfirmed::on_messages_delivered()` for every confirmed
// message // message
let callback_overhead = relayers_state let callback_overhead = Self::single_message_callback_overhead(db_weight)
.total_messages .saturating_mul(relayers_state.total_messages);
.saturating_mul(Self::single_message_callback_overhead(db_weight).ref_time());
transaction_overhead transaction_overhead
.saturating_add(messages_overhead) .saturating_add(messages_overhead)
.saturating_add(relayers_overhead) .saturating_add(relayers_overhead)
.saturating_add(proof_size_overhead) .saturating_add(proof_size_overhead)
.saturating_add(Weight::from_ref_time(callback_overhead)) .saturating_add(callback_overhead)
} }
// Functions that are used by extrinsics weights formulas. // Functions that are used by extrinsics weights formulas.
+1 -1
View File
@@ -748,7 +748,7 @@ mod tests {
let db_weight = <TestRuntime as frame_system::Config>::DbWeight::get(); let db_weight = <TestRuntime as frame_system::Config>::DbWeight::get();
WeightInfoOf::<TestRuntime, ()>::submit_parachain_heads_weight(db_weight, proof, 1) WeightInfoOf::<TestRuntime, ()>::submit_parachain_heads_weight(db_weight, proof, 1)
.saturating_sub(if prune_expected { .saturating_sub(if prune_expected {
Weight::from_ref_time(0) Weight::zero()
} else { } else {
WeightInfoOf::<TestRuntime, ()>::parachain_head_pruning_weight(db_weight) WeightInfoOf::<TestRuntime, ()>::parachain_head_pruning_weight(db_weight)
}) })
@@ -195,7 +195,7 @@ impl<SenderOrigin, Balance, Payload> MessagesBridge<SenderOrigin, Balance, Paylo
_message: Payload, _message: Payload,
_delivery_and_dispatch_fee: Balance, _delivery_and_dispatch_fee: Balance,
) -> Result<SendMessageArtifacts, Self::Error> { ) -> Result<SendMessageArtifacts, Self::Error> {
Ok(SendMessageArtifacts { nonce: 0, weight: Weight::from_ref_time(0) }) Ok(SendMessageArtifacts { nonce: 0, weight: Weight::zero() })
} }
} }
@@ -220,7 +220,7 @@ pub trait OnDeliveryConfirmed {
#[impl_trait_for_tuples::impl_for_tuples(30)] #[impl_trait_for_tuples::impl_for_tuples(30)]
impl OnDeliveryConfirmed for Tuple { impl OnDeliveryConfirmed for Tuple {
fn on_messages_delivered(lane: &LaneId, messages: &DeliveredMessages) -> Weight { fn on_messages_delivered(lane: &LaneId, messages: &DeliveredMessages) -> Weight {
let mut total_weight = Weight::from_ref_time(0); let mut total_weight = Weight::zero();
for_tuples!( for_tuples!(
#( #(
total_weight = total_weight.saturating_add(Tuple::on_messages_delivered(lane, messages)); total_weight = total_weight.saturating_add(Tuple::on_messages_delivered(lane, messages));
@@ -238,7 +238,7 @@ pub trait OnMessageAccepted {
impl OnMessageAccepted for () { impl OnMessageAccepted for () {
fn on_messages_accepted(_lane: &LaneId, _message: &MessageNonce) -> Weight { fn on_messages_accepted(_lane: &LaneId, _message: &MessageNonce) -> Weight {
Weight::from_ref_time(0) Weight::zero()
} }
} }
@@ -167,7 +167,7 @@ impl<AccountId, Fee> MessageDispatch<AccountId, Fee> for ForbidInboundMessages {
) -> MessageDispatchResult { ) -> MessageDispatchResult {
MessageDispatchResult { MessageDispatchResult {
dispatch_result: false, dispatch_result: false,
unspent_weight: Weight::from_ref_time(0), unspent_weight: Weight::zero(),
dispatch_fee_paid_during_dispatch: false, dispatch_fee_paid_during_dispatch: false,
} }
} }
+20 -1
View File
@@ -20,7 +20,8 @@
use codec::{Decode, Encode, FullCodec, MaxEncodedLen}; use codec::{Decode, Encode, FullCodec, MaxEncodedLen};
use frame_support::{ use frame_support::{
log, pallet_prelude::DispatchResult, PalletError, RuntimeDebug, StorageHasher, StorageValue, log, pallet_prelude::DispatchResult, weights::Weight, PalletError, RuntimeDebug, StorageHasher,
StorageValue,
}; };
use frame_system::RawOrigin; use frame_system::RawOrigin;
use scale_info::TypeInfo; use scale_info::TypeInfo;
@@ -456,6 +457,24 @@ pub trait FilterCall<Call> {
fn validate(call: &Call) -> TransactionValidity; fn validate(call: &Call) -> TransactionValidity;
} }
/// All extra operations with weights that we need in bridges.
pub trait WeightExtraOps {
/// Checked division of individual components of two weights.
///
/// Divides components and returns minimal division result. Returns `None` if one
/// of `other` weight components is zero.
fn min_components_checked_div(&self, other: Weight) -> Option<u64>;
}
impl WeightExtraOps for Weight {
fn min_components_checked_div(&self, other: Weight) -> Option<u64> {
Some(sp_std::cmp::min(
self.ref_time().checked_div(other.ref_time())?,
self.proof_size().checked_div(other.proof_size())?,
))
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@@ -27,7 +27,7 @@ use crate::{
use async_std::sync::Arc; use async_std::sync::Arc;
use bp_messages::{LaneId, MessageNonce}; use bp_messages::{LaneId, MessageNonce};
use bp_runtime::{AccountIdOf, Chain as _}; use bp_runtime::{AccountIdOf, Chain as _, WeightExtraOps};
use bridge_runtime_common::messages::{ use bridge_runtime_common::messages::{
source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof,
}; };
@@ -462,15 +462,12 @@ pub fn select_delivery_transaction_limits<W: pallet_bridge_messages::WeightInfoE
W::receive_messages_proof_outbound_lane_state_overhead(); W::receive_messages_proof_outbound_lane_state_overhead();
let delivery_tx_weight_rest = weight_for_delivery_tx - delivery_tx_base_weight; let delivery_tx_weight_rest = weight_for_delivery_tx - delivery_tx_base_weight;
let max_number_of_messages = if delivery_tx_weight_rest.ref_time() / let max_number_of_messages = std::cmp::min(
W::receive_messages_proof_messages_overhead(1).ref_time() < delivery_tx_weight_rest
max_unconfirmed_messages_at_inbound_lane .min_components_checked_div(W::receive_messages_proof_messages_overhead(1))
{ .unwrap_or(u64::MAX),
delivery_tx_weight_rest.ref_time() / max_unconfirmed_messages_at_inbound_lane,
W::receive_messages_proof_messages_overhead(1).ref_time() );
} else {
max_unconfirmed_messages_at_inbound_lane
};
assert!( assert!(
max_number_of_messages > 0, max_number_of_messages > 0,
@@ -653,7 +653,7 @@ mod tests {
.into_iter() .into_iter()
.map(|nonce| bp_messages::OutboundMessageDetails { .map(|nonce| bp_messages::OutboundMessageDetails {
nonce, nonce,
dispatch_weight: Weight::from_ref_time(0), dispatch_weight: Weight::zero(),
size: 0, size: 0,
delivery_and_dispatch_fee: 0, delivery_and_dispatch_fee: 0,
dispatch_fee_payment: DispatchFeePayment::AtSourceChain, dispatch_fee_payment: DispatchFeePayment::AtSourceChain,
@@ -730,7 +730,7 @@ mod tests {
for (idx, _) in payload_sizes.iter().enumerate() { for (idx, _) in payload_sizes.iter().enumerate() {
out_msgs_details.push(OutboundMessageDetails::<BalanceOf<Rialto>> { out_msgs_details.push(OutboundMessageDetails::<BalanceOf<Rialto>> {
nonce: idx as MessageNonce, nonce: idx as MessageNonce,
dispatch_weight: Weight::from_ref_time(0), dispatch_weight: Weight::zero(),
size: 0, size: 0,
delivery_and_dispatch_fee: 0, delivery_and_dispatch_fee: 0,
dispatch_fee_payment: DispatchFeePayment::AtTargetChain, dispatch_fee_payment: DispatchFeePayment::AtTargetChain,
@@ -295,7 +295,7 @@ impl<P: MessageLane, Strategy: RelayStrategy, SC, TC> MessageDeliveryStrategy<P,
.source_queue() .source_queue()
.iter() .iter()
.flat_map(|(_, range)| range.values().map(|details| details.dispatch_weight)) .flat_map(|(_, range)| range.values().map(|details| details.dispatch_weight))
.fold(Weight::from_ref_time(0), |total, weight| total.saturating_add(weight)) .fold(Weight::zero(), |total, weight| total.saturating_add(weight))
} }
} }
@@ -55,7 +55,7 @@ impl<Strategy: RelayStrategy> EnforcementStrategy<Strategy> {
let mut hard_selected_count = 0; let mut hard_selected_count = 0;
let mut soft_selected_count = 0; let mut soft_selected_count = 0;
let mut selected_weight = Weight::from_ref_time(0); let mut selected_weight = Weight::zero();
let mut selected_count: MessageNonce = 0; let mut selected_count: MessageNonce = 0;
let hard_selected_begin_nonce = let hard_selected_begin_nonce =
@@ -77,12 +77,12 @@ impl<Strategy: RelayStrategy> EnforcementStrategy<Strategy> {
hard_selected_begin_nonce, hard_selected_begin_nonce,
selected_prepaid_nonces: 0, selected_prepaid_nonces: 0,
selected_unpaid_weight: Weight::from_ref_time(0), selected_unpaid_weight: Weight::zero(),
index: 0, index: 0,
nonce: 0, nonce: 0,
details: MessageDetails { details: MessageDetails {
dispatch_weight: Weight::from_ref_time(0), dispatch_weight: Weight::zero(),
size: 0, size: 0,
reward: P::SourceChainBalance::zero(), reward: P::SourceChainBalance::zero(),
dispatch_fee_payment: DispatchFeePayment::AtSourceChain, dispatch_fee_payment: DispatchFeePayment::AtSourceChain,
@@ -107,8 +107,8 @@ impl<Strategy: RelayStrategy> EnforcementStrategy<Strategy> {
// limit messages in the batch by weight // limit messages in the batch by weight
let new_selected_weight = match selected_weight.checked_add(&details.dispatch_weight) { let new_selected_weight = match selected_weight.checked_add(&details.dispatch_weight) {
Some(new_selected_weight) Some(new_selected_weight)
if new_selected_weight.ref_time() <= if new_selected_weight
reference.max_messages_weight_in_single_batch.ref_time() => .all_lte(reference.max_messages_weight_in_single_batch) =>
new_selected_weight, new_selected_weight,
new_selected_weight if selected_count == 0 => { new_selected_weight if selected_count == 0 => {
log::warn!( log::warn!(