Skip to content

Commit ef962dc

Browse files
committed
Consider hop_payloads length and hmac fields.
1 parent 3131cba commit ef962dc

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lightning/src/routing/router.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub struct Route {
6868
/// last RouteHop in each path must be the same.
6969
/// Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the
7070
/// destination. Thus, this must always be at least length one. While the maximum length of any
71-
/// given path is variable, keeping the length of any path to less than 40 should currently
71+
/// given path is variable, keeping the length of any path to less than 20 should currently
7272
/// ensure it is viable.
7373
pub paths: Vec<Vec<RouteHop>>,
7474
/// The `payment_params` parameter passed to [`find_route`].
@@ -1476,21 +1476,21 @@ where L::Target: Logger {
14761476
}
14771477

14781478
// Step (5).
1479-
// We only consider paths shorter than our maximum length estimate.
1479+
// We only consider paths shorter than our maximum length estimate.
14801480
// In the legacy onion format, the maximum number of hops used to be a fixed value of 20.
14811481
// However, in the TLV onion format, there is no fixed maximum length, but the `hop_payloads`
14821482
// field is always 1300 bytes. As the `tlv_payload` for each hop may vary in length, we have to
14831483
// estimate how many hops the route may have so that it actually fits the `hop_payloads` field.
14841484
//
1485-
// We estimate 2+8 (amt_to_forward) + 2+4 (outgoing_cltv_value) + 2+8 (short_channel_id) = 26
1486-
// bytes for each intermediate hop and 2+8 (amt_to_forward) + 2+4 (outgoing_cltv_value) +
1487-
// 2+32+8 (payment_secret and total_msat) = 58 bytes for the final hop.
1488-
// Since the length of the potentially included `payment_metadata` is unkown to us, we
1489-
// generously round down from (1300-58) / 26 = 47 to arrive at a conservative estimate of a
1490-
// feasible maximum path length of 40 hops.
1491-
const MAX_PATH_LENGTH_ESTIMATE: usize = 40;
1485+
// We estimate 3+32 (payload length and HMAC) + 1+8 (amt_to_forward) + 1+4 (outgoing_cltv_value) +
1486+
// 1+8 (short_channel_id) = 58 bytes for each intermediate hop and 3+32
1487+
// (payload length and HMAC) + 1+8 (amt_to_forward) + 1+4 (outgoing_cltv_value) + 1+32+8
1488+
// (payment_secret and total_msat) = 90 bytes for the final hop.
1489+
// Since the length of the potentially included `payment_metadata` is unkown to us, we round
1490+
// down from (1300-90) / 58 = 21 just to arrive again at a conservative estimate of 20.
1491+
const MAX_PATH_LENGTH_ESTIMATE: usize = 20;
14921492
payment_paths.retain(|path| path.hops.len() <= MAX_PATH_LENGTH_ESTIMATE);
1493-
1493+
14941494
if payment_paths.len() == 0 {
14951495
return Err(LightningError{err: "Failed to find a path to the given destination".to_owned(), action: ErrorAction::IgnoreError});
14961496
}

0 commit comments

Comments
 (0)