@@ -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
@@ -7543,16 +7543,18 @@ where
75437543 &htlc.payment_hash
75447544 );
75457545 // We really want take() here, but, again, non-mut ref :(
7546- if let OutboundHTLCOutcome::Failure(mut reason) = outcome.clone() {
7547- hold_time(htlc.send_timestamp, now).map(|hold_time| {
7548- reason.set_hold_time(hold_time);
7549- });
7550-
7551- revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
7552- } else {
7553- finalized_claimed_htlcs.push(htlc.source.clone());
7554- // They fulfilled, so we sent them money
7555- value_to_self_msat_diff -= htlc.amount_msat as i64;
7546+ match outcome.clone() {
7547+ OutboundHTLCOutcome::Failure(mut reason) => {
7548+ hold_time(htlc.send_timestamp, now).map(|hold_time| {
7549+ reason.set_hold_time(hold_time);
7550+ });
7551+ revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
7552+ },
7553+ OutboundHTLCOutcome::Success(..) => {
7554+ finalized_claimed_htlcs.push(htlc.source.clone());
7555+ // They fulfilled, so we sent them money
7556+ value_to_self_msat_diff -= htlc.amount_msat as i64;
7557+ },
75567558 }
75577559 false
75587560 } else {
@@ -7636,7 +7638,7 @@ where
76367638 {
76377639 log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
76387640 // Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
7639- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
7641+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
76407642 mem::swap(outcome, &mut reason);
76417643 htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
76427644 require_commitment = true;
@@ -10775,7 +10777,7 @@ where
1077510777 if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
1077610778 log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
1077710779 // Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
10778- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
10780+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
1077910781 mem::swap(outcome, &mut reason);
1078010782 htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
1078110783 }
@@ -12550,6 +12552,7 @@ where
1255012552 // The elements of this vector will always be `Some` starting in 0.2,
1255112553 // but we still serialize the option to maintain backwards compatibility
1255212554 let mut preimages: Vec<Option<&PaymentPreimage>> = vec![];
12555+ let mut success_attribution_data = vec![];
1255312556 let mut pending_outbound_skimmed_fees: Vec<Option<u64>> = Vec::new();
1255412557 let mut pending_outbound_blinding_points: Vec<Option<PublicKey>> = Vec::new();
1255512558
@@ -12575,16 +12578,18 @@ where
1257512578 },
1257612579 &OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref outcome) => {
1257712580 3u8.write(writer)?;
12578- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12581+ if let OutboundHTLCOutcome::Success(preimage, attribution_data ) = outcome {
1257912582 preimages.push(Some(preimage));
12583+ success_attribution_data.push(attribution_data);
1258012584 }
1258112585 let reason: Option<&HTLCFailReason> = outcome.into();
1258212586 reason.write(writer)?;
1258312587 },
1258412588 &OutboundHTLCState::AwaitingRemovedRemoteRevoke(ref outcome) => {
1258512589 4u8.write(writer)?;
12586- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12590+ if let OutboundHTLCOutcome::Success(preimage, attribution_data ) = outcome {
1258712591 preimages.push(Some(preimage));
12592+ success_attribution_data.push(attribution_data);
1258812593 }
1258912594 let reason: Option<&HTLCFailReason> = outcome.into();
1259012595 reason.write(writer)?;
@@ -12868,6 +12873,7 @@ where
1286812873 (58, self.interactive_tx_signing_session, option), // Added in 0.2
1286912874 (59, self.funding.minimum_depth_override, option), // Added in 0.2
1287012875 (60, self.context.historical_scids, optional_vec), // Added in 0.2
12876+ (61, success_attribution_data, optional_vec),
1287112877 });
1287212878
1287312879 Ok(())
@@ -12989,7 +12995,7 @@ where
1298912995 let outcome = match option {
1299012996 Some(r) => OutboundHTLCOutcome::Failure(r),
1299112997 // Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12992- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12998+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
1299312999 };
1299413000 OutboundHTLCState::RemoteRemoved(outcome)
1299513001 },
@@ -12998,7 +13004,7 @@ where
1299813004 let outcome = match option {
1299913005 Some(r) => OutboundHTLCOutcome::Failure(r),
1300013006 // Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
13001- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
13007+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
1300213008 };
1300313009 OutboundHTLCState::AwaitingRemoteRevokeToRemove(outcome)
1300413010 },
@@ -13007,7 +13013,7 @@ where
1300713013 let outcome = match option {
1300813014 Some(r) => OutboundHTLCOutcome::Failure(r),
1300913015 // Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
13010- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
13016+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
1301113017 };
1301213018 OutboundHTLCState::AwaitingRemovedRemoteRevoke(outcome)
1301313019 },
@@ -13183,6 +13189,7 @@ where
1318313189 // Starting in 0.2, all the elements in this vector will be `Some`, but they are still
1318413190 // serialized as options to maintain backwards compatibility
1318513191 let mut preimages: Vec<Option<PaymentPreimage>> = Vec::new();
13192+ let mut success_attribution_data: Option<Vec<Option<AttributionData>>> = None;
1318613193
1318713194 // If we read an old Channel, for simplicity we just treat it as "we never sent an
1318813195 // AnnouncementSignatures" which implies we'll re-send it on reconnect, but that's fine.
@@ -13268,23 +13275,32 @@ where
1326813275 (58, interactive_tx_signing_session, option), // Added in 0.2
1326913276 (59, minimum_depth_override, option), // Added in 0.2
1327013277 (60, historical_scids, optional_vec), // Added in 0.2
13278+ (61, success_attribution_data, optional_vec),
1327113279 });
1327213280
1327313281 let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
1327413282
1327513283 let mut iter = preimages.into_iter();
13284+ let mut success_attribution_data_iter = success_attribution_data.map(Vec::into_iter);
1327613285 for htlc in pending_outbound_htlcs.iter_mut() {
1327713286 match &mut htlc.state {
1327813287 OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(
1327913288 ref mut preimage,
13289+ ref mut attribution_data,
1328013290 ))
1328113291 | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(
1328213292 ref mut preimage,
13293+ ref mut attribution_data,
1328313294 )) => {
1328413295 // This variant was initialized like this further above
1328513296 debug_assert_eq!(preimage, &PaymentPreimage([0u8; 32]));
1328613297 // Flatten and unwrap the preimage; they are always set starting in 0.2.
1328713298 *preimage = iter.next().flatten().ok_or(DecodeError::InvalidValue)?;
13299+
13300+ *attribution_data = success_attribution_data_iter
13301+ .as_mut()
13302+ .and_then(Iterator::next)
13303+ .ok_or(DecodeError::InvalidValue)?;
1328813304 },
1328913305 _ => {},
1329013306 }
0 commit comments