From cfc3fe3148b6d4bcf5b8b8eb974376a939e2edbb Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 31 Jul 2018 23:48:54 -0400 Subject: [PATCH] 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. --- src/ln/channel.rs | 6 ++++++ src/ln/channelmanager.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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); } -- 2.39.5