@@ -138,18 +138,16 @@ enum HTLCState {
138
138
AwaitingRemovedRemoteRevoke ,
139
139
/// Removed by us and a new commitment_signed was sent (if we were AwaitingRemoteRevoke when we
140
140
/// created it we would have put it in the holding cell instead). When they next revoke_and_ack
141
- /// we'll promote to LocalRemovedAwaitingCommitment if we fulfilled, otherwise we'll drop at
142
- /// that point.
141
+ /// we'll drop it.
143
142
/// Note that we have to keep an eye on the HTLC until we've received a broadcastable
144
143
/// commitment transaction without it as otherwise we'll have to force-close the channel to
145
144
/// claim it before the timeout (obviously doesn't apply to revoked HTLCs that we can't claim
146
- /// anyway).
145
+ /// anyway). That said, ChannelMonitor does this for us (see
146
+ /// ChannelMonitor::would_broadcast_at_height) so we actually remove the HTLC from our own
147
+ /// local state before then, once we're sure that the next commitment_signed and
148
+ /// ChannelMonitor::provide_latest_local_commitment_tx_info will not include this HTLC.
147
149
/// Implies HTLCOutput::outbound: false
148
150
LocalRemoved ,
149
- /// Removed by us, sent a new commitment_signed and got a revoke_and_ack. Just waiting on an
150
- /// updated local commitment transaction. Implies local_removed_fulfilled.
151
- /// Implies HTLCOutput::outbound: false
152
- LocalRemovedAwaitingCommitment ,
153
151
}
154
152
155
153
struct HTLCOutput { //TODO: Refactor into Outbound/InboundHTLCOutput (will save memory and fewer panics)
@@ -706,7 +704,6 @@ impl Channel {
706
704
HTLCState :: AwaitingRemoteRevokeToRemove => generated_by_local,
707
705
HTLCState :: AwaitingRemovedRemoteRevoke => false ,
708
706
HTLCState :: LocalRemoved => !generated_by_local,
709
- HTLCState :: LocalRemovedAwaitingCommitment => false ,
710
707
} ;
711
708
712
709
if include {
@@ -749,10 +746,6 @@ impl Channel {
749
746
value_to_self_msat_offset += htlc. amount_msat as i64 ;
750
747
}
751
748
} ,
752
- HTLCState :: LocalRemovedAwaitingCommitment => {
753
- assert ! ( htlc. local_removed_fulfilled) ;
754
- value_to_self_msat_offset += htlc. amount_msat as i64 ;
755
- } ,
756
749
_ => { } ,
757
750
}
758
751
}
@@ -1018,7 +1011,7 @@ impl Channel {
1018
1011
let mut pending_idx = std:: usize:: MAX ;
1019
1012
for ( idx, htlc) in self . pending_htlcs . iter ( ) . enumerate ( ) {
1020
1013
if !htlc. outbound && htlc. payment_hash == payment_hash_calc &&
1021
- htlc. state != HTLCState :: LocalRemoved && htlc . state != HTLCState :: LocalRemovedAwaitingCommitment {
1014
+ htlc. state != HTLCState :: LocalRemoved {
1022
1015
if let Some ( PendingHTLCStatus :: Fail ( _) ) = htlc. pending_forward_state {
1023
1016
} else {
1024
1017
if pending_idx != std:: usize:: MAX {
@@ -1143,7 +1136,7 @@ impl Channel {
1143
1136
// we'll fail this one as soon as remote commits to it.
1144
1137
continue ;
1145
1138
}
1146
- } else if htlc. state == HTLCState :: LocalRemoved || htlc . state == HTLCState :: LocalRemovedAwaitingCommitment {
1139
+ } else if htlc. state == HTLCState :: LocalRemoved {
1147
1140
return Err ( HandleError { err : "Unable to find a pending HTLC which matched the given payment preimage" , action : None } ) ;
1148
1141
} else {
1149
1142
panic ! ( "Have an inbound HTLC when not awaiting remote revoke that had a garbage state" ) ;
@@ -1379,7 +1372,6 @@ impl Channel {
1379
1372
HTLCState :: AwaitingRemoteRevokeToRemove => { if for_remote_update_check { continue ; } } ,
1380
1373
HTLCState :: AwaitingRemovedRemoteRevoke => { if for_remote_update_check { continue ; } } ,
1381
1374
HTLCState :: LocalRemoved => { } ,
1382
- HTLCState :: LocalRemovedAwaitingCommitment => { if for_remote_update_check { continue ; } } ,
1383
1375
}
1384
1376
if !htlc. outbound {
1385
1377
inbound_htlc_count += 1 ;
@@ -1556,16 +1548,6 @@ impl Channel {
1556
1548
need_our_commitment = true ;
1557
1549
}
1558
1550
}
1559
- // Finally delete all the LocalRemovedAwaitingCommitment HTLCs
1560
- // We really shouldnt have two passes here, but retain gives a non-mutable ref (Rust bug)
1561
- let mut claimed_value_msat = 0 ;
1562
- self . pending_htlcs . retain ( |htlc| {
1563
- if htlc. state == HTLCState :: LocalRemovedAwaitingCommitment {
1564
- claimed_value_msat += htlc. amount_msat ;
1565
- false
1566
- } else { true }
1567
- } ) ;
1568
- self . value_to_self_msat += claimed_value_msat;
1569
1551
1570
1552
self . cur_local_commitment_transaction_number -= 1 ;
1571
1553
self . last_local_commitment_txn = new_local_commitment_txn;
@@ -1689,7 +1671,10 @@ impl Channel {
1689
1671
// We really shouldnt have two passes here, but retain gives a non-mutable ref (Rust bug)
1690
1672
self . pending_htlcs . retain ( |htlc| {
1691
1673
if htlc. state == HTLCState :: LocalRemoved {
1692
- if htlc. local_removed_fulfilled { true } else { false }
1674
+ if htlc. local_removed_fulfilled {
1675
+ value_to_self_msat_diff += htlc. amount_msat as i64 ;
1676
+ }
1677
+ false
1693
1678
} else if htlc. state == HTLCState :: AwaitingRemovedRemoteRevoke {
1694
1679
if let Some ( reason) = htlc. fail_reason . clone ( ) { // We really want take() here, but, again, non-mut ref :(
1695
1680
revoked_htlcs. push ( ( htlc. payment_hash , reason) ) ;
@@ -1724,9 +1709,6 @@ impl Channel {
1724
1709
} else if htlc. state == HTLCState :: AwaitingRemoteRevokeToRemove {
1725
1710
htlc. state = HTLCState :: AwaitingRemovedRemoteRevoke ;
1726
1711
require_commitment = true ;
1727
- } else if htlc. state == HTLCState :: LocalRemoved {
1728
- assert ! ( htlc. local_removed_fulfilled) ;
1729
- htlc. state = HTLCState :: LocalRemovedAwaitingCommitment ;
1730
1712
}
1731
1713
}
1732
1714
self . value_to_self_msat = ( self . value_to_self_msat as i64 + value_to_self_msat_diff) as u64 ;
0 commit comments