Skip to content

Commit 9540e56

Browse files
authored
MaxValues for OutboundLanes map (paritytech#1871)
1 parent 0b9188b commit 9540e56

File tree

2 files changed

+75
-52
lines changed

2 files changed

+75
-52
lines changed

modules/messages/src/lib.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,14 @@ pub mod pallet {
583583

584584
/// Map of lane id => outbound lane data.
585585
#[pallet::storage]
586-
pub type OutboundLanes<T: Config<I>, I: 'static = ()> =
587-
StorageMap<_, Blake2_128Concat, LaneId, OutboundLaneData, ValueQuery>;
586+
pub type OutboundLanes<T: Config<I>, I: 'static = ()> = StorageMap<
587+
Hasher = Blake2_128Concat,
588+
Key = LaneId,
589+
Value = OutboundLaneData,
590+
QueryKind = ValueQuery,
591+
OnEmpty = GetDefault,
592+
MaxValues = MaybeOutboundLanesCount<T, I>,
593+
>;
588594

589595
/// All queued outbound messages.
590596
#[pallet::storage]
@@ -648,6 +654,15 @@ pub mod pallet {
648654
InboundLanes::<T, I>::get(lane).0
649655
}
650656
}
657+
658+
/// Get-parameter that returns number of active outbound lanes that the pallet maintains.
659+
pub struct MaybeOutboundLanesCount<T, I>(PhantomData<(T, I)>);
660+
661+
impl<T: Config<I>, I: 'static> Get<Option<u32>> for MaybeOutboundLanesCount<T, I> {
662+
fn get() -> Option<u32> {
663+
Some(T::ActiveOutboundLanes::get().len() as u32)
664+
}
665+
}
651666
}
652667

653668
impl<T, I> bp_messages::source_chain::MessagesBridge<T::RuntimeOrigin, T::OutboundPayload>
@@ -1962,4 +1977,12 @@ mod tests {
19621977
MessagesOperatingMode::Basic(BasicOperatingMode::Normal),
19631978
MessagesOperatingMode::Basic(BasicOperatingMode::Halted)
19641979
);
1980+
1981+
#[test]
1982+
fn maybe_outbound_lanes_count_returns_correct_value() {
1983+
assert_eq!(
1984+
MaybeOutboundLanesCount::<TestRuntime, ()>::get(),
1985+
Some(mock::ActiveOutboundLanes::get().len() as u32)
1986+
);
1987+
}
19651988
}

modules/messages/src/weights.rs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
8888
// Proof Size summary in bytes:
8989
// Measured: `693`
9090
// Estimated: `54703`
91-
// Minimum execution time: 76_449 nanoseconds.
92-
Weight::from_parts(127_110_000, 54703)
91+
// Minimum execution time: 50_655 nanoseconds.
92+
Weight::from_parts(60_502_000, 54703)
9393
.saturating_add(T::DbWeight::get().reads(4_u64))
9494
.saturating_add(T::DbWeight::get().writes(2_u64))
9595
}
@@ -116,8 +116,8 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
116116
// Proof Size summary in bytes:
117117
// Measured: `693`
118118
// Estimated: `54703`
119-
// Minimum execution time: 102_297 nanoseconds.
120-
Weight::from_parts(108_619_000, 54703)
119+
// Minimum execution time: 58_861 nanoseconds.
120+
Weight::from_parts(60_288_000, 54703)
121121
.saturating_add(T::DbWeight::get().reads(4_u64))
122122
.saturating_add(T::DbWeight::get().writes(2_u64))
123123
}
@@ -144,8 +144,8 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
144144
// Proof Size summary in bytes:
145145
// Measured: `693`
146146
// Estimated: `54703`
147-
// Minimum execution time: 84_911 nanoseconds.
148-
Weight::from_parts(87_518_000, 54703)
147+
// Minimum execution time: 53_459 nanoseconds.
148+
Weight::from_parts(54_577_000, 54703)
149149
.saturating_add(T::DbWeight::get().reads(4_u64))
150150
.saturating_add(T::DbWeight::get().writes(2_u64))
151151
}
@@ -167,8 +167,8 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
167167
// Proof Size summary in bytes:
168168
// Measured: `618`
169169
// Estimated: `54200`
170-
// Minimum execution time: 79_805 nanoseconds.
171-
Weight::from_parts(84_148_000, 54200)
170+
// Minimum execution time: 54_011 nanoseconds.
171+
Weight::from_parts(55_573_000, 54200)
172172
.saturating_add(T::DbWeight::get().reads(3_u64))
173173
.saturating_add(T::DbWeight::get().writes(1_u64))
174174
}
@@ -190,8 +190,8 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
190190
// Proof Size summary in bytes:
191191
// Measured: `618`
192192
// Estimated: `54200`
193-
// Minimum execution time: 141_515 nanoseconds.
194-
Weight::from_parts(150_421_000, 54200)
193+
// Minimum execution time: 105_856 nanoseconds.
194+
Weight::from_parts(109_112_000, 54200)
195195
.saturating_add(T::DbWeight::get().reads(3_u64))
196196
.saturating_add(T::DbWeight::get().writes(1_u64))
197197
}
@@ -207,8 +207,8 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
207207
///
208208
/// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1)
209209
///
210-
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added:
211-
/// 2519, mode: MaxEncodedLen)
210+
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: Some(1), max_size: Some(44), added:
211+
/// 539, mode: MaxEncodedLen)
212212
///
213213
/// Storage: BridgeRelayers RelayerRewards (r:1 w:1)
214214
///
@@ -217,9 +217,9 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
217217
fn receive_delivery_proof_for_single_message() -> Weight {
218218
// Proof Size summary in bytes:
219219
// Measured: `579`
220-
// Estimated: `7599`
221-
// Minimum execution time: 54_740 nanoseconds.
222-
Weight::from_parts(56_637_000, 7599)
220+
// Estimated: `5619`
221+
// Minimum execution time: 40_894 nanoseconds.
222+
Weight::from_parts(41_766_000, 5619)
223223
.saturating_add(T::DbWeight::get().reads(4_u64))
224224
.saturating_add(T::DbWeight::get().writes(2_u64))
225225
}
@@ -235,8 +235,8 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
235235
///
236236
/// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1)
237237
///
238-
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added:
239-
/// 2519, mode: MaxEncodedLen)
238+
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: Some(1), max_size: Some(44), added:
239+
/// 539, mode: MaxEncodedLen)
240240
///
241241
/// Storage: BridgeRelayers RelayerRewards (r:1 w:1)
242242
///
@@ -245,9 +245,9 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
245245
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight {
246246
// Proof Size summary in bytes:
247247
// Measured: `596`
248-
// Estimated: `7599`
249-
// Minimum execution time: 54_583 nanoseconds.
250-
Weight::from_parts(56_205_000, 7599)
248+
// Estimated: `5619`
249+
// Minimum execution time: 39_996 nanoseconds.
250+
Weight::from_parts(41_452_000, 5619)
251251
.saturating_add(T::DbWeight::get().reads(4_u64))
252252
.saturating_add(T::DbWeight::get().writes(2_u64))
253253
}
@@ -263,8 +263,8 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
263263
///
264264
/// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1)
265265
///
266-
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added:
267-
/// 2519, mode: MaxEncodedLen)
266+
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: Some(1), max_size: Some(44), added:
267+
/// 539, mode: MaxEncodedLen)
268268
///
269269
/// Storage: BridgeRelayers RelayerRewards (r:2 w:2)
270270
///
@@ -273,9 +273,9 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
273273
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight {
274274
// Proof Size summary in bytes:
275275
// Measured: `596`
276-
// Estimated: `10134`
277-
// Minimum execution time: 59_426 nanoseconds.
278-
Weight::from_parts(61_911_000, 10134)
276+
// Estimated: `8154`
277+
// Minimum execution time: 42_281 nanoseconds.
278+
Weight::from_parts(43_593_000, 8154)
279279
.saturating_add(T::DbWeight::get().reads(5_u64))
280280
.saturating_add(T::DbWeight::get().writes(3_u64))
281281
}
@@ -306,8 +306,8 @@ impl WeightInfo for () {
306306
// Proof Size summary in bytes:
307307
// Measured: `693`
308308
// Estimated: `54703`
309-
// Minimum execution time: 76_449 nanoseconds.
310-
Weight::from_parts(127_110_000, 54703)
309+
// Minimum execution time: 50_655 nanoseconds.
310+
Weight::from_parts(60_502_000, 54703)
311311
.saturating_add(RocksDbWeight::get().reads(4_u64))
312312
.saturating_add(RocksDbWeight::get().writes(2_u64))
313313
}
@@ -334,8 +334,8 @@ impl WeightInfo for () {
334334
// Proof Size summary in bytes:
335335
// Measured: `693`
336336
// Estimated: `54703`
337-
// Minimum execution time: 102_297 nanoseconds.
338-
Weight::from_parts(108_619_000, 54703)
337+
// Minimum execution time: 58_861 nanoseconds.
338+
Weight::from_parts(60_288_000, 54703)
339339
.saturating_add(RocksDbWeight::get().reads(4_u64))
340340
.saturating_add(RocksDbWeight::get().writes(2_u64))
341341
}
@@ -362,8 +362,8 @@ impl WeightInfo for () {
362362
// Proof Size summary in bytes:
363363
// Measured: `693`
364364
// Estimated: `54703`
365-
// Minimum execution time: 84_911 nanoseconds.
366-
Weight::from_parts(87_518_000, 54703)
365+
// Minimum execution time: 53_459 nanoseconds.
366+
Weight::from_parts(54_577_000, 54703)
367367
.saturating_add(RocksDbWeight::get().reads(4_u64))
368368
.saturating_add(RocksDbWeight::get().writes(2_u64))
369369
}
@@ -385,8 +385,8 @@ impl WeightInfo for () {
385385
// Proof Size summary in bytes:
386386
// Measured: `618`
387387
// Estimated: `54200`
388-
// Minimum execution time: 79_805 nanoseconds.
389-
Weight::from_parts(84_148_000, 54200)
388+
// Minimum execution time: 54_011 nanoseconds.
389+
Weight::from_parts(55_573_000, 54200)
390390
.saturating_add(RocksDbWeight::get().reads(3_u64))
391391
.saturating_add(RocksDbWeight::get().writes(1_u64))
392392
}
@@ -408,8 +408,8 @@ impl WeightInfo for () {
408408
// Proof Size summary in bytes:
409409
// Measured: `618`
410410
// Estimated: `54200`
411-
// Minimum execution time: 141_515 nanoseconds.
412-
Weight::from_parts(150_421_000, 54200)
411+
// Minimum execution time: 105_856 nanoseconds.
412+
Weight::from_parts(109_112_000, 54200)
413413
.saturating_add(RocksDbWeight::get().reads(3_u64))
414414
.saturating_add(RocksDbWeight::get().writes(1_u64))
415415
}
@@ -425,8 +425,8 @@ impl WeightInfo for () {
425425
///
426426
/// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1)
427427
///
428-
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added:
429-
/// 2519, mode: MaxEncodedLen)
428+
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: Some(1), max_size: Some(44), added:
429+
/// 539, mode: MaxEncodedLen)
430430
///
431431
/// Storage: BridgeRelayers RelayerRewards (r:1 w:1)
432432
///
@@ -435,9 +435,9 @@ impl WeightInfo for () {
435435
fn receive_delivery_proof_for_single_message() -> Weight {
436436
// Proof Size summary in bytes:
437437
// Measured: `579`
438-
// Estimated: `7599`
439-
// Minimum execution time: 54_740 nanoseconds.
440-
Weight::from_parts(56_637_000, 7599)
438+
// Estimated: `5619`
439+
// Minimum execution time: 40_894 nanoseconds.
440+
Weight::from_parts(41_766_000, 5619)
441441
.saturating_add(RocksDbWeight::get().reads(4_u64))
442442
.saturating_add(RocksDbWeight::get().writes(2_u64))
443443
}
@@ -453,8 +453,8 @@ impl WeightInfo for () {
453453
///
454454
/// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1)
455455
///
456-
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added:
457-
/// 2519, mode: MaxEncodedLen)
456+
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: Some(1), max_size: Some(44), added:
457+
/// 539, mode: MaxEncodedLen)
458458
///
459459
/// Storage: BridgeRelayers RelayerRewards (r:1 w:1)
460460
///
@@ -463,9 +463,9 @@ impl WeightInfo for () {
463463
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight {
464464
// Proof Size summary in bytes:
465465
// Measured: `596`
466-
// Estimated: `7599`
467-
// Minimum execution time: 54_583 nanoseconds.
468-
Weight::from_parts(56_205_000, 7599)
466+
// Estimated: `5619`
467+
// Minimum execution time: 39_996 nanoseconds.
468+
Weight::from_parts(41_452_000, 5619)
469469
.saturating_add(RocksDbWeight::get().reads(4_u64))
470470
.saturating_add(RocksDbWeight::get().writes(2_u64))
471471
}
@@ -481,8 +481,8 @@ impl WeightInfo for () {
481481
///
482482
/// Storage: BridgeRialtoMessages OutboundLanes (r:1 w:1)
483483
///
484-
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: None, max_size: Some(44), added:
485-
/// 2519, mode: MaxEncodedLen)
484+
/// Proof: BridgeRialtoMessages OutboundLanes (max_values: Some(1), max_size: Some(44), added:
485+
/// 539, mode: MaxEncodedLen)
486486
///
487487
/// Storage: BridgeRelayers RelayerRewards (r:2 w:2)
488488
///
@@ -491,9 +491,9 @@ impl WeightInfo for () {
491491
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight {
492492
// Proof Size summary in bytes:
493493
// Measured: `596`
494-
// Estimated: `10134`
495-
// Minimum execution time: 59_426 nanoseconds.
496-
Weight::from_parts(61_911_000, 10134)
494+
// Estimated: `8154`
495+
// Minimum execution time: 42_281 nanoseconds.
496+
Weight::from_parts(43_593_000, 8154)
497497
.saturating_add(RocksDbWeight::get().reads(5_u64))
498498
.saturating_add(RocksDbWeight::get().writes(3_u64))
499499
}

0 commit comments

Comments
 (0)