Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prune messages from confirmation tx body, not from the on_idle #2211

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ generate_bridge_reject_obsolete_headers_and_messages! {

bp_runtime::generate_static_str_provider!(BridgeRefundRialtoPara2000Lane0Msgs);
/// Signed extension that refunds relayers that are delivering messages from the Rialto parachain.
pub type PriorityBoostPerMessage = ConstU64<348_340_176>;
pub type PriorityBoostPerMessage = ConstU64<326_318_670>;
pub type BridgeRefundRialtoParachainMessages = RefundBridgedParachainMessages<
Runtime,
RefundableParachain<WithRialtoParachainsInstance, bp_rialto_parachain::RialtoParachain>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//! Autogenerated weights for `pallet_bridge_messages`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-06-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-06-15, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `serban-ROG-Zephyrus`, CPU: `12th Gen Intel(R) Core(TM) i7-12700H`
//! HOSTNAME: `covid`, CPU: `11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024

// Executed Command:
Expand Down Expand Up @@ -42,8 +42,8 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
// Proof Size summary in bytes:
// Measured: `490`
// Estimated: `52645`
// Minimum execution time: 35_366_000 picoseconds.
Weight::from_parts(38_231_000, 0)
// Minimum execution time: 48_275_000 picoseconds.
Weight::from_parts(52_131_000, 0)
.saturating_add(Weight::from_parts(0, 52645))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -60,11 +60,11 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
// Proof Size summary in bytes:
// Measured: `490`
// Estimated: `52645`
// Minimum execution time: 34_644_000 picoseconds.
Weight::from_parts(17_835_495, 0)
// Minimum execution time: 49_628_000 picoseconds.
Weight::from_parts(51_109_000, 0)
.saturating_add(Weight::from_parts(0, 52645))
// Standard Error: 4_354
.saturating_add(Weight::from_parts(7_517_907, 0).saturating_mul(n.into()))
// Standard Error: 62_097
.saturating_add(Weight::from_parts(11_370_587, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand All @@ -78,8 +78,8 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
// Proof Size summary in bytes:
// Measured: `490`
// Estimated: `52645`
// Minimum execution time: 40_916_000 picoseconds.
Weight::from_parts(42_815_000, 0)
// Minimum execution time: 56_876_000 picoseconds.
Weight::from_parts(58_559_000, 0)
.saturating_add(Weight::from_parts(0, 52645))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -96,11 +96,11 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
// Proof Size summary in bytes:
// Measured: `490`
// Estimated: `52645`
// Minimum execution time: 36_255_000 picoseconds.
Weight::from_parts(37_098_233, 0)
// Minimum execution time: 50_513_000 picoseconds.
Weight::from_parts(51_442_283, 0)
.saturating_add(Weight::from_parts(0, 52645))
// Standard Error: 4_401
.saturating_add(Weight::from_parts(1_186_679, 0).saturating_mul(n.into()))
// Standard Error: 5_133
.saturating_add(Weight::from_parts(1_322_471, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand All @@ -112,15 +112,17 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: Some(1), max_size: Some(44), added: 539, mode: MaxEncodedLen)
/// Storage: BridgeRelayers RelayerRewards (r:1 w:1)
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, mode: MaxEncodedLen)
/// Storage: BridgeRialtoMessages OutboundMessages (r:0 w:1)
/// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(2621472), added: 2623947, mode: MaxEncodedLen)
fn receive_delivery_proof_for_single_message() -> Weight {
// Proof Size summary in bytes:
// Measured: `515`
// Estimated: `3530`
// Minimum execution time: 34_098_000 picoseconds.
Weight::from_parts(35_428_000, 0)
// Minimum execution time: 45_093_000 picoseconds.
Weight::from_parts(46_478_000, 0)
.saturating_add(Weight::from_parts(0, 3530))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(2))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0)
/// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen)
Expand All @@ -130,15 +132,17 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: Some(1), max_size: Some(44), added: 539, mode: MaxEncodedLen)
/// Storage: BridgeRelayers RelayerRewards (r:1 w:1)
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, mode: MaxEncodedLen)
/// Storage: BridgeRialtoMessages OutboundMessages (r:0 w:2)
/// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(2621472), added: 2623947, mode: MaxEncodedLen)
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight {
// Proof Size summary in bytes:
// Measured: `532`
// Estimated: `3530`
// Minimum execution time: 33_381_000 picoseconds.
Weight::from_parts(34_557_000, 0)
// Minimum execution time: 45_643_000 picoseconds.
Weight::from_parts(46_807_000, 0)
.saturating_add(Weight::from_parts(0, 3530))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(2))
.saturating_add(T::DbWeight::get().writes(4))
}
/// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0)
/// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen)
Expand All @@ -148,15 +152,17 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: Some(1), max_size: Some(44), added: 539, mode: MaxEncodedLen)
/// Storage: BridgeRelayers RelayerRewards (r:2 w:2)
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, mode: MaxEncodedLen)
/// Storage: BridgeRialtoMessages OutboundMessages (r:0 w:2)
/// Proof: BridgeRialtoMessages OutboundMessages (max_values: None, max_size: Some(2621472), added: 2623947, mode: MaxEncodedLen)
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight {
// Proof Size summary in bytes:
// Measured: `532`
// Estimated: `6070`
// Minimum execution time: 36_060_000 picoseconds.
Weight::from_parts(37_322_000, 0)
// Minimum execution time: 48_659_000 picoseconds.
Weight::from_parts(49_612_000, 0)
.saturating_add(Weight::from_parts(0, 6070))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(3))
.saturating_add(T::DbWeight::get().writes(5))
}
/// Storage: BridgeRialtoMessages PalletOperatingMode (r:1 w:0)
/// Proof: BridgeRialtoMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen)
Expand All @@ -170,11 +176,11 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
// Proof Size summary in bytes:
// Measured: `490`
// Estimated: `52645`
// Minimum execution time: 74_819_000 picoseconds.
Weight::from_parts(74_915_515, 0)
// Minimum execution time: 105_383_000 picoseconds.
Weight::from_parts(99_478_649, 0)
.saturating_add(Weight::from_parts(0, 52645))
// Standard Error: 1_393
.saturating_add(Weight::from_parts(303_406, 0).saturating_mul(n.into()))
// Standard Error: 2_361
.saturating_add(Weight::from_parts(436_357, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//! Autogenerated weights for `pallet_bridge_messages`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-06-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-06-15, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `serban-ROG-Zephyrus`, CPU: `12th Gen Intel(R) Core(TM) i7-12700H`
//! HOSTNAME: `covid`, CPU: `11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024

// Executed Command:
Expand Down Expand Up @@ -42,8 +42,8 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
// Proof Size summary in bytes:
// Measured: `428`
// Estimated: `52645`
// Minimum execution time: 33_154_000 picoseconds.
Weight::from_parts(36_293_000, 0)
// Minimum execution time: 46_589_000 picoseconds.
Weight::from_parts(49_086_000, 0)
.saturating_add(Weight::from_parts(0, 52645))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -60,11 +60,11 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
// Proof Size summary in bytes:
// Measured: `428`
// Estimated: `52645`
// Minimum execution time: 34_026_000 picoseconds.
Weight::from_parts(14_732_760, 0)
// Minimum execution time: 47_603_000 picoseconds.
Weight::from_parts(49_179_000, 0)
.saturating_add(Weight::from_parts(0, 52645))
// Standard Error: 4_476
.saturating_add(Weight::from_parts(7_326_060, 0).saturating_mul(n.into()))
// Standard Error: 66_399
.saturating_add(Weight::from_parts(10_712_351, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand All @@ -78,8 +78,8 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
// Proof Size summary in bytes:
// Measured: `428`
// Estimated: `52645`
// Minimum execution time: 39_779_000 picoseconds.
Weight::from_parts(41_716_000, 0)
// Minimum execution time: 55_669_000 picoseconds.
Weight::from_parts(58_369_000, 0)
.saturating_add(Weight::from_parts(0, 52645))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -96,11 +96,11 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
// Proof Size summary in bytes:
// Measured: `428`
// Estimated: `52645`
// Minimum execution time: 35_279_000 picoseconds.
Weight::from_parts(35_429_607, 0)
// Minimum execution time: 48_479_000 picoseconds.
Weight::from_parts(48_917_533, 0)
.saturating_add(Weight::from_parts(0, 52645))
// Standard Error: 3_367
.saturating_add(Weight::from_parts(1_271_388, 0).saturating_mul(n.into()))
// Standard Error: 4_157
.saturating_add(Weight::from_parts(1_468_948, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand All @@ -112,15 +112,17 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
/// Proof: BridgeRialtoParachainMessages OutboundLanes (max_values: Some(1), max_size: Some(44), added: 539, mode: MaxEncodedLen)
/// Storage: BridgeRelayers RelayerRewards (r:1 w:1)
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, mode: MaxEncodedLen)
/// Storage: BridgeRialtoParachainMessages OutboundMessages (r:0 w:1)
/// Proof: BridgeRialtoParachainMessages OutboundMessages (max_values: None, max_size: Some(2621472), added: 2623947, mode: MaxEncodedLen)
fn receive_delivery_proof_for_single_message() -> Weight {
// Proof Size summary in bytes:
// Measured: `453`
// Estimated: `3530`
// Minimum execution time: 33_210_000 picoseconds.
Weight::from_parts(34_302_000, 0)
// Minimum execution time: 43_189_000 picoseconds.
Weight::from_parts(44_120_000, 0)
.saturating_add(Weight::from_parts(0, 3530))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(2))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: BridgeRialtoParachainMessages PalletOperatingMode (r:1 w:0)
/// Proof: BridgeRialtoParachainMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen)
Expand All @@ -130,15 +132,17 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
/// Proof: BridgeRialtoParachainMessages OutboundLanes (max_values: Some(1), max_size: Some(44), added: 539, mode: MaxEncodedLen)
/// Storage: BridgeRelayers RelayerRewards (r:1 w:1)
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, mode: MaxEncodedLen)
/// Storage: BridgeRialtoParachainMessages OutboundMessages (r:0 w:2)
/// Proof: BridgeRialtoParachainMessages OutboundMessages (max_values: None, max_size: Some(2621472), added: 2623947, mode: MaxEncodedLen)
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight {
// Proof Size summary in bytes:
// Measured: `470`
// Estimated: `3530`
// Minimum execution time: 32_096_000 picoseconds.
Weight::from_parts(33_223_000, 0)
// Minimum execution time: 43_845_000 picoseconds.
Weight::from_parts(44_937_000, 0)
.saturating_add(Weight::from_parts(0, 3530))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(2))
.saturating_add(T::DbWeight::get().writes(4))
}
/// Storage: BridgeRialtoParachainMessages PalletOperatingMode (r:1 w:0)
/// Proof: BridgeRialtoParachainMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen)
Expand All @@ -148,15 +152,17 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
/// Proof: BridgeRialtoParachainMessages OutboundLanes (max_values: Some(1), max_size: Some(44), added: 539, mode: MaxEncodedLen)
/// Storage: BridgeRelayers RelayerRewards (r:2 w:2)
/// Proof: BridgeRelayers RelayerRewards (max_values: None, max_size: Some(65), added: 2540, mode: MaxEncodedLen)
/// Storage: BridgeRialtoParachainMessages OutboundMessages (r:0 w:2)
/// Proof: BridgeRialtoParachainMessages OutboundMessages (max_values: None, max_size: Some(2621472), added: 2623947, mode: MaxEncodedLen)
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight {
// Proof Size summary in bytes:
// Measured: `470`
// Estimated: `6070`
// Minimum execution time: 34_795_000 picoseconds.
Weight::from_parts(36_118_000, 0)
// Minimum execution time: 47_106_000 picoseconds.
Weight::from_parts(48_426_000, 0)
.saturating_add(Weight::from_parts(0, 6070))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(3))
.saturating_add(T::DbWeight::get().writes(5))
}
/// Storage: BridgeRialtoParachainMessages PalletOperatingMode (r:1 w:0)
/// Proof: BridgeRialtoParachainMessages PalletOperatingMode (max_values: Some(1), max_size: Some(2), added: 497, mode: MaxEncodedLen)
Expand All @@ -170,11 +176,11 @@ impl<T: frame_system::Config> pallet_bridge_messages::WeightInfo for WeightInfo<
// Proof Size summary in bytes:
// Measured: `428`
// Estimated: `52645`
// Minimum execution time: 73_280_000 picoseconds.
Weight::from_parts(73_762_167, 0)
// Minimum execution time: 102_818_000 picoseconds.
Weight::from_parts(91_768_134, 0)
.saturating_add(Weight::from_parts(0, 52645))
// Standard Error: 1_436
.saturating_add(Weight::from_parts(301_526, 0).saturating_mul(n.into()))
// Standard Error: 2_202
.saturating_add(Weight::from_parts(424_113, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand Down
35 changes: 0 additions & 35 deletions modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ use bp_runtime::{
};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{dispatch::PostDispatchInfo, ensure, fail, traits::Get, DefaultNoBound};
use sp_runtime::traits::UniqueSaturatedFrom;
use sp_std::{marker::PhantomData, prelude::*};

mod inbound_lane;
Expand Down Expand Up @@ -150,40 +149,6 @@ pub mod pallet {
type OperatingModeStorage = PalletOperatingMode<T, I>;
}

#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I>
where
u32: TryFrom<<T as frame_system::Config>::BlockNumber>,
{
fn on_idle(_block: T::BlockNumber, remaining_weight: Weight) -> Weight {
// we'll need at least to read outbound lane state, kill a message and update lane state
let db_weight = T::DbWeight::get();
if !remaining_weight.all_gte(db_weight.reads_writes(1, 2)) {
return Weight::zero()
}

// messages from lane with index `i` in `ActiveOutboundLanes` are pruned when
// `System::block_number() % lanes.len() == i`. Otherwise we need to read lane states on
// every block, wasting the whole `remaining_weight` for nothing and causing starvation
// of the last lane pruning
let active_lanes = T::ActiveOutboundLanes::get();
let active_lanes_len = (active_lanes.len() as u32).into();
let active_lane_index = u32::unique_saturated_from(
frame_system::Pallet::<T>::block_number() % active_lanes_len,
);
let active_lane_id = active_lanes[active_lane_index as usize];

// first db read - outbound lane state
let mut active_lane = outbound_lane::<T, I>(active_lane_id);
let mut used_weight = db_weight.reads(1);
// and here we'll have writes
used_weight += active_lane.prune_messages(db_weight, remaining_weight - used_weight);

// we already checked we have enough `remaining_weight` to cover this `used_weight`
used_weight
}
}

#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Change `PalletOwner`.
Expand Down
Loading