@@ -402,7 +402,7 @@ impl OutboundHTLCState {
402402enum OutboundHTLCOutcome {
403403 /// We started always filling in the preimages here in 0.0.105, and the requirement
404404 /// that the preimages always be filled in was added in 0.2.
405- Success(PaymentPreimage, #[allow(dead_code)] Option<AttributionData>),
405+ Success(PaymentPreimage, Option<AttributionData>),
406406 Failure(HTLCFailReason),
407407}
408408
@@ -1181,7 +1181,7 @@ pub(super) struct MonitorRestoreUpdates {
11811181 pub order: RAACommitmentOrder,
11821182 pub accepted_htlcs: Vec<(PendingHTLCInfo, u64)>,
11831183 pub failed_htlcs: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
1184- pub finalized_claimed_htlcs: Vec<HTLCSource>,
1184+ pub finalized_claimed_htlcs: Vec<( HTLCSource, Option<AttributionData>) >,
11851185 pub pending_update_adds: Vec<msgs::UpdateAddHTLC>,
11861186 pub funding_broadcastable: Option<Transaction>,
11871187 pub channel_ready: Option<msgs::ChannelReady>,
@@ -2313,7 +2313,7 @@ where
23132313 // but need to handle this somehow or we run the risk of losing HTLCs!
23142314 monitor_pending_forwards: Vec<(PendingHTLCInfo, u64)>,
23152315 monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
2316- monitor_pending_finalized_fulfills: Vec<HTLCSource>,
2316+ monitor_pending_finalized_fulfills: Vec<( HTLCSource, Option<AttributionData>) >,
23172317 monitor_pending_update_adds: Vec<msgs::UpdateAddHTLC>,
23182318 monitor_pending_tx_signatures: Option<msgs::TxSignatures>,
23192319
@@ -6215,7 +6215,7 @@ where
62156215 assert!(!self.context.channel_state.can_generate_new_commitment());
62166216 let mon_update_id = self.context.latest_monitor_update_id; // Forget the ChannelMonitor update
62176217 let fulfill_resp =
6218- self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, logger);
6218+ self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, None, logger);
62196219 self.context.latest_monitor_update_id = mon_update_id;
62206220 if let UpdateFulfillFetch::NewClaim { update_blocked, .. } = fulfill_resp {
62216221 assert!(update_blocked); // The HTLC must have ended up in the holding cell.
@@ -6224,7 +6224,8 @@ where
62246224
62256225 fn get_update_fulfill_htlc<L: Deref>(
62266226 &mut self, htlc_id_arg: u64, payment_preimage_arg: PaymentPreimage,
6227- payment_info: Option<PaymentClaimDetails>, logger: &L,
6227+ payment_info: Option<PaymentClaimDetails>, attribution_data: Option<AttributionData>,
6228+ logger: &L,
62286229 ) -> UpdateFulfillFetch
62296230 where
62306231 L::Target: Logger,
@@ -6340,7 +6341,7 @@ where
63406341 self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
63416342 payment_preimage: payment_preimage_arg,
63426343 htlc_id: htlc_id_arg,
6343- attribution_data: None ,
6344+ attribution_data,
63446345 });
63456346 return UpdateFulfillFetch::NewClaim {
63466347 monitor_update,
@@ -6371,7 +6372,7 @@ where
63716372 );
63726373 htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(
63736374 payment_preimage_arg.clone(),
6374- None ,
6375+ attribution_data ,
63756376 ));
63766377 }
63776378
@@ -6380,13 +6381,20 @@ where
63806381
63816382 pub fn get_update_fulfill_htlc_and_commit<L: Deref>(
63826383 &mut self, htlc_id: u64, payment_preimage: PaymentPreimage,
6383- payment_info: Option<PaymentClaimDetails>, logger: &L,
6384+ payment_info: Option<PaymentClaimDetails>, attribution_data: Option<AttributionData>,
6385+ logger: &L,
63846386 ) -> UpdateFulfillCommitFetch
63856387 where
63866388 L::Target: Logger,
63876389 {
63886390 let release_cs_monitor = self.context.blocked_monitor_updates.is_empty();
6389- match self.get_update_fulfill_htlc(htlc_id, payment_preimage, payment_info, logger) {
6391+ match self.get_update_fulfill_htlc(
6392+ htlc_id,
6393+ payment_preimage,
6394+ payment_info,
6395+ attribution_data,
6396+ logger,
6397+ ) {
63906398 UpdateFulfillFetch::NewClaim {
63916399 mut monitor_update,
63926400 htlc_value_msat,
@@ -6720,7 +6728,7 @@ where
67206728
67216729 pub fn update_fulfill_htlc(
67226730 &mut self, msg: &msgs::UpdateFulfillHTLC,
6723- ) -> Result<(HTLCSource, u64, Option<u64>), ChannelError> {
6731+ ) -> Result<(HTLCSource, u64, Option<u64>, Option<Duration> ), ChannelError> {
67246732 if self.context.channel_state.is_remote_stfu_sent()
67256733 || self.context.channel_state.is_quiescent()
67266734 {
@@ -6741,9 +6749,11 @@ where
67416749
67426750 self.mark_outbound_htlc_removed(
67436751 msg.htlc_id,
6744- OutboundHTLCOutcome::Success(msg.payment_preimage, None ),
6752+ OutboundHTLCOutcome::Success(msg.payment_preimage, msg.attribution_data.clone() ),
67456753 )
6746- .map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
6754+ .map(|htlc| {
6755+ (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat, htlc.send_timestamp)
6756+ })
67476757 }
67486758
67496759 #[rustfmt::skip]
@@ -7279,7 +7289,11 @@ where
72797289 }
72807290 None
72817291 },
7282- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, htlc_id, .. } => {
7292+ &HTLCUpdateAwaitingACK::ClaimHTLC {
7293+ ref payment_preimage,
7294+ htlc_id,
7295+ ref attribution_data,
7296+ } => {
72837297 // If an HTLC claim was previously added to the holding cell (via
72847298 // `get_update_fulfill_htlc`, then generating the claim message itself must
72857299 // not fail - any in between attempts to claim the HTLC will have resulted
@@ -7292,8 +7306,13 @@ where
72927306 // We do not bother to track and include `payment_info` here, however.
72937307 let mut additional_monitor_update =
72947308 if let UpdateFulfillFetch::NewClaim { monitor_update, .. } = self
7295- .get_update_fulfill_htlc(htlc_id, *payment_preimage, None, logger)
7296- {
7309+ .get_update_fulfill_htlc(
7310+ htlc_id,
7311+ *payment_preimage,
7312+ None,
7313+ attribution_data.clone(),
7314+ logger,
7315+ ) {
72977316 monitor_update
72987317 } else {
72997318 unreachable!()
@@ -7535,8 +7554,11 @@ where
75357554 });
75367555 revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
75377556 },
7538- OutboundHTLCOutcome::Success(..) => {
7539- finalized_claimed_htlcs.push(htlc.source.clone());
7557+ OutboundHTLCOutcome::Success(_, attribution_data) => {
7558+ // Even though a fast track was taken for fulfilled HTLCs to the incoming side, we still
7559+ // pass along attribution data here so that we can include hold time information in the
7560+ // final PaymentPathSuccessful events.
7561+ finalized_claimed_htlcs.push((htlc.source.clone(), attribution_data));
75407562 // They fulfilled, so we sent them money
75417563 value_to_self_msat_diff -= htlc.amount_msat as i64;
75427564 },
@@ -8029,7 +8051,7 @@ where
80298051 &mut self, resend_raa: bool, resend_commitment: bool, resend_channel_ready: bool,
80308052 mut pending_forwards: Vec<(PendingHTLCInfo, u64)>,
80318053 mut pending_fails: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
8032- mut pending_finalized_claimed_htlcs: Vec<HTLCSource>,
8054+ mut pending_finalized_claimed_htlcs: Vec<( HTLCSource, Option<AttributionData>) >,
80338055 ) {
80348056 self.context.monitor_pending_revoke_and_ack |= resend_raa;
80358057 self.context.monitor_pending_commitment_signed |= resend_commitment;
@@ -13586,7 +13608,7 @@ where
1358613608 }
1358713609}
1358813610
13589- fn duration_since_epoch() -> Option<Duration> {
13611+ pub(crate) fn duration_since_epoch() -> Option<Duration> {
1359013612 #[cfg(not(feature = "std"))]
1359113613 let now = None;
1359213614
@@ -13600,7 +13622,9 @@ fn duration_since_epoch() -> Option<Duration> {
1360013622 now
1360113623}
1360213624
13603- fn get_hold_time(send_timestamp: Option<Duration>, now: Option<Duration>) -> Option<u32> {
13625+ pub(crate) fn get_hold_time(
13626+ send_timestamp: Option<Duration>, now: Option<Duration>,
13627+ ) -> Option<u32> {
1360413628 send_timestamp.and_then(|t| {
1360513629 now.map(|now| {
1360613630 let elapsed = now.saturating_sub(t).as_millis() / HOLD_TIME_UNIT_MILLIS;
0 commit comments