@@ -1709,7 +1709,8 @@ impl Channel {
1709
1709
let ( msg, monitor) = self . send_commitment_no_status_check ( ) ?;
1710
1710
( Some ( msg) , monitor, None )
1711
1711
} else if !need_our_commitment && self . channel_state & ( BOTH_SIDES_SHUTDOWN_MASK | ChannelState :: AwaitingRemoteRevoke as u32 ) == BOTH_SIDES_SHUTDOWN_MASK &&
1712
- self . channel_outbound && self . pending_inbound_htlcs . is_empty ( ) && self . pending_outbound_htlcs . is_empty ( ) && self . last_sent_closing_fee . is_none ( ) {
1712
+ self . channel_outbound && self . pending_inbound_htlcs . is_empty ( ) && self . pending_outbound_htlcs . is_empty ( ) && self . last_sent_closing_fee . is_none ( ) &&
1713
+ self . cur_remote_commitment_transaction_number == self . cur_local_commitment_transaction_number {
1713
1714
( None , self . channel_monitor . clone ( ) , Some ( self . propose_first_closing_signed ( fee_estimator) ) )
1714
1715
} else { ( None , self . channel_monitor . clone ( ) , None ) } ;
1715
1716
@@ -1976,7 +1977,9 @@ impl Channel {
1976
1977
commitment_signed
1977
1978
} ) , to_forward_infos, revoked_htlcs, None , monitor_update) )
1978
1979
} else {
1979
- if self . channel_state & BOTH_SIDES_SHUTDOWN_MASK == BOTH_SIDES_SHUTDOWN_MASK && self . channel_outbound && self . pending_inbound_htlcs . is_empty ( ) && self . pending_outbound_htlcs . is_empty ( ) && self . last_sent_closing_fee . is_none ( ) {
1980
+ if self . channel_state & BOTH_SIDES_SHUTDOWN_MASK == BOTH_SIDES_SHUTDOWN_MASK && self . channel_outbound &&
1981
+ self . pending_inbound_htlcs . is_empty ( ) && self . pending_outbound_htlcs . is_empty ( ) && self . last_sent_closing_fee . is_none ( ) &&
1982
+ self . cur_remote_commitment_transaction_number == self . cur_local_commitment_transaction_number {
1980
1983
Ok ( ( None , to_forward_infos, revoked_htlcs, Some ( self . propose_first_closing_signed ( fee_estimator) ) , self . channel_monitor . clone ( ) ) )
1981
1984
} else {
1982
1985
Ok ( ( None , to_forward_infos, revoked_htlcs, None , self . channel_monitor . clone ( ) ) )
@@ -2149,6 +2152,9 @@ impl Channel {
2149
2152
if self . channel_outbound {
2150
2153
return Err ( ChannelError :: Close ( "Non-funding remote tried to update channel fee" ) ) ;
2151
2154
}
2155
+ if ( self . channel_state & ( ChannelState :: ChannelFunded as u32 | ChannelState :: RemoteShutdownSent as u32 ) ) != ( ChannelState :: ChannelFunded as u32 ) {
2156
+ return Err ( ChannelError :: Close ( "Got update_fee message when channel was not in an operational state" ) ) ;
2157
+ }
2152
2158
if self . channel_state & ( ChannelState :: PeerDisconnected as u32 ) == ChannelState :: PeerDisconnected as u32 {
2153
2159
return Err ( ChannelError :: Close ( "Peer sent update_fee when we needed a channel_reestablish" ) ) ;
2154
2160
}
@@ -2414,6 +2420,7 @@ impl Channel {
2414
2420
// We can't send our shutdown until we've committed all of our pending HTLCs, but the
2415
2421
// remote side is unlikely to accept any new HTLCs, so we go ahead and "free" any holding
2416
2422
// cell HTLCs and return them to fail the payment.
2423
+ self . holding_cell_update_fee = None ;
2417
2424
let mut dropped_outbound_htlcs = Vec :: with_capacity ( self . holding_cell_htlc_updates . len ( ) ) ;
2418
2425
self . holding_cell_htlc_updates . retain ( |htlc_update| {
2419
2426
match htlc_update {
@@ -2439,7 +2446,9 @@ impl Channel {
2439
2446
2440
2447
self . channel_state |= ChannelState :: LocalShutdownSent as u32 ;
2441
2448
self . channel_update_count += 1 ;
2442
- if self . channel_outbound && self . pending_inbound_htlcs . is_empty ( ) && self . pending_outbound_htlcs . is_empty ( ) {
2449
+ if self . channel_outbound && self . pending_inbound_htlcs . is_empty ( ) && self . pending_outbound_htlcs . is_empty ( ) &&
2450
+ self . cur_remote_commitment_transaction_number == self . cur_local_commitment_transaction_number &&
2451
+ self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) == 0 {
2443
2452
// There are no more HTLCs and we're the funder, this means we start the closing_signed
2444
2453
// dance with an initial fee proposal!
2445
2454
Ok ( ( our_shutdown, Some ( self . propose_first_closing_signed ( fee_estimator) ) , dropped_outbound_htlcs) )
@@ -3224,9 +3233,9 @@ impl Channel {
3224
3233
}
3225
3234
self . channel_update_count += 1 ;
3226
3235
3227
- // We can't send our shutdown until we've committed all of our pending HTLCs, but the
3228
- // remote side is unlikely to accept any new HTLCs, so we go ahead and "free" any holding
3229
- // cell HTLCs and return them to fail the payment.
3236
+ // Go ahead and drop holding cell updates as we'd rather fail payments than wait to send
3237
+ // our shutdown until we've committed all of the pending changes.
3238
+ self . holding_cell_update_fee = None ;
3230
3239
let mut dropped_outbound_htlcs = Vec :: with_capacity ( self . holding_cell_htlc_updates . len ( ) ) ;
3231
3240
self . holding_cell_htlc_updates . retain ( |htlc_update| {
3232
3241
match htlc_update {
0 commit comments