Skip to content

Commit

Permalink
Use match instead of compare chain as suggested by clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
ckoopmann committed Nov 17, 2023
1 parent 54fc298 commit c439092
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/rpc/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::rpc::result::internal_rpc_err;
use jsonrpsee::core::RpcResult;
use std::cmp::Ordering;

pub fn compare_values<T: std::cmp::PartialEq + std::fmt::Display>(
name: &str,
Expand Down Expand Up @@ -30,13 +31,15 @@ pub fn calc_gas_limit(parent_gas_limit: u64, desired_limit: u64) -> u64 {
// TODO: Understand why 1 is subtracted here
let delta = parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR - 1;
let desired_limit = std::cmp::max(desired_limit, MIN_GAS_LIMIT);
if parent_gas_limit < desired_limit {
let max_acceptable_limit = parent_gas_limit + delta;
std::cmp::min(max_acceptable_limit, desired_limit)
} else if parent_gas_limit > desired_limit {
let min_acceptable_limit = parent_gas_limit - delta;
std::cmp::max(min_acceptable_limit, desired_limit)
} else {
parent_gas_limit
match parent_gas_limit.cmp(&desired_limit) {
Ordering::Less => {
let max_acceptable_limit = parent_gas_limit + delta;
std::cmp::min(max_acceptable_limit, desired_limit)
}
Ordering::Greater => {
let min_acceptable_limit = parent_gas_limit - delta;
std::cmp::max(min_acceptable_limit, desired_limit)
}
Ordering::Equal => parent_gas_limit,
}
}

0 comments on commit c439092

Please sign in to comment.