Skip to content

Commit

Permalink
use saturating_len where possible (#2316)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik committed Aug 2, 2023
1 parent 2378b91 commit 95bcf32
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions bin/runtime-common/src/refund_relayer_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,7 @@ where
};

// compute total number of messages in transaction
let bundled_messages =
parsed_call.messages_call_info().bundled_messages().checked_len().unwrap_or(0);
let bundled_messages = parsed_call.messages_call_info().bundled_messages().saturating_len();

// a quick check to avoid invalid high-priority transactions
let max_unconfirmed_messages_in_confirmation_tx = <Runtime as MessagesConfig<Msgs::Instance>>::BridgedChain
Expand Down
2 changes: 1 addition & 1 deletion modules/messages/src/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn verify_messages_proof<T: Config<I>, 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)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/messages/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,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(),
Expand Down
2 changes: 1 addition & 1 deletion modules/xcm-bridge-hub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,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",
Expand Down

0 comments on commit 95bcf32

Please sign in to comment.