From e7ddeec322ccf480c0d66fae4a4a4d187ecb20a6 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Wed, 2 Aug 2023 11:57:44 +0300 Subject: [PATCH] use saturating_len where possible (#2316) --- bridges/modules/messages/src/proofs.rs | 2 +- bridges/modules/messages/src/tests/mock.rs | 2 +- bridges/modules/xcm-bridge-hub/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bridges/modules/messages/src/proofs.rs b/bridges/modules/messages/src/proofs.rs index 917748bd4f9ba..f4a6923030e99 100644 --- a/bridges/modules/messages/src/proofs.rs +++ b/bridges/modules/messages/src/proofs.rs @@ -57,7 +57,7 @@ pub fn verify_messages_proof, I: 'static>( let nonces_range = nonces_start..=nonces_end; // receiving proofs where end < begin is ok (if proof includes outbound lane state) - let messages_in_the_proof = nonces_range.checked_len().unwrap_or(0); + let messages_in_the_proof = nonces_range.saturating_len(); if messages_in_the_proof != MessageNonce::from(messages_count) { return Err(VerificationError::MessagesCountMismatch) } diff --git a/bridges/modules/messages/src/tests/mock.rs b/bridges/modules/messages/src/tests/mock.rs index 0da860dffc344..8ed47859ee00b 100644 --- a/bridges/modules/messages/src/tests/mock.rs +++ b/bridges/modules/messages/src/tests/mock.rs @@ -218,7 +218,7 @@ impl crate::benchmarking::Config<()> for TestRuntime { use bp_runtime::RangeInclusiveExt; let dispatch_weight = - REGULAR_PAYLOAD.declared_weight * params.message_nonces.checked_len().unwrap_or(0); + REGULAR_PAYLOAD.declared_weight * params.message_nonces.saturating_len(); ( *prepare_messages_proof( params.message_nonces.into_iter().map(|n| message(n, REGULAR_PAYLOAD)).collect(), diff --git a/bridges/modules/xcm-bridge-hub/src/lib.rs b/bridges/modules/xcm-bridge-hub/src/lib.rs index 05b568bb533b5..71e191175ebb2 100644 --- a/bridges/modules/xcm-bridge-hub/src/lib.rs +++ b/bridges/modules/xcm-bridge-hub/src/lib.rs @@ -308,7 +308,7 @@ pub mod pallet { outbound_lane.set_state(LaneState::Closed); // write something to log - let enqueued_messages = outbound_lane.queued_messages().checked_len().unwrap_or(0); + let enqueued_messages = outbound_lane.queued_messages().saturating_len(); log::trace!( target: LOG_TARGET, "Bridge {:?} between {:?} and {:?} is closing. {} messages remaining",