@@ -348,11 +348,11 @@ impl From<&OutboundHTLCState> for OutboundHTLCStateDetails {
348
348
// the state yet.
349
349
OutboundHTLCState::RemoteRemoved(_) =>
350
350
OutboundHTLCStateDetails::Committed,
351
- OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) =>
351
+ OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) =>
352
352
OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveSuccess,
353
353
OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Failure(_)) =>
354
354
OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFailure,
355
- OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) =>
355
+ OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _ )) =>
356
356
OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveSuccess,
357
357
OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Failure(_)) =>
358
358
OutboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFailure,
@@ -387,9 +387,9 @@ impl OutboundHTLCState {
387
387
#[rustfmt::skip]
388
388
fn preimage(&self) -> Option<PaymentPreimage> {
389
389
match self {
390
- OutboundHTLCState::RemoteRemoved(OutboundHTLCOutcome::Success(preimage))
391
- | OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(preimage))
392
- | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(preimage)) => {
390
+ OutboundHTLCState::RemoteRemoved(OutboundHTLCOutcome::Success(preimage, _ ))
391
+ | OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(preimage, _ ))
392
+ | OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(preimage, _ )) => {
393
393
Some(*preimage)
394
394
},
395
395
_ => None,
@@ -402,14 +402,14 @@ impl OutboundHTLCState {
402
402
enum OutboundHTLCOutcome {
403
403
/// We started always filling in the preimages here in 0.0.105, and the requirement
404
404
/// that the preimages always be filled in was added in 0.2.
405
- Success(PaymentPreimage),
405
+ Success(PaymentPreimage, Option<AttributionData> ),
406
406
Failure(HTLCFailReason),
407
407
}
408
408
409
409
impl<'a> Into<Option<&'a HTLCFailReason>> for &'a OutboundHTLCOutcome {
410
410
fn into(self) -> Option<&'a HTLCFailReason> {
411
411
match self {
412
- OutboundHTLCOutcome::Success(_) => None,
412
+ OutboundHTLCOutcome::Success(__, _) => None,
413
413
OutboundHTLCOutcome::Failure(ref r) => Some(r),
414
414
}
415
415
}
@@ -1181,7 +1181,7 @@ pub(super) struct MonitorRestoreUpdates {
1181
1181
pub order: RAACommitmentOrder,
1182
1182
pub accepted_htlcs: Vec<(PendingHTLCInfo, u64)>,
1183
1183
pub failed_htlcs: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
1184
- pub finalized_claimed_htlcs: Vec<HTLCSource>,
1184
+ pub finalized_claimed_htlcs: Vec<( HTLCSource, Option<AttributionData>) >,
1185
1185
pub pending_update_adds: Vec<msgs::UpdateAddHTLC>,
1186
1186
pub funding_broadcastable: Option<Transaction>,
1187
1187
pub channel_ready: Option<msgs::ChannelReady>,
@@ -2313,7 +2313,7 @@ where
2313
2313
// but need to handle this somehow or we run the risk of losing HTLCs!
2314
2314
monitor_pending_forwards: Vec<(PendingHTLCInfo, u64)>,
2315
2315
monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
2316
- monitor_pending_finalized_fulfills: Vec<HTLCSource>,
2316
+ monitor_pending_finalized_fulfills: Vec<( HTLCSource, Option<AttributionData>) >,
2317
2317
monitor_pending_update_adds: Vec<msgs::UpdateAddHTLC>,
2318
2318
monitor_pending_tx_signatures: Option<msgs::TxSignatures>,
2319
2319
@@ -4160,9 +4160,9 @@ where
4160
4160
// transaction).
4161
4161
let mut removed_outbound_total_msat = 0;
4162
4162
for ref htlc in self.pending_outbound_htlcs.iter() {
4163
- if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) = htlc.state {
4163
+ if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) = htlc.state {
4164
4164
removed_outbound_total_msat += htlc.amount_msat;
4165
- } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) = htlc.state {
4165
+ } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _ )) = htlc.state {
4166
4166
removed_outbound_total_msat += htlc.amount_msat;
4167
4167
}
4168
4168
}
@@ -4425,9 +4425,9 @@ where
4425
4425
4426
4426
let mut removed_outbound_total_msat = 0;
4427
4427
for ref htlc in self.pending_outbound_htlcs.iter() {
4428
- if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_)) = htlc.state {
4428
+ if let OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(_, _ )) = htlc.state {
4429
4429
removed_outbound_total_msat += htlc.amount_msat;
4430
- } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_)) = htlc.state {
4430
+ } else if let OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(_, _ )) = htlc.state {
4431
4431
removed_outbound_total_msat += htlc.amount_msat;
4432
4432
}
4433
4433
}
@@ -6705,7 +6705,7 @@ where
6705
6705
fn mark_outbound_htlc_removed(&mut self, htlc_id: u64, outcome: OutboundHTLCOutcome) -> Result<&OutboundHTLCOutput, ChannelError> {
6706
6706
for htlc in self.context.pending_outbound_htlcs.iter_mut() {
6707
6707
if htlc.htlc_id == htlc_id {
6708
- if let OutboundHTLCOutcome::Success(ref payment_preimage) = outcome {
6708
+ if let OutboundHTLCOutcome::Success(ref payment_preimage, .. ) = outcome {
6709
6709
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
6710
6710
if payment_hash != htlc.payment_hash {
6711
6711
return Err(ChannelError::close(format!("Remote tried to fulfill HTLC ({}) with an incorrect preimage", htlc_id)));
@@ -6749,7 +6749,7 @@ where
6749
6749
6750
6750
self.mark_outbound_htlc_removed(
6751
6751
msg.htlc_id,
6752
- OutboundHTLCOutcome::Success(msg.payment_preimage),
6752
+ OutboundHTLCOutcome::Success(msg.payment_preimage, msg.attribution_data.clone() ),
6753
6753
)
6754
6754
.map(|htlc| {
6755
6755
(htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat, htlc.send_timestamp)
@@ -7091,9 +7091,9 @@ where
7091
7091
log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToRemove due to commitment_signed in channel {}.",
7092
7092
&htlc.payment_hash, &self.context.channel_id);
7093
7093
// Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
7094
- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
7094
+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
7095
7095
mem::swap(outcome, &mut reason);
7096
- if let OutboundHTLCOutcome::Success(preimage) = reason {
7096
+ if let OutboundHTLCOutcome::Success(preimage, _ ) = reason {
7097
7097
// If a user (a) receives an HTLC claim using LDK 0.0.104 or before, then (b)
7098
7098
// upgrades to LDK 0.0.114 or later before the HTLC is fully resolved, we could
7099
7099
// have a `Success(None)` reason. In this case we could forget some HTLC
@@ -7547,19 +7547,21 @@ where
7547
7547
&htlc.payment_hash
7548
7548
);
7549
7549
// We really want take() here, but, again, non-mut ref :(
7550
- if let OutboundHTLCOutcome::Failure(mut reason) = outcome.clone() {
7551
- if let (Some(timestamp), Some(now)) = (htlc.send_timestamp, now) {
7552
- let elapsed_millis = now.saturating_sub(timestamp).as_millis();
7553
- let elapsed_units = elapsed_millis / HOLD_TIME_UNIT_MILLIS;
7554
- let hold_time = u32::try_from(elapsed_units).unwrap_or(u32::MAX);
7555
- reason.set_hold_time(hold_time);
7556
- }
7557
-
7558
- revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
7559
- } else {
7560
- finalized_claimed_htlcs.push(htlc.source.clone());
7561
- // They fulfilled, so we sent them money
7562
- value_to_self_msat_diff -= htlc.amount_msat as i64;
7550
+ match outcome.clone() {
7551
+ OutboundHTLCOutcome::Failure(mut reason) => {
7552
+ if let (Some(timestamp), Some(now)) = (htlc.send_timestamp, now) {
7553
+ let elapsed_millis = now.saturating_sub(timestamp).as_millis();
7554
+ let elapsed_units = elapsed_millis / HOLD_TIME_UNIT_MILLIS;
7555
+ let hold_time = u32::try_from(elapsed_units).unwrap_or(u32::MAX);
7556
+ reason.set_hold_time(hold_time);
7557
+ }
7558
+ revoked_htlcs.push((htlc.source.clone(), htlc.payment_hash, reason));
7559
+ },
7560
+ OutboundHTLCOutcome::Success(_, attribution_data) => {
7561
+ finalized_claimed_htlcs.push((htlc.source.clone(), attribution_data));
7562
+ // They fulfilled, so we sent them money
7563
+ value_to_self_msat_diff -= htlc.amount_msat as i64;
7564
+ },
7563
7565
}
7564
7566
false
7565
7567
} else {
@@ -7643,7 +7645,7 @@ where
7643
7645
{
7644
7646
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
7645
7647
// Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
7646
- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
7648
+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
7647
7649
mem::swap(outcome, &mut reason);
7648
7650
htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
7649
7651
require_commitment = true;
@@ -8049,7 +8051,7 @@ where
8049
8051
&mut self, resend_raa: bool, resend_commitment: bool, resend_channel_ready: bool,
8050
8052
mut pending_forwards: Vec<(PendingHTLCInfo, u64)>,
8051
8053
mut pending_fails: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
8052
- mut pending_finalized_claimed_htlcs: Vec<HTLCSource>,
8054
+ mut pending_finalized_claimed_htlcs: Vec<( HTLCSource, Option<AttributionData>) >,
8053
8055
) {
8054
8056
self.context.monitor_pending_revoke_and_ack |= resend_raa;
8055
8057
self.context.monitor_pending_commitment_signed |= resend_commitment;
@@ -10776,7 +10778,7 @@ where
10776
10778
if let &mut OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref mut outcome) = &mut htlc.state {
10777
10779
log_trace!(logger, " ...promoting outbound AwaitingRemoteRevokeToRemove {} to AwaitingRemovedRemoteRevoke", &htlc.payment_hash);
10778
10780
// Swap against a dummy variant to avoid a potentially expensive clone of `OutboundHTLCOutcome::Failure(HTLCFailReason)`
10779
- let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]));
10781
+ let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None );
10780
10782
mem::swap(outcome, &mut reason);
10781
10783
htlc.state = OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason);
10782
10784
}
@@ -12520,10 +12522,10 @@ where
12520
12522
1u8.write(writer)?;
12521
12523
(hash, code).write(writer)?;
12522
12524
},
12523
- InboundHTLCRemovalReason::Fulfill(preimage, _) => {
12524
- // TODO: Persistence
12525
+ InboundHTLCRemovalReason::Fulfill(preimage, attribution_data) => {
12525
12526
2u8.write(writer)?;
12526
12527
preimage.write(writer)?;
12528
+ removed_htlc_attribution_data.push(&attribution_data);
12527
12529
},
12528
12530
}
12529
12531
},
@@ -12558,15 +12560,15 @@ where
12558
12560
},
12559
12561
&OutboundHTLCState::AwaitingRemoteRevokeToRemove(ref outcome) => {
12560
12562
3u8.write(writer)?;
12561
- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12563
+ if let OutboundHTLCOutcome::Success(preimage, _ ) = outcome {
12562
12564
preimages.push(Some(preimage));
12563
12565
}
12564
12566
let reason: Option<&HTLCFailReason> = outcome.into();
12565
12567
reason.write(writer)?;
12566
12568
},
12567
12569
&OutboundHTLCState::AwaitingRemovedRemoteRevoke(ref outcome) => {
12568
12570
4u8.write(writer)?;
12569
- if let OutboundHTLCOutcome::Success(preimage) = outcome {
12571
+ if let OutboundHTLCOutcome::Success(preimage, _ ) = outcome {
12570
12572
preimages.push(Some(preimage));
12571
12573
}
12572
12574
let reason: Option<&HTLCFailReason> = outcome.into();
@@ -12972,7 +12974,7 @@ where
12972
12974
let outcome = match option {
12973
12975
Some(r) => OutboundHTLCOutcome::Failure(r),
12974
12976
// Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12975
- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12977
+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
12976
12978
};
12977
12979
OutboundHTLCState::RemoteRemoved(outcome)
12978
12980
},
@@ -12981,7 +12983,7 @@ where
12981
12983
let outcome = match option {
12982
12984
Some(r) => OutboundHTLCOutcome::Failure(r),
12983
12985
// Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12984
- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12986
+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
12985
12987
};
12986
12988
OutboundHTLCState::AwaitingRemoteRevokeToRemove(outcome)
12987
12989
},
@@ -12990,7 +12992,7 @@ where
12990
12992
let outcome = match option {
12991
12993
Some(r) => OutboundHTLCOutcome::Failure(r),
12992
12994
// Initialize this variant with a dummy preimage, the actual preimage will be filled in further down
12993
- None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32])),
12995
+ None => OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None ),
12994
12996
};
12995
12997
OutboundHTLCState::AwaitingRemovedRemoteRevoke(outcome)
12996
12998
},
@@ -13260,6 +13262,7 @@ where
13260
13262
match &mut htlc.state {
13261
13263
OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(
13262
13264
ref mut preimage,
13265
+ ..,
13263
13266
)) => {
13264
13267
// This variant was initialized like this further above
13265
13268
debug_assert_eq!(preimage, &PaymentPreimage([0u8; 32]));
@@ -13268,6 +13271,7 @@ where
13268
13271
},
13269
13272
OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(
13270
13273
ref mut preimage,
13274
+ ..,
13271
13275
)) => {
13272
13276
// This variant was initialized like this further above
13273
13277
debug_assert_eq!(preimage, &PaymentPreimage([0u8; 32]));
0 commit comments