]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Use `ChannelUnavailable` for a peer disconnecting not `MisuseError` 2022-01-fuzz-hashbrown
authorMatt Corallo <git@bluematt.me>
Sun, 15 Jan 2023 23:37:00 +0000 (23:37 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 15 Jan 2023 23:38:24 +0000 (23:38 +0000)
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.

fuzz/src/full_stack.rs
lightning/src/ln/channelmanager.rs

index 8a0b6de65f9b532fc1c66f9695fa01b9d74233cf..6d952b42d3cd4bc324e510e7b18546258e1fb861 100644 (file)
@@ -632,7 +632,9 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
                                                // 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);
index 1ab2157356b18840951e743254453f0edfe5bbc5..43d1806f90bbbdeba35f08389b084e7d325d06d4 100644 (file)
@@ -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();