@@ -348,11 +348,11 @@ impl From<&OutboundHTLCState> for OutboundHTLCStateDetails {
348348 // the state yet.
349349 OutboundHTLCState::RemoteRemoved(_) =>
350350 OutboundHTLCStateDetails::Committed,
351- OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) =>
351+ OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) =>
352352 OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveSuccess,
353353 OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Failure(_)) =>
354354 OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFailure,
355- OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) =>
355+ OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _ )) =>
356356 OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveSuccess,
357357 OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Failure(_)) =>
358358 OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFailure,
@@ -387,9 +387,9 @@ impl OutboundHTLCState {
387387 #[rustfmt::skip]
388388 fn preimage(&self) -> Option<PaymentPreimage> {
389389 match self {
390- OutboundHTLCState::RemoteRemoved(OutboundHTLCOutcome::Success(preimage))
391- | OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(preimage))
392- | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(preimage)) => {
390+ OutboundHTLCState::RemoteRemoved(OutboundHTLCOutcome::Success(preimage, _ ))
391+ | OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(preimage, _ ))
392+ | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(preimage, _ )) => {
393393 Some(*preimage)
394394 },
395395 _ => None,
@@ -402,14 +402,14 @@ 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),
405+ Success(PaymentPreimage, #[allow(dead_code)] Option<AttributionData> ),
406406 Failure(HTLCFailReason),
407407}
408408
409409impl<'a> Into<Option<&'a HTLCFailReason>> for &'a OutboundHTLCOutcome {
410410 fn into(self) -> Option<&'a HTLCFailReason> {
411411 match self {
412- OutboundHTLCOutcome::Success(_) => None,
412+ OutboundHTLCOutcome::Success(_, _ ) => None,
413413 OutboundHTLCOutcome::Failure(ref r) => Some(r),
414414 }
415415 }
@@ -4160,9 +4160,9 @@ where
41604160 // transaction).
41614161 let mut removed_outbound_total_msat = 0;
41624162 for ref htlc in self.pending_outbound_htlcs.iter() {
4163- if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) = htlc.state {
4163+ if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) = htlc.state {
41644164 removed_outbound_total_msat += htlc.amount_msat;
4165- } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) = htlc.state {
4165+ } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _ )) = htlc.state {
41664166 removed_outbound_total_msat += htlc.amount_msat;
41674167 }
41684168 }
@@ -4425,9 +4425,9 @@ where
44254425
44264426 let mut removed_outbound_total_msat = 0;
44274427 for ref htlc in self.pending_outbound_htlcs.iter() {
4428- if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) = htlc.state {
4428+ if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) = htlc.state {
44294429 removed_outbound_total_msat += htlc.amount_msat;
4430- } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) = htlc.state {
4430+ } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _ )) = htlc.state {
44314431 removed_outbound_total_msat += htlc.amount_msat;
44324432 }
44334433 }
@@ -6705,7 +6705,7 @@ where
67056705 fn mark_outbound_htlc_removed(&mut self, htlc_id: u64, outcome: OutboundHTLCOutcome) -> Result<&OutboundHTLCOutput, ChannelError> {
67066706 for htlc in self.context.pending_outbound_htlcs.iter_mut() {
67076707 if htlc.htlc_id == htlc_id {
6708- if let OutboundHTLCOutcome::Success(ref payment_preimage) = outcome {
6708+ if let OutboundHTLCOutcome::Success(ref payment_preimage, .. ) = outcome {
67096709 let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
67106710 if payment_hash != htlc.payment_hash {
67116711 return Err(ChannelError::close(format!("Remote tried to fulfill HTLC ({}) with an incorrect preimage", htlc_id)));
@@ -6749,7 +6749,7 @@ where
67496749
67506750 self.mark_outbound_htlc_removed(
67516751 msg.htlc_id,
6752- OutboundHTLCOutcome::Success(msg.payment_preimage),
6752+ OutboundHTLCOutcome::Success(msg.payment_preimage, None ),
67536753 )
67546754 .map(|htlc| {
67556755 (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat, htlc.send_timestamp)
@@ -7091,9 +7091,9 @@ where
70917091 log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToRemove due to commitment_signed in channel {}.",
70927092 &htlc.payment_hash, &self.context.channel_id);
70937093 // Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
7094- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
7094+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
70957095 mem::swap(outcome, &mut reason);
7096- if let OutboundHTLCOutcome::Success(preimage) = reason {
7096+ if let OutboundHTLCOutcome::Success(preimage, _ ) = reason {
70977097 // If a user (a) receives an HTLC claim using LDK 0.0.104 or before, then (b)
70987098 // upgrades to LDK 0.0.114 or later before the HTLC is fully resolved, we could
70997099 // have a `Success(None)` reason. In this case we could forget some HTLC
@@ -7547,16 +7547,18 @@ where
75477547 &htlc.payment_hash
75487548 );
75497549 // We really want take() here, but, again, non-mut ref :(
7550- if let OutboundHTLCOutcome::Failure(mut reason) = outcome.clone() {
7551- get_hold_time(htlc.send_timestamp, now).map(|hold_time| {
7552- reason.set_hold_time(hold_time);
7553- });
7554-
7555- revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
7556- } else {
7557- finalized_claimed_htlcs.push(htlc.source.clone());
7558- // They fulfilled, so we sent them money
7559- value_to_self_msat_diff -= htlc.amount_msat as i64;
7550+ match outcome.clone() {
7551+ OutboundHTLCOutcome::Failure(mut reason) => {
7552+ get_hold_time(htlc.send_timestamp, now).map(|hold_time| {
7553+ reason.set_hold_time(hold_time);
7554+ });
7555+ revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
7556+ },
7557+ OutboundHTLCOutcome::Success(..) => {
7558+ finalized_claimed_htlcs.push(htlc.source.clone());
7559+ // They fulfilled, so we sent them money
7560+ value_to_self_msat_diff -= htlc.amount_msat as i64;
7561+ },
75607562 }
75617563 false
75627564 } else {
@@ -7640,7 +7642,7 @@ where
76407642 {
76417643 log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
76427644 // Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
7643- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
7645+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
76447646 mem::swap(outcome, &mut reason);
76457647 htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
76467648 require_commitment = true;
@@ -10773,7 +10775,7 @@ where
1077310775 if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
1077410776 log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
1077510777 // Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
10776- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
10778+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
1077710779 mem::swap(outcome, &mut reason);
1077810780 htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
1077910781 }
@@ -12530,6 +12532,7 @@ where
1253012532 // The elements of this vector will always be `Some` starting in 0.2,
1253112533 // but we still serialize the option to maintain backwards compatibility
1253212534 let mut preimages: Vec<Option<&PaymentPreimage>> = vec![];
12535+ let mut success_attribution_data = vec![];
1253312536 let mut pending_outbound_skimmed_fees: Vec<Option<u64>> = Vec::new();
1253412537 let mut pending_outbound_blinding_points: Vec<Option<PublicKey>> = Vec::new();
1253512538
@@ -12555,16 +12558,18 @@ where
1255512558 },
1255612559 &OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref outcome) => {
1255712560 3u8.write(writer)?;
12558- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12561+ if let OutboundHTLCOutcome::Success(preimage, attribution_data ) = outcome {
1255912562 preimages.push(Some(preimage));
12563+ success_attribution_data.push(attribution_data);
1256012564 }
1256112565 let reason: Option<&HTLCFailReason> = outcome.into();
1256212566 reason.write(writer)?;
1256312567 },
1256412568 &OutboundHTLCState::AwaitingRemovedRemoteRevoke(ref outcome) => {
1256512569 4u8.write(writer)?;
12566- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12570+ if let OutboundHTLCOutcome::Success(preimage, attribution_data ) = outcome {
1256712571 preimages.push(Some(preimage));
12572+ success_attribution_data.push(attribution_data);
1256812573 }
1256912574 let reason: Option<&HTLCFailReason> = outcome.into();
1257012575 reason.write(writer)?;
@@ -12848,6 +12853,7 @@ where
1284812853 (58, self.interactive_tx_signing_session, option), // Added in 0.2
1284912854 (59, self.funding.minimum_depth_override, option), // Added in 0.2
1285012855 (60, self.context.historical_scids, optional_vec), // Added in 0.2
12856+ (61, success_attribution_data, optional_vec),
1285112857 });
1285212858
1285312859 Ok(())
@@ -12969,7 +12975,7 @@ where
1296912975 let outcome = match option {
1297012976 Some(r) => OutboundHTLCOutcome::Failure(r),
1297112977 // Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12972- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12978+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
1297312979 };
1297412980 OutboundHTLCState::RemoteRemoved(outcome)
1297512981 },
@@ -12978,7 +12984,7 @@ where
1297812984 let outcome = match option {
1297912985 Some(r) => OutboundHTLCOutcome::Failure(r),
1298012986 // Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12981- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12987+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
1298212988 };
1298312989 OutboundHTLCState::AwaitingRemoteRevokeToRemove(outcome)
1298412990 },
@@ -12987,7 +12993,7 @@ where
1298712993 let outcome = match option {
1298812994 Some(r) => OutboundHTLCOutcome::Failure(r),
1298912995 // Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12990- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12996+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
1299112997 };
1299212998 OutboundHTLCState::AwaitingRemovedRemoteRevoke(outcome)
1299312999 },
@@ -13163,6 +13169,7 @@ where
1316313169 // Starting in 0.2, all the elements in this vector will be `Some`, but they are still
1316413170 // serialized as options to maintain backwards compatibility
1316513171 let mut preimages: Vec<Option<PaymentPreimage>> = Vec::new();
13172+ let mut success_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1316613173
1316713174 // If we read an old Channel, for simplicity we just treat it as "we never sent an
1316813175 // AnnouncementSignatures" which implies we'll re-send it on reconnect, but that's fine.
@@ -13248,23 +13255,32 @@ where
1324813255 (58, interactive_tx_signing_session, option), // Added in 0.2
1324913256 (59, minimum_depth_override, option), // Added in 0.2
1325013257 (60, historical_scids, optional_vec), // Added in 0.2
13258+ (61, success_attribution_data, optional_vec),
1325113259 });
1325213260
1325313261 let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
1325413262
1325513263 let mut iter = preimages.into_iter();
13264+ let mut success_attribution_data_iter = success_attribution_data.map(Vec::into_iter);
1325613265 for htlc in pending_outbound_htlcs.iter_mut() {
1325713266 match &mut htlc.state {
1325813267 OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(
1325913268 ref mut preimage,
13269+ ref mut attribution_data,
1326013270 ))
1326113271 | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(
1326213272 ref mut preimage,
13273+ ref mut attribution_data,
1326313274 )) => {
1326413275 // This variant was initialized like this further above
1326513276 debug_assert_eq!(preimage, &PaymentPreimage([0u8; 32]));
1326613277 // Flatten and unwrap the preimage; they are always set starting in 0.2.
1326713278 *preimage = iter.next().flatten().ok_or(DecodeError::InvalidValue)?;
13279+
13280+ *attribution_data = success_attribution_data_iter
13281+ .as_mut()
13282+ .and_then(Iterator::next)
13283+ .ok_or(DecodeError::InvalidValue)?;
1326813284 },
1326913285 _ => {},
1327013286 }
0 commit comments