@@ -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: AttributionData,
469
470
htlc_id: u64,
470
471
},
471
472
FailHTLC {
@@ -6212,7 +6213,7 @@ where
6212
6213
// (see equivalent if condition there).
6213
6214
assert!(!self.context.channel_state.can_generate_new_commitment());
6214
6215
let mon_update_id = self.context.latest_monitor_update_id; // Forget the ChannelMonitor update
6215
- let fulfill_resp = self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, logger);
6216
+ let fulfill_resp = self.get_update_fulfill_htlc(htlc_id_arg, payment_preimage_arg, None, AttributionData::new(), logger);
6216
6217
self.context.latest_monitor_update_id = mon_update_id;
6217
6218
if let UpdateFulfillFetch::NewClaim { update_blocked, .. } = fulfill_resp {
6218
6219
assert!(update_blocked); // The HTLC must have ended up in the holding cell.
@@ -6222,7 +6223,7 @@ where
6222
6223
#[rustfmt::skip]
6223
6224
fn get_update_fulfill_htlc<L: Deref>(
6224
6225
&mut self, htlc_id_arg: u64, payment_preimage_arg: PaymentPreimage,
6225
- payment_info: Option<PaymentClaimDetails>, logger: &L,
6226
+ payment_info: Option<PaymentClaimDetails>, attribution_data: AttributionData, logger: &L,
6226
6227
) -> UpdateFulfillFetch where L::Target: Logger {
6227
6228
// Either ChannelReady got set (which means it won't be unset) or there is no way any
6228
6229
// caller thought we could have something claimed (cause we wouldn't have accepted in an
@@ -6246,7 +6247,7 @@ where
6246
6247
match htlc.state {
6247
6248
InboundHTLCState::Committed => {},
6248
6249
InboundHTLCState::LocalRemoved(ref reason) => {
6249
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
6250
+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
6250
6251
} else {
6251
6252
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());
6252
6253
debug_assert!(false, "Tried to fulfill an HTLC that was already failed");
@@ -6312,6 +6313,7 @@ where
6312
6313
log_trace!(logger, "Adding HTLC claim to holding_cell in channel {}! Current state: {}", &self.context.channel_id(), self.context.channel_state.to_u32());
6313
6314
self.context.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::ClaimHTLC {
6314
6315
payment_preimage: payment_preimage_arg, htlc_id: htlc_id_arg,
6316
+ attribution_data,
6315
6317
});
6316
6318
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, update_blocked: true };
6317
6319
}
@@ -6324,7 +6326,7 @@ where
6324
6326
return UpdateFulfillFetch::NewClaim { monitor_update, htlc_value_msat, update_blocked: true };
6325
6327
}
6326
6328
log_trace!(logger, "Upgrading HTLC {} to LocalRemoved with a Fulfill in channel {}!", &htlc.payment_hash, &self.context.channel_id);
6327
- htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(payment_preimage_arg.clone()));
6329
+ htlc.state = InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(payment_preimage_arg.clone(), Some(attribution_data) ));
6328
6330
}
6329
6331
6330
6332
UpdateFulfillFetch::NewClaim {
@@ -6337,10 +6339,10 @@ where
6337
6339
#[rustfmt::skip]
6338
6340
pub fn get_update_fulfill_htlc_and_commit<L: Deref>(
6339
6341
&mut self, htlc_id: u64, payment_preimage: PaymentPreimage,
6340
- payment_info: Option<PaymentClaimDetails>, logger: &L,
6342
+ payment_info: Option<PaymentClaimDetails>, attribution_data: AttributionData, logger: &L,
6341
6343
) -> UpdateFulfillCommitFetch where L::Target: Logger {
6342
6344
let release_cs_monitor = self.context.blocked_monitor_updates.is_empty();
6343
- match self.get_update_fulfill_htlc(htlc_id, payment_preimage, payment_info, logger) {
6345
+ match self.get_update_fulfill_htlc(htlc_id, payment_preimage, payment_info, attribution_data, logger) {
6344
6346
UpdateFulfillFetch::NewClaim { mut monitor_update, htlc_value_msat, update_blocked } => {
6345
6347
// Even if we aren't supposed to let new monitor updates with commitment state
6346
6348
// updates run, we still need to push the preimage ChannelMonitorUpdateStep no
@@ -6658,7 +6660,7 @@ where
6658
6660
}
6659
6661
6660
6662
#[rustfmt::skip]
6661
- pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<(HTLCSource, u64, Option<u64>), ChannelError> {
6663
+ pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<(HTLCSource, u64, Option<u64>, Option<Duration> ), ChannelError> {
6662
6664
if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
6663
6665
return Err(ChannelError::WarnAndDisconnect("Got fulfill HTLC message while quiescent".to_owned()));
6664
6666
}
@@ -6669,7 +6671,7 @@ where
6669
6671
return Err(ChannelError::close("Peer sent update_fulfill_htlc when we needed a channel_reestablish".to_owned()));
6670
6672
}
6671
6673
6672
- 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))
6674
+ 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 ))
6673
6675
}
6674
6676
6675
6677
#[rustfmt::skip]
@@ -7160,7 +7162,7 @@ where
7160
7162
}
7161
7163
None
7162
7164
},
7163
- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, htlc_id, .. } => {
7165
+ &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, htlc_id, ref attribution_data } => {
7164
7166
// If an HTLC claim was previously added to the holding cell (via
7165
7167
// `get_update_fulfill_htlc`, then generating the claim message itself must
7166
7168
// not fail - any in between attempts to claim the HTLC will have resulted
@@ -7173,7 +7175,7 @@ where
7173
7175
// We do not bother to track and include `payment_info` here, however.
7174
7176
let mut additional_monitor_update =
7175
7177
if let UpdateFulfillFetch::NewClaim { monitor_update, .. } =
7176
- self.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, logger)
7178
+ self.get_update_fulfill_htlc(htlc_id, *payment_preimage, None, attribution_data.clone(), logger)
7177
7179
{ monitor_update } else { unreachable!() };
7178
7180
update_fulfill_count += 1;
7179
7181
monitor_update.updates.append(&mut additional_monitor_update.updates);
@@ -7376,7 +7378,7 @@ where
7376
7378
pending_inbound_htlcs.retain(|htlc| {
7377
7379
if let &InboundHTLCState::LocalRemoved(ref reason) = &htlc.state {
7378
7380
log_trace!(logger, " ...removing inbound LocalRemoved {}", &htlc.payment_hash);
7379
- if let &InboundHTLCRemovalReason::Fulfill(_) = reason {
7381
+ if let &InboundHTLCRemovalReason::Fulfill(_, _ ) = reason {
7380
7382
value_to_self_msat_diff += htlc.amount_msat as i64;
7381
7383
}
7382
7384
*expecting_peer_commitment_signed = true;
@@ -8242,11 +8244,12 @@ where
8242
8244
failure_code: failure_code.clone(),
8243
8245
});
8244
8246
},
8245
- &InboundHTLCRemovalReason::Fulfill(ref payment_preimage) => {
8247
+ &InboundHTLCRemovalReason::Fulfill(ref payment_preimage, ref attribution_data ) => {
8246
8248
update_fulfill_htlcs.push(msgs::UpdateFulfillHTLC {
8247
8249
channel_id: self.context.channel_id(),
8248
8250
htlc_id: htlc.htlc_id,
8249
8251
payment_preimage: payment_preimage.clone(),
8252
+ attribution_data: attribution_data.clone(),
8250
8253
});
8251
8254
},
8252
8255
}
@@ -12338,7 +12341,7 @@ where
12338
12341
1u8.write(writer)?;
12339
12342
(hash, code).write(writer)?;
12340
12343
},
12341
- InboundHTLCRemovalReason::Fulfill(preimage) => {
12344
+ InboundHTLCRemovalReason::Fulfill(preimage, _ ) => { // TODO: Persistence
12342
12345
2u8.write(writer)?;
12343
12346
preimage.write(writer)?;
12344
12347
},
@@ -12417,7 +12420,7 @@ where
12417
12420
holding_cell_skimmed_fees.push(skimmed_fee_msat);
12418
12421
holding_cell_blinding_points.push(blinding_point);
12419
12422
},
12420
- &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id } => {
12423
+ &HTLCUpdateAwaitingACK::ClaimHTLC { ref payment_preimage, ref htlc_id, .. } => {
12421
12424
1u8.write(writer)?;
12422
12425
payment_preimage.write(writer)?;
12423
12426
htlc_id.write(writer)?;
@@ -12704,7 +12707,7 @@ where
12704
12707
attribution_data: None,
12705
12708
}),
12706
12709
1 => InboundHTLCRemovalReason::FailMalformed(Readable::read(reader)?),
12707
- 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?),
12710
+ 2 => InboundHTLCRemovalReason::Fulfill(Readable::read(reader)?, None), // TODO: Persistence
12708
12711
_ => return Err(DecodeError::InvalidValue),
12709
12712
};
12710
12713
InboundHTLCState::LocalRemoved(reason)
@@ -12777,6 +12780,7 @@ where
12777
12780
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
12778
12781
payment_preimage: Readable::read(reader)?,
12779
12782
htlc_id: Readable::read(reader)?,
12783
+ attribution_data: AttributionData::new(), // TODO: Persistence
12780
12784
},
12781
12785
2 => HTLCUpdateAwaitingACK::FailHTLC {
12782
12786
htlc_id: Readable::read(reader)?,
@@ -13282,7 +13286,7 @@ where
13282
13286
}
13283
13287
}
13284
13288
13285
- fn duration_since_epoch() -> Option<Duration> {
13289
+ pub(crate) fn duration_since_epoch() -> Option<Duration> {
13286
13290
#[cfg(not(feature = "std"))]
13287
13291
let now = None;
13288
13292
@@ -14003,6 +14007,7 @@ mod tests {
14003
14007
let dummy_holding_cell_claim_htlc = HTLCUpdateAwaitingACK::ClaimHTLC {
14004
14008
payment_preimage: PaymentPreimage([42; 32]),
14005
14009
htlc_id: 0,
14010
+ attribution_data: AttributionData::new(),
14006
14011
};
14007
14012
let dummy_holding_cell_failed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailHTLC {
14008
14013
htlc_id, err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data: Some(AttributionData::new()) }
0 commit comments