Skip to content

Commit d83295f

Browse files
get_route: fix path_min for first_hop<>blinded_hint candidates
See previous commit, but the bug where we would underestimate how much a first hop candidate needed to be able to relay was also present in blinded paths.
1 parent 2aacbae commit d83295f

File tree

1 file changed

+57
-4
lines changed

1 file changed

+57
-4
lines changed

lightning/src/routing/router.rs

+57-4
Original file line numberDiff line numberDiff line change
@@ -2102,9 +2102,10 @@ where L::Target: Logger {
21022102
Some(fee) => fee,
21032103
None => continue
21042104
};
2105+
let path_min = candidate.htlc_minimum_msat().saturating_add(
2106+
compute_fees_saturating(candidate.htlc_minimum_msat(), candidate.fees()));
21052107
add_entry!(first_hop_candidate, our_node_id, intro_node_id, blinded_path_fee,
2106-
path_contribution_msat, candidate.htlc_minimum_msat(), 0_u64,
2107-
candidate.cltv_expiry_delta(),
2108+
path_contribution_msat, path_min, 0_u64, candidate.cltv_expiry_delta(),
21082109
candidate.blinded_path().map_or(1, |bp| bp.blinded_hops.len() as u8));
21092110
}
21102111
}
@@ -7286,6 +7287,10 @@ mod tests {
72867287

72877288
#[test]
72887289
fn min_htlc_overpay_violates_max_htlc() {
7290+
do_min_htlc_overpay_violates_max_htlc(true);
7291+
do_min_htlc_overpay_violates_max_htlc(false);
7292+
}
7293+
fn do_min_htlc_overpay_violates_max_htlc(blinded_payee: bool) {
72897294
// Test that if overpaying to meet a later hop's min_htlc and causes us to violate an earlier
72907295
// hop's max_htlc, we don't consider that candidate hop valid. Previously we would add this hop
72917296
// to `targets` and build an invalid path with it, and subsquently hit a debug panic asserting
@@ -7309,7 +7314,27 @@ mod tests {
73097314

73107315
let base_fee = 1_6778_3453;
73117316
let htlc_min = 2_5165_8240;
7312-
let payment_params = {
7317+
let payment_params = if blinded_payee {
7318+
let blinded_path = BlindedPath {
7319+
introduction_node_id: nodes[0],
7320+
blinding_point: ln_test_utils::pubkey(42),
7321+
blinded_hops: vec![
7322+
BlindedHop { blinded_node_id: ln_test_utils::pubkey(42 as u8), encrypted_payload: Vec::new() },
7323+
BlindedHop { blinded_node_id: ln_test_utils::pubkey(42 as u8), encrypted_payload: Vec::new() }
7324+
],
7325+
};
7326+
let blinded_payinfo = BlindedPayInfo {
7327+
fee_base_msat: base_fee,
7328+
fee_proportional_millionths: 0,
7329+
htlc_minimum_msat: htlc_min,
7330+
htlc_maximum_msat: htlc_min * 1000,
7331+
cltv_expiry_delta: 0,
7332+
features: BlindedHopFeatures::empty(),
7333+
};
7334+
let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_invoice_features(&config).to_context();
7335+
PaymentParameters::blinded(vec![(blinded_payinfo, blinded_path)])
7336+
.with_bolt12_features(bolt12_features.clone()).unwrap()
7337+
} else {
73137338
let route_hint = RouteHint(vec![RouteHintHop {
73147339
src_node_id: nodes[0],
73157340
short_channel_id: 42,
@@ -7340,6 +7365,11 @@ mod tests {
73407365

73417366
#[test]
73427367
fn previously_used_liquidity_violates_max_htlc() {
7368+
do_previously_used_liquidity_violates_max_htlc(true);
7369+
do_previously_used_liquidity_violates_max_htlc(false);
7370+
7371+
}
7372+
fn do_previously_used_liquidity_violates_max_htlc(blinded_payee: bool) {
73437373
// Test that if a candidate first_hop<>route_hint_src_node channel does not have enough
73447374
// contribution amount to cover the next hop's min_htlc plus fees, we will not consider that
73457375
// candidate. In this case, the candidate does not have enough due to a previous path taking up
@@ -7364,7 +7394,30 @@ mod tests {
73647394

73657395
let base_fees = [0, 425_9840, 0, 0];
73667396
let htlc_mins = [1_4392, 19_7401, 1027, 6_5535];
7367-
let payment_params = {
7397+
let payment_params = if blinded_payee {
7398+
let blinded_path = BlindedPath {
7399+
introduction_node_id: nodes[0],
7400+
blinding_point: ln_test_utils::pubkey(42),
7401+
blinded_hops: vec![
7402+
BlindedHop { blinded_node_id: ln_test_utils::pubkey(42 as u8), encrypted_payload: Vec::new() },
7403+
BlindedHop { blinded_node_id: ln_test_utils::pubkey(42 as u8), encrypted_payload: Vec::new() }
7404+
],
7405+
};
7406+
let mut blinded_hints = Vec::new();
7407+
for (base_fee, htlc_min) in base_fees.iter().zip(htlc_mins.iter()) {
7408+
blinded_hints.push((BlindedPayInfo {
7409+
fee_base_msat: *base_fee,
7410+
fee_proportional_millionths: 0,
7411+
htlc_minimum_msat: *htlc_min,
7412+
htlc_maximum_msat: htlc_min * 100,
7413+
cltv_expiry_delta: 10,
7414+
features: BlindedHopFeatures::empty(),
7415+
}, blinded_path.clone()));
7416+
}
7417+
let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_invoice_features(&config).to_context();
7418+
PaymentParameters::blinded(blinded_hints.clone())
7419+
.with_bolt12_features(bolt12_features.clone()).unwrap()
7420+
} else {
73687421
let mut route_hints = Vec::new();
73697422
for (idx, (base_fee, htlc_min)) in base_fees.iter().zip(htlc_mins.iter()).enumerate() {
73707423
route_hints.push(RouteHint(vec![RouteHintHop {

0 commit comments

Comments
 (0)