X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=inline;f=src%2Fln%2Fchannel.rs;h=1b7db97d3d342d1a97551b3a274c37425a07d8a2;hb=d318184c9e17b58dfaa9d5152da9b2ca43ca5a2e;hp=188e1c7256da194e2d81f1694250be7fe1cba584;hpb=17375b055146f55af75f1a22e5891b54ff94f9ca;p=rust-lightning diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 188e1c72..1b7db97d 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -269,6 +269,7 @@ enum ChannelState { ShutdownComplete = 2048, } const BOTH_SIDES_SHUTDOWN_MASK: u32 = (ChannelState::LocalShutdownSent as u32 | ChannelState::RemoteShutdownSent as u32); +const MULTI_STATE_FLAGS: u32 = (BOTH_SIDES_SHUTDOWN_MASK | ChannelState::PeerDisconnected as u32); const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1; @@ -1959,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); @@ -2560,7 +2563,7 @@ impl Channel { /// apply - no calls may be made except those explicitly stated to be allowed post-shutdown. /// Only returns an ErrorAction of DisconnectPeer, if Err. pub fn block_connected(&mut self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]) -> Result, HandleError> { - let non_shutdown_state = self.channel_state & (!BOTH_SIDES_SHUTDOWN_MASK); + let non_shutdown_state = self.channel_state & (!MULTI_STATE_FLAGS); if self.funding_tx_confirmations > 0 { if header.bitcoin_hash() != self.last_block_connected { self.last_block_connected = header.bitcoin_hash(); @@ -2570,10 +2573,10 @@ impl Channel { self.channel_state |= ChannelState::OurFundingLocked as u32; true } else if non_shutdown_state == (ChannelState::FundingSent as u32 | ChannelState::TheirFundingLocked as u32) { - self.channel_state = ChannelState::ChannelFunded as u32 | (self.channel_state & BOTH_SIDES_SHUTDOWN_MASK); + self.channel_state = ChannelState::ChannelFunded as u32 | (self.channel_state & MULTI_STATE_FLAGS); self.channel_update_count += 1; true - } else if self.channel_state == (ChannelState::FundingSent as u32 | ChannelState::OurFundingLocked as u32) { + } else if non_shutdown_state == (ChannelState::FundingSent as u32 | ChannelState::OurFundingLocked as u32) { // We got a reorg but not enough to trigger a force close, just update // funding_tx_confirmed_in and return. false