Skip to content

Commit f9bafa6

Browse files
committed
Use ChannelUnavailable for a peer disconnecting not MisuseError
This fixes a crash in the `full_stack_target` fuzz test (found by Chaincode's generous fuzzing infrastructure!) but ultimately is a better error code - a peer disconnecting before we can fund a channel isn't a "misuse error" its an unavailable channel.
1 parent fb5b427 commit f9bafa6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

fuzz/src/full_stack.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,9 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
632632
// It's possible the channel has been closed in the mean time, but any other
633633
// failure may be a bug.
634634
if let APIError::ChannelUnavailable { err } = e {
635-
assert_eq!(err, "No such channel");
635+
if !err.starts_with("Can't find a peer matching the passed counterparty node_id ") {
636+
assert_eq!(err, "No such channel");
637+
}
636638
} else { panic!(); }
637639
}
638640
pending_funding_signatures.insert(funding_output, tx);

lightning/src/ln/channelmanager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2552,7 +2552,7 @@ where
25522552
let per_peer_state = self.per_peer_state.read().unwrap();
25532553
let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id);
25542554
if let None = peer_state_mutex_opt {
2555-
return Err(APIError::APIMisuseError { err: format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id) })
2555+
return Err(APIError::ChannelUnavailable { err: format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id) })
25562556
}
25572557

25582558
let mut peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();

0 commit comments

Comments
 (0)