Skip to content

Commit 964d365

Browse files
TheBlueMattadi2011
authored andcommitted
Replace a few router expects with debug_assert + Err-returns
The router is a somewhat complicated beast, and though the last few commits removed some code from it, a complicated beast it remains. Thus, having `expect`s in it is somewhat risky, so we take this opportunity to replace some of them with `debug_assert!(false)`s and an `Err`-return.
1 parent 5e81762 commit 964d365

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lightning/src/routing/router.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,10 +2352,16 @@ where L::Target: Logger {
23522352
for (hop, prev_hop_id) in hop_iter.zip(prev_hop_iter) {
23532353
let (target, private_target_node_counter) =
23542354
node_counters.private_node_counter_from_pubkey(&prev_hop_id)
2355-
.expect("node_counter_from_pubkey is called on all unblinded_route_hints keys above, so is always Some here");
2355+
.ok_or_else(|| {
2356+
debug_assert!(false);
2357+
LightningError { err: "We should always have private target node counters available".to_owned(), action: ErrorAction::IgnoreError }
2358+
})?;
23562359
let (_src_id, private_source_node_counter) =
23572360
node_counters.private_node_counter_from_pubkey(&hop.src_node_id)
2358-
.expect("node_counter_from_pubkey is called on all unblinded_route_hints keys above, so is always Some here");
2361+
.ok_or_else(|| {
2362+
debug_assert!(false);
2363+
LightningError { err: "We should always have private source node counters available".to_owned(), action: ErrorAction::IgnoreError }
2364+
})?;
23592365

23602366
if let Some((first_channels, _)) = first_hop_targets.get(target) {
23612367
if first_channels.iter().any(|d| d.outbound_scid_alias == Some(hop.short_channel_id)) {

0 commit comments

Comments
 (0)