From: Matt Corallo Date: Sun, 15 Jan 2023 23:37:00 +0000 (+0000) Subject: Use `ChannelUnavailable` for a peer disconnecting not `MisuseError` X-Git-Tag: v0.0.114-beta~61^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=refs%2Fheads%2F2022-01-fuzz-hashbrown;p=rust-lightning 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. --- diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 8a0b6de65..6d952b42d 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -632,7 +632,9 @@ pub fn do_test(data: &[u8], logger: &Arc) { // It's possible the channel has been closed in the mean time, but any other // failure may be a bug. if let APIError::ChannelUnavailable { err } = e { - assert_eq!(err, "No such channel"); + if !err.starts_with("Can't find a peer matching the passed counterparty node_id ") { + assert_eq!(err, "No such channel"); + } } else { panic!(); } } pending_funding_signatures.insert(funding_output, tx); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 1ab215735..43d1806f9 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -2552,7 +2552,7 @@ where let per_peer_state = self.per_peer_state.read().unwrap(); let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id); if let None = peer_state_mutex_opt { - return Err(APIError::APIMisuseError { err: format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id) }) + return Err(APIError::ChannelUnavailable { err: format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id) }) } let mut peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();