-
Notifications
You must be signed in to change notification settings - Fork 417
Hold times for successful payments #3801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
47ce774
5eecba3
5938a99
f212530
ba7deab
72414f2
348ba4b
418b353
bed274f
4674ddd
ba52885
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1102,6 +1102,12 @@ pub enum Event { | |
/// | ||
/// May contain a closed channel if the HTLC sent along the path was fulfilled on chain. | ||
path: Path, | ||
/// The hold times as reported by each hop. The unit in which the hold times are expressed are 100's of | ||
/// milliseconds. So a hop reporting 2 is a hold time that corresponds to roughly 200 milliseconds. As earlier | ||
/// hops hold on to an HTLC for longer, the hold times in the list are expected to decrease. When our peer | ||
/// didn't provide attribution data, the list is empty. The same applies to HTLCs that were resolved onchain. | ||
/// Because of unavailability of hold times, the list may be shorter than the number of hops in the path. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might be useful to clarify that the hold time at idx 0 corresponds to the hop at path.hops[0], etc |
||
hold_times: Vec<u32>, | ||
}, | ||
/// Indicates an outbound HTLC we sent failed, likely due to an intermediary node being unable to | ||
/// handle the HTLC. | ||
|
@@ -1153,7 +1159,11 @@ pub enum Event { | |
error_code: Option<u16>, | ||
#[cfg(any(test, feature = "_test_utils"))] | ||
error_data: Option<Vec<u8>>, | ||
#[cfg(any(test, feature = "_test_utils"))] | ||
/// The hold times as reported by each hop. The unit in which the hold times are expressed are 100's of | ||
/// milliseconds. So a hop reporting 2 is a hold time that corresponds to roughly 200 milliseconds. As earlier | ||
/// hops hold on to an HTLC for longer, the hold times in the list are expected to decrease. When our peer | ||
/// didn't provide attribution data, the list is empty. The same applies to HTLCs that were resolved onchain. | ||
/// Because of unavailability of hold times, the list may be shorter than the number of hops in the path. | ||
hold_times: Vec<u32>, | ||
}, | ||
/// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination. | ||
|
@@ -1792,16 +1802,13 @@ impl Writeable for Event { | |
ref error_code, | ||
#[cfg(any(test, feature = "_test_utils"))] | ||
ref error_data, | ||
#[cfg(any(test, feature = "_test_utils"))] | ||
ref hold_times, | ||
} => { | ||
3u8.write(writer)?; | ||
#[cfg(any(test, feature = "_test_utils"))] | ||
error_code.write(writer)?; | ||
#[cfg(any(test, feature = "_test_utils"))] | ||
error_data.write(writer)?; | ||
#[cfg(any(test, feature = "_test_utils"))] | ||
hold_times.write(writer)?; | ||
write_tlv_fields!(writer, { | ||
(0, payment_hash, required), | ||
(1, None::<NetworkUpdate>, option), // network_update in LDK versions prior to 0.0.114 | ||
|
@@ -1813,6 +1820,7 @@ impl Writeable for Event { | |
(9, None::<RouteParameters>, option), // retry in LDK versions prior to 0.0.115 | ||
(11, payment_id, option), | ||
(13, failure, required), | ||
(15, *hold_times, optional_vec), | ||
}); | ||
}, | ||
&Event::PendingHTLCsForwardable { time_forwardable: _ } => { | ||
|
@@ -1910,10 +1918,16 @@ impl Writeable for Event { | |
(4, funding_info, required), | ||
}) | ||
}, | ||
&Event::PaymentPathSuccessful { ref payment_id, ref payment_hash, ref path } => { | ||
&Event::PaymentPathSuccessful { | ||
ref payment_id, | ||
ref payment_hash, | ||
ref path, | ||
ref hold_times, | ||
} => { | ||
13u8.write(writer)?; | ||
write_tlv_fields!(writer, { | ||
(0, payment_id, required), | ||
(1, *hold_times, optional_vec), | ||
(2, payment_hash, option), | ||
(4, path.hops, required_vec), | ||
(6, path.blinded_tail, option), | ||
|
@@ -2232,8 +2246,6 @@ impl MaybeReadable for Event { | |
let error_code = Readable::read(reader)?; | ||
#[cfg(any(test, feature = "_test_utils"))] | ||
let error_data = Readable::read(reader)?; | ||
#[cfg(any(test, feature = "_test_utils"))] | ||
let hold_times = Readable::read(reader)?; | ||
let mut payment_hash = PaymentHash([0; 32]); | ||
let mut payment_failed_permanently = false; | ||
let mut network_update = None; | ||
|
@@ -2242,6 +2254,7 @@ impl MaybeReadable for Event { | |
let mut short_channel_id = None; | ||
let mut payment_id = None; | ||
let mut failure_opt = None; | ||
let mut hold_times = None; | ||
read_tlv_fields!(reader, { | ||
(0, payment_hash, required), | ||
(1, network_update, upgradable_option), | ||
|
@@ -2253,7 +2266,9 @@ impl MaybeReadable for Event { | |
(7, short_channel_id, option), | ||
(11, payment_id, option), | ||
(13, failure_opt, upgradable_option), | ||
(15, hold_times, optional_vec), | ||
}); | ||
let hold_times = hold_times.unwrap_or(Vec::new()); | ||
let failure = | ||
failure_opt.unwrap_or_else(|| PathFailure::OnPath { network_update }); | ||
Ok(Some(Event::PaymentPathFailed { | ||
|
@@ -2267,7 +2282,6 @@ impl MaybeReadable for Event { | |
error_code, | ||
#[cfg(any(test, feature = "_test_utils"))] | ||
error_data, | ||
#[cfg(any(test, feature = "_test_utils"))] | ||
hold_times, | ||
})) | ||
}; | ||
|
@@ -2413,14 +2427,19 @@ impl MaybeReadable for Event { | |
let mut f = || { | ||
_init_and_read_len_prefixed_tlv_fields!(reader, { | ||
(0, payment_id, required), | ||
(1, hold_times, optional_vec), | ||
(2, payment_hash, option), | ||
(4, path, required_vec), | ||
(6, blinded_tail, option), | ||
}); | ||
|
||
let hold_times = hold_times.unwrap_or(Vec::new()); | ||
|
||
Ok(Some(Event::PaymentPathSuccessful { | ||
payment_id: payment_id.0.unwrap(), | ||
payment_hash, | ||
path: Path { hops: path, blinded_tail }, | ||
hold_times, | ||
})) | ||
}; | ||
f() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2890,8 +2890,12 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f | |
as_raa = Some(get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, node_b_id)); | ||
} | ||
|
||
let fulfill_msg = | ||
msgs::UpdateFulfillHTLC { channel_id: chan_id_2, htlc_id: 0, payment_preimage }; | ||
let mut fulfill_msg = msgs::UpdateFulfillHTLC { | ||
channel_id: chan_id_2, | ||
htlc_id: 0, | ||
payment_preimage, | ||
attribution_data: None, | ||
}; | ||
if second_fails { | ||
nodes[2].node.fail_htlc_backwards(&payment_hash); | ||
expect_pending_htlcs_forwardable_and_htlc_handling_failed!( | ||
|
@@ -2900,15 +2904,24 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f | |
); | ||
check_added_monitors!(nodes[2], 1); | ||
get_htlc_update_msgs!(nodes[2], node_b_id); | ||
// Note that we don't populate fulfill_msg.attribution_data here, which will lead to hold times being | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rustfmt 🤷♂️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's putting the comment on the |
||
// unavailable. | ||
} else { | ||
nodes[2].node.claim_funds(payment_preimage); | ||
check_added_monitors!(nodes[2], 1); | ||
expect_payment_claimed!(nodes[2], payment_hash, 100_000); | ||
|
||
let cs_updates = get_htlc_update_msgs!(nodes[2], node_b_id); | ||
assert_eq!(cs_updates.update_fulfill_htlcs.len(), 1); | ||
// Check that the message we're about to deliver matches the one generated: | ||
assert_eq!(fulfill_msg, cs_updates.update_fulfill_htlcs[0]); | ||
|
||
// Check that the message we're about to deliver matches the one generated. Ignore attribution data. | ||
assert_eq!(fulfill_msg.channel_id, cs_updates.update_fulfill_htlcs[0].channel_id); | ||
assert_eq!(fulfill_msg.htlc_id, cs_updates.update_fulfill_htlcs[0].htlc_id); | ||
assert_eq!( | ||
fulfill_msg.payment_preimage, | ||
cs_updates.update_fulfill_htlcs[0].payment_preimage | ||
); | ||
fulfill_msg.attribution_data = cs_updates.update_fulfill_htlcs[0].attribution_data.clone(); | ||
} | ||
nodes[1].node.handle_update_fulfill_htlc(node_c_id, &fulfill_msg); | ||
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), false, false); | ||
|
Uh oh!
There was an error while loading. Please reload this page.