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
@@ -27,7 +27,7 @@ use crate::{
use async_std::sync::Arc;
use bp_messages::{LaneId, MessageNonce};
use bp_runtime::{AccountIdOf, Chain as _};
use bp_runtime::{AccountIdOf, Chain as _, WeightExtraOps};
use bridge_runtime_common::messages::{
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();
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() /
W::receive_messages_proof_messages_overhead(1).ref_time() <
max_unconfirmed_messages_at_inbound_lane
{
delivery_tx_weight_rest.ref_time() /
W::receive_messages_proof_messages_overhead(1).ref_time()
} else {
max_unconfirmed_messages_at_inbound_lane
};
let max_number_of_messages = std::cmp::min(
delivery_tx_weight_rest
.min_components_checked_div(W::receive_messages_proof_messages_overhead(1))
.unwrap_or(u64::MAX),
max_unconfirmed_messages_at_inbound_lane,
);
assert!(
max_number_of_messages > 0,
@@ -653,7 +653,7 @@ mod tests {
.into_iter()
.map(|nonce| bp_messages::OutboundMessageDetails {
nonce,
dispatch_weight: Weight::from_ref_time(0),
dispatch_weight: Weight::zero(),
size: 0,
delivery_and_dispatch_fee: 0,
dispatch_fee_payment: DispatchFeePayment::AtSourceChain,
@@ -730,7 +730,7 @@ mod tests {
for (idx, _) in payload_sizes.iter().enumerate() {
out_msgs_details.push(OutboundMessageDetails::<BalanceOf<Rialto>> {
nonce: idx as MessageNonce,
dispatch_weight: Weight::from_ref_time(0),
dispatch_weight: Weight::zero(),
size: 0,
delivery_and_dispatch_fee: 0,
dispatch_fee_payment: DispatchFeePayment::AtTargetChain,
@@ -295,7 +295,7 @@ impl<P: MessageLane, Strategy: RelayStrategy, SC, TC> MessageDeliveryStrategy<P,
.source_queue()
.iter()
.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 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 hard_selected_begin_nonce =
@@ -77,12 +77,12 @@ impl<Strategy: RelayStrategy> EnforcementStrategy<Strategy> {
hard_selected_begin_nonce,
selected_prepaid_nonces: 0,
selected_unpaid_weight: Weight::from_ref_time(0),
selected_unpaid_weight: Weight::zero(),
index: 0,
nonce: 0,
details: MessageDetails {
dispatch_weight: Weight::from_ref_time(0),
dispatch_weight: Weight::zero(),
size: 0,
reward: P::SourceChainBalance::zero(),
dispatch_fee_payment: DispatchFeePayment::AtSourceChain,
@@ -107,8 +107,8 @@ impl<Strategy: RelayStrategy> EnforcementStrategy<Strategy> {
// limit messages in the batch by weight
let new_selected_weight = match selected_weight.checked_add(&details.dispatch_weight) {
Some(new_selected_weight)
if new_selected_weight.ref_time() <=
reference.max_messages_weight_in_single_batch.ref_time() =>
if new_selected_weight
.all_lte(reference.max_messages_weight_in_single_batch) =>
new_selected_weight,
new_selected_weight if selected_count == 0 => {
log::warn!(