@@ -296,6 +296,12 @@ pub(super) struct Channel {
296
296
cur_local_commitment_transaction_number : u64 ,
297
297
cur_remote_commitment_transaction_number : u64 ,
298
298
value_to_self_msat : u64 , // Excluding all pending_htlcs, excluding fees
299
+ /// Upon receipt of a channel_reestablish we have to figure out whether to send a
300
+ /// revoke_and_ack first or a commitment update first. Generally, we prefer to send
301
+ /// revoke_and_ack first, but if we had a pending commitment update of our own waiting on a
302
+ /// remote revoke when we received the latest commitment update from the remote we have to make
303
+ /// sure that commitment update gets resent first.
304
+ received_commitment_while_awaiting_raa : bool ,
299
305
pending_inbound_htlcs : Vec < InboundHTLCOutput > ,
300
306
pending_outbound_htlcs : Vec < OutboundHTLCOutput > ,
301
307
holding_cell_htlc_updates : Vec < HTLCUpdateAwaitingACK > ,
@@ -492,6 +498,8 @@ impl Channel {
492
498
cur_local_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
493
499
cur_remote_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
494
500
value_to_self_msat : channel_value_satoshis * 1000 - push_msat,
501
+ received_commitment_while_awaiting_raa : false ,
502
+
495
503
pending_inbound_htlcs : Vec :: new ( ) ,
496
504
pending_outbound_htlcs : Vec :: new ( ) ,
497
505
holding_cell_htlc_updates : Vec :: new ( ) ,
@@ -647,6 +655,8 @@ impl Channel {
647
655
cur_local_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
648
656
cur_remote_commitment_transaction_number : INITIAL_COMMITMENT_NUMBER ,
649
657
value_to_self_msat : msg. push_msat ,
658
+ received_commitment_while_awaiting_raa : false ,
659
+
650
660
pending_inbound_htlcs : Vec :: new ( ) ,
651
661
pending_outbound_htlcs : Vec :: new ( ) ,
652
662
holding_cell_htlc_updates : Vec :: new ( ) ,
@@ -1696,6 +1706,7 @@ impl Channel {
1696
1706
1697
1707
self . cur_local_commitment_transaction_number -= 1 ;
1698
1708
self . last_local_commitment_txn = new_local_commitment_txn;
1709
+ self . received_commitment_while_awaiting_raa = ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) != 0 ;
1699
1710
1700
1711
let ( our_commitment_signed, monitor_update) = if need_our_commitment && ( self . channel_state & ( ChannelState :: AwaitingRemoteRevoke as u32 ) ) == 0 {
1701
1712
// If we're AwaitingRemoteRevoke we can't send a new commitment here, but that's ok -
@@ -1831,6 +1842,7 @@ impl Channel {
1831
1842
self . their_prev_commitment_point = self . their_cur_commitment_point ;
1832
1843
self . their_cur_commitment_point = Some ( msg. next_per_commitment_point ) ;
1833
1844
self . cur_remote_commitment_transaction_number -= 1 ;
1845
+ self . received_commitment_while_awaiting_raa = false ;
1834
1846
1835
1847
let mut to_forward_infos = Vec :: new ( ) ;
1836
1848
let mut revoked_htlcs = Vec :: new ( ) ;
@@ -2120,7 +2132,11 @@ impl Channel {
2120
2132
} )
2121
2133
} else { None } ;
2122
2134
2123
- let order = RAACommitmentOrder :: RevokeAndACKFirst ;
2135
+ let order = if self . received_commitment_while_awaiting_raa {
2136
+ RAACommitmentOrder :: CommitmentFirst
2137
+ } else {
2138
+ RAACommitmentOrder :: RevokeAndACKFirst
2139
+ } ;
2124
2140
2125
2141
if msg. next_local_commitment_number == our_next_remote_commitment_number {
2126
2142
if required_revoke. is_some ( ) {
0 commit comments