Sync get_update_fail_htlc, get_update_fulfill_htlc state err result
authorMatt Corallo <git@bluematt.me>
Thu, 6 Sep 2018 23:12:32 +0000 (19:12 -0400)
committerMatt Corallo <git@bluematt.me>
Sun, 9 Sep 2018 15:36:00 +0000 (11:36 -0400)
Both get_update_fail_htlc and get_update_fulfill_htlc should never
be called before any HTLC could have been accepted (ie
pre-ChannelFunded) nor should they ever be called
post-ShutdownComplete as the Channel object should be destroyed at
that point. Previously get_update_fulfill_htlc would panic, but
get_update_fail_htlc would return an Err. For now make them both
panic but we can revisit this if we want to have fewer panics in
the future.

src/ln/channel.rs

index d620ff4f8b57b7f33b1490d2d7931dc777dec1b3..77bd70143da75c37f7f8e38fe1a95fe0d710e8a9 100644 (file)
@@ -1094,7 +1094,7 @@ impl Channel {
 
        pub fn get_update_fail_htlc(&mut self, payment_hash_arg: &[u8; 32], err_packet: msgs::OnionErrorPacket) -> Result<Option<msgs::UpdateFailHTLC>, HandleError> {
                if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
-                       return Err(HandleError{err: "Was asked to fail an HTLC when channel was not in an operational state", action: None});
+                       panic!("Was asked to fail an HTLC when channel was not in an operational state");
                }
                assert_eq!(self.channel_state & ChannelState::ShutdownComplete as u32, 0);