From: Matt Corallo Date: Wed, 1 Aug 2018 03:48:54 +0000 (-0400) Subject: Fix panic!() in block_connected on unfunded channels (fixes #42) X-Git-Tag: v0.0.12~354^2~6 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=cfc3fe3148b6d4bcf5b8b8eb974376a939e2edbb;p=rust-lightning Fix panic!() in block_connected on unfunded channels (fixes #42) 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. --- diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 188af477d..614c13b44 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -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. diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index f39d0c093..900b7c02b 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -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); }