Skip to content

Commit 8fdad85

Browse files
Update monitor event id on duplicate inbound claim
The first time we claim an HTLC in a channel, we may not have an associated monitor event id. Once we later process the monitor event for the claim, we need to update the channel's internal htlc state to include the monitor event id, so the event can be properly acked afer the htlc is removed.
1 parent 0ece3d6 commit 8fdad85

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7535,7 +7535,8 @@ where
75357535

75367536
let mut pending_idx = core::usize::MAX;
75377537
let mut htlc_value_msat = 0;
7538-
for (idx, htlc) in self.context.pending_inbound_htlcs.iter().enumerate() {
7538+
let channel_id = self.context.channel_id();
7539+
for (idx, htlc) in self.context.pending_inbound_htlcs.iter_mut().enumerate() {
75397540
if htlc.htlc_id == htlc_id_arg {
75407541
let expected_hash =
75417542
PaymentHash(Sha256::hash(&payment_preimage_arg.0[..]).to_byte_array());
@@ -7549,10 +7550,17 @@ where
75497550
);
75507551
match htlc.state {
75517552
InboundHTLCState::Committed { .. } => {},
7552-
InboundHTLCState::LocalRemoved { ref reason, .. } => {
7553+
InboundHTLCState::LocalRemoved {
7554+
ref reason,
7555+
monitor_event_id: ref mut id,
7556+
..
7557+
} => {
7558+
if monitor_event_id.is_some() {
7559+
*id = monitor_event_id;
7560+
}
75537561
if let &InboundHTLCRemovalReason::Fulfill { .. } = reason {
75547562
} else {
7555-
log_warn!(logger, "Have preimage and want to fulfill HTLC with payment hash {} we already failed against channel {}", &htlc.payment_hash, &self.context.channel_id());
7563+
log_warn!(logger, "Have preimage and want to fulfill HTLC with payment hash {} we already failed against channel {channel_id}", &htlc.payment_hash);
75567564
debug_assert!(
75577565
false,
75587566
"Tried to fulfill an HTLC that was already failed"
@@ -7593,17 +7601,24 @@ where
75937601
// `claim_htlc_while_disconnected_dropping_mon_update` and must match exactly -
75947602
// `claim_htlc_while_disconnected_dropping_mon_update` would not work correctly if we
75957603
// do not not get into this branch.
7596-
for pending_update in self.context.holding_cell_htlc_updates.iter() {
7604+
for pending_update in self.context.holding_cell_htlc_updates.iter_mut() {
75977605
match pending_update {
7598-
&HTLCUpdateAwaitingACK::ClaimHTLC { htlc_id, .. } => {
7606+
&mut HTLCUpdateAwaitingACK::ClaimHTLC {
7607+
htlc_id,
7608+
monitor_event_id: ref mut id,
7609+
..
7610+
} => {
75997611
if htlc_id_arg == htlc_id {
76007612
// Make sure we don't leave latest_monitor_update_id incremented here:
76017613
self.context.latest_monitor_update_id -= 1;
7614+
if monitor_event_id.is_some() {
7615+
*id = monitor_event_id;
7616+
}
76027617
return UpdateFulfillFetch::DuplicateClaim {};
76037618
}
76047619
},
7605-
&HTLCUpdateAwaitingACK::FailHTLC { htlc_id, .. }
7606-
| &HTLCUpdateAwaitingACK::FailMalformedHTLC { htlc_id, .. } => {
7620+
&mut HTLCUpdateAwaitingACK::FailHTLC { htlc_id, .. }
7621+
| &mut HTLCUpdateAwaitingACK::FailMalformedHTLC { htlc_id, .. } => {
76077622
if htlc_id_arg == htlc_id {
76087623
log_warn!(logger, "Have preimage and want to fulfill HTLC with pending failure against channel {}", &self.context.channel_id());
76097624
// TODO: We may actually be able to switch to a fulfill here, though its

0 commit comments

Comments
 (0)