@@ -244,9 +244,9 @@ enum HTLCUpdateAwaitingACK {
244
244
/// There are a few "states" and then a number of flags which can be applied:
245
245
/// We first move through init with OurInitSent -> TheirInitSent -> FundingCreated -> FundingSent.
246
246
/// 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
250
250
/// move on to ShutdownComplete, at which point most calls into this channel are disallowed.
251
251
enum ChannelState {
252
252
/// Implies we have (or are prepared to) send our open_channel/accept_channel message
@@ -262,17 +262,17 @@ enum ChannelState {
262
262
/// and our counterparty consider the funding transaction confirmed.
263
263
FundingSent = 8 ,
264
264
/// 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 .
266
266
TheirChannelReady = 1 << 4 ,
267
267
/// 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 .
269
269
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
272
272
/// "disconnected" and no updates are allowed until after we've done a channel_reestablish
273
273
/// dance.
274
274
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
276
276
/// told us a ChannelMonitor update is pending async persistence somewhere and we should pause
277
277
/// sending any outbound messages until they've managed to finish.
278
278
MonitorUpdateInProgress = 1 << 8 ,
@@ -281,13 +281,13 @@ enum ChannelState {
281
281
/// messages as then we will be unable to determine which HTLCs they included in their
282
282
/// revoke_and_ack implicit ACK, so instead we have to hold them away temporarily to be sent
283
283
/// later.
284
- /// Flag is set on ChannelFunded .
284
+ /// Flag is set on ChannelReady .
285
285
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
287
287
/// the remote end. If set, they may not add any new HTLCs to the channel, and we are expected
288
288
/// to respond with our own shutdown message when possible.
289
289
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
291
291
/// point, we may not add any new HTLCs to the channel.
292
292
LocalShutdownSent = 1 << 11 ,
293
293
/// We've successfully negotiated a closing_signed dance. At this point ChannelManager is about
@@ -1793,11 +1793,11 @@ impl<Signer: Sign> Channel<Signer> {
1793
1793
}
1794
1794
1795
1795
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
1797
1797
// caller thought we could have something claimed (cause we wouldn't have accepted in an
1798
1798
// incoming HTLC anyway). If we got to ShutdownComplete, callers aren't allowed to call us,
1799
1799
// 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 ) {
1801
1801
panic ! ( "Was asked to fulfill an HTLC when channel was not in an operational state" ) ;
1802
1802
}
1803
1803
assert_eq ! ( self . channel_state & ChannelState :: ShutdownComplete as u32 , 0 ) ;
@@ -1940,7 +1940,7 @@ impl<Signer: Sign> Channel<Signer> {
1940
1940
/// If we do fail twice, we debug_assert!(false) and return Ok(None). Thus, will always return
1941
1941
/// Ok(_) if debug assertions are turned on or preconditions are met.
1942
1942
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 ) {
1944
1944
panic ! ( "Was asked to fail an HTLC when channel was not in an operational state" ) ;
1945
1945
}
1946
1946
assert_eq ! ( self . channel_state & ChannelState :: ShutdownComplete as u32 , 0 ) ;
@@ -2356,9 +2356,9 @@ impl<Signer: Sign> Channel<Signer> {
2356
2356
if non_shutdown_state == ChannelState :: FundingSent as u32 {
2357
2357
self . channel_state |= ChannelState :: TheirChannelReady as u32 ;
2358
2358
} 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 ) ;
2360
2360
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 ||
2362
2362
// If we reconnected before sending our `channel_ready` they may still resend theirs:
2363
2363
( self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: TheirChannelReady as u32 ) ==
2364
2364
( ChannelState :: FundingSent as u32 | ChannelState :: TheirChannelReady as u32 ) )
@@ -2719,12 +2719,12 @@ impl<Signer: Sign> Channel<Signer> {
2719
2719
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 >
2720
2720
where F : for < ' a > Fn ( & ' a Self , PendingHTLCStatus , u16 ) -> PendingHTLCStatus , L :: Target : Logger {
2721
2721
// 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 ) ;
2723
2723
if local_sent_shutdown {
2724
2724
pending_forward_status = create_pending_htlc_status ( self , pending_forward_status, 0x4000 |8 ) ;
2725
2725
}
2726
2726
// 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 ) ;
2728
2728
if remote_sent_shutdown {
2729
2729
return Err ( ChannelError :: Close ( "Got add HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
2730
2730
}
@@ -2901,7 +2901,7 @@ impl<Signer: Sign> Channel<Signer> {
2901
2901
}
2902
2902
2903
2903
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 ) {
2905
2905
return Err ( ChannelError :: Close ( "Got fulfill HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
2906
2906
}
2907
2907
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -2912,7 +2912,7 @@ impl<Signer: Sign> Channel<Signer> {
2912
2912
}
2913
2913
2914
2914
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 ) {
2916
2916
return Err ( ChannelError :: Close ( "Got fail HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
2917
2917
}
2918
2918
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -2924,7 +2924,7 @@ impl<Signer: Sign> Channel<Signer> {
2924
2924
}
2925
2925
2926
2926
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 ) {
2928
2928
return Err ( ChannelError :: Close ( "Got fail malformed HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
2929
2929
}
2930
2930
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -2938,7 +2938,7 @@ impl<Signer: Sign> Channel<Signer> {
2938
2938
pub fn commitment_signed < L : Deref > ( & mut self , msg : & msgs:: CommitmentSigned , logger : & L ) -> Result < ( msgs:: RevokeAndACK , Option < msgs:: CommitmentSigned > , ChannelMonitorUpdate ) , ( Option < ChannelMonitorUpdate > , ChannelError ) >
2939
2939
where L :: Target : Logger
2940
2940
{
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 ) {
2942
2942
return Err ( ( None , ChannelError :: Close ( "Got commitment signed message when channel was not in an operational state" . to_owned ( ) ) ) ) ;
2943
2943
}
2944
2944
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -3131,7 +3131,7 @@ impl<Signer: Sign> Channel<Signer> {
3131
3131
/// If we're not in a state where freeing the holding cell makes sense, this is a no-op and
3132
3132
/// returns `(None, Vec::new())`.
3133
3133
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 &&
3135
3135
( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 | ChannelState :: PeerDisconnected as u32 | ChannelState :: MonitorUpdateInProgress as u32 ) ) == 0 {
3136
3136
self . free_holding_cell_htlcs ( logger)
3137
3137
} else { Ok ( ( None , Vec :: new ( ) ) ) }
@@ -3259,7 +3259,7 @@ impl<Signer: Sign> Channel<Signer> {
3259
3259
pub fn revoke_and_ack < L : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , logger : & L ) -> Result < RAAUpdates , ChannelError >
3260
3260
where L :: Target : Logger ,
3261
3261
{
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 ) {
3263
3263
return Err ( ChannelError :: Close ( "Got revoke/ACK message when channel was not in an operational state" . to_owned ( ) ) ) ;
3264
3264
}
3265
3265
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -3703,7 +3703,7 @@ impl<Signer: Sign> Channel<Signer> {
3703
3703
} else { None } ;
3704
3704
// That said, if the funding transaction is already confirmed (ie we're active with a
3705
3705
// 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 ) {
3707
3707
funding_broadcastable = None ;
3708
3708
}
3709
3709
@@ -4783,8 +4783,8 @@ impl<Signer: Sign> Channel<Signer> {
4783
4783
/// Returns true if this channel is fully established and not known to be closing.
4784
4784
/// Allowed in any state (including after shutdown)
4785
4785
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
4788
4788
}
4789
4789
4790
4790
/// Returns true if this channel is currently available for use. This is a superset of
@@ -4843,7 +4843,7 @@ impl<Signer: Sign> Channel<Signer> {
4843
4843
4844
4844
/// Returns true if our channel_ready has been sent
4845
4845
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
4847
4847
}
4848
4848
4849
4849
/// Returns true if our peer has either initiated or agreed to shut down the channel.
@@ -4897,14 +4897,14 @@ impl<Signer: Sign> Channel<Signer> {
4897
4897
self . channel_state |= ChannelState :: OurChannelReady as u32 ;
4898
4898
true
4899
4899
} 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 ) ;
4901
4901
self . update_time_counter += 1 ;
4902
4902
true
4903
4903
} else if non_shutdown_state == ( ChannelState :: FundingSent as u32 | ChannelState :: OurChannelReady as u32 ) {
4904
4904
// We got a reorg but not enough to trigger a force close, just ignore.
4905
4905
false
4906
4906
} 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 {
4908
4908
// We should never see a funding transaction on-chain until we've received
4909
4909
// funding_signed (if we're an outbound channel), or seen funding_generated (if we're
4910
4910
// an inbound channel - before that we have no known funding TXID). The fuzzer,
@@ -5048,7 +5048,7 @@ impl<Signer: Sign> Channel<Signer> {
5048
5048
}
5049
5049
5050
5050
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 ||
5052
5052
( non_shutdown_state & ChannelState :: OurChannelReady as u32 ) == ChannelState :: OurChannelReady as u32 {
5053
5053
let mut funding_tx_confirmations = height as i64 - self . funding_tx_confirmation_height as i64 + 1 ;
5054
5054
if self . funding_tx_confirmation_height == 0 {
@@ -5076,7 +5076,7 @@ impl<Signer: Sign> Channel<Signer> {
5076
5076
height >= self . channel_creation_height + FUNDING_CONF_DEADLINE_BLOCKS {
5077
5077
log_info ! ( logger, "Closing channel {} due to funding timeout" , log_bytes!( self . channel_id) ) ;
5078
5078
// 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 ) ;
5080
5080
assert_eq ! ( non_shutdown_state & ChannelState :: OurChannelReady as u32 , 0 ) ;
5081
5081
return Err ( ClosureReason :: FundingTimedOut ) ;
5082
5082
}
@@ -5501,7 +5501,7 @@ impl<Signer: Sign> Channel<Signer> {
5501
5501
///
5502
5502
/// If an Err is returned, it's a ChannelError::Ignore!
5503
5503
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 ) {
5505
5505
return Err ( ChannelError :: Ignore ( "Cannot send HTLC until channel is fully established and we haven't started shutting down" . to_owned ( ) ) ) ;
5506
5506
}
5507
5507
let channel_total_msat = self . channel_value_satoshis * 1000 ;
@@ -5634,7 +5634,7 @@ impl<Signer: Sign> Channel<Signer> {
5634
5634
/// last call to this Channel) send_htlc returned Ok(Some(_)) and there is an Err.
5635
5635
/// May panic if called except immediately after a successful, Ok(Some(_))-returning send_htlc.
5636
5636
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 ) {
5638
5638
panic ! ( "Cannot create commitment tx until channel is fully established" ) ;
5639
5639
}
5640
5640
if ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == ( ChannelState :: AwaitingRemoteRevoke as u32 ) {
@@ -5923,7 +5923,7 @@ impl<Signer: Sign> Channel<Signer> {
5923
5923
// funding transaction, don't return a funding txo (which prevents providing the
5924
5924
// monitor update to the user, even if we return one).
5925
5925
// 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 {
5927
5927
self . latest_monitor_update_id += 1 ;
5928
5928
Some ( ( funding_txo, ChannelMonitorUpdate {
5929
5929
update_id : self . latest_monitor_update_id ,
0 commit comments