Skip to content

Commit 8360b6e

Browse files
committed
remove unwrap() calls
1 parent babd23c commit 8360b6e

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/probing.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ impl ProbingStrategy for HighDegreeStrategy {
323323
let top_node_count = self.top_node_count.min(nodes_by_degree.len());
324324
let now = Instant::now();
325325

326-
let mut probed = self.recently_probed.lock().unwrap();
326+
let mut probed =
327+
self.recently_probed.lock().unwrap_or_else(|e| e.into_inner());
327328

328329
// We could check staleness when we use the entry, but that way we'd not clear cache at
329330
// all. For hundreds of top nodes it's okay to call retain each tick.
@@ -444,7 +445,7 @@ impl RandomStrategy {
444445
let graph = self.network_graph.read_only();
445446
let first_hop =
446447
&initial_channels[random_range(0, initial_channels.len() as u64 - 1) as usize];
447-
let first_hop_scid = first_hop.short_channel_id.unwrap();
448+
let first_hop_scid = first_hop.short_channel_id?;
448449
let next_peer_pubkey = first_hop.counterparty.node_id;
449450
let next_peer_node_id = NodeId::from_pubkey(&next_peer_pubkey);
450451

@@ -488,11 +489,15 @@ impl RandomStrategy {
488489
break;
489490
};
490491
// Retrieve the direction-specific update via the public ChannelInfo fields.
491-
// Safe to unwrap: as_directed_from already checked both directions are Some.
492-
let update = if directed.source() == &next_channel.node_one {
493-
next_channel.one_to_two.as_ref().unwrap()
492+
// as_directed_from already checked both directions are Some, but we break
493+
// defensively rather than unwrap.
494+
let update = match if directed.source() == &next_channel.node_one {
495+
next_channel.one_to_two.as_ref()
494496
} else {
495-
next_channel.two_to_one.as_ref().unwrap()
497+
next_channel.two_to_one.as_ref()
498+
} {
499+
Some(u) => u,
500+
None => break,
496501
};
497502

498503
if !update.enabled {
@@ -560,10 +565,13 @@ impl RandomStrategy {
560565
let (_, next_scid, _) = route[i + 1];
561566
let next_channel = graph.channel(next_scid)?;
562567
let (directed, _) = next_channel.as_directed_from(&node_id)?;
563-
let update = if directed.source() == &next_channel.node_one {
564-
next_channel.one_to_two.as_ref().unwrap()
568+
let update = match if directed.source() == &next_channel.node_one {
569+
next_channel.one_to_two.as_ref()
565570
} else {
566-
next_channel.two_to_one.as_ref().unwrap()
571+
next_channel.two_to_one.as_ref()
572+
} {
573+
Some(u) => u,
574+
None => return None,
567575
};
568576
let fee = update.fees.base_msat as u64
569577
+ (forwarded * update.fees.proportional_millionths as u64 / 1_000_000);

0 commit comments

Comments
 (0)