Fix panic!() in block_connected on unfunded channels (fixes #42)
authorMatt Corallo <git@bluematt.me>
Wed, 1 Aug 2018 03:48:54 +0000 (23:48 -0400)
committerMatt Corallo <git@bluematt.me>
Fri, 3 Aug 2018 02:26:44 +0000 (22:26 -0400)
The new full_stack_target fuzzing stuff was able to find this bug,
which gives me a bit of hope for full_stack_target's utility.

src/ln/channel.rs
src/ln/channelmanager.rs

index 188af477dded2049771aa6d800ffe3cc3421407e..614c13b442d76d9826875178879da20c6ef0d226 100644 (file)
@@ -1827,6 +1827,7 @@ impl Channel {
                self.user_id
        }
 
+       /// May only be called after funding has been initiated (ie is_funding_initiated() is true)
        pub fn channel_monitor(&self) -> ChannelMonitor {
                if self.channel_state < ChannelState::FundingCreated as u32 {
                        panic!("Can't get a channel monitor until funding has been created");
@@ -1904,6 +1905,11 @@ impl Channel {
                self.is_usable()
        }
 
+       /// Returns true if funding_created was sent/received.
+       pub fn is_funding_initiated(&self) -> bool {
+               self.channel_state >= ChannelState::FundingCreated as u32
+       }
+
        /// Returns true if this channel is fully shut down. True here implies that no further actions
        /// may/will be taken on this channel, and thus this object should be freed. Any future changes
        /// will be handled appropriately by the chain monitor.
index f39d0c093ceac2055c7105821a8396c7be431fd8..900b7c02b1f1ee03c0a8d1b247fff6f72e358e1a 100644 (file)
@@ -1188,7 +1188,7 @@ impl ChainListener for ChannelManager {
                                                }
                                        }
                                }
-                               if channel.channel_monitor().would_broadcast_at_height(height) {
+                               if channel.is_funding_initiated() && channel.channel_monitor().would_broadcast_at_height(height) {
                                        if let Some(short_id) = channel.get_short_channel_id() {
                                                short_to_id.remove(&short_id);
                                        }