Skip to content

Commit d1568ca

Browse files
committed
Drop HTLCState::LocalRemovedAwaitingCommitment
This was redundant and was included because the HTLC still needed to be monitored, but that happens in ChannelMonitor, so there is no need for it in Channel itself.
1 parent 8e4c062 commit d1568ca

File tree

1 file changed

+11
-29
lines changed

1 file changed

+11
-29
lines changed

src/ln/channel.rs

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,16 @@ enum HTLCState {
138138
AwaitingRemovedRemoteRevoke,
139139
/// Removed by us and a new commitment_signed was sent (if we were AwaitingRemoteRevoke when we
140140
/// 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.
143142
/// Note that we have to keep an eye on the HTLC until we've received a broadcastable
144143
/// commitment transaction without it as otherwise we'll have to force-close the channel to
145144
/// 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.
147149
/// Implies HTLCOutput::outbound: false
148150
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,
153151
}
154152

155153
struct HTLCOutput { //TODO: Refactor into Outbound/InboundHTLCOutput (will save memory and fewer panics)
@@ -706,7 +704,6 @@ impl Channel {
706704
HTLCState::AwaitingRemoteRevokeToRemove => generated_by_local,
707705
HTLCState::AwaitingRemovedRemoteRevoke => false,
708706
HTLCState::LocalRemoved => !generated_by_local,
709-
HTLCState::LocalRemovedAwaitingCommitment => false,
710707
};
711708

712709
if include {
@@ -749,10 +746,6 @@ impl Channel {
749746
value_to_self_msat_offset += htlc.amount_msat as i64;
750747
}
751748
},
752-
HTLCState::LocalRemovedAwaitingCommitment => {
753-
assert!(htlc.local_removed_fulfilled);
754-
value_to_self_msat_offset += htlc.amount_msat as i64;
755-
},
756749
_ => {},
757750
}
758751
}
@@ -1018,7 +1011,7 @@ impl Channel {
10181011
let mut pending_idx = std::usize::MAX;
10191012
for (idx, htlc) in self.pending_htlcs.iter().enumerate() {
10201013
if !htlc.outbound && htlc.payment_hash == payment_hash_calc &&
1021-
htlc.state != HTLCState::LocalRemoved && htlc.state != HTLCState::LocalRemovedAwaitingCommitment {
1014+
htlc.state != HTLCState::LocalRemoved {
10221015
if let Some(PendingHTLCStatus::Fail(_)) = htlc.pending_forward_state {
10231016
} else {
10241017
if pending_idx != std::usize::MAX {
@@ -1143,7 +1136,7 @@ impl Channel {
11431136
// we'll fail this one as soon as remote commits to it.
11441137
continue;
11451138
}
1146-
} else if htlc.state == HTLCState::LocalRemoved || htlc.state == HTLCState::LocalRemovedAwaitingCommitment {
1139+
} else if htlc.state == HTLCState::LocalRemoved {
11471140
return Err(HandleError{err: "Unable to find a pending HTLC which matched the given payment preimage", action: None});
11481141
} else {
11491142
panic!("Have an inbound HTLC when not awaiting remote revoke that had a garbage state");
@@ -1379,7 +1372,6 @@ impl Channel {
13791372
HTLCState::AwaitingRemoteRevokeToRemove => { if for_remote_update_check { continue; } },
13801373
HTLCState::AwaitingRemovedRemoteRevoke => { if for_remote_update_check { continue; } },
13811374
HTLCState::LocalRemoved => {},
1382-
HTLCState::LocalRemovedAwaitingCommitment => { if for_remote_update_check { continue; } },
13831375
}
13841376
if !htlc.outbound {
13851377
inbound_htlc_count += 1;
@@ -1556,16 +1548,6 @@ impl Channel {
15561548
need_our_commitment = true;
15571549
}
15581550
}
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;
15691551

15701552
self.cur_local_commitment_transaction_number -= 1;
15711553
self.last_local_commitment_txn = new_local_commitment_txn;
@@ -1689,7 +1671,10 @@ impl Channel {
16891671
// We really shouldnt have two passes here, but retain gives a non-mutable ref (Rust bug)
16901672
self.pending_htlcs.retain(|htlc| {
16911673
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
16931678
} else if htlc.state == HTLCState::AwaitingRemovedRemoteRevoke {
16941679
if let Some(reason) = htlc.fail_reason.clone() { // We really want take() here, but, again, non-mut ref :(
16951680
revoked_htlcs.push((htlc.payment_hash, reason));
@@ -1724,9 +1709,6 @@ impl Channel {
17241709
} else if htlc.state == HTLCState::AwaitingRemoteRevokeToRemove {
17251710
htlc.state = HTLCState::AwaitingRemovedRemoteRevoke;
17261711
require_commitment = true;
1727-
} else if htlc.state == HTLCState::LocalRemoved {
1728-
assert!(htlc.local_removed_fulfilled);
1729-
htlc.state = HTLCState::LocalRemovedAwaitingCommitment;
17301712
}
17311713
}
17321714
self.value_to_self_msat = (self.value_to_self_msat as i64 + value_to_self_msat_diff) as u64;

0 commit comments

Comments
 (0)