Skip to content

Mark failed one-hop HTLCs as retrably #1702

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions lightning-invoice/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ where

match event {
Event::PaymentPathFailed {
payment_id, payment_hash, rejected_by_dest, path, short_channel_id, retry, ..
payment_id, payment_hash, payment_failed_permanently, path, short_channel_id, retry, ..
} => {
if let Some(short_channel_id) = short_channel_id {
let path = path.iter().collect::<Vec<_>>();
Expand All @@ -726,7 +726,7 @@ where

if payment_id.is_none() {
log_trace!(self.logger, "Payment {} has no id; not retrying", log_bytes!(payment_hash.0));
} else if *rejected_by_dest {
} else if *payment_failed_permanently {
log_trace!(self.logger, "Payment {} rejected by destination; not retrying", log_bytes!(payment_hash.0));
self.payer.abandon_payment(payment_id.unwrap());
} else if retry.is_none() {
Expand Down Expand Up @@ -916,7 +916,7 @@ mod tests {
payment_id,
payment_hash,
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: false,
path: TestRouter::path_for_value(final_value_msat),
short_channel_id: None,
Expand Down Expand Up @@ -981,7 +981,7 @@ mod tests {
payment_id,
payment_hash,
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: false,
path: TestRouter::path_for_value(final_value_msat),
short_channel_id: None,
Expand Down Expand Up @@ -1028,7 +1028,7 @@ mod tests {
payment_id,
payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: true,
path: TestRouter::path_for_value(final_value_msat),
short_channel_id: None,
Expand All @@ -1042,7 +1042,7 @@ mod tests {
payment_id,
payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: false,
path: TestRouter::path_for_value(final_value_msat / 2),
short_channel_id: None,
Expand Down Expand Up @@ -1088,7 +1088,7 @@ mod tests {
payment_id,
payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: true,
path: TestRouter::path_for_value(final_value_msat),
short_channel_id: None,
Expand Down Expand Up @@ -1128,7 +1128,7 @@ mod tests {
payment_id,
payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: false,
path: vec![],
short_channel_id: None,
Expand Down Expand Up @@ -1189,7 +1189,7 @@ mod tests {
payment_id,
payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: false,
path: vec![],
short_channel_id: None,
Expand Down Expand Up @@ -1226,7 +1226,7 @@ mod tests {
payment_id,
payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: false,
path: TestRouter::path_for_value(final_value_msat / 2),
short_channel_id: None,
Expand Down Expand Up @@ -1260,7 +1260,7 @@ mod tests {
payment_id,
payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
network_update: None,
rejected_by_dest: true,
payment_failed_permanently: true,
all_paths_failed: false,
path: vec![],
short_channel_id: None,
Expand Down Expand Up @@ -1309,7 +1309,7 @@ mod tests {
payment_id,
payment_hash,
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: false,
path: vec![],
short_channel_id: None,
Expand Down Expand Up @@ -1444,7 +1444,7 @@ mod tests {
payment_id,
payment_hash,
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: false,
path: vec![],
short_channel_id: None,
Expand Down Expand Up @@ -1490,7 +1490,7 @@ mod tests {
payment_id,
payment_hash,
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: false,
path,
short_channel_id,
Expand Down Expand Up @@ -1680,7 +1680,7 @@ mod tests {
payment_id,
payment_hash,
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: false,
path: TestRouter::path_for_value(final_value_msat),
short_channel_id: None,
Expand All @@ -1692,7 +1692,7 @@ mod tests {
payment_id,
payment_hash,
network_update: None,
rejected_by_dest: false,
payment_failed_permanently: false,
all_paths_failed: false,
path: TestRouter::path_for_value(final_value_msat / 2),
short_channel_id: None,
Expand Down Expand Up @@ -2393,8 +2393,8 @@ mod tests {
// treated this as "HTLC complete" and dropped the retry counter, causing us to retry again
// if the final HTLC failed.
expected_events.borrow_mut().push_back(&|ev: &Event| {
if let Event::PaymentPathFailed { rejected_by_dest, all_paths_failed, .. } = ev {
assert!(!rejected_by_dest);
if let Event::PaymentPathFailed { payment_failed_permanently, all_paths_failed, .. } = ev {
assert!(!payment_failed_permanently);
assert!(all_paths_failed);
} else { panic!("Unexpected event"); }
});
Expand All @@ -2411,8 +2411,8 @@ mod tests {
commitment_signed_dance!(nodes[0], nodes[1], &bs_fail_update.commitment_signed, false, true);

expected_events.borrow_mut().push_back(&|ev: &Event| {
if let Event::PaymentPathFailed { rejected_by_dest, all_paths_failed, .. } = ev {
assert!(!rejected_by_dest);
if let Event::PaymentPathFailed { payment_failed_permanently, all_paths_failed, .. } = ev {
assert!(!payment_failed_permanently);
assert!(all_paths_failed);
} else { panic!("Unexpected event"); }
});
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/chanmon_update_fail_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1744,9 +1744,9 @@ fn test_monitor_update_on_pending_forwards() {

let events = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events.len(), 2);
if let Event::PaymentPathFailed { payment_hash, rejected_by_dest, .. } = events[0] {
if let Event::PaymentPathFailed { payment_hash, payment_failed_permanently, .. } = events[0] {
assert_eq!(payment_hash, payment_hash_1);
assert!(rejected_by_dest);
assert!(payment_failed_permanently);
} else { panic!("Unexpected event!"); }
match events[1] {
Event::PendingHTLCsForwardable { .. } => { },
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3844,7 +3844,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
pending_events.push(events::Event::PaymentPathFailed {
payment_id: Some(payment_id),
payment_hash,
rejected_by_dest: false,
payment_failed_permanently: false,
network_update: None,
all_paths_failed: payment.get().remaining_parts() == 0,
path: path.clone(),
Expand Down Expand Up @@ -3959,7 +3959,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
events::Event::PaymentPathFailed {
payment_id: Some(payment_id),
payment_hash: payment_hash.clone(),
rejected_by_dest: !payment_retryable,
payment_failed_permanently: !payment_retryable,
network_update,
all_paths_failed,
path: path.clone(),
Expand Down Expand Up @@ -3990,7 +3990,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
events::Event::PaymentPathFailed {
payment_id: Some(payment_id),
payment_hash: payment_hash.clone(),
rejected_by_dest: path.len() == 1,
payment_failed_permanently: false,
network_update: None,
all_paths_failed,
path: path.clone(),
Expand Down
22 changes: 11 additions & 11 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,38 +1580,38 @@ impl<'a> PaymentFailedConditions<'a> {

#[cfg(test)]
macro_rules! expect_payment_failed_with_update {
($node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr, $scid: expr, $chan_closed: expr) => {
($node: expr, $expected_payment_hash: expr, $payment_failed_permanently: expr, $scid: expr, $chan_closed: expr) => {
$crate::ln::functional_test_utils::expect_payment_failed_conditions(
&$node, $expected_payment_hash, $rejected_by_dest,
&$node, $expected_payment_hash, $payment_failed_permanently,
$crate::ln::functional_test_utils::PaymentFailedConditions::new()
.blamed_scid($scid).blamed_chan_closed($chan_closed));
}
}

#[cfg(test)]
macro_rules! expect_payment_failed {
($node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr $(, $expected_error_code: expr, $expected_error_data: expr)*) => {
($node: expr, $expected_payment_hash: expr, $payment_failed_permanently: expr $(, $expected_error_code: expr, $expected_error_data: expr)*) => {
#[allow(unused_mut)]
let mut conditions = $crate::ln::functional_test_utils::PaymentFailedConditions::new();
$(
conditions = conditions.expected_htlc_error_data($expected_error_code, &$expected_error_data);
)*
$crate::ln::functional_test_utils::expect_payment_failed_conditions(&$node, $expected_payment_hash, $rejected_by_dest, conditions);
$crate::ln::functional_test_utils::expect_payment_failed_conditions(&$node, $expected_payment_hash, $payment_failed_permanently, conditions);
};
}

pub fn expect_payment_failed_conditions_event<'a, 'b, 'c, 'd, 'e>(
node: &'a Node<'b, 'c, 'd>, payment_failed_event: Event, expected_payment_hash: PaymentHash,
expected_rejected_by_dest: bool, conditions: PaymentFailedConditions<'e>
expected_payment_failed_permanently: bool, conditions: PaymentFailedConditions<'e>
) {
let expected_payment_id = match payment_failed_event {
Event::PaymentPathFailed { payment_hash, rejected_by_dest, path, retry, payment_id, network_update, short_channel_id,
Event::PaymentPathFailed { payment_hash, payment_failed_permanently, path, retry, payment_id, network_update, short_channel_id,
#[cfg(test)]
error_code,
#[cfg(test)]
error_data, .. } => {
assert_eq!(payment_hash, expected_payment_hash, "unexpected payment_hash");
assert_eq!(rejected_by_dest, expected_rejected_by_dest, "unexpected rejected_by_dest value");
assert_eq!(payment_failed_permanently, expected_payment_failed_permanently, "unexpected payment_failed_permanently value");
assert!(retry.is_some(), "expected retry.is_some()");
assert_eq!(retry.as_ref().unwrap().final_value_msat, path.last().unwrap().fee_msat, "Retry amount should match last hop in path");
assert_eq!(retry.as_ref().unwrap().payment_params.payee_pubkey, path.last().unwrap().pubkey, "Retry payee node_id should match last hop in path");
Expand Down Expand Up @@ -1668,12 +1668,12 @@ pub fn expect_payment_failed_conditions_event<'a, 'b, 'c, 'd, 'e>(
}

pub fn expect_payment_failed_conditions<'a, 'b, 'c, 'd, 'e>(
node: &'a Node<'b, 'c, 'd>, expected_payment_hash: PaymentHash, expected_rejected_by_dest: bool,
node: &'a Node<'b, 'c, 'd>, expected_payment_hash: PaymentHash, expected_payment_failed_permanently: bool,
conditions: PaymentFailedConditions<'e>
) {
let mut events = node.node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
expect_payment_failed_conditions_event(node, events.pop().unwrap(), expected_payment_hash, expected_rejected_by_dest, conditions);
expect_payment_failed_conditions_event(node, events.pop().unwrap(), expected_payment_hash, expected_payment_failed_permanently, conditions);
}

pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_paths: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret) -> PaymentId {
Expand Down Expand Up @@ -2017,9 +2017,9 @@ pub fn pass_failed_payment_back<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expe
let events = origin_node.node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
let expected_payment_id = match events[0] {
Event::PaymentPathFailed { payment_hash, rejected_by_dest, all_paths_failed, ref path, ref payment_id, .. } => {
Event::PaymentPathFailed { payment_hash, payment_failed_permanently, all_paths_failed, ref path, ref payment_id, .. } => {
assert_eq!(payment_hash, our_payment_hash);
assert!(rejected_by_dest);
assert!(payment_failed_permanently);
assert_eq!(all_paths_failed, i == expected_paths.len() - 1);
for (idx, hop) in expected_route.iter().enumerate() {
assert_eq!(hop.node.get_our_node_id(), path[idx].pubkey);
Expand Down
Loading