Skip to content

Commit 5ea3aba

Browse files
committed
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 f35179f commit 5ea3aba

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
@@ -2318,10 +2318,16 @@ where L::Target: Logger {
23182318
for (hop, prev_hop_id) in hop_iter.zip(prev_hop_iter) {
23192319
let (target, private_target_node_counter) =
23202320
node_counters.private_node_counter_from_pubkey(&prev_hop_id)
2321-
.expect("node_counter_from_pubkey is called on all unblinded_route_hints keys above, so is always Some here");
2321+
.ok_or_else(|| {
2322+
debug_assert!(false);
2323+
LightningError { err: "We should always have private target node counters available".to_owned(), action: ErrorAction::IgnoreError }
2324+
})?;
23222325
let (_src_id, private_source_node_counter) =
23232326
node_counters.private_node_counter_from_pubkey(&hop.src_node_id)
2324-
.expect("node_counter_from_pubkey is called on all unblinded_route_hints keys above, so is always Some here");
2327+
.ok_or_else(|| {
2328+
debug_assert!(false);
2329+
LightningError { err: "We should always have private source node counters available".to_owned(), action: ErrorAction::IgnoreError }
2330+
})?;
23252331

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

0 commit comments

Comments
 (0)