@@ -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 ) ;
@@ -2370,9 +2370,9 @@ impl<Signer: Sign> Channel<Signer> {
23702370 if non_shutdown_state == ChannelState :: FundingSent as u32 {
23712371 self . channel_state |= ChannelState :: TheirChannelReady as u32 ;
23722372 } else if non_shutdown_state == ( ChannelState :: FundingSent as u32 | ChannelState :: OurChannelReady as u32 ) {
2373- self . channel_state = ChannelState :: ChannelFunded as u32 | ( self . channel_state & MULTI_STATE_FLAGS ) ;
2373+ self . channel_state = ChannelState :: ChannelReady as u32 | ( self . channel_state & MULTI_STATE_FLAGS ) ;
23742374 self . update_time_counter += 1 ;
2375- } else if self . channel_state & ( ChannelState :: ChannelFunded as u32 ) != 0 ||
2375+ } else if self . channel_state & ( ChannelState :: ChannelReady as u32 ) != 0 ||
23762376 // If we reconnected before sending our `channel_ready` they may still resend theirs:
23772377 ( self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: TheirChannelReady as u32 ) ==
23782378 ( ChannelState :: FundingSent as u32 | ChannelState :: TheirChannelReady as u32 ) )
@@ -2733,12 +2733,12 @@ impl<Signer: Sign> Channel<Signer> {
27332733 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 >
27342734 where F : for < ' a > Fn ( & ' a Self , PendingHTLCStatus , u16 ) -> PendingHTLCStatus , L :: Target : Logger {
27352735 // We can't accept HTLCs sent after we've sent a shutdown.
2736- let local_sent_shutdown = ( self . channel_state & ( ChannelState :: ChannelFunded as u32 | ChannelState :: LocalShutdownSent as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) ;
2736+ let local_sent_shutdown = ( self . channel_state & ( ChannelState :: ChannelReady as u32 | ChannelState :: LocalShutdownSent as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) ;
27372737 if local_sent_shutdown {
27382738 pending_forward_status = create_pending_htlc_status ( self , pending_forward_status, 0x4000 |8 ) ;
27392739 }
27402740 // If the remote has sent a shutdown prior to adding this HTLC, then they are in violation of the spec.
2741- let remote_sent_shutdown = ( self . channel_state & ( ChannelState :: ChannelFunded as u32 | ChannelState :: RemoteShutdownSent as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) ;
2741+ let remote_sent_shutdown = ( self . channel_state & ( ChannelState :: ChannelReady as u32 | ChannelState :: RemoteShutdownSent as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) ;
27422742 if remote_sent_shutdown {
27432743 return Err ( ChannelError :: Close ( "Got add HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
27442744 }
@@ -2915,7 +2915,7 @@ impl<Signer: Sign> Channel<Signer> {
29152915 }
29162916
29172917 pub fn update_fulfill_htlc ( & mut self , msg : & msgs:: UpdateFulfillHTLC ) -> Result < ( HTLCSource , u64 ) , ChannelError > {
2918- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2918+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
29192919 return Err ( ChannelError :: Close ( "Got fulfill HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
29202920 }
29212921 if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -2926,7 +2926,7 @@ impl<Signer: Sign> Channel<Signer> {
29262926 }
29272927
29282928 pub fn update_fail_htlc ( & mut self , msg : & msgs:: UpdateFailHTLC , fail_reason : HTLCFailReason ) -> Result < ( ) , ChannelError > {
2929- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2929+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
29302930 return Err ( ChannelError :: Close ( "Got fail HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
29312931 }
29322932 if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -2938,7 +2938,7 @@ impl<Signer: Sign> Channel<Signer> {
29382938 }
29392939
29402940 pub fn update_fail_malformed_htlc ( & mut self , msg : & msgs:: UpdateFailMalformedHTLC , fail_reason : HTLCFailReason ) -> Result < ( ) , ChannelError > {
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 ( ChannelError :: Close ( "Got fail malformed HTLC 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 {
@@ -2952,7 +2952,7 @@ impl<Signer: Sign> Channel<Signer> {
29522952 pub fn commitment_signed < L : Deref > ( & mut self , msg : & msgs:: CommitmentSigned , logger : & L ) -> Result < ( msgs:: RevokeAndACK , Option < msgs:: CommitmentSigned > , ChannelMonitorUpdate ) , ( Option < ChannelMonitorUpdate > , ChannelError ) >
29532953 where L :: Target : Logger
29542954 {
2955- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2955+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
29562956 return Err ( ( None , ChannelError :: Close ( "Got commitment signed message when channel was not in an operational state" . to_owned ( ) ) ) ) ;
29572957 }
29582958 if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -3145,7 +3145,7 @@ impl<Signer: Sign> Channel<Signer> {
31453145 /// If we're not in a state where freeing the holding cell makes sense, this is a no-op and
31463146 /// returns `(None, Vec::new())`.
31473147 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 {
3148- if self . channel_state >= ChannelState :: ChannelFunded as u32 &&
3148+ if self . channel_state >= ChannelState :: ChannelReady as u32 &&
31493149 ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 | ChannelState :: PeerDisconnected as u32 | ChannelState :: MonitorUpdateInProgress as u32 ) ) == 0 {
31503150 self . free_holding_cell_htlcs ( logger)
31513151 } else { Ok ( ( None , Vec :: new ( ) ) ) }
@@ -3273,7 +3273,7 @@ impl<Signer: Sign> Channel<Signer> {
32733273 pub fn revoke_and_ack < L : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , logger : & L ) -> Result < RAAUpdates , ChannelError >
32743274 where L :: Target : Logger ,
32753275 {
3276- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
3276+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
32773277 return Err ( ChannelError :: Close ( "Got revoke/ACK message when channel was not in an operational state" . to_owned ( ) ) ) ;
32783278 }
32793279 if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -3717,7 +3717,7 @@ impl<Signer: Sign> Channel<Signer> {
37173717 } else { None } ;
37183718 // That said, if the funding transaction is already confirmed (ie we're active with a
37193719 // minimum_depth over 0) don't bother re-broadcasting the confirmed funding tx.
3720- if self . channel_state & !MULTI_STATE_FLAGS >= ChannelState :: ChannelFunded as u32 && self . minimum_depth != Some ( 0 ) {
3720+ if self . channel_state & !MULTI_STATE_FLAGS >= ChannelState :: ChannelReady as u32 && self . minimum_depth != Some ( 0 ) {
37213721 funding_broadcastable = None ;
37223722 }
37233723
@@ -4797,8 +4797,8 @@ impl<Signer: Sign> Channel<Signer> {
47974797 /// Returns true if this channel is fully established and not known to be closing.
47984798 /// Allowed in any state (including after shutdown)
47994799 pub fn is_usable ( & self ) -> bool {
4800- let mask = ChannelState :: ChannelFunded as u32 | BOTH_SIDES_SHUTDOWN_MASK ;
4801- ( self . channel_state & mask) == ( ChannelState :: ChannelFunded as u32 ) && !self . monitor_pending_channel_ready
4800+ let mask = ChannelState :: ChannelReady as u32 | BOTH_SIDES_SHUTDOWN_MASK ;
4801+ ( self . channel_state & mask) == ( ChannelState :: ChannelReady as u32 ) && !self . monitor_pending_channel_ready
48024802 }
48034803
48044804 /// Returns true if this channel is currently available for use. This is a superset of
@@ -4857,7 +4857,7 @@ impl<Signer: Sign> Channel<Signer> {
48574857
48584858 /// Returns true if our channel_ready has been sent
48594859 pub fn is_our_channel_ready ( & self ) -> bool {
4860- ( self . channel_state & ChannelState :: OurChannelReady as u32 ) != 0 || self . channel_state >= ChannelState :: ChannelFunded as u32
4860+ ( self . channel_state & ChannelState :: OurChannelReady as u32 ) != 0 || self . channel_state >= ChannelState :: ChannelReady as u32
48614861 }
48624862
48634863 /// Returns true if our peer has either initiated or agreed to shut down the channel.
@@ -4911,14 +4911,14 @@ impl<Signer: Sign> Channel<Signer> {
49114911 self . channel_state |= ChannelState :: OurChannelReady as u32 ;
49124912 true
49134913 } else if non_shutdown_state == ( ChannelState :: FundingSent as u32 | ChannelState :: TheirChannelReady as u32 ) {
4914- self . channel_state = ChannelState :: ChannelFunded as u32 | ( self . channel_state & MULTI_STATE_FLAGS ) ;
4914+ self . channel_state = ChannelState :: ChannelReady as u32 | ( self . channel_state & MULTI_STATE_FLAGS ) ;
49154915 self . update_time_counter += 1 ;
49164916 true
49174917 } else if non_shutdown_state == ( ChannelState :: FundingSent as u32 | ChannelState :: OurChannelReady as u32 ) {
49184918 // We got a reorg but not enough to trigger a force close, just ignore.
49194919 false
49204920 } else {
4921- if self . funding_tx_confirmation_height != 0 && self . channel_state < ChannelState :: ChannelFunded as u32 {
4921+ if self . funding_tx_confirmation_height != 0 && self . channel_state < ChannelState :: ChannelReady as u32 {
49224922 // We should never see a funding transaction on-chain until we've received
49234923 // funding_signed (if we're an outbound channel), or seen funding_generated (if we're
49244924 // an inbound channel - before that we have no known funding TXID). The fuzzer,
@@ -5073,7 +5073,7 @@ impl<Signer: Sign> Channel<Signer> {
50735073 }
50745074
50755075 let non_shutdown_state = self . channel_state & ( !MULTI_STATE_FLAGS ) ;
5076- if non_shutdown_state >= ChannelState :: ChannelFunded as u32 ||
5076+ if non_shutdown_state >= ChannelState :: ChannelReady as u32 ||
50775077 ( non_shutdown_state & ChannelState :: OurChannelReady as u32 ) == ChannelState :: OurChannelReady as u32 {
50785078 let mut funding_tx_confirmations = height as i64 - self . funding_tx_confirmation_height as i64 + 1 ;
50795079 if self . funding_tx_confirmation_height == 0 {
@@ -5101,7 +5101,7 @@ impl<Signer: Sign> Channel<Signer> {
51015101 height >= self . channel_creation_height + FUNDING_CONF_DEADLINE_BLOCKS {
51025102 log_info ! ( logger, "Closing channel {} due to funding timeout" , log_bytes!( self . channel_id) ) ;
51035103 // If funding_tx_confirmed_in is unset, the channel must not be active
5104- assert ! ( non_shutdown_state <= ChannelState :: ChannelFunded as u32 ) ;
5104+ assert ! ( non_shutdown_state <= ChannelState :: ChannelReady as u32 ) ;
51055105 assert_eq ! ( non_shutdown_state & ChannelState :: OurChannelReady as u32 , 0 ) ;
51065106 return Err ( ClosureReason :: FundingTimedOut ) ;
51075107 }
@@ -5527,7 +5527,7 @@ impl<Signer: Sign> Channel<Signer> {
55275527 ///
55285528 /// If an Err is returned, it's a ChannelError::Ignore!
55295529 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 {
5530- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 | BOTH_SIDES_SHUTDOWN_MASK ) ) != ( ChannelState :: ChannelFunded as u32 ) {
5530+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 | BOTH_SIDES_SHUTDOWN_MASK ) ) != ( ChannelState :: ChannelReady as u32 ) {
55315531 return Err ( ChannelError :: Ignore ( "Cannot send HTLC until channel is fully established and we haven't started shutting down" . to_owned ( ) ) ) ;
55325532 }
55335533 let channel_total_msat = self . channel_value_satoshis * 1000 ;
@@ -5660,7 +5660,7 @@ impl<Signer: Sign> Channel<Signer> {
56605660 /// last call to this Channel) send_htlc returned Ok(Some(_)) and there is an Err.
56615661 /// May panic if called except immediately after a successful, Ok(Some(_))-returning send_htlc.
56625662 pub fn send_commitment < L : Deref > ( & mut self , logger : & L ) -> Result < ( msgs:: CommitmentSigned , ChannelMonitorUpdate ) , ChannelError > where L :: Target : Logger {
5663- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
5663+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
56645664 panic ! ( "Cannot create commitment tx until channel is fully established" ) ;
56655665 }
56665666 if ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == ( ChannelState :: AwaitingRemoteRevoke as u32 ) {
@@ -5949,7 +5949,7 @@ impl<Signer: Sign> Channel<Signer> {
59495949 // funding transaction, don't return a funding txo (which prevents providing the
59505950 // monitor update to the user, even if we return one).
59515951 // See test_duplicate_chan_id and test_pre_lockin_no_chan_closed_update for more.
5952- if self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: ChannelFunded as u32 | ChannelState :: ShutdownComplete as u32 ) != 0 {
5952+ if self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: ChannelReady as u32 | ChannelState :: ShutdownComplete as u32 ) != 0 {
59535953 self . latest_monitor_update_id += 1 ;
59545954 Some ( ( funding_txo, ChannelMonitorUpdate {
59555955 update_id : self . latest_monitor_update_id ,
0 commit comments