Skip to content

Commit 4f77c81

Browse files
committed
Fix crash introduced in lightningdevkit#124
I'm rapidly starting to regret holding failed HTLCs in Channel, given we allow them to violate the no-duplicate-hashes precondition. Found by fuzzer
1 parent a66e597 commit 4f77c81

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/ln/channel.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,10 +1018,13 @@ impl Channel {
10181018
for (idx, htlc) in self.pending_htlcs.iter().enumerate() {
10191019
if !htlc.outbound && htlc.payment_hash == payment_hash_calc &&
10201020
htlc.state != HTLCState::LocalRemoved && htlc.state != HTLCState::LocalRemovedAwaitingCommitment {
1021-
if pending_idx != std::usize::MAX {
1022-
panic!("Duplicate HTLC payment_hash, ChannelManager should have prevented this!");
1021+
if let Some(PendingHTLCStatus::Fail(_)) = htlc.pending_forward_state {
1022+
} else {
1023+
if pending_idx != std::usize::MAX {
1024+
panic!("Duplicate HTLC payment_hash, ChannelManager should have prevented this!");
1025+
}
1026+
pending_idx = idx;
10231027
}
1024-
pending_idx = idx;
10251028
}
10261029
}
10271030
if pending_idx == std::usize::MAX {

0 commit comments

Comments
 (0)