@@ -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
}
@@ -4142,7 +4142,7 @@ where
4142
4142
let (local_balance_before_fee_msat, remote_balance_before_fee_msat) = {
4143
4143
let mut removed_outbound_total_msat = 0;
4144
4144
for htlc in self.pending_outbound_htlcs.iter() {
4145
- if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) = htlc.state {
4145
+ if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _)) = htlc.state {
4146
4146
removed_outbound_total_msat += htlc.amount_msat;
4147
4147
}
4148
4148
}
@@ -4372,7 +4372,7 @@ where
4372
4372
if !funding.is_outbound() {
4373
4373
let mut removed_outbound_total_msat = 0;
4374
4374
for htlc in self.pending_outbound_htlcs.iter() {
4375
- if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) = htlc.state {
4375
+ if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _)) = htlc.state {
4376
4376
removed_outbound_total_msat += htlc.amount_msat;
4377
4377
}
4378
4378
}
@@ -6635,7 +6635,7 @@ where
6635
6635
fn mark_outbound_htlc_removed(&mut self, htlc_id: u64, outcome: OutboundHTLCOutcome) -> Result<&OutboundHTLCOutput, ChannelError> {
6636
6636
for htlc in self.context.pending_outbound_htlcs.iter_mut() {
6637
6637
if htlc.htlc_id == htlc_id {
6638
- if let OutboundHTLCOutcome::Success(ref payment_preimage) = outcome {
6638
+ if let OutboundHTLCOutcome::Success(ref payment_preimage, .. ) = outcome {
6639
6639
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
6640
6640
if payment_hash != htlc.payment_hash {
6641
6641
return Err(ChannelError::close(format!("Remote tried to fulfill HTLC ({}) with an incorrect preimage", htlc_id)));
@@ -6677,7 +6677,7 @@ where
6677
6677
));
6678
6678
}
6679
6679
6680
- let outcome = OutboundHTLCOutcome::Success(msg.payment_preimage);
6680
+ let outcome = OutboundHTLCOutcome::Success(msg.payment_preimage, None );
6681
6681
self.mark_outbound_htlc_removed(msg.htlc_id, outcome).map(|htlc| {
6682
6682
(htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat, htlc.send_timestamp)
6683
6683
})
@@ -7037,9 +7037,9 @@ where
7037
7037
log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToRemove due to commitment_signed in channel {}.",
7038
7038
&htlc.payment_hash, &self.context.channel_id);
7039
7039
// Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
7040
- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
7040
+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
7041
7041
mem::swap(outcome, &mut reason);
7042
- if let OutboundHTLCOutcome::Success(preimage) = reason {
7042
+ if let OutboundHTLCOutcome::Success(preimage, _ ) = reason {
7043
7043
// If a user (a) receives an HTLC claim using LDK 0.0.104 or before, then (b)
7044
7044
// upgrades to LDK 0.0.114 or later before the HTLC is fully resolved, we could
7045
7045
// have a `Success(None)` reason. In this case we could forget some HTLC
@@ -7591,7 +7591,7 @@ where
7591
7591
{
7592
7592
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
7593
7593
// Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
7594
- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
7594
+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
7595
7595
mem::swap(outcome, &mut reason);
7596
7596
htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
7597
7597
require_commitment = true;
@@ -10718,7 +10718,7 @@ where
10718
10718
if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
10719
10719
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
10720
10720
// Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
10721
- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
10721
+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
10722
10722
mem::swap(outcome, &mut reason);
10723
10723
htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
10724
10724
}
@@ -12489,6 +12489,7 @@ where
12489
12489
// The elements of this vector will always be `Some` starting in 0.2,
12490
12490
// but we still serialize the option to maintain backwards compatibility
12491
12491
let mut preimages: Vec<Option<&PaymentPreimage>> = vec![];
12492
+ let mut fulfill_attribution_data = vec![];
12492
12493
let mut pending_outbound_skimmed_fees: Vec<Option<u64>> = Vec::new();
12493
12494
let mut pending_outbound_blinding_points: Vec<Option<PublicKey>> = Vec::new();
12494
12495
@@ -12514,16 +12515,18 @@ where
12514
12515
},
12515
12516
&OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref outcome) => {
12516
12517
3u8.write(writer)?;
12517
- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12518
+ if let OutboundHTLCOutcome::Success(preimage, attribution_data ) = outcome {
12518
12519
preimages.push(Some(preimage));
12520
+ fulfill_attribution_data.push(attribution_data);
12519
12521
}
12520
12522
let reason: Option<&HTLCFailReason> = outcome.into();
12521
12523
reason.write(writer)?;
12522
12524
},
12523
12525
&OutboundHTLCState::AwaitingRemovedRemoteRevoke(ref outcome) => {
12524
12526
4u8.write(writer)?;
12525
- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12527
+ if let OutboundHTLCOutcome::Success(preimage, attribution_data ) = outcome {
12526
12528
preimages.push(Some(preimage));
12529
+ fulfill_attribution_data.push(attribution_data);
12527
12530
}
12528
12531
let reason: Option<&HTLCFailReason> = outcome.into();
12529
12532
reason.write(writer)?;
@@ -12807,6 +12810,7 @@ where
12807
12810
(58, self.interactive_tx_signing_session, option), // Added in 0.2
12808
12811
(59, self.funding.minimum_depth_override, option), // Added in 0.2
12809
12812
(60, self.context.historical_scids, optional_vec), // Added in 0.2
12813
+ (61, fulfill_attribution_data, optional_vec),
12810
12814
});
12811
12815
12812
12816
Ok(())
@@ -12928,7 +12932,7 @@ where
12928
12932
let outcome = match option {
12929
12933
Some(r) => OutboundHTLCOutcome::Failure(r),
12930
12934
// Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12931
- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12935
+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
12932
12936
};
12933
12937
OutboundHTLCState::RemoteRemoved(outcome)
12934
12938
},
@@ -12937,7 +12941,7 @@ where
12937
12941
let outcome = match option {
12938
12942
Some(r) => OutboundHTLCOutcome::Failure(r),
12939
12943
// Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12940
- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12944
+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
12941
12945
};
12942
12946
OutboundHTLCState::AwaitingRemoteRevokeToRemove(outcome)
12943
12947
},
@@ -12946,7 +12950,7 @@ where
12946
12950
let outcome = match option {
12947
12951
Some(r) => OutboundHTLCOutcome::Failure(r),
12948
12952
// Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12949
- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12953
+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
12950
12954
};
12951
12955
OutboundHTLCState::AwaitingRemovedRemoteRevoke(outcome)
12952
12956
},
@@ -13122,6 +13126,7 @@ where
13122
13126
// Starting in 0.2, all the elements in this vector will be `Some`, but they are still
13123
13127
// serialized as options to maintain backwards compatibility
13124
13128
let mut preimages: Vec<Option<PaymentPreimage>> = Vec::new();
13129
+ let mut fulfill_attribution_data: Option<Vec<Option<AttributionData>>> = None;
13125
13130
13126
13131
// If we read an old Channel, for simplicity we just treat it as "we never sent an
13127
13132
// AnnouncementSignatures" which implies we'll re-send it on reconnect, but that's fine.
@@ -13207,23 +13212,32 @@ where
13207
13212
(58, interactive_tx_signing_session, option), // Added in 0.2
13208
13213
(59, minimum_depth_override, option), // Added in 0.2
13209
13214
(60, historical_scids, optional_vec), // Added in 0.2
13215
+ (61, fulfill_attribution_data, optional_vec),
13210
13216
});
13211
13217
13212
13218
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
13213
13219
13214
13220
let mut iter = preimages.into_iter();
13221
+ let mut fulfill_attribution_data_iter = fulfill_attribution_data.map(Vec::into_iter);
13215
13222
for htlc in pending_outbound_htlcs.iter_mut() {
13216
13223
match &mut htlc.state {
13217
13224
OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(
13218
13225
ref mut preimage,
13226
+ ref mut attribution_data,
13219
13227
))
13220
13228
| OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(
13221
13229
ref mut preimage,
13230
+ ref mut attribution_data,
13222
13231
)) => {
13223
13232
// This variant was initialized like this further above
13224
13233
debug_assert_eq!(preimage, &PaymentPreimage([0u8; 32]));
13225
13234
// Flatten and unwrap the preimage; they are always set starting in 0.2.
13226
13235
*preimage = iter.next().flatten().ok_or(DecodeError::InvalidValue)?;
13236
+
13237
+ *attribution_data = fulfill_attribution_data_iter
13238
+ .as_mut()
13239
+ .and_then(Iterator::next)
13240
+ .ok_or(DecodeError::InvalidValue)?;
13227
13241
},
13228
13242
_ => {},
13229
13243
}
0 commit comments