Skip to content

Commit 83ce6c4

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 303143a commit 83ce6c4

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
@@ -2320,10 +2320,16 @@ where L::Target: Logger {
23202320
for (hop, prev_hop_id) in hop_iter.zip(prev_hop_iter) {
23212321
let (target, private_target_node_counter) =
23222322
node_counters.private_node_counter_from_pubkey(&prev_hop_id)
2323-
.expect("node_counter_from_pubkey is called on all unblinded_route_hints keys above, so is always Some here");
2323+
.ok_or_else(|| {
2324+
debug_assert!(false);
2325+
LightningError { err: "We should always have private target node counters available".to_owned(), action: ErrorAction::IgnoreError }
2326+
})?;
23242327
let (_src_id, private_source_node_counter) =
23252328
node_counters.private_node_counter_from_pubkey(&hop.src_node_id)
2326-
.expect("node_counter_from_pubkey is called on all unblinded_route_hints keys above, so is always Some here");
2329+
.ok_or_else(|| {
2330+
debug_assert!(false);
2331+
LightningError { err: "We should always have private source node counters available".to_owned(), action: ErrorAction::IgnoreError }
2332+
})?;
23272333

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

0 commit comments

Comments
 (0)