Ensure channel is live, not usable for sending fee updates
authorMatt Corallo <git@bluematt.me>
Sun, 14 Oct 2018 20:37:21 +0000 (05:37 +0900)
committerMatt Corallo <git@bluematt.me>
Thu, 18 Oct 2018 01:28:22 +0000 (21:28 -0400)
+ a freebie TODO removal

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

index 5c861b2eae7b4dec8293815fdab53f28535c79eb..1b7db97d3d342d1a97551b3a274c37425a07d8a2 100644 (file)
@@ -1960,10 +1960,12 @@ impl Channel {
                if !self.channel_outbound {
                        panic!("Cannot send fee from inbound channel");
                }
-
                if !self.is_usable() {
                        panic!("Cannot update fee until channel is fully established and we haven't started shutting down");
                }
+               if !self.is_live() {
+                       panic!("Cannot update fee while peer is disconnected (ChannelManager should have caught this)");
+               }
 
                if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
                        self.holding_cell_update_fee = Some(feerate_per_kw);
index b967a6774d1f98c721ea7bce305065643476df59..d0df159e22bb25b5fd96eed2273220f328557535 100644 (file)
@@ -1000,7 +1000,7 @@ impl ChannelManager {
                };
 
                let msg_hash = Sha256dHash::from_data(&unsigned.encode()[..]);
-               let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key); //TODO Can we unwrap here?
+               let sig = self.secp_ctx.sign(&Message::from_slice(&msg_hash[..]).unwrap(), &self.our_network_key);
 
                Ok(msgs::ChannelUpdate {
                        signature: sig,
@@ -1105,7 +1105,6 @@ impl ChannelManager {
        /// May panic if the funding_txo is duplicative with some other channel (note that this should
        /// be trivially prevented by using unique funding transaction keys per-channel).
        pub fn funding_transaction_generated(&self, temporary_channel_id: &[u8; 32], funding_txo: OutPoint) {
-
                macro_rules! add_pending_event {
                        ($event: expr) => {
                                {
@@ -2001,7 +2000,7 @@ impl ChannelManager {
                match channel_state.by_id.get_mut(&channel_id) {
                        None => return Err(APIError::APIMisuseError{err: "Failed to find corresponding channel"}),
                        Some(chan) => {
-                               if !chan.is_usable() {
+                               if !chan.is_live() {
                                        return Err(APIError::APIMisuseError{err: "Channel is not in usuable state"});
                                }
                                if !chan.is_outbound() {