Skip to content

Commit d7437fe

Browse files
committed
fix(ccp): clippy lints
1 parent 4e301c5 commit d7437fe

File tree

2 files changed

+49
-55
lines changed

2 files changed

+49
-55
lines changed

crates/interledger-ccp/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use serde::{Deserialize, Serialize};
3030

3131
/// Data structure used to describe the routing relation of an account with its peers.
3232
#[repr(u8)]
33-
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Serialize, Deserialize)]
33+
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Serialize, Deserialize, Ord, Eq)]
3434
pub enum RoutingRelation {
3535
/// An account from which we do not receive routes from, neither broadcast
3636
/// routes to

crates/interledger-ccp/src/server.rs

+48-54
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use interledger_service::{
1616
use log::{debug, error, trace, warn};
1717
use parking_lot::{Mutex, RwLock};
1818
use ring::digest::{digest, SHA256};
19+
use std::cmp::Ordering as StdOrdering;
1920
use std::collections::HashMap;
2021
use std::{
2122
cmp::min,
@@ -185,13 +186,13 @@ where
185186
pub async fn start_broadcast_interval(&self, interval: u64) -> Result<(), ()> {
186187
self.request_all_routes().await?;
187188
let mut interval = tokio::time::interval(Duration::from_millis(interval));
188-
while let _ = interval.tick().await {
189+
loop {
190+
interval.tick().await;
189191
// ensure we have the latest ILP Address from the store
190192
self.update_ilp_address();
191193
// Do not consume the result if an error since we want to keep the loop going
192194
let _ = self.broadcast_routes().await;
193195
}
194-
Ok(())
195196
}
196197

197198
fn update_ilp_address(&self) {
@@ -424,38 +425,24 @@ where
424425
{
425426
tokio::spawn({
426427
let self_clone = self.clone();
427-
async move {
428-
self_clone
429-
.update_best_routes(Some(
430-
prefixes_updated
431-
.into_iter()
432-
.map(|s| s.to_string())
433-
.collect(),
434-
))
435-
.await
436-
}
428+
async move { self_clone.update_best_routes(Some(prefixes_updated)).await }
437429
});
438430
}
439431

440432
#[cfg(test)]
441433
{
442434
let ilp_address = self.ilp_address.clone();
443-
self.update_best_routes(Some(
444-
prefixes_updated
445-
.into_iter()
446-
.map(|s| s.to_string())
447-
.collect(),
448-
))
449-
.map_err(move |_| {
450-
RejectBuilder {
451-
code: ErrorCode::T00_INTERNAL_ERROR,
452-
message: b"Error processing route update",
453-
data: &[],
454-
triggered_by: Some(&ilp_address.read()),
455-
}
456-
.build()
457-
})
458-
.await?;
435+
self.update_best_routes(Some(prefixes_updated))
436+
.map_err(move |_| {
437+
RejectBuilder {
438+
code: ErrorCode::T00_INTERNAL_ERROR,
439+
message: b"Error processing route update",
440+
data: &[],
441+
triggered_by: Some(&ilp_address.read()),
442+
}
443+
.build()
444+
})
445+
.await?;
459446
}
460447
Ok(CCP_RESPONSE.clone())
461448
}
@@ -476,7 +463,7 @@ where
476463
let table = table.clone();
477464
let self_clone = self.clone();
478465
async move {
479-
self_clone
466+
let _ = self_clone
480467
.send_route_control_request(
481468
request.from.clone(),
482469
table.id(),
@@ -487,7 +474,8 @@ where
487474
});
488475

489476
#[cfg(test)]
490-
self.send_route_control_request(request.from.clone(), table.id(), table.epoch())
477+
let _ = self
478+
.send_route_control_request(request.from.clone(), table.id(), table.epoch())
491479
.await;
492480
Err(reject)
493481
}
@@ -668,7 +656,10 @@ where
668656
let epoch = forwarding_table.increment_epoch();
669657
forwarding_table_updates.push((
670658
new_routes,
671-
withdrawn_routes.iter().map(|s| s.to_string()).collect(),
659+
withdrawn_routes
660+
.into_iter()
661+
.map(|s| s.to_string())
662+
.collect(),
672663
));
673664
debug_assert_eq!(epoch as usize + 1, forwarding_table_updates.len());
674665

@@ -886,8 +877,8 @@ where
886877
from_epoch_index,
887878
to_epoch_index,
888879
current_epoch_index,
889-
new_routes: new_routes.clone(),
890-
withdrawn_routes: withdrawn_routes.clone(),
880+
new_routes,
881+
withdrawn_routes,
891882
speaker: self.ilp_address.read().clone(),
892883
hold_down_time: DEFAULT_ROUTE_EXPIRY_TIME,
893884
}
@@ -977,24 +968,27 @@ fn get_best_route_for_prefix<A: CcpRoutingAccount>(
977968
(account, route),
978969
|(best_account, best_route), (account, route)| {
979970
// Prioritize child > peer > parent
980-
if best_account.routing_relation() > account.routing_relation() {
981-
return (best_account, best_route);
982-
} else if best_account.routing_relation() < account.routing_relation() {
983-
return (account, route);
984-
}
985-
986-
// Prioritize shortest path
987-
if best_route.path.len() < route.path.len() {
988-
return (best_account, best_route);
989-
} else if best_route.path.len() > route.path.len() {
990-
return (account, route);
991-
}
992-
993-
// Finally base it on account ID
994-
if best_account.id().to_string() < account.id().to_string() {
995-
(best_account, best_route)
996-
} else {
997-
(account, route)
971+
match best_account
972+
.routing_relation()
973+
.cmp(&account.routing_relation())
974+
{
975+
StdOrdering::Greater => (best_account, best_route),
976+
StdOrdering::Less => (account, route),
977+
_ => {
978+
// Prioritize shortest path
979+
match best_route.path.len().cmp(&route.path.len()) {
980+
StdOrdering::Less => (best_account, best_route),
981+
StdOrdering::Greater => (account, route),
982+
_ => {
983+
// Finally base it on account ID
984+
if best_account.id().to_string() < account.id().to_string() {
985+
(best_account, best_route)
986+
} else {
987+
(account, route)
988+
}
989+
}
990+
}
991+
}
998992
}
999993
},
1000994
);
@@ -1063,7 +1057,7 @@ mod ranking_routes {
10631057
let mut child = TestAccount::new(Uuid::from_slice(&[6; 16]).unwrap(), "example.child");
10641058
child.relation = RoutingRelation::Child;
10651059
child_table.add_route(
1066-
child.clone(),
1060+
child,
10671061
Route {
10681062
prefix: "example.d".to_string(),
10691063
path: vec!["example.one".to_string()],
@@ -1092,7 +1086,7 @@ mod ranking_routes {
10921086
},
10931087
);
10941088
peer_table_1.add_route(
1095-
peer_1.clone(),
1089+
peer_1,
10961090
Route {
10971091
// This route should be overridden by the configured "example.a" route
10981092
prefix: "example.a.sub-prefix".to_string(),
@@ -1104,7 +1098,7 @@ mod ranking_routes {
11041098
let mut peer_table_2 = RoutingTable::default();
11051099
let peer_2 = TestAccount::new(Uuid::from_slice(&[8; 16]).unwrap(), "example.peer2");
11061100
peer_table_2.add_route(
1107-
peer_2.clone(),
1101+
peer_2,
11081102
Route {
11091103
prefix: "example.e".to_string(),
11101104
path: vec!["example.one".to_string(), "example.two".to_string()],

0 commit comments

Comments
 (0)