Skip to content

Commit f70314b

Browse files
author
Antoine Riard
committed
Replace HTLCUpdateAwaitingACK::FailHTLC by claim if we got preimage
1 parent 461501e commit f70314b

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/ln/channel.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,28 +1193,32 @@ impl Channel {
11931193
self.channel_monitor.provide_payment_preimage(&payment_hash_calc, &payment_preimage_arg);
11941194

11951195
if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32 | ChannelState::PeerDisconnected as u32 | ChannelState::MonitorUpdateFailed as u32)) != 0 {
1196-
for pending_update in self.holding_cell_htlc_updates.iter() {
1196+
let mut need_update = true;
1197+
self.holding_cell_htlc_updates.retain(|pending_update| {
11971198
match pending_update {
11981199
&HTLCUpdateAwaitingACK::ClaimHTLC { htlc_id, .. } => {
11991200
if htlc_id_arg == htlc_id {
1200-
return Ok((None, None));
1201+
need_update = false;
12011202
}
1203+
true
12021204
},
12031205
&HTLCUpdateAwaitingACK::FailHTLC { htlc_id, .. } => {
12041206
if htlc_id_arg == htlc_id {
1205-
log_warn!(self, "Have preimage and want to fulfill HTLC with pending failure against channel {}", log_bytes!(self.channel_id()));
1206-
// TODO: We may actually be able to switch to a fulfill here, though its
1207-
// rare enough it may not be worth the complexity burden.
1208-
return Ok((None, Some(self.channel_monitor.clone())));
1207+
return false
12091208
}
1209+
true
12101210
},
1211-
_ => {}
1211+
_ => { true }
12121212
}
1213-
}
1214-
self.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
1215-
payment_preimage: payment_preimage_arg, htlc_id: htlc_id_arg,
12161213
});
1217-
return Ok((None, Some(self.channel_monitor.clone())));
1214+
if need_update {
1215+
self.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
1216+
payment_preimage: payment_preimage_arg, htlc_id: htlc_id_arg,
1217+
});
1218+
return Ok((None, Some(self.channel_monitor.clone())));
1219+
} else {
1220+
return Ok((None, None));
1221+
}
12181222
}
12191223

12201224
{

0 commit comments

Comments
 (0)