Skip to content

Commit ba52885

Browse files
committed
Surface failure hold times
Now that fulfill hold times are surfaced in the event always, this commit follow ups with the failure hold times.
1 parent 4674ddd commit ba52885

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lightning/src/events/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,11 @@ pub enum Event {
11591159
error_code: Option<u16>,
11601160
#[cfg(any(test, feature = "_test_utils"))]
11611161
error_data: Option<Vec<u8>>,
1162-
#[cfg(any(test, feature = "_test_utils"))]
1162+
/// The hold times as reported by each hop. The unit in which the hold times are expressed are 100's of
1163+
/// milliseconds. So a hop reporting 2 is a hold time that corresponds to roughly 200 milliseconds. As earlier
1164+
/// hops hold on to an HTLC for longer, the hold times in the list are expected to decrease. When our peer
1165+
/// didn't provide attribution data, the list is empty. The same applies to HTLCs that were resolved onchain.
1166+
/// Because of unavailability of hold times, the list may be shorter than the number of hops in the path.
11631167
hold_times: Vec<u32>,
11641168
},
11651169
/// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination.
@@ -1798,16 +1802,13 @@ impl Writeable for Event {
17981802
ref error_code,
17991803
#[cfg(any(test, feature = "_test_utils"))]
18001804
ref error_data,
1801-
#[cfg(any(test, feature = "_test_utils"))]
18021805
ref hold_times,
18031806
} => {
18041807
3u8.write(writer)?;
18051808
#[cfg(any(test, feature = "_test_utils"))]
18061809
error_code.write(writer)?;
18071810
#[cfg(any(test, feature = "_test_utils"))]
18081811
error_data.write(writer)?;
1809-
#[cfg(any(test, feature = "_test_utils"))]
1810-
hold_times.write(writer)?;
18111812
write_tlv_fields!(writer, {
18121813
(0, payment_hash, required),
18131814
(1, None::<NetworkUpdate>, option), // network_update in LDK versions prior to 0.0.114
@@ -1819,6 +1820,7 @@ impl Writeable for Event {
18191820
(9, None::<RouteParameters>, option), // retry in LDK versions prior to 0.0.115
18201821
(11, payment_id, option),
18211822
(13, failure, required),
1823+
(15, *hold_times, optional_vec),
18221824
});
18231825
},
18241826
&Event::PendingHTLCsForwardable { time_forwardable: _ } => {
@@ -2244,8 +2246,6 @@ impl MaybeReadable for Event {
22442246
let error_code = Readable::read(reader)?;
22452247
#[cfg(any(test, feature = "_test_utils"))]
22462248
let error_data = Readable::read(reader)?;
2247-
#[cfg(any(test, feature = "_test_utils"))]
2248-
let hold_times = Readable::read(reader)?;
22492249
let mut payment_hash = PaymentHash([0; 32]);
22502250
let mut payment_failed_permanently = false;
22512251
let mut network_update = None;
@@ -2254,6 +2254,7 @@ impl MaybeReadable for Event {
22542254
let mut short_channel_id = None;
22552255
let mut payment_id = None;
22562256
let mut failure_opt = None;
2257+
let mut hold_times = None;
22572258
read_tlv_fields!(reader, {
22582259
(0, payment_hash, required),
22592260
(1, network_update, upgradable_option),
@@ -2265,7 +2266,9 @@ impl MaybeReadable for Event {
22652266
(7, short_channel_id, option),
22662267
(11, payment_id, option),
22672268
(13, failure_opt, upgradable_option),
2269+
(15, hold_times, optional_vec),
22682270
});
2271+
let hold_times = hold_times.unwrap_or(Vec::new());
22692272
let failure =
22702273
failure_opt.unwrap_or_else(|| PathFailure::OnPath { network_update });
22712274
Ok(Some(Event::PaymentPathFailed {
@@ -2279,7 +2282,6 @@ impl MaybeReadable for Event {
22792282
error_code,
22802283
#[cfg(any(test, feature = "_test_utils"))]
22812284
error_data,
2282-
#[cfg(any(test, feature = "_test_utils"))]
22832285
hold_times,
22842286
}))
22852287
};

lightning/src/ln/outbound_payment.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,6 @@ impl OutboundPayments {
16871687
error_code: None,
16881688
#[cfg(any(test, feature = "_test_utils"))]
16891689
error_data: None,
1690-
#[cfg(any(test, feature = "_test_utils"))]
16911690
hold_times: Vec::new(),
16921691
};
16931692
events.push_back((event, None));
@@ -2328,6 +2327,7 @@ impl OutboundPayments {
23282327
short_channel_id,
23292328
payment_failed_permanently,
23302329
failed_within_blinded_path,
2330+
hold_times,
23312331
..
23322332
} = onion_error.decode_onion_failure(secp_ctx, logger, &source);
23332333

@@ -2456,7 +2456,6 @@ impl OutboundPayments {
24562456
error_code: onion_error_code.map(|f| f.failure_code()),
24572457
#[cfg(any(test, feature = "_test_utils"))]
24582458
error_data: onion_error_data,
2459-
#[cfg(any(test, feature = "_test_utils"))]
24602459
hold_times,
24612460
}
24622461
}

0 commit comments

Comments
 (0)