@@ -350,11 +350,11 @@ impl From<&OutboundHTLCState> for OutboundHTLCStateDetails {
350350 // the state yet.
351351 OutboundHTLCState::RemoteRemoved(_) =>
352352 OutboundHTLCStateDetails::Committed,
353- OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) =>
353+ OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) =>
354354 OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveSuccess,
355355 OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Failure(_)) =>
356356 OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFailure,
357- OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) =>
357+ OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _ )) =>
358358 OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveSuccess,
359359 OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Failure(_)) =>
360360 OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFailure,
@@ -389,9 +389,9 @@ impl OutboundHTLCState {
389389 #[rustfmt::skip]
390390 fn preimage(&self) -> Option<PaymentPreimage> {
391391 match self {
392- OutboundHTLCState::RemoteRemoved(OutboundHTLCOutcome::Success(preimage))
393- | OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(preimage))
394- | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(preimage)) => {
392+ OutboundHTLCState::RemoteRemoved(OutboundHTLCOutcome::Success(preimage, _ ))
393+ | OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(preimage, _ ))
394+ | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(preimage, _ )) => {
395395 Some(*preimage)
396396 },
397397 _ => None,
@@ -404,14 +404,14 @@ impl OutboundHTLCState {
404404enum OutboundHTLCOutcome {
405405 /// We started always filling in the preimages here in 0.0.105, and the requirement
406406 /// that the preimages always be filled in was added in 0.2.
407- Success(PaymentPreimage),
407+ Success(PaymentPreimage, #[allow(dead_code)] Option<AttributionData> ),
408408 Failure(HTLCFailReason),
409409}
410410
411411impl<'a> Into<Option<&'a HTLCFailReason>> for &'a OutboundHTLCOutcome {
412412 fn into(self) -> Option<&'a HTLCFailReason> {
413413 match self {
414- OutboundHTLCOutcome::Success(_) => None,
414+ OutboundHTLCOutcome::Success(_, _ ) => None,
415415 OutboundHTLCOutcome::Failure(ref r) => Some(r),
416416 }
417417 }
@@ -4160,7 +4160,7 @@ where
41604160 let (local_balance_before_fee_msat, remote_balance_before_fee_msat) = {
41614161 let mut removed_outbound_total_msat = 0;
41624162 for htlc in self.pending_outbound_htlcs.iter() {
4163- if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) = htlc.state {
4163+ if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _)) = htlc.state {
41644164 removed_outbound_total_msat += htlc.amount_msat;
41654165 }
41664166 }
@@ -4390,7 +4390,7 @@ where
43904390 if !funding.is_outbound() {
43914391 let mut removed_outbound_total_msat = 0;
43924392 for htlc in self.pending_outbound_htlcs.iter() {
4393- if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) = htlc.state {
4393+ if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _)) = htlc.state {
43944394 removed_outbound_total_msat += htlc.amount_msat;
43954395 }
43964396 }
@@ -6653,7 +6653,7 @@ where
66536653 fn mark_outbound_htlc_removed(&mut self, htlc_id: u64, outcome: OutboundHTLCOutcome) -> Result<&OutboundHTLCOutput, ChannelError> {
66546654 for htlc in self.context.pending_outbound_htlcs.iter_mut() {
66556655 if htlc.htlc_id == htlc_id {
6656- if let OutboundHTLCOutcome::Success(ref payment_preimage) = outcome {
6656+ if let OutboundHTLCOutcome::Success(ref payment_preimage, .. ) = outcome {
66576657 let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
66586658 if payment_hash != htlc.payment_hash {
66596659 return Err(ChannelError::close(format!("Remote tried to fulfill HTLC ({}) with an incorrect preimage", htlc_id)));
@@ -6695,7 +6695,7 @@ where
66956695 ));
66966696 }
66976697
6698- let outcome = OutboundHTLCOutcome::Success(msg.payment_preimage);
6698+ let outcome = OutboundHTLCOutcome::Success(msg.payment_preimage, None );
66996699 self.mark_outbound_htlc_removed(msg.htlc_id, outcome).map(|htlc| {
67006700 (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat, htlc.send_timestamp)
67016701 })
@@ -7055,9 +7055,9 @@ where
70557055 log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToRemove due to commitment_signed in channel {}.",
70567056 &htlc.payment_hash, &self.context.channel_id);
70577057 // Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
7058- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
7058+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
70597059 mem::swap(outcome, &mut reason);
7060- if let OutboundHTLCOutcome::Success(preimage) = reason {
7060+ if let OutboundHTLCOutcome::Success(preimage, _ ) = reason {
70617061 // If a user (a) receives an HTLC claim using LDK 0.0.104 or before, then (b)
70627062 // upgrades to LDK 0.0.114 or later before the HTLC is fully resolved, we could
70637063 // have a `Success(None)` reason. In this case we could forget some HTLC
@@ -7609,7 +7609,7 @@ where
76097609 {
76107610 log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
76117611 // Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
7612- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
7612+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
76137613 mem::swap(outcome, &mut reason);
76147614 htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
76157615 require_commitment = true;
@@ -10736,7 +10736,7 @@ where
1073610736 if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
1073710737 log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
1073810738 // Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
10739- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
10739+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
1074010740 mem::swap(outcome, &mut reason);
1074110741 htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
1074210742 }
@@ -12514,6 +12514,7 @@ where
1251412514 // The elements of this vector will always be `Some` starting in 0.2,
1251512515 // but we still serialize the option to maintain backwards compatibility
1251612516 let mut preimages: Vec<Option<&PaymentPreimage>> = vec![];
12517+ let mut fulfill_attribution_data = vec![];
1251712518 let mut pending_outbound_skimmed_fees: Vec<Option<u64>> = Vec::new();
1251812519 let mut pending_outbound_blinding_points: Vec<Option<PublicKey>> = Vec::new();
1251912520
@@ -12539,16 +12540,18 @@ where
1253912540 },
1254012541 &OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref outcome) => {
1254112542 3u8.write(writer)?;
12542- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12543+ if let OutboundHTLCOutcome::Success(preimage, attribution_data ) = outcome {
1254312544 preimages.push(Some(preimage));
12545+ fulfill_attribution_data.push(attribution_data);
1254412546 }
1254512547 let reason: Option<&HTLCFailReason> = outcome.into();
1254612548 reason.write(writer)?;
1254712549 },
1254812550 &OutboundHTLCState::AwaitingRemovedRemoteRevoke(ref outcome) => {
1254912551 4u8.write(writer)?;
12550- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12552+ if let OutboundHTLCOutcome::Success(preimage, attribution_data ) = outcome {
1255112553 preimages.push(Some(preimage));
12554+ fulfill_attribution_data.push(attribution_data);
1255212555 }
1255312556 let reason: Option<&HTLCFailReason> = outcome.into();
1255412557 reason.write(writer)?;
@@ -12832,6 +12835,7 @@ where
1283212835 (58, self.interactive_tx_signing_session, option), // Added in 0.2
1283312836 (59, self.funding.minimum_depth_override, option), // Added in 0.2
1283412837 (60, self.context.historical_scids, optional_vec), // Added in 0.2
12838+ (61, fulfill_attribution_data, optional_vec),
1283512839 });
1283612840
1283712841 Ok(())
@@ -12953,7 +12957,7 @@ where
1295312957 let outcome = match option {
1295412958 Some(r) => OutboundHTLCOutcome::Failure(r),
1295512959 // Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12956- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12960+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
1295712961 };
1295812962 OutboundHTLCState::RemoteRemoved(outcome)
1295912963 },
@@ -12962,7 +12966,7 @@ where
1296212966 let outcome = match option {
1296312967 Some(r) => OutboundHTLCOutcome::Failure(r),
1296412968 // Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12965- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12969+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
1296612970 };
1296712971 OutboundHTLCState::AwaitingRemoteRevokeToRemove(outcome)
1296812972 },
@@ -12971,7 +12975,7 @@ where
1297112975 let outcome = match option {
1297212976 Some(r) => OutboundHTLCOutcome::Failure(r),
1297312977 // Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12974- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12978+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
1297512979 };
1297612980 OutboundHTLCState::AwaitingRemovedRemoteRevoke(outcome)
1297712981 },
@@ -13147,6 +13151,7 @@ where
1314713151 // Starting in 0.2, all the elements in this vector will be `Some`, but they are still
1314813152 // serialized as options to maintain backwards compatibility
1314913153 let mut preimages: Vec<Option<PaymentPreimage>> = Vec::new();
13154+ let mut fulfill_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1315013155
1315113156 // If we read an old Channel, for simplicity we just treat it as "we never sent an
1315213157 // AnnouncementSignatures" which implies we'll re-send it on reconnect, but that's fine.
@@ -13232,23 +13237,32 @@ where
1323213237 (58, interactive_tx_signing_session, option), // Added in 0.2
1323313238 (59, minimum_depth_override, option), // Added in 0.2
1323413239 (60, historical_scids, optional_vec), // Added in 0.2
13240+ (61, fulfill_attribution_data, optional_vec),
1323513241 });
1323613242
1323713243 let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
1323813244
1323913245 let mut iter = preimages.into_iter();
13246+ let mut fulfill_attribution_data_iter = fulfill_attribution_data.map(Vec::into_iter);
1324013247 for htlc in pending_outbound_htlcs.iter_mut() {
1324113248 match &mut htlc.state {
1324213249 OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(
1324313250 ref mut preimage,
13251+ ref mut attribution_data,
1324413252 ))
1324513253 | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(
1324613254 ref mut preimage,
13255+ ref mut attribution_data,
1324713256 )) => {
1324813257 // This variant was initialized like this further above
1324913258 debug_assert_eq!(preimage, &PaymentPreimage([0u8; 32]));
1325013259 // Flatten and unwrap the preimage; they are always set starting in 0.2.
1325113260 *preimage = iter.next().flatten().ok_or(DecodeError::InvalidValue)?;
13261+
13262+ *attribution_data = fulfill_attribution_data_iter
13263+ .as_mut()
13264+ .and_then(Iterator::next)
13265+ .ok_or(DecodeError::InvalidValue)?;
1325213266 },
1325313267 _ => {},
1325413268 }
0 commit comments