@@ -121,7 +121,7 @@ enum FeeUpdateState {
121
121
enum InboundHTLCRemovalReason {
122
122
FailRelay(msgs::OnionErrorPacket),
123
123
FailMalformed(([u8; 32], u16)),
124
- Fulfill(PaymentPreimage),
124
+ Fulfill(PaymentPreimage, Option<AttributionData> ),
125
125
}
126
126
127
127
/// Represents the resolution status of an inbound HTLC.
@@ -220,7 +220,7 @@ impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> {
220
220
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
221
221
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailMalformed(_)) =>
222
222
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
223
- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) =>
223
+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_, _ )) =>
224
224
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFulfill),
225
225
}
226
226
}
@@ -251,7 +251,7 @@ impl InboundHTLCState {
251
251
252
252
fn preimage(&self) -> Option<PaymentPreimage> {
253
253
match self {
254
- InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage)) => Some(*preimage),
254
+ InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(preimage, _ )) => Some(*preimage),
255
255
_ => None,
256
256
}
257
257
}
@@ -439,6 +439,7 @@ enum HTLCUpdateAwaitingACK {
439
439
},
440
440
ClaimHTLC {
441
441
payment_preimage: PaymentPreimage,
442
+ attribution_data: AttributionData,
442
443
htlc_id: u64,
443
444
},
444
445
FailHTLC {
@@ -5347,7 +5348,7 @@ impl<SP: Deref> FundedChannel<SP> where
5347
5348
// (see equivalent if condition there).
5348
5349
assert!(!self.context.channel_state.can_generate_new_commitment());
5349
5350
let mon_update_id = self.context.latest_monitor_update_id; // Forget the ChannelMonitor update
5350
- let fulfill_resp = self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, logger);
5351
+ let fulfill_resp = self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, AttributionData::new(), logger);
5351
5352
self.context.latest_monitor_update_id = mon_update_id;
5352
5353
if let UpdateFulfillFetch::NewClaim { msg, .. } = fulfill_resp {
5353
5354
assert!(!msg); // The HTLC must have ended up in the holding cell.
@@ -5356,7 +5357,7 @@ impl<SP: Deref> FundedChannel<SP> where
5356
5357
5357
5358
fn get_update_fulfill_htlc<L: Deref>(
5358
5359
&mut self, htlc_id_arg: u64, payment_preimage_arg: PaymentPreimage,
5359
- payment_info: Option<PaymentClaimDetails>, logger: &L,
5360
+ payment_info: Option<PaymentClaimDetails>, attribution_data: AttributionData, logger: &L,
5360
5361
) -> UpdateFulfillFetch where L::Target: Logger {
5361
5362
// Either ChannelReady got set (which means it won't be unset) or there is no way any
5362
5363
// caller thought we could have something claimed (cause we wouldn't have accepted in an
@@ -5380,7 +5381,7 @@ impl<SP: Deref> FundedChannel<SP> where
5380
5381
match htlc.state {
5381
5382
InboundHTLCState::Committed => {},
5382
5383
InboundHTLCState::LocalRemoved(ref reason) => {
5383
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
5384
+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
5384
5385
} else {
5385
5386
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());
5386
5387
debug_assert!(false, "Tried to fulfill an HTLC that was already failed");
@@ -5446,6 +5447,7 @@ impl<SP: Deref> FundedChannel<SP> where
5446
5447
log_trace!(logger, "Adding HTLC claim to holding_cell in channel {}! Current state: {}", &self.context.channel_id(), self.context.channel_state.to_u32());
5447
5448
self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
5448
5449
payment_preimage: payment_preimage_arg, htlc_id: htlc_id_arg,
5450
+ attribution_data,
5449
5451
});
5450
5452
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: false };
5451
5453
}
@@ -5458,7 +5460,7 @@ impl<SP: Deref> FundedChannel<SP> where
5458
5460
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, msg: false };
5459
5461
}
5460
5462
log_trace!(logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!", &htlc.payment_hash, &self.context.channel_id);
5461
- htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(payment_preimage_arg.clone()));
5463
+ htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(payment_preimage_arg.clone(), Some(attribution_data) ));
5462
5464
}
5463
5465
5464
5466
UpdateFulfillFetch::NewClaim {
@@ -5470,10 +5472,10 @@ impl<SP: Deref> FundedChannel<SP> where
5470
5472
5471
5473
pub fn get_update_fulfill_htlc_and_commit<L: Deref>(
5472
5474
&mut self, htlc_id: u64, payment_preimage: PaymentPreimage,
5473
- payment_info: Option<PaymentClaimDetails>, logger: &L,
5475
+ payment_info: Option<PaymentClaimDetails>, attribution_data: AttributionData, logger: &L,
5474
5476
) -> UpdateFulfillCommitFetch where L::Target: Logger {
5475
5477
let release_cs_monitor = self.context.blocked_monitor_updates.is_empty();
5476
- match self.get_update_fulfill_htlc(htlc_id, payment_preimage, payment_info, logger) {
5478
+ match self.get_update_fulfill_htlc(htlc_id, payment_preimage, payment_info, attribution_data, logger) {
5477
5479
UpdateFulfillFetch::NewClaim { mut monitor_update, htlc_value_msat, msg } => {
5478
5480
// Even if we aren't supposed to let new monitor updates with commitment state
5479
5481
// updates run, we still need to push the preimage ChannelMonitorUpdateStep no
@@ -5848,7 +5850,7 @@ impl<SP: Deref> FundedChannel<SP> where
5848
5850
Err(ChannelError::close("Remote tried to fulfill/fail an HTLC we couldn't find".to_owned()))
5849
5851
}
5850
5852
5851
- pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<(HTLCSource, u64, Option<u64>), ChannelError> {
5853
+ pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<(HTLCSource, u64, Option<u64>, Option<Duration> ), ChannelError> {
5852
5854
if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
5853
5855
return Err(ChannelError::WarnAndDisconnect("Got fulfill HTLC message while quiescent".to_owned()));
5854
5856
}
@@ -5859,7 +5861,7 @@ impl<SP: Deref> FundedChannel<SP> where
5859
5861
return Err(ChannelError::close("Peer sent update_fulfill_htlc when we needed a channel_reestablish".to_owned()));
5860
5862
}
5861
5863
5862
- self.mark_outbound_htlc_removed(msg.htlc_id, OutboundHTLCOutcome::Success(msg.payment_preimage)).map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat))
5864
+ self.mark_outbound_htlc_removed(msg.htlc_id, OutboundHTLCOutcome::Success(msg.payment_preimage)).map(|htlc| (htlc.source.clone(), htlc.amount_msat, htlc.skimmed_fee_msat, htlc.send_timestamp ))
5863
5865
}
5864
5866
5865
5867
pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailReason) -> Result<(), ChannelError> {
@@ -6188,7 +6190,7 @@ impl<SP: Deref> FundedChannel<SP> where
6188
6190
}
6189
6191
None
6190
6192
},
6191
- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, htlc_id, .. } => {
6193
+ &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, htlc_id, ref attribution_data } => {
6192
6194
// If an HTLC claim was previously added to the holding cell (via
6193
6195
// `get_update_fulfill_htlc`, then generating the claim message itself must
6194
6196
// not fail - any in between attempts to claim the HTLC will have resulted
@@ -6201,7 +6203,7 @@ impl<SP: Deref> FundedChannel<SP> where
6201
6203
// We do not bother to track and include `payment_info` here, however.
6202
6204
let mut additional_monitor_update =
6203
6205
if let UpdateFulfillFetch::NewClaim { monitor_update, .. } =
6204
- self.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, logger)
6206
+ self.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, attribution_data.clone(), logger)
6205
6207
{ monitor_update } else { unreachable!() };
6206
6208
update_fulfill_count += 1;
6207
6209
monitor_update.updates.append(&mut additional_monitor_update.updates);
@@ -6366,7 +6368,7 @@ impl<SP: Deref> FundedChannel<SP> where
6366
6368
pending_inbound_htlcs.retain(|htlc| {
6367
6369
if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
6368
6370
log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
6369
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
6371
+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
6370
6372
value_to_self_msat_diff += htlc.amount_msat as i64;
6371
6373
}
6372
6374
*expecting_peer_commitment_signed = true;
@@ -7139,11 +7141,12 @@ impl<SP: Deref> FundedChannel<SP> where
7139
7141
failure_code: failure_code.clone(),
7140
7142
});
7141
7143
},
7142
- &InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
7144
+ &InboundHTLCRemovalReason::Fulfill(ref payment_preimage, ref attribution_data ) => {
7143
7145
update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
7144
7146
channel_id: self.context.channel_id(),
7145
7147
htlc_id: htlc.htlc_id,
7146
7148
payment_preimage: payment_preimage.clone(),
7149
+ attribution_data: attribution_data.clone(),
7147
7150
});
7148
7151
},
7149
7152
}
@@ -10642,7 +10645,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10642
10645
1u8.write(writer)?;
10643
10646
(hash, code).write(writer)?;
10644
10647
},
10645
- InboundHTLCRemovalReason::Fulfill(preimage) => {
10648
+ InboundHTLCRemovalReason::Fulfill(preimage, _ ) => { // TODO: Persistence
10646
10649
2u8.write(writer)?;
10647
10650
preimage.write(writer)?;
10648
10651
},
@@ -10721,7 +10724,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10721
10724
holding_cell_skimmed_fees.push(skimmed_fee_msat);
10722
10725
holding_cell_blinding_points.push(blinding_point);
10723
10726
},
10724
- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
10727
+ &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id, .. } => {
10725
10728
1u8.write(writer)?;
10726
10729
payment_preimage.write(writer)?;
10727
10730
htlc_id.write(writer)?;
@@ -11003,7 +11006,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
11003
11006
attribution_data: None,
11004
11007
}),
11005
11008
1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
11006
- 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
11009
+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None), // TODO: Persistence
11007
11010
_ => return Err(DecodeError::InvalidValue),
11008
11011
};
11009
11012
InboundHTLCState::LocalRemoved(reason)
@@ -11076,6 +11079,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
11076
11079
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
11077
11080
payment_preimage: Readable::read(reader)?,
11078
11081
htlc_id: Readable::read(reader)?,
11082
+ attribution_data: AttributionData::new(), // TODO: Persistence
11079
11083
},
11080
11084
2 => HTLCUpdateAwaitingACK::FailHTLC {
11081
11085
htlc_id: Readable::read(reader)?,
@@ -11584,7 +11588,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
11584
11588
}
11585
11589
}
11586
11590
11587
- fn duration_since_epoch() -> Option<Duration> {
11591
+ pub(crate) fn duration_since_epoch() -> Option<Duration> {
11588
11592
#[cfg(not(feature = "std"))]
11589
11593
let now = None;
11590
11594
@@ -12248,6 +12252,7 @@ mod tests {
12248
12252
let dummy_holding_cell_claim_htlc = HTLCUpdateAwaitingACK::ClaimHTLC {
12249
12253
payment_preimage: PaymentPreimage([42; 32]),
12250
12254
htlc_id: 0,
12255
+ attribution_data: AttributionData::new(),
12251
12256
};
12252
12257
let dummy_holding_cell_failed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailHTLC {
12253
12258
htlc_id, err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data: Some(AttributionData::new()) }
0 commit comments