@@ -350,11 +350,11 @@ impl From<&OutboundHTLCState> for OutboundHTLCStateDetails {
350
350
// the state yet.
351
351
OutboundHTLCState::RemoteRemoved(_) =>
352
352
OutboundHTLCStateDetails::Committed,
353
- OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) =>
353
+ OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) =>
354
354
OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveSuccess,
355
355
OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Failure(_)) =>
356
356
OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFailure,
357
- OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) =>
357
+ OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _ )) =>
358
358
OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveSuccess,
359
359
OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Failure(_)) =>
360
360
OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFailure,
@@ -389,9 +389,9 @@ impl OutboundHTLCState {
389
389
#[rustfmt::skip]
390
390
fn preimage(&self) -> Option<PaymentPreimage> {
391
391
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, _ )) => {
395
395
Some(*preimage)
396
396
},
397
397
_ => None,
@@ -404,14 +404,14 @@ impl OutboundHTLCState {
404
404
enum OutboundHTLCOutcome {
405
405
/// We started always filling in the preimages here in 0.0.105, and the requirement
406
406
/// that the preimages always be filled in was added in 0.2.
407
- Success(PaymentPreimage),
407
+ Success(PaymentPreimage, #[allow(dead_code)] Option<AttributionData> ),
408
408
Failure(HTLCFailReason),
409
409
}
410
410
411
411
impl<'a> Into<Option<&'a HTLCFailReason>> for &'a OutboundHTLCOutcome {
412
412
fn into(self) -> Option<&'a HTLCFailReason> {
413
413
match self {
414
- OutboundHTLCOutcome::Success(_) => None,
414
+ OutboundHTLCOutcome::Success(_, _ ) => None,
415
415
OutboundHTLCOutcome::Failure(ref r) => Some(r),
416
416
}
417
417
}
@@ -4160,7 +4160,7 @@ where
4160
4160
let (local_balance_before_fee_msat, remote_balance_before_fee_msat) = {
4161
4161
let mut removed_outbound_total_msat = 0;
4162
4162
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 {
4164
4164
removed_outbound_total_msat += htlc.amount_msat;
4165
4165
}
4166
4166
}
@@ -4390,7 +4390,7 @@ where
4390
4390
if !funding.is_outbound() {
4391
4391
let mut removed_outbound_total_msat = 0;
4392
4392
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 {
4394
4394
removed_outbound_total_msat += htlc.amount_msat;
4395
4395
}
4396
4396
}
@@ -6653,7 +6653,7 @@ where
6653
6653
fn mark_outbound_htlc_removed(&mut self, htlc_id: u64, outcome: OutboundHTLCOutcome) -> Result<&OutboundHTLCOutput, ChannelError> {
6654
6654
for htlc in self.context.pending_outbound_htlcs.iter_mut() {
6655
6655
if htlc.htlc_id == htlc_id {
6656
- if let OutboundHTLCOutcome::Success(ref payment_preimage) = outcome {
6656
+ if let OutboundHTLCOutcome::Success(ref payment_preimage, .. ) = outcome {
6657
6657
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
6658
6658
if payment_hash != htlc.payment_hash {
6659
6659
return Err(ChannelError::close(format!("Remote tried to fulfill HTLC ({}) with an incorrect preimage", htlc_id)));
@@ -6695,7 +6695,7 @@ where
6695
6695
));
6696
6696
}
6697
6697
6698
- let outcome = OutboundHTLCOutcome::Success(msg.payment_preimage);
6698
+ let outcome = OutboundHTLCOutcome::Success(msg.payment_preimage, None );
6699
6699
self.mark_outbound_htlc_removed(msg.htlc_id, outcome).map(|htlc| {
6700
6700
(htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat, htlc.send_timestamp)
6701
6701
})
@@ -7055,9 +7055,9 @@ where
7055
7055
log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToRemove due to commitment_signed in channel {}.",
7056
7056
&htlc.payment_hash, &self.context.channel_id);
7057
7057
// 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 );
7059
7059
mem::swap(outcome, &mut reason);
7060
- if let OutboundHTLCOutcome::Success(preimage) = reason {
7060
+ if let OutboundHTLCOutcome::Success(preimage, _ ) = reason {
7061
7061
// If a user (a) receives an HTLC claim using LDK 0.0.104 or before, then (b)
7062
7062
// upgrades to LDK 0.0.114 or later before the HTLC is fully resolved, we could
7063
7063
// have a `Success(None)` reason. In this case we could forget some HTLC
@@ -7609,7 +7609,7 @@ where
7609
7609
{
7610
7610
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
7611
7611
// 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 );
7613
7613
mem::swap(outcome, &mut reason);
7614
7614
htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
7615
7615
require_commitment = true;
@@ -10736,7 +10736,7 @@ where
10736
10736
if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
10737
10737
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
10738
10738
// 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 );
10740
10740
mem::swap(outcome, &mut reason);
10741
10741
htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
10742
10742
}
@@ -12514,6 +12514,7 @@ where
12514
12514
// The elements of this vector will always be `Some` starting in 0.2,
12515
12515
// but we still serialize the option to maintain backwards compatibility
12516
12516
let mut preimages: Vec<Option<&PaymentPreimage>> = vec![];
12517
+ let mut fulfill_attribution_data = vec![];
12517
12518
let mut pending_outbound_skimmed_fees: Vec<Option<u64>> = Vec::new();
12518
12519
let mut pending_outbound_blinding_points: Vec<Option<PublicKey>> = Vec::new();
12519
12520
@@ -12539,16 +12540,18 @@ where
12539
12540
},
12540
12541
&OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref outcome) => {
12541
12542
3u8.write(writer)?;
12542
- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12543
+ if let OutboundHTLCOutcome::Success(preimage, attribution_data ) = outcome {
12543
12544
preimages.push(Some(preimage));
12545
+ fulfill_attribution_data.push(attribution_data);
12544
12546
}
12545
12547
let reason: Option<&HTLCFailReason> = outcome.into();
12546
12548
reason.write(writer)?;
12547
12549
},
12548
12550
&OutboundHTLCState::AwaitingRemovedRemoteRevoke(ref outcome) => {
12549
12551
4u8.write(writer)?;
12550
- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12552
+ if let OutboundHTLCOutcome::Success(preimage, attribution_data ) = outcome {
12551
12553
preimages.push(Some(preimage));
12554
+ fulfill_attribution_data.push(attribution_data);
12552
12555
}
12553
12556
let reason: Option<&HTLCFailReason> = outcome.into();
12554
12557
reason.write(writer)?;
@@ -12832,6 +12835,7 @@ where
12832
12835
(58, self.interactive_tx_signing_session, option), // Added in 0.2
12833
12836
(59, self.funding.minimum_depth_override, option), // Added in 0.2
12834
12837
(60, self.context.historical_scids, optional_vec), // Added in 0.2
12838
+ (61, fulfill_attribution_data, optional_vec),
12835
12839
});
12836
12840
12837
12841
Ok(())
@@ -12953,7 +12957,7 @@ where
12953
12957
let outcome = match option {
12954
12958
Some(r) => OutboundHTLCOutcome::Failure(r),
12955
12959
// 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 ),
12957
12961
};
12958
12962
OutboundHTLCState::RemoteRemoved(outcome)
12959
12963
},
@@ -12962,7 +12966,7 @@ where
12962
12966
let outcome = match option {
12963
12967
Some(r) => OutboundHTLCOutcome::Failure(r),
12964
12968
// 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 ),
12966
12970
};
12967
12971
OutboundHTLCState::AwaitingRemoteRevokeToRemove(outcome)
12968
12972
},
@@ -12971,7 +12975,7 @@ where
12971
12975
let outcome = match option {
12972
12976
Some(r) => OutboundHTLCOutcome::Failure(r),
12973
12977
// 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 ),
12975
12979
};
12976
12980
OutboundHTLCState::AwaitingRemovedRemoteRevoke(outcome)
12977
12981
},
@@ -13147,6 +13151,7 @@ where
13147
13151
// Starting in 0.2, all the elements in this vector will be `Some`, but they are still
13148
13152
// serialized as options to maintain backwards compatibility
13149
13153
let mut preimages: Vec<Option<PaymentPreimage>> = Vec::new();
13154
+ let mut fulfill_attribution_data: Option<Vec<Option<AttributionData>>> = None;
13150
13155
13151
13156
// If we read an old Channel, for simplicity we just treat it as "we never sent an
13152
13157
// AnnouncementSignatures" which implies we'll re-send it on reconnect, but that's fine.
@@ -13232,23 +13237,32 @@ where
13232
13237
(58, interactive_tx_signing_session, option), // Added in 0.2
13233
13238
(59, minimum_depth_override, option), // Added in 0.2
13234
13239
(60, historical_scids, optional_vec), // Added in 0.2
13240
+ (61, fulfill_attribution_data, optional_vec),
13235
13241
});
13236
13242
13237
13243
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
13238
13244
13239
13245
let mut iter = preimages.into_iter();
13246
+ let mut fulfill_attribution_data_iter = fulfill_attribution_data.map(Vec::into_iter);
13240
13247
for htlc in pending_outbound_htlcs.iter_mut() {
13241
13248
match &mut htlc.state {
13242
13249
OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(
13243
13250
ref mut preimage,
13251
+ ref mut attribution_data,
13244
13252
))
13245
13253
| OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(
13246
13254
ref mut preimage,
13255
+ ref mut attribution_data,
13247
13256
)) => {
13248
13257
// This variant was initialized like this further above
13249
13258
debug_assert_eq!(preimage, &PaymentPreimage([0u8; 32]));
13250
13259
// Flatten and unwrap the preimage; they are always set starting in 0.2.
13251
13260
*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)?;
13252
13266
},
13253
13267
_ => {},
13254
13268
}
0 commit comments