@@ -5595,71 +5595,70 @@ where
55955595				let claiming_chan_funding_outpoint = hop_data.outpoint;
55965596				let res = self.claim_funds_from_hop(hop_data, payment_preimage,
55975597					|htlc_claim_value_msat, definitely_duplicate| {
5598- 						if let Some(forwarded_htlc_value) = forwarded_htlc_value_msat {
5599- 							let fee_earned_msat = if let Some(claimed_htlc_value) = htlc_claim_value_msat {
5600- 								Some(claimed_htlc_value - forwarded_htlc_value)
5601- 							} else { None };
5602- 
5603- 							let chan_to_release =
5604- 								if let Some(node_id) = next_channel_counterparty_node_id {
5605- 									Some((node_id, next_channel_outpoint, completed_blocker))
5606- 								} else {
5607- 									// We can only get `None` here if we are processing a
5608- 									// `ChannelMonitor`-originated event, in which case we
5609- 									// don't care about ensuring we wake the downstream
5610- 									// channel's monitor updating - the channel is already
5611- 									// closed.
5612- 									None
5613- 								};
5614- 
5615- 							if definitely_duplicate && startup_replay {
5616- 								// On startup we may get redundant claims which are related to
5617- 								// monitor updates still in flight. In that case, we shouldn't
5618- 								// immediately free, but instead let that monitor update complete
5619- 								// in the background.
5620- 								#[cfg(debug_assertions)] {
5621- 									let background_events = self.pending_background_events.lock().unwrap();
5622- 									// There should be a `BackgroundEvent` pending...
5623- 									assert!(background_events.iter().any(|ev| {
5624- 										match ev {
5625- 											// to apply a monitor update that blocked channel,
5626- 											BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
5627- 												funding_txo, ..
5628- 											} => *funding_txo == claiming_chan_funding_outpoint,
5629- 											// or the channel we'd unblock is already closed,
5630- 											BackgroundEvent::ClosedMonitorUpdateRegeneratedOnStartup((funding_txo, ..))
5631- 												=> *funding_txo == next_channel_outpoint,
5632- 											// or the monitor update has completed and will unblock
5633- 											// immediately once we get going.
5634- 											BackgroundEvent::MonitorUpdatesComplete {
5635- 												channel_id, ..
5636- 											} =>
5637- 												*channel_id == claiming_chan_funding_outpoint.to_channel_id(),
5638- 										}
5639- 									}), "{:?}", *background_events);
5640- 								}
5641- 								None
5642- 							} else if definitely_duplicate {
5643- 								if let Some(other_chan) = chan_to_release {
5644- 									Some(MonitorUpdateCompletionAction::FreeOtherChannelImmediately {
5645- 										downstream_counterparty_node_id: other_chan.0,
5646- 										downstream_funding_outpoint: other_chan.1,
5647- 										blocking_action: other_chan.2,
5648- 									})
5649- 								} else { None }
5598+ 						let chan_to_release =
5599+ 							if let Some(node_id) = next_channel_counterparty_node_id {
5600+ 								Some((node_id, next_channel_outpoint, completed_blocker))
56505601							} else {
5651- 								Some(MonitorUpdateCompletionAction::EmitEventAndFreeOtherChannel {
5652- 									event: events::Event::PaymentForwarded {
5653- 										fee_earned_msat,
5654- 										claim_from_onchain_tx: from_onchain,
5655- 										prev_channel_id: Some(prev_outpoint.to_channel_id()),
5656- 										next_channel_id: Some(next_channel_outpoint.to_channel_id()),
5657- 										outbound_amount_forwarded_msat: forwarded_htlc_value_msat,
5658- 									},
5659- 									downstream_counterparty_and_funding_outpoint: chan_to_release,
5660- 								})
5602+ 								// We can only get `None` here if we are processing a
5603+ 								// `ChannelMonitor`-originated event, in which case we
5604+ 								// don't care about ensuring we wake the downstream
5605+ 								// channel's monitor updating - the channel is already
5606+ 								// closed.
5607+ 								None
5608+ 							};
5609+ 
5610+ 						if definitely_duplicate && startup_replay {
5611+ 							// On startup we may get redundant claims which are related to
5612+ 							// monitor updates still in flight. In that case, we shouldn't
5613+ 							// immediately free, but instead let that monitor update complete
5614+ 							// in the background.
5615+ 							#[cfg(debug_assertions)] {
5616+ 								let background_events = self.pending_background_events.lock().unwrap();
5617+ 								// There should be a `BackgroundEvent` pending...
5618+ 								assert!(background_events.iter().any(|ev| {
5619+ 									match ev {
5620+ 										// to apply a monitor update that blocked channel,
5621+ 										BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
5622+ 											funding_txo, ..
5623+ 										} => *funding_txo == claiming_chan_funding_outpoint,
5624+ 										// or the channel we'd unblock is already closed,
5625+ 										BackgroundEvent::ClosedMonitorUpdateRegeneratedOnStartup((funding_txo, ..))
5626+ 											=> *funding_txo == next_channel_outpoint,
5627+ 										// or the monitor update has completed and will unblock
5628+ 										// immediately once we get going.
5629+ 										BackgroundEvent::MonitorUpdatesComplete {
5630+ 											channel_id, ..
5631+ 										} =>
5632+ 											*channel_id == claiming_chan_funding_outpoint.to_channel_id(),
5633+ 									}
5634+ 								}), "{:?}", *background_events);
56615635							}
5662- 						} else { None }
5636+ 							None
5637+ 						} else if definitely_duplicate {
5638+ 							if let Some(other_chan) = chan_to_release {
5639+ 								Some(MonitorUpdateCompletionAction::FreeOtherChannelImmediately {
5640+ 									downstream_counterparty_node_id: other_chan.0,
5641+ 									downstream_funding_outpoint: other_chan.1,
5642+ 									blocking_action: other_chan.2,
5643+ 								})
5644+ 							} else { None }
5645+ 						} else {
5646+ 							let fee_earned_msat = if let Some(forwarded_htlc_value) = forwarded_htlc_value_msat {
5647+ 								if let Some(claimed_htlc_value) = htlc_claim_value_msat {
5648+ 									Some(claimed_htlc_value - forwarded_htlc_value)
5649+ 								} else { None }
5650+ 							} else { None };
5651+ 							Some(MonitorUpdateCompletionAction::EmitEventAndFreeOtherChannel {
5652+ 								event: events::Event::PaymentForwarded {
5653+ 									fee_earned_msat,
5654+ 									claim_from_onchain_tx: from_onchain,
5655+ 									prev_channel_id: Some(prev_outpoint.to_channel_id()),
5656+ 									next_channel_id: Some(next_channel_outpoint.to_channel_id()),
5657+ 									outbound_amount_forwarded_msat: forwarded_htlc_value_msat,
5658+ 								},
5659+ 								downstream_counterparty_and_funding_outpoint: chan_to_release,
5660+ 							})
5661+ 						}
56635662					});
56645663				if let Err((pk, err)) = res {
56655664					let result: Result<(), _> = Err(err);
0 commit comments