@@ -138,7 +138,7 @@ enum FeeUpdateState {
138138enum InboundHTLCRemovalReason {
139139 FailRelay(msgs::OnionErrorPacket),
140140 FailMalformed(([u8; 32], u16)),
141- Fulfill(PaymentPreimage),
141+ Fulfill(PaymentPreimage, Option<AttributionData> ),
142142}
143143
144144/// Represents the resolution status of an inbound HTLC.
@@ -234,7 +234,7 @@ impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> {
234234 Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
235235 InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailMalformed(_)) =>
236236 Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
237- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) =>
237+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_, _ )) =>
238238 Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFulfill),
239239 }
240240 }
@@ -266,7 +266,7 @@ impl InboundHTLCState {
266266
267267 fn preimage(&self) -> Option<PaymentPreimage> {
268268 match self {
269- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage)) => {
269+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage, _ )) => {
270270 Some(*preimage)
271271 },
272272 _ => None,
@@ -466,6 +466,7 @@ enum HTLCUpdateAwaitingACK {
466466 },
467467 ClaimHTLC {
468468 payment_preimage: PaymentPreimage,
469+ attribution_data: Option<AttributionData>,
469470 htlc_id: u64,
470471 },
471472 FailHTLC {
@@ -6212,7 +6213,7 @@ where
62126213 // (see equivalent if condition there).
62136214 assert!(!self.context.channel_state.can_generate_new_commitment());
62146215 let mon_update_id = self.context.latest_monitor_update_id; // Forget the ChannelMonitor update
6215- let fulfill_resp = self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, logger);
6216+ let fulfill_resp = self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, None, logger);
62166217 self.context.latest_monitor_update_id = mon_update_id;
62176218 if let UpdateFulfillFetch::NewClaim { update_blocked, .. } = fulfill_resp {
62186219 assert!(update_blocked); // The HTLC must have ended up in the holding cell.
@@ -6222,7 +6223,7 @@ where
62226223 #[rustfmt::skip]
62236224 fn get_update_fulfill_htlc<L: Deref>(
62246225 &mut self, htlc_id_arg: u64, payment_preimage_arg: PaymentPreimage,
6225- payment_info: Option<PaymentClaimDetails>, logger: &L,
6226+ payment_info: Option<PaymentClaimDetails>, attribution_data: Option<AttributionData>, logger: &L,
62266227 ) -> UpdateFulfillFetch where L::Target: Logger {
62276228 // Either ChannelReady got set (which means it won't be unset) or there is no way any
62286229 // caller thought we could have something claimed (cause we wouldn't have accepted in an
@@ -6246,7 +6247,7 @@ where
62466247 match htlc.state {
62476248 InboundHTLCState::Committed => {},
62486249 InboundHTLCState::LocalRemoved(ref reason) => {
6249- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
6250+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
62506251 } else {
62516252 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());
62526253 debug_assert!(false, "Tried to fulfill an HTLC that was already failed");
@@ -6312,6 +6313,7 @@ where
63126313 log_trace!(logger, "Adding HTLC claim to holding_cell in channel {}! Current state: {}", &self.context.channel_id(), self.context.channel_state.to_u32());
63136314 self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
63146315 payment_preimage: payment_preimage_arg, htlc_id: htlc_id_arg,
6316+ attribution_data: attribution_data,
63156317 });
63166318 return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, update_blocked: true };
63176319 }
@@ -6324,7 +6326,7 @@ where
63246326 return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, update_blocked: true };
63256327 }
63266328 log_trace!(logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!", &htlc.payment_hash, &self.context.channel_id);
6327- htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(payment_preimage_arg.clone()));
6329+ htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(payment_preimage_arg.clone(), attribution_data ));
63286330 }
63296331
63306332 UpdateFulfillFetch::NewClaim {
@@ -6337,10 +6339,10 @@ where
63376339 #[rustfmt::skip]
63386340 pub fn get_update_fulfill_htlc_and_commit<L: Deref>(
63396341 &mut self, htlc_id: u64, payment_preimage: PaymentPreimage,
6340- payment_info: Option<PaymentClaimDetails>, logger: &L,
6342+ payment_info: Option<PaymentClaimDetails>, attribution_data: Option<AttributionData>, logger: &L,
63416343 ) -> UpdateFulfillCommitFetch where L::Target: Logger {
63426344 let release_cs_monitor = self.context.blocked_monitor_updates.is_empty();
6343- match self.get_update_fulfill_htlc(htlc_id, payment_preimage, payment_info, logger) {
6345+ match self.get_update_fulfill_htlc(htlc_id, payment_preimage, payment_info, attribution_data, logger) {
63446346 UpdateFulfillFetch::NewClaim { mut monitor_update, htlc_value_msat, update_blocked } => {
63456347 // Even if we aren't supposed to let new monitor updates with commitment state
63466348 // updates run, we still need to push the preimage ChannelMonitorUpdateStep no
@@ -6658,7 +6660,7 @@ where
66586660 }
66596661
66606662 #[rustfmt::skip]
6661- pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<(HTLCSource, u64, Option<u64>), ChannelError> {
6663+ pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<(HTLCSource, u64, Option<u64>, Option<Duration> ), ChannelError> {
66626664 if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
66636665 return Err(ChannelError::WarnAndDisconnect("Got fulfill HTLC message while quiescent".to_owned()));
66646666 }
@@ -6669,7 +6671,7 @@ where
66696671 return Err(ChannelError::close("Peer sent update_fulfill_htlc when we needed a channel_reestablish".to_owned()));
66706672 }
66716673
6672- 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))
6674+ 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 ))
66736675 }
66746676
66756677 #[rustfmt::skip]
@@ -7160,7 +7162,7 @@ where
71607162 }
71617163 None
71627164 },
7163- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, htlc_id, .. } => {
7165+ &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, htlc_id, ref attribution_data } => {
71647166 // If an HTLC claim was previously added to the holding cell (via
71657167 // `get_update_fulfill_htlc`, then generating the claim message itself must
71667168 // not fail - any in between attempts to claim the HTLC will have resulted
@@ -7173,7 +7175,7 @@ where
71737175 // We do not bother to track and include `payment_info` here, however.
71747176 let mut additional_monitor_update =
71757177 if let UpdateFulfillFetch::NewClaim { monitor_update, .. } =
7176- self.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, logger)
7178+ self.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, attribution_data.clone(), logger)
71777179 { monitor_update } else { unreachable!() };
71787180 update_fulfill_count += 1;
71797181 monitor_update.updates.append(&mut additional_monitor_update.updates);
@@ -7376,7 +7378,7 @@ where
73767378 pending_inbound_htlcs.retain(|htlc| {
73777379 if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
73787380 log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
7379- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
7381+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
73807382 value_to_self_msat_diff += htlc.amount_msat as i64;
73817383 }
73827384 *expecting_peer_commitment_signed = true;
@@ -8242,12 +8244,12 @@ where
82428244 failure_code: failure_code.clone(),
82438245 });
82448246 },
8245- &InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
8247+ &InboundHTLCRemovalReason::Fulfill(ref payment_preimage, ref attribution_data ) => {
82468248 update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
82478249 channel_id: self.context.channel_id(),
82488250 htlc_id: htlc.htlc_id,
82498251 payment_preimage: payment_preimage.clone(),
8250- attribution_data: None ,
8252+ attribution_data: attribution_data.clone() ,
82518253 });
82528254 },
82538255 }
@@ -12304,7 +12306,7 @@ where
1230412306 dropped_inbound_htlcs += 1;
1230512307 }
1230612308 }
12307- let mut removed_htlc_failure_attribution_data : Vec<&Option<AttributionData>> = Vec::new();
12309+ let mut removed_htlc_attribution_data : Vec<&Option<AttributionData>> = Vec::new();
1230812310 (self.context.pending_inbound_htlcs.len() as u64 - dropped_inbound_htlcs).write(writer)?;
1230912311 for htlc in self.context.pending_inbound_htlcs.iter() {
1231012312 if let &InboundHTLCState::RemoteAnnounced(_) = &htlc.state {
@@ -12333,13 +12335,13 @@ where
1233312335 InboundHTLCRemovalReason::FailRelay(msgs::OnionErrorPacket { data, attribution_data }) => {
1233412336 0u8.write(writer)?;
1233512337 data.write(writer)?;
12336- removed_htlc_failure_attribution_data .push(&attribution_data);
12338+ removed_htlc_attribution_data .push(&attribution_data);
1233712339 },
1233812340 InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
1233912341 1u8.write(writer)?;
1234012342 (hash, code).write(writer)?;
1234112343 },
12342- InboundHTLCRemovalReason::Fulfill(preimage) => {
12344+ InboundHTLCRemovalReason::Fulfill(preimage, _ ) => { // TODO: Persistence
1234312345 2u8.write(writer)?;
1234412346 preimage.write(writer)?;
1234512347 },
@@ -12398,7 +12400,7 @@ where
1239812400 let holding_cell_htlc_update_count = self.context.holding_cell_htlc_updates.len();
1239912401 let mut holding_cell_skimmed_fees: Vec<Option<u64>> = Vec::with_capacity(holding_cell_htlc_update_count);
1240012402 let mut holding_cell_blinding_points: Vec<Option<PublicKey>> = Vec::with_capacity(holding_cell_htlc_update_count);
12401- let mut holding_cell_failure_attribution_data : Vec<Option<&AttributionData>> = Vec::with_capacity(holding_cell_htlc_update_count);
12403+ let mut holding_cell_attribution_data : Vec<Option<&AttributionData>> = Vec::with_capacity(holding_cell_htlc_update_count);
1240212404 // Vec of (htlc_id, failure_code, sha256_of_onion)
1240312405 let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
1240412406 (holding_cell_htlc_update_count as u64).write(writer)?;
@@ -12418,18 +12420,21 @@ where
1241812420 holding_cell_skimmed_fees.push(skimmed_fee_msat);
1241912421 holding_cell_blinding_points.push(blinding_point);
1242012422 },
12421- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
12423+ &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id, ref attribution_data } => {
1242212424 1u8.write(writer)?;
1242312425 payment_preimage.write(writer)?;
1242412426 htlc_id.write(writer)?;
12427+
12428+ // Store the attribution data for later writing.
12429+ holding_cell_attribution_data.push(attribution_data.as_ref());
1242512430 },
1242612431 &HTLCUpdateAwaitingACK::FailHTLC { ref htlc_id, ref err_packet } => {
1242712432 2u8.write(writer)?;
1242812433 htlc_id.write(writer)?;
1242912434 err_packet.data.write(writer)?;
1243012435
1243112436 // Store the attribution data for later writing.
12432- holding_cell_failure_attribution_data .push(err_packet.attribution_data.as_ref());
12437+ holding_cell_attribution_data .push(err_packet.attribution_data.as_ref());
1243312438 }
1243412439 &HTLCUpdateAwaitingACK::FailMalformedHTLC {
1243512440 htlc_id, failure_code, sha256_of_onion
@@ -12444,7 +12449,7 @@ where
1244412449
1244512450 // Push 'None' attribution data for FailMalformedHTLC, because FailMalformedHTLC uses the same
1244612451 // type 2 and is deserialized as a FailHTLC.
12447- holding_cell_failure_attribution_data .push(None);
12452+ holding_cell_attribution_data .push(None);
1244812453 }
1244912454 }
1245012455 }
@@ -12618,8 +12623,8 @@ where
1261812623 (51, is_manual_broadcast, option), // Added in 0.0.124
1261912624 (53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
1262012625 (54, self.pending_funding, optional_vec), // Added in 0.2
12621- (55, removed_htlc_failure_attribution_data , optional_vec), // Added in 0.2
12622- (57, holding_cell_failure_attribution_data , optional_vec), // Added in 0.2
12626+ (55, removed_htlc_attribution_data , optional_vec), // Added in 0.2
12627+ (57, holding_cell_attribution_data , optional_vec), // Added in 0.2
1262312628 (58, self.interactive_tx_signing_session, option), // Added in 0.2
1262412629 (59, self.funding.minimum_depth_override, option), // Added in 0.2
1262512630 (60, self.context.historical_scids, optional_vec), // Added in 0.2
@@ -12705,7 +12710,7 @@ where
1270512710 attribution_data: None,
1270612711 }),
1270712712 1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
12708- 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
12713+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None ),
1270912714 _ => return Err(DecodeError::InvalidValue),
1271012715 };
1271112716 InboundHTLCState::LocalRemoved(reason)
@@ -12778,6 +12783,7 @@ where
1277812783 1 => HTLCUpdateAwaitingACK::ClaimHTLC {
1277912784 payment_preimage: Readable::read(reader)?,
1278012785 htlc_id: Readable::read(reader)?,
12786+ attribution_data: None,
1278112787 },
1278212788 2 => HTLCUpdateAwaitingACK::FailHTLC {
1278312789 htlc_id: Readable::read(reader)?,
@@ -12929,8 +12935,8 @@ where
1292912935 let mut pending_outbound_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1293012936 let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
1293112937
12932- let mut removed_htlc_failure_attribution_data : Option<Vec<Option<AttributionData>>> = None;
12933- let mut holding_cell_failure_attribution_data : Option<Vec<Option<AttributionData>>> = None;
12938+ let mut removed_htlc_attribution_data : Option<Vec<Option<AttributionData>>> = None;
12939+ let mut holding_cell_attribution_data : Option<Vec<Option<AttributionData>>> = None;
1293412940
1293512941 let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
1293612942 let mut monitor_pending_update_adds: Option<Vec<msgs::UpdateAddHTLC>> = None;
@@ -12982,8 +12988,8 @@ where
1298212988 (51, is_manual_broadcast, option),
1298312989 (53, funding_tx_broadcast_safe_event_emitted, option),
1298412990 (54, pending_funding, optional_vec), // Added in 0.2
12985- (55, removed_htlc_failure_attribution_data , optional_vec),
12986- (57, holding_cell_failure_attribution_data , optional_vec),
12991+ (55, removed_htlc_attribution_data , optional_vec),
12992+ (57, holding_cell_attribution_data , optional_vec),
1298712993 (58, interactive_tx_signing_session, option), // Added in 0.2
1298812994 (59, minimum_depth_override, option), // Added in 0.2
1298912995 (60, historical_scids, optional_vec), // Added in 0.2
@@ -13072,11 +13078,15 @@ where
1307213078 if iter.next().is_some() { return Err(DecodeError::InvalidValue) }
1307313079 }
1307413080
13075- if let Some(attribution_data_list) = removed_htlc_failure_attribution_data {
13081+ if let Some(attribution_data_list) = removed_htlc_attribution_data {
1307613082 let mut removed_htlc_relay_failures =
1307713083 pending_inbound_htlcs.iter_mut().filter_map(|status|
13078- if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(ref mut packet)) = &mut status.state {
13079- Some(&mut packet.attribution_data)
13084+ if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
13085+ match reason {
13086+ InboundHTLCRemovalReason::FailRelay(ref mut packet) => Some(&mut packet.attribution_data),
13087+ InboundHTLCRemovalReason::Fulfill(_, ref mut attribution_data) => Some(attribution_data),
13088+ _ => None,
13089+ }
1308013090 } else {
1308113091 None
1308213092 }
@@ -13088,13 +13098,13 @@ where
1308813098 if removed_htlc_relay_failures.next().is_some() { return Err(DecodeError::InvalidValue); }
1308913099 }
1309013100
13091- if let Some(attribution_data_list) = holding_cell_failure_attribution_data {
13101+ if let Some(attribution_data_list) = holding_cell_attribution_data {
1309213102 let mut holding_cell_failures =
1309313103 holding_cell_htlc_updates.iter_mut().filter_map(|upd|
13094- if let HTLCUpdateAwaitingACK::FailHTLC { err_packet: OnionErrorPacket { ref mut attribution_data, .. }, .. } = upd {
13095- Some(attribution_data)
13096- } else {
13097- None
13104+ match upd {
13105+ HTLCUpdateAwaitingACK::FailHTLC { err_packet: OnionErrorPacket { ref mut attribution_data, .. }, .. } => Some(attribution_data),
13106+ HTLCUpdateAwaitingACK::ClaimHTLC { attribution_data, .. } => Some(attribution_data),
13107+ _ => None
1309813108 }
1309913109 );
1310013110
@@ -13283,7 +13293,7 @@ where
1328313293 }
1328413294}
1328513295
13286- fn duration_since_epoch() -> Option<Duration> {
13296+ pub(crate) fn duration_since_epoch() -> Option<Duration> {
1328713297 #[cfg(not(feature = "std"))]
1328813298 let now = None;
1328913299
@@ -14004,6 +14014,7 @@ mod tests {
1400414014 let dummy_holding_cell_claim_htlc = HTLCUpdateAwaitingACK::ClaimHTLC {
1400514015 payment_preimage: PaymentPreimage([42; 32]),
1400614016 htlc_id: 0,
14017+ attribution_data: None,
1400714018 };
1400814019 let dummy_holding_cell_failed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailHTLC {
1400914020 htlc_id, err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data: Some(AttributionData::new()) }
0 commit comments