@@ -138,7 +138,7 @@ enum FeeUpdateState {
138
138
enum InboundHTLCRemovalReason {
139
139
FailRelay(msgs::OnionErrorPacket),
140
140
FailMalformed(([u8; 32], u16)),
141
- Fulfill(PaymentPreimage),
141
+ Fulfill(PaymentPreimage, Option<AttributionData> ),
142
142
}
143
143
144
144
/// Represents the resolution status of an inbound HTLC.
@@ -234,7 +234,7 @@ impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> {
234
234
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
235
235
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailMalformed(_)) =>
236
236
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
237
- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) =>
237
+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_, _ )) =>
238
238
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFulfill),
239
239
}
240
240
}
@@ -266,7 +266,7 @@ impl InboundHTLCState {
266
266
267
267
fn preimage(&self) -> Option<PaymentPreimage> {
268
268
match self {
269
- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage)) => {
269
+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage, _ )) => {
270
270
Some(*preimage)
271
271
},
272
272
_ => None,
@@ -466,6 +466,7 @@ enum HTLCUpdateAwaitingACK {
466
466
},
467
467
ClaimHTLC {
468
468
payment_preimage: PaymentPreimage,
469
+ attribution_data: Option<AttributionData>,
469
470
htlc_id: u64,
470
471
},
471
472
FailHTLC {
@@ -6214,7 +6215,7 @@ where
6214
6215
assert!(!self.context.channel_state.can_generate_new_commitment());
6215
6216
let mon_update_id = self.context.latest_monitor_update_id; // Forget the ChannelMonitor update
6216
6217
let fulfill_resp =
6217
- self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, logger);
6218
+ self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, None, logger);
6218
6219
self.context.latest_monitor_update_id = mon_update_id;
6219
6220
if let UpdateFulfillFetch::NewClaim { update_blocked, .. } = fulfill_resp {
6220
6221
assert!(update_blocked); // The HTLC must have ended up in the holding cell.
@@ -6223,7 +6224,8 @@ where
6223
6224
6224
6225
fn get_update_fulfill_htlc<L: Deref>(
6225
6226
&mut self, htlc_id_arg: u64, payment_preimage_arg: PaymentPreimage,
6226
- payment_info: Option<PaymentClaimDetails>, logger: &L,
6227
+ payment_info: Option<PaymentClaimDetails>, attribution_data: Option<AttributionData>,
6228
+ logger: &L,
6227
6229
) -> UpdateFulfillFetch
6228
6230
where
6229
6231
L::Target: Logger,
@@ -6258,7 +6260,7 @@ where
6258
6260
match htlc.state {
6259
6261
InboundHTLCState::Committed => {},
6260
6262
InboundHTLCState::LocalRemoved(ref reason) => {
6261
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
6263
+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
6262
6264
} else {
6263
6265
log_warn!(logger, "Have preimage and want to fulfill HTLC with payment hash {} we already failed against channel {}", &htlc.payment_hash, &self.context.channel_id());
6264
6266
debug_assert!(
@@ -6339,6 +6341,7 @@ where
6339
6341
self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
6340
6342
payment_preimage: payment_preimage_arg,
6341
6343
htlc_id: htlc_id_arg,
6344
+ attribution_data,
6342
6345
});
6343
6346
return UpdateFulfillFetch::NewClaim {
6344
6347
monitor_update,
@@ -6369,6 +6372,7 @@ where
6369
6372
);
6370
6373
htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(
6371
6374
payment_preimage_arg.clone(),
6375
+ attribution_data,
6372
6376
));
6373
6377
}
6374
6378
@@ -6377,13 +6381,20 @@ where
6377
6381
6378
6382
pub fn get_update_fulfill_htlc_and_commit<L: Deref>(
6379
6383
&mut self, htlc_id: u64, payment_preimage: PaymentPreimage,
6380
- payment_info: Option<PaymentClaimDetails>, logger: &L,
6384
+ payment_info: Option<PaymentClaimDetails>, attribution_data: Option<AttributionData>,
6385
+ logger: &L,
6381
6386
) -> UpdateFulfillCommitFetch
6382
6387
where
6383
6388
L::Target: Logger,
6384
6389
{
6385
6390
let release_cs_monitor = self.context.blocked_monitor_updates.is_empty();
6386
- match self.get_update_fulfill_htlc(htlc_id, payment_preimage, payment_info, logger) {
6391
+ match self.get_update_fulfill_htlc(
6392
+ htlc_id,
6393
+ payment_preimage,
6394
+ payment_info,
6395
+ attribution_data,
6396
+ logger,
6397
+ ) {
6387
6398
UpdateFulfillFetch::NewClaim {
6388
6399
mut monitor_update,
6389
6400
htlc_value_msat,
@@ -6717,7 +6728,7 @@ where
6717
6728
6718
6729
pub fn update_fulfill_htlc(
6719
6730
&mut self, msg: &msgs::UpdateFulfillHTLC,
6720
- ) -> Result<(HTLCSource, u64, Option<u64>), ChannelError> {
6731
+ ) -> Result<(HTLCSource, u64, Option<u64>, Option<Duration> ), ChannelError> {
6721
6732
if self.context.channel_state.is_remote_stfu_sent()
6722
6733
|| self.context.channel_state.is_quiescent()
6723
6734
{
@@ -6740,7 +6751,9 @@ where
6740
6751
msg.htlc_id,
6741
6752
OutboundHTLCOutcome::Success(msg.payment_preimage),
6742
6753
)
6743
- .map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
6754
+ .map(|htlc| {
6755
+ (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat, htlc.send_timestamp)
6756
+ })
6744
6757
}
6745
6758
6746
6759
#[rustfmt::skip]
@@ -7276,7 +7289,11 @@ where
7276
7289
}
7277
7290
None
7278
7291
},
7279
- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, htlc_id, .. } => {
7292
+ &HTLCUpdateAwaitingACK::ClaimHTLC {
7293
+ ref payment_preimage,
7294
+ htlc_id,
7295
+ ref attribution_data,
7296
+ } => {
7280
7297
// If an HTLC claim was previously added to the holding cell (via
7281
7298
// `get_update_fulfill_htlc`, then generating the claim message itself must
7282
7299
// not fail - any in between attempts to claim the HTLC will have resulted
@@ -7289,8 +7306,13 @@ where
7289
7306
// We do not bother to track and include `payment_info` here, however.
7290
7307
let mut additional_monitor_update =
7291
7308
if let UpdateFulfillFetch::NewClaim { monitor_update, .. } = self
7292
- .get_update_fulfill_htlc(htlc_id, *payment_preimage, None, logger)
7293
- {
7309
+ .get_update_fulfill_htlc(
7310
+ htlc_id,
7311
+ *payment_preimage,
7312
+ None,
7313
+ attribution_data.clone(),
7314
+ logger,
7315
+ ) {
7294
7316
monitor_update
7295
7317
} else {
7296
7318
unreachable!()
@@ -7507,7 +7529,7 @@ where
7507
7529
pending_inbound_htlcs.retain(|htlc| {
7508
7530
if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
7509
7531
log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
7510
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
7532
+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
7511
7533
value_to_self_msat_diff += htlc.amount_msat as i64;
7512
7534
}
7513
7535
*expecting_peer_commitment_signed = true;
@@ -8380,12 +8402,15 @@ where
8380
8402
failure_code: failure_code.clone(),
8381
8403
});
8382
8404
},
8383
- &InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
8405
+ &InboundHTLCRemovalReason::Fulfill(
8406
+ ref payment_preimage,
8407
+ ref attribution_data,
8408
+ ) => {
8384
8409
update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
8385
8410
channel_id: self.context.channel_id(),
8386
8411
htlc_id: htlc.htlc_id,
8387
8412
payment_preimage: payment_preimage.clone(),
8388
- attribution_data: None ,
8413
+ attribution_data: attribution_data.clone() ,
8389
8414
});
8390
8415
},
8391
8416
}
@@ -12457,7 +12482,7 @@ where
12457
12482
dropped_inbound_htlcs += 1;
12458
12483
}
12459
12484
}
12460
- let mut removed_htlc_failure_attribution_data : Vec<&Option<AttributionData>> = Vec::new();
12485
+ let mut removed_htlc_attribution_data : Vec<&Option<AttributionData>> = Vec::new();
12461
12486
(self.context.pending_inbound_htlcs.len() as u64 - dropped_inbound_htlcs).write(writer)?;
12462
12487
for htlc in self.context.pending_inbound_htlcs.iter() {
12463
12488
if let &InboundHTLCState::RemoteAnnounced(_) = &htlc.state {
@@ -12489,13 +12514,14 @@ where
12489
12514
}) => {
12490
12515
0u8.write(writer)?;
12491
12516
data.write(writer)?;
12492
- removed_htlc_failure_attribution_data .push(&attribution_data);
12517
+ removed_htlc_attribution_data .push(&attribution_data);
12493
12518
},
12494
12519
InboundHTLCRemovalReason::FailMalformed((hash, code)) => {
12495
12520
1u8.write(writer)?;
12496
12521
(hash, code).write(writer)?;
12497
12522
},
12498
- InboundHTLCRemovalReason::Fulfill(preimage) => {
12523
+ InboundHTLCRemovalReason::Fulfill(preimage, _) => {
12524
+ // TODO: Persistence
12499
12525
2u8.write(writer)?;
12500
12526
preimage.write(writer)?;
12501
12527
},
@@ -12556,7 +12582,7 @@ where
12556
12582
Vec::with_capacity(holding_cell_htlc_update_count);
12557
12583
let mut holding_cell_blinding_points: Vec<Option<PublicKey>> =
12558
12584
Vec::with_capacity(holding_cell_htlc_update_count);
12559
- let mut holding_cell_failure_attribution_data : Vec<Option<&AttributionData>> =
12585
+ let mut holding_cell_attribution_data : Vec<Option<&AttributionData>> =
12560
12586
Vec::with_capacity(holding_cell_htlc_update_count);
12561
12587
// Vec of (htlc_id, failure_code, sha256_of_onion)
12562
12588
let mut malformed_htlcs: Vec<(u64, u16, [u8; 32])> = Vec::new();
@@ -12582,19 +12608,25 @@ where
12582
12608
holding_cell_skimmed_fees.push(skimmed_fee_msat);
12583
12609
holding_cell_blinding_points.push(blinding_point);
12584
12610
},
12585
- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
12611
+ &HTLCUpdateAwaitingACK::ClaimHTLC {
12612
+ ref payment_preimage,
12613
+ ref htlc_id,
12614
+ ref attribution_data,
12615
+ } => {
12586
12616
1u8.write(writer)?;
12587
12617
payment_preimage.write(writer)?;
12588
12618
htlc_id.write(writer)?;
12619
+
12620
+ // Store the attribution data for later writing.
12621
+ holding_cell_attribution_data.push(attribution_data.as_ref());
12589
12622
},
12590
12623
&HTLCUpdateAwaitingACK::FailHTLC { ref htlc_id, ref err_packet } => {
12591
12624
2u8.write(writer)?;
12592
12625
htlc_id.write(writer)?;
12593
12626
err_packet.data.write(writer)?;
12594
12627
12595
12628
// Store the attribution data for later writing.
12596
- holding_cell_failure_attribution_data
12597
- .push(err_packet.attribution_data.as_ref());
12629
+ holding_cell_attribution_data.push(err_packet.attribution_data.as_ref());
12598
12630
},
12599
12631
&HTLCUpdateAwaitingACK::FailMalformedHTLC {
12600
12632
htlc_id,
@@ -12611,7 +12643,7 @@ where
12611
12643
12612
12644
// Push 'None' attribution data for FailMalformedHTLC, because FailMalformedHTLC uses the same
12613
12645
// type 2 and is deserialized as a FailHTLC.
12614
- holding_cell_failure_attribution_data .push(None);
12646
+ holding_cell_attribution_data .push(None);
12615
12647
},
12616
12648
}
12617
12649
}
@@ -12814,8 +12846,8 @@ where
12814
12846
(51, is_manual_broadcast, option), // Added in 0.0.124
12815
12847
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
12816
12848
(54, self.pending_funding, optional_vec), // Added in 0.2
12817
- (55, removed_htlc_failure_attribution_data , optional_vec), // Added in 0.2
12818
- (57, holding_cell_failure_attribution_data , optional_vec), // Added in 0.2
12849
+ (55, removed_htlc_attribution_data , optional_vec), // Added in 0.2
12850
+ (57, holding_cell_attribution_data , optional_vec), // Added in 0.2
12819
12851
(58, self.interactive_tx_signing_session, option), // Added in 0.2
12820
12852
(59, self.funding.minimum_depth_override, option), // Added in 0.2
12821
12853
(60, self.context.historical_scids, optional_vec), // Added in 0.2
@@ -12910,7 +12942,7 @@ where
12910
12942
attribution_data: None,
12911
12943
}),
12912
12944
1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
12913
- 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
12945
+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None ),
12914
12946
_ => return Err(DecodeError::InvalidValue),
12915
12947
};
12916
12948
InboundHTLCState::LocalRemoved(reason)
@@ -12989,6 +13021,7 @@ where
12989
13021
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
12990
13022
payment_preimage: Readable::read(reader)?,
12991
13023
htlc_id: Readable::read(reader)?,
13024
+ attribution_data: None,
12992
13025
},
12993
13026
2 => HTLCUpdateAwaitingACK::FailHTLC {
12994
13027
htlc_id: Readable::read(reader)?,
@@ -13160,8 +13193,8 @@ where
13160
13193
let mut pending_outbound_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
13161
13194
let mut holding_cell_blinding_points_opt: Option<Vec<Option<PublicKey>>> = None;
13162
13195
13163
- let mut removed_htlc_failure_attribution_data : Option<Vec<Option<AttributionData>>> = None;
13164
- let mut holding_cell_failure_attribution_data : Option<Vec<Option<AttributionData>>> = None;
13196
+ let mut removed_htlc_attribution_data : Option<Vec<Option<AttributionData>>> = None;
13197
+ let mut holding_cell_attribution_data : Option<Vec<Option<AttributionData>>> = None;
13165
13198
13166
13199
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
13167
13200
let mut monitor_pending_update_adds: Option<Vec<msgs::UpdateAddHTLC>> = None;
@@ -13213,8 +13246,8 @@ where
13213
13246
(51, is_manual_broadcast, option),
13214
13247
(53, funding_tx_broadcast_safe_event_emitted, option),
13215
13248
(54, pending_funding, optional_vec), // Added in 0.2
13216
- (55, removed_htlc_failure_attribution_data , optional_vec),
13217
- (57, holding_cell_failure_attribution_data , optional_vec),
13249
+ (55, removed_htlc_attribution_data , optional_vec),
13250
+ (57, holding_cell_attribution_data , optional_vec),
13218
13251
(58, interactive_tx_signing_session, option), // Added in 0.2
13219
13252
(59, minimum_depth_override, option), // Added in 0.2
13220
13253
(60, historical_scids, optional_vec), // Added in 0.2
@@ -13317,14 +13350,19 @@ where
13317
13350
}
13318
13351
}
13319
13352
13320
- if let Some(attribution_data_list) = removed_htlc_failure_attribution_data {
13353
+ if let Some(attribution_data_list) = removed_htlc_attribution_data {
13321
13354
let mut removed_htlc_relay_failures =
13322
13355
pending_inbound_htlcs.iter_mut().filter_map(|status| {
13323
- if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(
13324
- ref mut packet,
13325
- )) = &mut status.state
13326
- {
13327
- Some(&mut packet.attribution_data)
13356
+ if let InboundHTLCState::LocalRemoved(reason) = &mut status.state {
13357
+ match reason {
13358
+ InboundHTLCRemovalReason::FailRelay(ref mut packet) => {
13359
+ Some(&mut packet.attribution_data)
13360
+ },
13361
+ InboundHTLCRemovalReason::Fulfill(_, ref mut attribution_data) => {
13362
+ Some(attribution_data)
13363
+ },
13364
+ _ => None,
13365
+ }
13328
13366
} else {
13329
13367
None
13330
13368
}
@@ -13339,18 +13377,17 @@ where
13339
13377
}
13340
13378
}
13341
13379
13342
- if let Some(attribution_data_list) = holding_cell_failure_attribution_data {
13380
+ if let Some(attribution_data_list) = holding_cell_attribution_data {
13343
13381
let mut holding_cell_failures =
13344
- holding_cell_htlc_updates.iter_mut().filter_map(|upd| {
13345
- if let HTLCUpdateAwaitingACK::FailHTLC {
13382
+ holding_cell_htlc_updates.iter_mut().filter_map(|upd| match upd {
13383
+ HTLCUpdateAwaitingACK::FailHTLC {
13346
13384
err_packet: OnionErrorPacket { ref mut attribution_data, .. },
13347
13385
..
13348
- } = upd
13349
- {
13386
+ } => Some(attribution_data),
13387
+ HTLCUpdateAwaitingACK::ClaimHTLC { attribution_data, .. } => {
13350
13388
Some(attribution_data)
13351
- } else {
13352
- None
13353
- }
13389
+ },
13390
+ _ => None,
13354
13391
});
13355
13392
13356
13393
for attribution_data in attribution_data_list {
@@ -13567,7 +13604,7 @@ where
13567
13604
}
13568
13605
}
13569
13606
13570
- fn duration_since_epoch() -> Option<Duration> {
13607
+ pub(crate) fn duration_since_epoch() -> Option<Duration> {
13571
13608
#[cfg(not(feature = "std"))]
13572
13609
let now = None;
13573
13610
@@ -14339,6 +14376,7 @@ mod tests {
14339
14376
let dummy_holding_cell_claim_htlc = HTLCUpdateAwaitingACK::ClaimHTLC {
14340
14377
payment_preimage: PaymentPreimage([42; 32]),
14341
14378
htlc_id: 0,
14379
+ attribution_data: None,
14342
14380
};
14343
14381
let dummy_holding_cell_failed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailHTLC {
14344
14382
htlc_id,
0 commit comments