@@ -121,7 +121,7 @@ enum FeeUpdateState {
121121enum InboundHTLCRemovalReason {
122122 FailRelay(msgs::OnionErrorPacket),
123123 FailMalformed(([u8; 32], u16)),
124- Fulfill(PaymentPreimage),
124+ Fulfill(PaymentPreimage, Option<AttributionData> ),
125125}
126126
127127/// Represents the resolution status of an inbound HTLC.
@@ -220,7 +220,7 @@ impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> {
220220 Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
221221 InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailMalformed(_)) =>
222222 Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
223- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) =>
223+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_, _ )) =>
224224 Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFulfill),
225225 }
226226 }
@@ -251,7 +251,7 @@ impl InboundHTLCState {
251251
252252 fn preimage(&self) -> Option<PaymentPreimage> {
253253 match self {
254- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage)) => Some(*preimage),
254+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage, _ )) => Some(*preimage),
255255 _ => None,
256256 }
257257 }
@@ -439,6 +439,7 @@ enum HTLCUpdateAwaitingACK {
439439 },
440440 ClaimHTLC {
441441 payment_preimage: PaymentPreimage,
442+ attribution_data: AttributionData,
442443 htlc_id: u64,
443444 },
444445 FailHTLC {
@@ -5347,7 +5348,7 @@ impl<SP: Deref> FundedChannel<SP> where
53475348 // (see equivalent if condition there).
53485349 assert!(!self.context.channel_state.can_generate_new_commitment());
53495350 let mon_update_id = self.context.latest_monitor_update_id; // Forget the ChannelMonitor update
5350- let fulfill_resp = self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, logger);
5351+ let fulfill_resp = self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, AttributionData::new(), logger);
53515352 self.context.latest_monitor_update_id = mon_update_id;
53525353 if let UpdateFulfillFetch::NewClaim { msg, .. } = fulfill_resp {
53535354 assert!(!msg); // The HTLC must have ended up in the holding cell.
@@ -5356,7 +5357,7 @@ impl<SP: Deref> FundedChannel<SP> where
53565357
53575358 fn get_update_fulfill_htlc<L: Deref>(
53585359 &mut self, htlc_id_arg: u64, payment_preimage_arg: PaymentPreimage,
5359- payment_info: Option<PaymentClaimDetails>, logger: &L,
5360+ payment_info: Option<PaymentClaimDetails>, attribution_data: AttributionData, logger: &L,
53605361 ) -> UpdateFulfillFetch where L::Target: Logger {
53615362 // Either ChannelReady got set (which means it won't be unset) or there is no way any
53625363 // caller thought we could have something claimed (cause we wouldn't have accepted in an
@@ -5380,7 +5381,7 @@ impl<SP: Deref> FundedChannel<SP> where
53805381 match htlc.state {
53815382 InboundHTLCState::Committed => {},
53825383 InboundHTLCState::LocalRemoved(ref reason) => {
5383- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
5384+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
53845385 } else {
53855386 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());
53865387 debug_assert!(false, "Tried to fulfill an HTLC that was already failed");
@@ -5446,6 +5447,7 @@ impl<SP: Deref> FundedChannel<SP> where
54465447 log_trace!(logger, "Adding HTLC claim to holding_cell in channel {}! Current state: {}", &self.context.channel_id(), self.context.channel_state.to_u32());
54475448 self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
54485449 payment_preimage: payment_preimage_arg, htlc_id: htlc_id_arg,
5450+ attribution_data,
54495451 });
54505452 return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: false };
54515453 }
@@ -5458,7 +5460,7 @@ impl<SP: Deref> FundedChannel<SP> where
54585460 return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: false };
54595461 }
54605462 log_trace!(logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!", &htlc.payment_hash, &self.context.channel_id);
5461- htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(payment_preimage_arg.clone()));
5463+ htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(payment_preimage_arg.clone(), Some(attribution_data) ));
54625464 }
54635465
54645466 UpdateFulfillFetch::NewClaim {
@@ -5470,10 +5472,10 @@ impl<SP: Deref> FundedChannel<SP> where
54705472
54715473 pub fn get_update_fulfill_htlc_and_commit<L: Deref>(
54725474 &mut self, htlc_id: u64, payment_preimage: PaymentPreimage,
5473- payment_info: Option<PaymentClaimDetails>, logger: &L,
5475+ payment_info: Option<PaymentClaimDetails>, attribution_data: AttributionData, logger: &L,
54745476 ) -> UpdateFulfillCommitFetch where L::Target: Logger {
54755477 let release_cs_monitor = self.context.blocked_monitor_updates.is_empty();
5476- match self.get_update_fulfill_htlc(htlc_id, payment_preimage, payment_info, logger) {
5478+ match self.get_update_fulfill_htlc(htlc_id, payment_preimage, payment_info, attribution_data, logger) {
54775479 UpdateFulfillFetch::NewClaim { mut monitor_update, htlc_value_msat, msg } => {
54785480 // Even if we aren't supposed to let new monitor updates with commitment state
54795481 // updates run, we still need to push the preimage ChannelMonitorUpdateStep no
@@ -5848,7 +5850,7 @@ impl<SP: Deref> FundedChannel<SP> where
58485850 Err(ChannelError::close("Remote tried to fulfill/fail an HTLC we couldn't find".to_owned()))
58495851 }
58505852
5851- pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<(HTLCSource, u64, Option<u64>), ChannelError> {
5853+ pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<(HTLCSource, u64, Option<u64>, Option<Duration> ), ChannelError> {
58525854 if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
58535855 return Err(ChannelError::WarnAndDisconnect("Got fulfill HTLC message while quiescent".to_owned()));
58545856 }
@@ -5859,7 +5861,7 @@ impl<SP: Deref> FundedChannel<SP> where
58595861 return Err(ChannelError::close("Peer sent update_fulfill_htlc when we needed a channel_reestablish".to_owned()));
58605862 }
58615863
5862- self.mark_outbound_htlc_removed(msg.htlc_id, OutboundHTLCOutcome::Success(msg.payment_preimage)).map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
5864+ self.mark_outbound_htlc_removed(msg.htlc_id, OutboundHTLCOutcome::Success(msg.payment_preimage)).map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat, htlc.send_timestamp ))
58635865 }
58645866
58655867 pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailReason) -> Result<(), ChannelError> {
@@ -6188,7 +6190,7 @@ impl<SP: Deref> FundedChannel<SP> where
61886190 }
61896191 None
61906192 },
6191- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, htlc_id, .. } => {
6193+ &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, htlc_id, ref attribution_data } => {
61926194 // If an HTLC claim was previously added to the holding cell (via
61936195 // `get_update_fulfill_htlc`, then generating the claim message itself must
61946196 // not fail - any in between attempts to claim the HTLC will have resulted
@@ -6201,7 +6203,7 @@ impl<SP: Deref> FundedChannel<SP> where
62016203 // We do not bother to track and include `payment_info` here, however.
62026204 let mut additional_monitor_update =
62036205 if let UpdateFulfillFetch::NewClaim { monitor_update, .. } =
6204- self.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, logger)
6206+ self.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, attribution_data.clone(), logger)
62056207 { monitor_update } else { unreachable!() };
62066208 update_fulfill_count += 1;
62076209 monitor_update.updates.append(&mut additional_monitor_update.updates);
@@ -6366,7 +6368,7 @@ impl<SP: Deref> FundedChannel<SP> where
63666368 pending_inbound_htlcs.retain(|htlc| {
63676369 if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
63686370 log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
6369- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
6371+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
63706372 value_to_self_msat_diff += htlc.amount_msat as i64;
63716373 }
63726374 *expecting_peer_commitment_signed = true;
@@ -7139,11 +7141,12 @@ impl<SP: Deref> FundedChannel<SP> where
71397141 failure_code: failure_code.clone(),
71407142 });
71417143 },
7142- &InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
7144+ &InboundHTLCRemovalReason::Fulfill(ref payment_preimage, ref attribution_data ) => {
71437145 update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
71447146 channel_id: self.context.channel_id(),
71457147 htlc_id: htlc.htlc_id,
71467148 payment_preimage: payment_preimage.clone(),
7149+ attribution_data: attribution_data.clone(),
71477150 });
71487151 },
71497152 }
@@ -10642,7 +10645,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1064210645 1u8.write(writer)?;
1064310646 (hash, code).write(writer)?;
1064410647 },
10645- InboundHTLCRemovalReason::Fulfill(preimage) => {
10648+ InboundHTLCRemovalReason::Fulfill(preimage, _ ) => { // TODO: Persistence
1064610649 2u8.write(writer)?;
1064710650 preimage.write(writer)?;
1064810651 },
@@ -10721,7 +10724,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1072110724 holding_cell_skimmed_fees.push(skimmed_fee_msat);
1072210725 holding_cell_blinding_points.push(blinding_point);
1072310726 },
10724- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
10727+ &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id, .. } => {
1072510728 1u8.write(writer)?;
1072610729 payment_preimage.write(writer)?;
1072710730 htlc_id.write(writer)?;
@@ -11003,7 +11006,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1100311006 attribution_data: None,
1100411007 }),
1100511008 1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
11006- 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
11009+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None), // TODO: Persistence
1100711010 _ => return Err(DecodeError::InvalidValue),
1100811011 };
1100911012 InboundHTLCState::LocalRemoved(reason)
@@ -11076,6 +11079,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1107611079 1 => HTLCUpdateAwaitingACK::ClaimHTLC {
1107711080 payment_preimage: Readable::read(reader)?,
1107811081 htlc_id: Readable::read(reader)?,
11082+ attribution_data: AttributionData::new(), // TODO: Persistence
1107911083 },
1108011084 2 => HTLCUpdateAwaitingACK::FailHTLC {
1108111085 htlc_id: Readable::read(reader)?,
@@ -11584,7 +11588,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1158411588 }
1158511589}
1158611590
11587- fn duration_since_epoch() -> Option<Duration> {
11591+ pub(crate) fn duration_since_epoch() -> Option<Duration> {
1158811592 #[cfg(not(feature = "std"))]
1158911593 let now = None;
1159011594
@@ -12248,6 +12252,7 @@ mod tests {
1224812252 let dummy_holding_cell_claim_htlc = HTLCUpdateAwaitingACK::ClaimHTLC {
1224912253 payment_preimage: PaymentPreimage([42; 32]),
1225012254 htlc_id: 0,
12255+ attribution_data: AttributionData::new(),
1225112256 };
1225212257 let dummy_holding_cell_failed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailHTLC {
1225312258 htlc_id, err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data: Some(AttributionData::new()) }
0 commit comments