@@ -349,11 +349,11 @@ impl From<&OutboundHTLCState> for OutboundHTLCStateDetails {
349349 // the state yet.
350350 OutboundHTLCState::RemoteRemoved(_) =>
351351 OutboundHTLCStateDetails::Committed,
352- OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) =>
352+ OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) =>
353353 OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveSuccess,
354354 OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Failure(_)) =>
355355 OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFailure,
356- OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) =>
356+ OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _ )) =>
357357 OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveSuccess,
358358 OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Failure(_)) =>
359359 OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFailure,
@@ -388,9 +388,9 @@ impl OutboundHTLCState {
388388 #[rustfmt::skip]
389389 fn preimage(&self) -> Option<PaymentPreimage> {
390390 match self {
391- OutboundHTLCState::RemoteRemoved(OutboundHTLCOutcome::Success(preimage))
392- | OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(preimage))
393- | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(preimage)) => {
391+ OutboundHTLCState::RemoteRemoved(OutboundHTLCOutcome::Success(preimage, _ ))
392+ | OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(preimage, _ ))
393+ | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(preimage, _ )) => {
394394 Some(*preimage)
395395 },
396396 _ => None,
@@ -403,14 +403,14 @@ impl OutboundHTLCState {
403403enum OutboundHTLCOutcome {
404404 /// We started always filling in the preimages here in 0.0.105, and the requirement
405405 /// that the preimages always be filled in was added in 0.2.
406- Success(PaymentPreimage),
406+ Success(PaymentPreimage, #[allow(dead_code)] Option<AttributionData> ),
407407 Failure(HTLCFailReason),
408408}
409409
410410impl<'a> Into<Option<&'a HTLCFailReason>> for &'a OutboundHTLCOutcome {
411411 fn into(self) -> Option<&'a HTLCFailReason> {
412412 match self {
413- OutboundHTLCOutcome::Success(_) => None,
413+ OutboundHTLCOutcome::Success(_, _ ) => None,
414414 OutboundHTLCOutcome::Failure(ref r) => Some(r),
415415 }
416416 }
@@ -4161,9 +4161,9 @@ where
41614161 // transaction).
41624162 let mut removed_outbound_total_msat = 0;
41634163 for ref htlc in self.pending_outbound_htlcs.iter() {
4164- if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) = htlc.state {
4164+ if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) = htlc.state {
41654165 removed_outbound_total_msat += htlc.amount_msat;
4166- } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) = htlc.state {
4166+ } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _ )) = htlc.state {
41674167 removed_outbound_total_msat += htlc.amount_msat;
41684168 }
41694169 }
@@ -4409,9 +4409,9 @@ where
44094409
44104410 let mut removed_outbound_total_msat = 0;
44114411 for ref htlc in self.pending_outbound_htlcs.iter() {
4412- if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) = htlc.state {
4412+ if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) = htlc.state {
44134413 removed_outbound_total_msat += htlc.amount_msat;
4414- } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) = htlc.state {
4414+ } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _ )) = htlc.state {
44154415 removed_outbound_total_msat += htlc.amount_msat;
44164416 }
44174417 }
@@ -6678,7 +6678,7 @@ where
66786678 fn mark_outbound_htlc_removed(&mut self, htlc_id: u64, outcome: OutboundHTLCOutcome) -> Result<&OutboundHTLCOutput, ChannelError> {
66796679 for htlc in self.context.pending_outbound_htlcs.iter_mut() {
66806680 if htlc.htlc_id == htlc_id {
6681- if let OutboundHTLCOutcome::Success(ref payment_preimage) = outcome {
6681+ if let OutboundHTLCOutcome::Success(ref payment_preimage, .. ) = outcome {
66826682 let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
66836683 if payment_hash != htlc.payment_hash {
66846684 return Err(ChannelError::close(format!("Remote tried to fulfill HTLC ({}) with an incorrect preimage", htlc_id)));
@@ -6720,7 +6720,7 @@ where
67206720 ));
67216721 }
67226722
6723- let outcome = OutboundHTLCOutcome::Success(msg.payment_preimage);
6723+ let outcome = OutboundHTLCOutcome::Success(msg.payment_preimage, None );
67246724 self.mark_outbound_htlc_removed(msg.htlc_id, outcome).map(|htlc| {
67256725 (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat, htlc.send_timestamp)
67266726 })
@@ -7082,9 +7082,9 @@ where
70827082 log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToRemove due to commitment_signed in channel {}.",
70837083 &htlc.payment_hash, &self.context.channel_id);
70847084 // Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
7085- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
7085+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
70867086 mem::swap(outcome, &mut reason);
7087- if let OutboundHTLCOutcome::Success(preimage) = reason {
7087+ if let OutboundHTLCOutcome::Success(preimage, _ ) = reason {
70887088 // If a user (a) receives an HTLC claim using LDK 0.0.104 or before, then (b)
70897089 // upgrades to LDK 0.0.114 or later before the HTLC is fully resolved, we could
70907090 // have a `Success(None)` reason. In this case we could forget some HTLC
@@ -7636,7 +7636,7 @@ where
76367636 {
76377637 log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
76387638 // Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
7639- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
7639+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
76407640 mem::swap(outcome, &mut reason);
76417641 htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
76427642 require_commitment = true;
@@ -10775,7 +10775,7 @@ where
1077510775 if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
1077610776 log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
1077710777 // Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
10778- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
10778+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
1077910779 mem::swap(outcome, &mut reason);
1078010780 htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
1078110781 }
@@ -12550,6 +12550,7 @@ where
1255012550 // The elements of this vector will always be `Some` starting in 0.2,
1255112551 // but we still serialize the option to maintain backwards compatibility
1255212552 let mut preimages: Vec<Option<&PaymentPreimage>> = vec![];
12553+ let mut success_attribution_data = vec![];
1255312554 let mut pending_outbound_skimmed_fees: Vec<Option<u64>> = Vec::new();
1255412555 let mut pending_outbound_blinding_points: Vec<Option<PublicKey>> = Vec::new();
1255512556
@@ -12575,16 +12576,18 @@ where
1257512576 },
1257612577 &OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref outcome) => {
1257712578 3u8.write(writer)?;
12578- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12579+ if let OutboundHTLCOutcome::Success(preimage, attribution_data ) = outcome {
1257912580 preimages.push(Some(preimage));
12581+ success_attribution_data.push(attribution_data);
1258012582 }
1258112583 let reason: Option<&HTLCFailReason> = outcome.into();
1258212584 reason.write(writer)?;
1258312585 },
1258412586 &OutboundHTLCState::AwaitingRemovedRemoteRevoke(ref outcome) => {
1258512587 4u8.write(writer)?;
12586- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12588+ if let OutboundHTLCOutcome::Success(preimage, attribution_data ) = outcome {
1258712589 preimages.push(Some(preimage));
12590+ success_attribution_data.push(attribution_data);
1258812591 }
1258912592 let reason: Option<&HTLCFailReason> = outcome.into();
1259012593 reason.write(writer)?;
@@ -12868,6 +12871,7 @@ where
1286812871 (58, self.interactive_tx_signing_session, option), // Added in 0.2
1286912872 (59, self.funding.minimum_depth_override, option), // Added in 0.2
1287012873 (60, self.context.historical_scids, optional_vec), // Added in 0.2
12874+ (61, success_attribution_data, optional_vec),
1287112875 });
1287212876
1287312877 Ok(())
@@ -12989,7 +12993,7 @@ where
1298912993 let outcome = match option {
1299012994 Some(r) => OutboundHTLCOutcome::Failure(r),
1299112995 // Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12992- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12996+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
1299312997 };
1299412998 OutboundHTLCState::RemoteRemoved(outcome)
1299512999 },
@@ -12998,7 +13002,7 @@ where
1299813002 let outcome = match option {
1299913003 Some(r) => OutboundHTLCOutcome::Failure(r),
1300013004 // Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
13001- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
13005+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
1300213006 };
1300313007 OutboundHTLCState::AwaitingRemoteRevokeToRemove(outcome)
1300413008 },
@@ -13007,7 +13011,7 @@ where
1300713011 let outcome = match option {
1300813012 Some(r) => OutboundHTLCOutcome::Failure(r),
1300913013 // Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
13010- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
13014+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
1301113015 };
1301213016 OutboundHTLCState::AwaitingRemovedRemoteRevoke(outcome)
1301313017 },
@@ -13183,6 +13187,7 @@ where
1318313187 // Starting in 0.2, all the elements in this vector will be `Some`, but they are still
1318413188 // serialized as options to maintain backwards compatibility
1318513189 let mut preimages: Vec<Option<PaymentPreimage>> = Vec::new();
13190+ let mut success_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1318613191
1318713192 // If we read an old Channel, for simplicity we just treat it as "we never sent an
1318813193 // AnnouncementSignatures" which implies we'll re-send it on reconnect, but that's fine.
@@ -13268,23 +13273,32 @@ where
1326813273 (58, interactive_tx_signing_session, option), // Added in 0.2
1326913274 (59, minimum_depth_override, option), // Added in 0.2
1327013275 (60, historical_scids, optional_vec), // Added in 0.2
13276+ (61, success_attribution_data, optional_vec),
1327113277 });
1327213278
1327313279 let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
1327413280
1327513281 let mut iter = preimages.into_iter();
13282+ let mut success_attribution_data_iter = success_attribution_data.map(Vec::into_iter);
1327613283 for htlc in pending_outbound_htlcs.iter_mut() {
1327713284 match &mut htlc.state {
1327813285 OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(
1327913286 ref mut preimage,
13287+ ref mut attribution_data,
1328013288 ))
1328113289 | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(
1328213290 ref mut preimage,
13291+ ref mut attribution_data,
1328313292 )) => {
1328413293 // This variant was initialized like this further above
1328513294 debug_assert_eq!(preimage, &PaymentPreimage([0u8; 32]));
1328613295 // Flatten and unwrap the preimage; they are always set starting in 0.2.
1328713296 *preimage = iter.next().flatten().ok_or(DecodeError::InvalidValue)?;
13297+
13298+ *attribution_data = success_attribution_data_iter
13299+ .as_mut()
13300+ .and_then(Iterator::next)
13301+ .ok_or(DecodeError::InvalidValue)?;
1328813302 },
1328913303 _ => {},
1329013304 }
0 commit comments