@@ -244,9 +244,9 @@ enum HTLCUpdateAwaitingACK {
244244/// There are a few "states" and then a number of flags which can be applied:
245245/// We first move through init with OurInitSent -> TheirInitSent -> FundingCreated -> FundingSent.
246246/// TheirChannelReady and OurChannelReady then get set on FundingSent, and when both are set we
247- /// move on to ChannelFunded .
248- /// Note that PeerDisconnected can be set on both ChannelFunded and FundingSent.
249- /// ChannelFunded can then get all remaining flags set on it, until we finish shutdown, then we
247+ /// move on to ChannelReady .
248+ /// Note that PeerDisconnected can be set on both ChannelReady and FundingSent.
249+ /// ChannelReady can then get all remaining flags set on it, until we finish shutdown, then we
250250/// move on to ShutdownComplete, at which point most calls into this channel are disallowed.
251251enum ChannelState {
252252 /// Implies we have (or are prepared to) send our open_channel/accept_channel message
@@ -262,17 +262,17 @@ enum ChannelState {
262262 /// and our counterparty consider the funding transaction confirmed.
263263 FundingSent = 8 ,
264264 /// Flag which can be set on FundingSent to indicate they sent us a channel_ready message.
265- /// Once both TheirChannelReady and OurChannelReady are set, state moves on to ChannelFunded .
265+ /// Once both TheirChannelReady and OurChannelReady are set, state moves on to ChannelReady .
266266 TheirChannelReady = 1 << 4 ,
267267 /// Flag which can be set on FundingSent to indicate we sent them a channel_ready message.
268- /// Once both TheirChannelReady and OurChannelReady are set, state moves on to ChannelFunded .
268+ /// Once both TheirChannelReady and OurChannelReady are set, state moves on to ChannelReady .
269269 OurChannelReady = 1 << 5 ,
270- ChannelFunded = 64 ,
271- /// Flag which is set on ChannelFunded and FundingSent indicating remote side is considered
270+ ChannelReady = 64 ,
271+ /// Flag which is set on ChannelReady and FundingSent indicating remote side is considered
272272 /// "disconnected" and no updates are allowed until after we've done a channel_reestablish
273273 /// dance.
274274 PeerDisconnected = 1 << 7 ,
275- /// Flag which is set on ChannelFunded , FundingCreated, and FundingSent indicating the user has
275+ /// Flag which is set on ChannelReady , FundingCreated, and FundingSent indicating the user has
276276 /// told us a ChannelMonitor update is pending async persistence somewhere and we should pause
277277 /// sending any outbound messages until they've managed to finish.
278278 MonitorUpdateInProgress = 1 << 8 ,
@@ -281,13 +281,13 @@ enum ChannelState {
281281 /// messages as then we will be unable to determine which HTLCs they included in their
282282 /// revoke_and_ack implicit ACK, so instead we have to hold them away temporarily to be sent
283283 /// later.
284- /// Flag is set on ChannelFunded .
284+ /// Flag is set on ChannelReady .
285285 AwaitingRemoteRevoke = 1 << 9 ,
286- /// Flag which is set on ChannelFunded or FundingSent after receiving a shutdown message from
286+ /// Flag which is set on ChannelReady or FundingSent after receiving a shutdown message from
287287 /// the remote end. If set, they may not add any new HTLCs to the channel, and we are expected
288288 /// to respond with our own shutdown message when possible.
289289 RemoteShutdownSent = 1 << 10 ,
290- /// Flag which is set on ChannelFunded or FundingSent after sending a shutdown message. At this
290+ /// Flag which is set on ChannelReady or FundingSent after sending a shutdown message. At this
291291 /// point, we may not add any new HTLCs to the channel.
292292 LocalShutdownSent = 1 << 11 ,
293293 /// We've successfully negotiated a closing_signed dance. At this point ChannelManager is about
@@ -1793,11 +1793,11 @@ impl<Signer: Sign> Channel<Signer> {
17931793 }
17941794
17951795 fn get_update_fulfill_htlc < L : Deref > ( & mut self , htlc_id_arg : u64 , payment_preimage_arg : PaymentPreimage , logger : & L ) -> UpdateFulfillFetch where L :: Target : Logger {
1796- // Either ChannelFunded got set (which means it won't be unset) or there is no way any
1796+ // Either ChannelReady got set (which means it won't be unset) or there is no way any
17971797 // caller thought we could have something claimed (cause we wouldn't have accepted in an
17981798 // incoming HTLC anyway). If we got to ShutdownComplete, callers aren't allowed to call us,
17991799 // either.
1800- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
1800+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
18011801 panic ! ( "Was asked to fulfill an HTLC when channel was not in an operational state" ) ;
18021802 }
18031803 assert_eq ! ( self . channel_state & ChannelState :: ShutdownComplete as u32 , 0 ) ;
@@ -1940,7 +1940,7 @@ impl<Signer: Sign> Channel<Signer> {
19401940 /// If we do fail twice, we debug_assert!(false) and return Ok(None). Thus, will always return
19411941 /// Ok(_) if debug assertions are turned on or preconditions are met.
19421942 pub fn get_update_fail_htlc < L : Deref > ( & mut self , htlc_id_arg : u64 , err_packet : msgs:: OnionErrorPacket , logger : & L ) -> Result < Option < msgs:: UpdateFailHTLC > , ChannelError > where L :: Target : Logger {
1943- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
1943+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
19441944 panic ! ( "Was asked to fail an HTLC when channel was not in an operational state" ) ;
19451945 }
19461946 assert_eq ! ( self . channel_state & ChannelState :: ShutdownComplete as u32 , 0 ) ;
@@ -2356,9 +2356,9 @@ impl<Signer: Sign> Channel<Signer> {
23562356 if non_shutdown_state == ChannelState :: FundingSent as u32 {
23572357 self . channel_state |= ChannelState :: TheirChannelReady as u32 ;
23582358 } else if non_shutdown_state == ( ChannelState :: FundingSent as u32 | ChannelState :: OurChannelReady as u32 ) {
2359- self . channel_state = ChannelState :: ChannelFunded as u32 | ( self . channel_state & MULTI_STATE_FLAGS ) ;
2359+ self . channel_state = ChannelState :: ChannelReady as u32 | ( self . channel_state & MULTI_STATE_FLAGS ) ;
23602360 self . update_time_counter += 1 ;
2361- } else if self . channel_state & ( ChannelState :: ChannelFunded as u32 ) != 0 ||
2361+ } else if self . channel_state & ( ChannelState :: ChannelReady as u32 ) != 0 ||
23622362 // If we reconnected before sending our `channel_ready` they may still resend theirs:
23632363 ( self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: TheirChannelReady as u32 ) ==
23642364 ( ChannelState :: FundingSent as u32 | ChannelState :: TheirChannelReady as u32 ) )
@@ -2719,12 +2719,12 @@ impl<Signer: Sign> Channel<Signer> {
27192719 pub fn update_add_htlc < F , L : Deref > ( & mut self , msg : & msgs:: UpdateAddHTLC , mut pending_forward_status : PendingHTLCStatus , create_pending_htlc_status : F , logger : & L ) -> Result < ( ) , ChannelError >
27202720 where F : for < ' a > Fn ( & ' a Self , PendingHTLCStatus , u16 ) -> PendingHTLCStatus , L :: Target : Logger {
27212721 // We can't accept HTLCs sent after we've sent a shutdown.
2722- let local_sent_shutdown = ( self . channel_state & ( ChannelState :: ChannelFunded as u32 | ChannelState :: LocalShutdownSent as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) ;
2722+ let local_sent_shutdown = ( self . channel_state & ( ChannelState :: ChannelReady as u32 | ChannelState :: LocalShutdownSent as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) ;
27232723 if local_sent_shutdown {
27242724 pending_forward_status = create_pending_htlc_status ( self , pending_forward_status, 0x4000 |8 ) ;
27252725 }
27262726 // If the remote has sent a shutdown prior to adding this HTLC, then they are in violation of the spec.
2727- let remote_sent_shutdown = ( self . channel_state & ( ChannelState :: ChannelFunded as u32 | ChannelState :: RemoteShutdownSent as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) ;
2727+ let remote_sent_shutdown = ( self . channel_state & ( ChannelState :: ChannelReady as u32 | ChannelState :: RemoteShutdownSent as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) ;
27282728 if remote_sent_shutdown {
27292729 return Err ( ChannelError :: Close ( "Got add HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
27302730 }
@@ -2901,7 +2901,7 @@ impl<Signer: Sign> Channel<Signer> {
29012901 }
29022902
29032903 pub fn update_fulfill_htlc ( & mut self , msg : & msgs:: UpdateFulfillHTLC ) -> Result < ( HTLCSource , u64 ) , ChannelError > {
2904- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2904+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
29052905 return Err ( ChannelError :: Close ( "Got fulfill HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
29062906 }
29072907 if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -2912,7 +2912,7 @@ impl<Signer: Sign> Channel<Signer> {
29122912 }
29132913
29142914 pub fn update_fail_htlc ( & mut self , msg : & msgs:: UpdateFailHTLC , fail_reason : HTLCFailReason ) -> Result < ( ) , ChannelError > {
2915- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2915+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
29162916 return Err ( ChannelError :: Close ( "Got fail HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
29172917 }
29182918 if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -2924,7 +2924,7 @@ impl<Signer: Sign> Channel<Signer> {
29242924 }
29252925
29262926 pub fn update_fail_malformed_htlc ( & mut self , msg : & msgs:: UpdateFailMalformedHTLC , fail_reason : HTLCFailReason ) -> Result < ( ) , ChannelError > {
2927- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2927+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
29282928 return Err ( ChannelError :: Close ( "Got fail malformed HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
29292929 }
29302930 if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -2938,7 +2938,7 @@ impl<Signer: Sign> Channel<Signer> {
29382938 pub fn commitment_signed < L : Deref > ( & mut self , msg : & msgs:: CommitmentSigned , logger : & L ) -> Result < ( msgs:: RevokeAndACK , Option < msgs:: CommitmentSigned > , ChannelMonitorUpdate ) , ( Option < ChannelMonitorUpdate > , ChannelError ) >
29392939 where L :: Target : Logger
29402940 {
2941- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2941+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
29422942 return Err ( ( None , ChannelError :: Close ( "Got commitment signed message when channel was not in an operational state" . to_owned ( ) ) ) ) ;
29432943 }
29442944 if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -3131,7 +3131,7 @@ impl<Signer: Sign> Channel<Signer> {
31313131 /// If we're not in a state where freeing the holding cell makes sense, this is a no-op and
31323132 /// returns `(None, Vec::new())`.
31333133 pub fn maybe_free_holding_cell_htlcs < L : Deref > ( & mut self , logger : & L ) -> Result < ( Option < ( msgs:: CommitmentUpdate , ChannelMonitorUpdate ) > , Vec < ( HTLCSource , PaymentHash ) > ) , ChannelError > where L :: Target : Logger {
3134- if self . channel_state >= ChannelState :: ChannelFunded as u32 &&
3134+ if self . channel_state >= ChannelState :: ChannelReady as u32 &&
31353135 ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 | ChannelState :: PeerDisconnected as u32 | ChannelState :: MonitorUpdateInProgress as u32 ) ) == 0 {
31363136 self . free_holding_cell_htlcs ( logger)
31373137 } else { Ok ( ( None , Vec :: new ( ) ) ) }
@@ -3259,7 +3259,7 @@ impl<Signer: Sign> Channel<Signer> {
32593259 pub fn revoke_and_ack < L : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , logger : & L ) -> Result < RAAUpdates , ChannelError >
32603260 where L :: Target : Logger ,
32613261 {
3262- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
3262+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
32633263 return Err ( ChannelError :: Close ( "Got revoke/ACK message when channel was not in an operational state" . to_owned ( ) ) ) ;
32643264 }
32653265 if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -3703,7 +3703,7 @@ impl<Signer: Sign> Channel<Signer> {
37033703 } else { None } ;
37043704 // That said, if the funding transaction is already confirmed (ie we're active with a
37053705 // minimum_depth over 0) don't bother re-broadcasting the confirmed funding tx.
3706- if self . channel_state & !MULTI_STATE_FLAGS >= ChannelState :: ChannelFunded as u32 && self . minimum_depth != Some ( 0 ) {
3706+ if self . channel_state & !MULTI_STATE_FLAGS >= ChannelState :: ChannelReady as u32 && self . minimum_depth != Some ( 0 ) {
37073707 funding_broadcastable = None ;
37083708 }
37093709
@@ -4783,8 +4783,8 @@ impl<Signer: Sign> Channel<Signer> {
47834783 /// Returns true if this channel is fully established and not known to be closing.
47844784 /// Allowed in any state (including after shutdown)
47854785 pub fn is_usable ( & self ) -> bool {
4786- let mask = ChannelState :: ChannelFunded as u32 | BOTH_SIDES_SHUTDOWN_MASK ;
4787- ( self . channel_state & mask) == ( ChannelState :: ChannelFunded as u32 ) && !self . monitor_pending_channel_ready
4786+ let mask = ChannelState :: ChannelReady as u32 | BOTH_SIDES_SHUTDOWN_MASK ;
4787+ ( self . channel_state & mask) == ( ChannelState :: ChannelReady as u32 ) && !self . monitor_pending_channel_ready
47884788 }
47894789
47904790 /// Returns true if this channel is currently available for use. This is a superset of
@@ -4843,7 +4843,7 @@ impl<Signer: Sign> Channel<Signer> {
48434843
48444844 /// Returns true if our channel_ready has been sent
48454845 pub fn is_our_channel_ready ( & self ) -> bool {
4846- ( self . channel_state & ChannelState :: OurChannelReady as u32 ) != 0 || self . channel_state >= ChannelState :: ChannelFunded as u32
4846+ ( self . channel_state & ChannelState :: OurChannelReady as u32 ) != 0 || self . channel_state >= ChannelState :: ChannelReady as u32
48474847 }
48484848
48494849 /// Returns true if our peer has either initiated or agreed to shut down the channel.
@@ -4897,14 +4897,14 @@ impl<Signer: Sign> Channel<Signer> {
48974897 self . channel_state |= ChannelState :: OurChannelReady as u32 ;
48984898 true
48994899 } else if non_shutdown_state == ( ChannelState :: FundingSent as u32 | ChannelState :: TheirChannelReady as u32 ) {
4900- self . channel_state = ChannelState :: ChannelFunded as u32 | ( self . channel_state & MULTI_STATE_FLAGS ) ;
4900+ self . channel_state = ChannelState :: ChannelReady as u32 | ( self . channel_state & MULTI_STATE_FLAGS ) ;
49014901 self . update_time_counter += 1 ;
49024902 true
49034903 } else if non_shutdown_state == ( ChannelState :: FundingSent as u32 | ChannelState :: OurChannelReady as u32 ) {
49044904 // We got a reorg but not enough to trigger a force close, just ignore.
49054905 false
49064906 } else {
4907- if self . funding_tx_confirmation_height != 0 && self . channel_state < ChannelState :: ChannelFunded as u32 {
4907+ if self . funding_tx_confirmation_height != 0 && self . channel_state < ChannelState :: ChannelReady as u32 {
49084908 // We should never see a funding transaction on-chain until we've received
49094909 // funding_signed (if we're an outbound channel), or seen funding_generated (if we're
49104910 // an inbound channel - before that we have no known funding TXID). The fuzzer,
@@ -5048,7 +5048,7 @@ impl<Signer: Sign> Channel<Signer> {
50485048 }
50495049
50505050 let non_shutdown_state = self . channel_state & ( !MULTI_STATE_FLAGS ) ;
5051- if non_shutdown_state >= ChannelState :: ChannelFunded as u32 ||
5051+ if non_shutdown_state >= ChannelState :: ChannelReady as u32 ||
50525052 ( non_shutdown_state & ChannelState :: OurChannelReady as u32 ) == ChannelState :: OurChannelReady as u32 {
50535053 let mut funding_tx_confirmations = height as i64 - self . funding_tx_confirmation_height as i64 + 1 ;
50545054 if self . funding_tx_confirmation_height == 0 {
@@ -5076,7 +5076,7 @@ impl<Signer: Sign> Channel<Signer> {
50765076 height >= self . channel_creation_height + FUNDING_CONF_DEADLINE_BLOCKS {
50775077 log_info ! ( logger, "Closing channel {} due to funding timeout" , log_bytes!( self . channel_id) ) ;
50785078 // If funding_tx_confirmed_in is unset, the channel must not be active
5079- assert ! ( non_shutdown_state <= ChannelState :: ChannelFunded as u32 ) ;
5079+ assert ! ( non_shutdown_state <= ChannelState :: ChannelReady as u32 ) ;
50805080 assert_eq ! ( non_shutdown_state & ChannelState :: OurChannelReady as u32 , 0 ) ;
50815081 return Err ( ClosureReason :: FundingTimedOut ) ;
50825082 }
@@ -5501,7 +5501,7 @@ impl<Signer: Sign> Channel<Signer> {
55015501 ///
55025502 /// If an Err is returned, it's a ChannelError::Ignore!
55035503 pub fn send_htlc < L : Deref > ( & mut self , amount_msat : u64 , payment_hash : PaymentHash , cltv_expiry : u32 , source : HTLCSource , onion_routing_packet : msgs:: OnionPacket , logger : & L ) -> Result < Option < msgs:: UpdateAddHTLC > , ChannelError > where L :: Target : Logger {
5504- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 | BOTH_SIDES_SHUTDOWN_MASK ) ) != ( ChannelState :: ChannelFunded as u32 ) {
5504+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 | BOTH_SIDES_SHUTDOWN_MASK ) ) != ( ChannelState :: ChannelReady as u32 ) {
55055505 return Err ( ChannelError :: Ignore ( "Cannot send HTLC until channel is fully established and we haven't started shutting down" . to_owned ( ) ) ) ;
55065506 }
55075507 let channel_total_msat = self . channel_value_satoshis * 1000 ;
@@ -5634,7 +5634,7 @@ impl<Signer: Sign> Channel<Signer> {
56345634 /// last call to this Channel) send_htlc returned Ok(Some(_)) and there is an Err.
56355635 /// May panic if called except immediately after a successful, Ok(Some(_))-returning send_htlc.
56365636 pub fn send_commitment < L : Deref > ( & mut self , logger : & L ) -> Result < ( msgs:: CommitmentSigned , ChannelMonitorUpdate ) , ChannelError > where L :: Target : Logger {
5637- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
5637+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
56385638 panic ! ( "Cannot create commitment tx until channel is fully established" ) ;
56395639 }
56405640 if ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == ( ChannelState :: AwaitingRemoteRevoke as u32 ) {
@@ -5923,7 +5923,7 @@ impl<Signer: Sign> Channel<Signer> {
59235923 // funding transaction, don't return a funding txo (which prevents providing the
59245924 // monitor update to the user, even if we return one).
59255925 // See test_duplicate_chan_id and test_pre_lockin_no_chan_closed_update for more.
5926- if self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: ChannelFunded as u32 | ChannelState :: ShutdownComplete as u32 ) != 0 {
5926+ if self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: ChannelReady as u32 | ChannelState :: ShutdownComplete as u32 ) != 0 {
59275927 self . latest_monitor_update_id += 1 ;
59285928 Some ( ( funding_txo, ChannelMonitorUpdate {
59295929 update_id : self . latest_monitor_update_id ,
0 commit comments