Skip to content

Commit 5e7930f

Browse files
authored
Merge pull request #3803 from joostjager/claim-without-msg
Simplify `UpdateFulfillFetch::NewClaim`
2 parents c46d0df + d0288cd commit 5e7930f

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

lightning/src/ln/channel.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ enum UpdateFulfillFetch {
10481048
NewClaim {
10491049
monitor_update: ChannelMonitorUpdate,
10501050
htlc_value_msat: u64,
1051-
msg: Option<msgs::UpdateFulfillHTLC>,
1051+
update_blocked: bool,
10521052
},
10531053
DuplicateClaim {},
10541054
}
@@ -5388,8 +5388,8 @@ impl<SP: Deref> FundedChannel<SP> where
53885388
let mon_update_id = self.context.latest_monitor_update_id; // Forget the ChannelMonitor update
53895389
let fulfill_resp = self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, logger);
53905390
self.context.latest_monitor_update_id = mon_update_id;
5391-
if let UpdateFulfillFetch::NewClaim { msg, .. } = fulfill_resp {
5392-
assert!(msg.is_none()); // The HTLC must have ended up in the holding cell.
5391+
if let UpdateFulfillFetch::NewClaim { update_blocked, .. } = fulfill_resp {
5392+
assert!(update_blocked); // The HTLC must have ended up in the holding cell.
53935393
}
53945394
}
53955395

@@ -5476,7 +5476,7 @@ impl<SP: Deref> FundedChannel<SP> where
54765476
// TODO: We may actually be able to switch to a fulfill here, though its
54775477
// rare enough it may not be worth the complexity burden.
54785478
debug_assert!(false, "Tried to fulfill an HTLC that was already failed");
5479-
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: None };
5479+
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, update_blocked: true };
54805480
}
54815481
},
54825482
_ => {}
@@ -5486,15 +5486,15 @@ impl<SP: Deref> FundedChannel<SP> where
54865486
self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
54875487
payment_preimage: payment_preimage_arg, htlc_id: htlc_id_arg,
54885488
});
5489-
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: None };
5489+
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, update_blocked: true };
54905490
}
54915491

54925492
{
54935493
let htlc = &mut self.context.pending_inbound_htlcs[pending_idx];
54945494
if let InboundHTLCState::Committed = htlc.state {
54955495
} else {
54965496
debug_assert!(false, "Have an inbound HTLC we tried to claim before it was fully committed to");
5497-
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: None };
5497+
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, update_blocked: true };
54985498
}
54995499
log_trace!(logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!", &htlc.payment_hash, &self.context.channel_id);
55005500
htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(payment_preimage_arg.clone()));
@@ -5503,11 +5503,7 @@ impl<SP: Deref> FundedChannel<SP> where
55035503
UpdateFulfillFetch::NewClaim {
55045504
monitor_update,
55055505
htlc_value_msat,
5506-
msg: Some(msgs::UpdateFulfillHTLC {
5507-
channel_id: self.context.channel_id(),
5508-
htlc_id: htlc_id_arg,
5509-
payment_preimage: payment_preimage_arg,
5510-
}),
5506+
update_blocked: false,
55115507
}
55125508
}
55135509

@@ -5517,13 +5513,13 @@ impl<SP: Deref> FundedChannel<SP> where
55175513
) -> UpdateFulfillCommitFetch where L::Target: Logger {
55185514
let release_cs_monitor = self.context.blocked_monitor_updates.is_empty();
55195515
match self.get_update_fulfill_htlc(htlc_id, payment_preimage, payment_info, logger) {
5520-
UpdateFulfillFetch::NewClaim { mut monitor_update, htlc_value_msat, msg } => {
5516+
UpdateFulfillFetch::NewClaim { mut monitor_update, htlc_value_msat, update_blocked } => {
55215517
// Even if we aren't supposed to let new monitor updates with commitment state
55225518
// updates run, we still need to push the preimage ChannelMonitorUpdateStep no
55235519
// matter what. Sadly, to push a new monitor update which flies before others
55245520
// already queued, we have to insert it into the pending queue and update the
55255521
// update_ids of all the following monitors.
5526-
if release_cs_monitor && msg.is_some() {
5522+
if release_cs_monitor && !update_blocked {
55275523
let mut additional_update = self.build_commitment_no_status_check(logger);
55285524
// build_commitment_no_status_check may bump latest_monitor_id but we want them
55295525
// to be strictly increasing by one, so decrement it here.
@@ -5536,7 +5532,7 @@ impl<SP: Deref> FundedChannel<SP> where
55365532
for held_update in self.context.blocked_monitor_updates.iter_mut() {
55375533
held_update.update.update_id += 1;
55385534
}
5539-
if msg.is_some() {
5535+
if !update_blocked {
55405536
debug_assert!(false, "If there is a pending blocked monitor we should have MonitorUpdateInProgress set");
55415537
let update = self.build_commitment_no_status_check(logger);
55425538
self.context.blocked_monitor_updates.push(PendingChannelMonitorUpdate {
@@ -5545,7 +5541,7 @@ impl<SP: Deref> FundedChannel<SP> where
55455541
}
55465542
}
55475543

5548-
self.monitor_updating_paused(false, msg.is_some(), false, Vec::new(), Vec::new(), Vec::new());
5544+
self.monitor_updating_paused(false, !update_blocked, false, Vec::new(), Vec::new(), Vec::new());
55495545
UpdateFulfillCommitFetch::NewClaim { monitor_update, htlc_value_msat, }
55505546
},
55515547
UpdateFulfillFetch::DuplicateClaim {} => UpdateFulfillCommitFetch::DuplicateClaim {},

0 commit comments

Comments
 (0)