@@ -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 ) ;
@@ -2370,9 +2370,9 @@ impl<Signer: Sign> Channel<Signer> {
2370
2370
if non_shutdown_state == ChannelState :: FundingSent as u32 {
2371
2371
self . channel_state |= ChannelState :: TheirChannelReady as u32 ;
2372
2372
} 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 ) ;
2374
2374
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 ||
2376
2376
// If we reconnected before sending our `channel_ready` they may still resend theirs:
2377
2377
( self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: TheirChannelReady as u32 ) ==
2378
2378
( ChannelState :: FundingSent as u32 | ChannelState :: TheirChannelReady as u32 ) )
@@ -2733,12 +2733,12 @@ impl<Signer: Sign> Channel<Signer> {
2733
2733
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 >
2734
2734
where F : for < ' a > Fn ( & ' a Self , PendingHTLCStatus , u16 ) -> PendingHTLCStatus , L :: Target : Logger {
2735
2735
// 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 ) ;
2737
2737
if local_sent_shutdown {
2738
2738
pending_forward_status = create_pending_htlc_status ( self , pending_forward_status, 0x4000 |8 ) ;
2739
2739
}
2740
2740
// 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 ) ;
2742
2742
if remote_sent_shutdown {
2743
2743
return Err ( ChannelError :: Close ( "Got add HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
2744
2744
}
@@ -2915,7 +2915,7 @@ impl<Signer: Sign> Channel<Signer> {
2915
2915
}
2916
2916
2917
2917
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 ) {
2919
2919
return Err ( ChannelError :: Close ( "Got fulfill HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
2920
2920
}
2921
2921
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -2926,7 +2926,7 @@ impl<Signer: Sign> Channel<Signer> {
2926
2926
}
2927
2927
2928
2928
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 ) {
2930
2930
return Err ( ChannelError :: Close ( "Got fail HTLC message when channel was not in an operational state" . to_owned ( ) ) ) ;
2931
2931
}
2932
2932
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -2938,7 +2938,7 @@ impl<Signer: Sign> Channel<Signer> {
2938
2938
}
2939
2939
2940
2940
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 ) {
2942
2942
return Err ( ChannelError :: Close ( "Got fail malformed HTLC 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 {
@@ -2952,7 +2952,7 @@ impl<Signer: Sign> Channel<Signer> {
2952
2952
pub fn commitment_signed < L : Deref > ( & mut self , msg : & msgs:: CommitmentSigned , logger : & L ) -> Result < ( msgs:: RevokeAndACK , Option < msgs:: CommitmentSigned > , ChannelMonitorUpdate ) , ( Option < ChannelMonitorUpdate > , ChannelError ) >
2953
2953
where L :: Target : Logger
2954
2954
{
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 ) {
2956
2956
return Err ( ( None , ChannelError :: Close ( "Got commitment signed message when channel was not in an operational state" . to_owned ( ) ) ) ) ;
2957
2957
}
2958
2958
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -3145,7 +3145,7 @@ impl<Signer: Sign> Channel<Signer> {
3145
3145
/// If we're not in a state where freeing the holding cell makes sense, this is a no-op and
3146
3146
/// returns `(None, Vec::new())`.
3147
3147
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 &&
3149
3149
( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 | ChannelState :: PeerDisconnected as u32 | ChannelState :: MonitorUpdateInProgress as u32 ) ) == 0 {
3150
3150
self . free_holding_cell_htlcs ( logger)
3151
3151
} else { Ok ( ( None , Vec :: new ( ) ) ) }
@@ -3273,7 +3273,7 @@ impl<Signer: Sign> Channel<Signer> {
3273
3273
pub fn revoke_and_ack < L : Deref > ( & mut self , msg : & msgs:: RevokeAndACK , logger : & L ) -> Result < RAAUpdates , ChannelError >
3274
3274
where L :: Target : Logger ,
3275
3275
{
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 ) {
3277
3277
return Err ( ChannelError :: Close ( "Got revoke/ACK message when channel was not in an operational state" . to_owned ( ) ) ) ;
3278
3278
}
3279
3279
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
@@ -3717,7 +3717,7 @@ impl<Signer: Sign> Channel<Signer> {
3717
3717
} else { None } ;
3718
3718
// That said, if the funding transaction is already confirmed (ie we're active with a
3719
3719
// 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 ) {
3721
3721
funding_broadcastable = None ;
3722
3722
}
3723
3723
@@ -4798,8 +4798,8 @@ impl<Signer: Sign> Channel<Signer> {
4798
4798
/// Returns true if this channel is fully established and not known to be closing.
4799
4799
/// Allowed in any state (including after shutdown)
4800
4800
pub fn is_usable ( & self ) -> bool {
4801
- let mask = ChannelState :: ChannelFunded as u32 | BOTH_SIDES_SHUTDOWN_MASK ;
4802
- ( self . channel_state & mask) == ( ChannelState :: ChannelFunded as u32 ) && !self . monitor_pending_channel_ready
4801
+ let mask = ChannelState :: ChannelReady as u32 | BOTH_SIDES_SHUTDOWN_MASK ;
4802
+ ( self . channel_state & mask) == ( ChannelState :: ChannelReady as u32 ) && !self . monitor_pending_channel_ready
4803
4803
}
4804
4804
4805
4805
/// Returns true if this channel is currently available for use. This is a superset of
@@ -4858,7 +4858,7 @@ impl<Signer: Sign> Channel<Signer> {
4858
4858
4859
4859
/// Returns true if our channel_ready has been sent
4860
4860
pub fn is_our_channel_ready ( & self ) -> bool {
4861
- ( self . channel_state & ChannelState :: OurChannelReady as u32 ) != 0 || self . channel_state >= ChannelState :: ChannelFunded as u32
4861
+ ( self . channel_state & ChannelState :: OurChannelReady as u32 ) != 0 || self . channel_state >= ChannelState :: ChannelReady as u32
4862
4862
}
4863
4863
4864
4864
/// Returns true if our peer has either initiated or agreed to shut down the channel.
@@ -4912,14 +4912,14 @@ impl<Signer: Sign> Channel<Signer> {
4912
4912
self . channel_state |= ChannelState :: OurChannelReady as u32 ;
4913
4913
true
4914
4914
} else if non_shutdown_state == ( ChannelState :: FundingSent as u32 | ChannelState :: TheirChannelReady as u32 ) {
4915
- self . channel_state = ChannelState :: ChannelFunded as u32 | ( self . channel_state & MULTI_STATE_FLAGS ) ;
4915
+ self . channel_state = ChannelState :: ChannelReady as u32 | ( self . channel_state & MULTI_STATE_FLAGS ) ;
4916
4916
self . update_time_counter += 1 ;
4917
4917
true
4918
4918
} else if non_shutdown_state == ( ChannelState :: FundingSent as u32 | ChannelState :: OurChannelReady as u32 ) {
4919
4919
// We got a reorg but not enough to trigger a force close, just ignore.
4920
4920
false
4921
4921
} else {
4922
- if self . funding_tx_confirmation_height != 0 && self . channel_state < ChannelState :: ChannelFunded as u32 {
4922
+ if self . funding_tx_confirmation_height != 0 && self . channel_state < ChannelState :: ChannelReady as u32 {
4923
4923
// We should never see a funding transaction on-chain until we've received
4924
4924
// funding_signed (if we're an outbound channel), or seen funding_generated (if we're
4925
4925
// an inbound channel - before that we have no known funding TXID). The fuzzer,
@@ -5074,7 +5074,7 @@ impl<Signer: Sign> Channel<Signer> {
5074
5074
}
5075
5075
5076
5076
let non_shutdown_state = self . channel_state & ( !MULTI_STATE_FLAGS ) ;
5077
- if non_shutdown_state >= ChannelState :: ChannelFunded as u32 ||
5077
+ if non_shutdown_state >= ChannelState :: ChannelReady as u32 ||
5078
5078
( non_shutdown_state & ChannelState :: OurChannelReady as u32 ) == ChannelState :: OurChannelReady as u32 {
5079
5079
let mut funding_tx_confirmations = height as i64 - self . funding_tx_confirmation_height as i64 + 1 ;
5080
5080
if self . funding_tx_confirmation_height == 0 {
@@ -5102,7 +5102,7 @@ impl<Signer: Sign> Channel<Signer> {
5102
5102
height >= self . channel_creation_height + FUNDING_CONF_DEADLINE_BLOCKS {
5103
5103
log_info ! ( logger, "Closing channel {} due to funding timeout" , log_bytes!( self . channel_id) ) ;
5104
5104
// If funding_tx_confirmed_in is unset, the channel must not be active
5105
- assert ! ( non_shutdown_state <= ChannelState :: ChannelFunded as u32 ) ;
5105
+ assert ! ( non_shutdown_state <= ChannelState :: ChannelReady as u32 ) ;
5106
5106
assert_eq ! ( non_shutdown_state & ChannelState :: OurChannelReady as u32 , 0 ) ;
5107
5107
return Err ( ClosureReason :: FundingTimedOut ) ;
5108
5108
}
@@ -5528,7 +5528,7 @@ impl<Signer: Sign> Channel<Signer> {
5528
5528
///
5529
5529
/// If an Err is returned, it's a ChannelError::Ignore!
5530
5530
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 {
5531
- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 | BOTH_SIDES_SHUTDOWN_MASK ) ) != ( ChannelState :: ChannelFunded as u32 ) {
5531
+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 | BOTH_SIDES_SHUTDOWN_MASK ) ) != ( ChannelState :: ChannelReady as u32 ) {
5532
5532
return Err ( ChannelError :: Ignore ( "Cannot send HTLC until channel is fully established and we haven't started shutting down" . to_owned ( ) ) ) ;
5533
5533
}
5534
5534
let channel_total_msat = self . channel_value_satoshis * 1000 ;
@@ -5661,7 +5661,7 @@ impl<Signer: Sign> Channel<Signer> {
5661
5661
/// last call to this Channel) send_htlc returned Ok(Some(_)) and there is an Err.
5662
5662
/// May panic if called except immediately after a successful, Ok(Some(_))-returning send_htlc.
5663
5663
pub fn send_commitment < L : Deref > ( & mut self , logger : & L ) -> Result < ( msgs:: CommitmentSigned , ChannelMonitorUpdate ) , ChannelError > where L :: Target : Logger {
5664
- if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
5664
+ if ( self . channel_state & ( ChannelState :: ChannelReady as u32 ) ) != ( ChannelState :: ChannelReady as u32 ) {
5665
5665
panic ! ( "Cannot create commitment tx until channel is fully established" ) ;
5666
5666
}
5667
5667
if ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == ( ChannelState :: AwaitingRemoteRevoke as u32 ) {
@@ -5950,7 +5950,7 @@ impl<Signer: Sign> Channel<Signer> {
5950
5950
// funding transaction, don't return a funding txo (which prevents providing the
5951
5951
// monitor update to the user, even if we return one).
5952
5952
// See test_duplicate_chan_id and test_pre_lockin_no_chan_closed_update for more.
5953
- if self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: ChannelFunded as u32 | ChannelState :: ShutdownComplete as u32 ) != 0 {
5953
+ if self . channel_state & ( ChannelState :: FundingSent as u32 | ChannelState :: ChannelReady as u32 | ChannelState :: ShutdownComplete as u32 ) != 0 {
5954
5954
self . latest_monitor_update_id += 1 ;
5955
5955
Some ( ( funding_txo, ChannelMonitorUpdate {
5956
5956
update_id : self . latest_monitor_update_id ,
0 commit comments