Skip to content

Commit 65cf4f8

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 a2886a2 commit 65cf4f8

File tree

1 file changed

+57
-4
lines changed

1 file changed

+57
-4
lines changed

lightning/src/routing/router.rs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,9 +2061,10 @@ where L::Target: Logger {
20612061
Some(fee) => fee,
20622062
None => continue
20632063
};
2064+
let path_min = candidate.htlc_minimum_msat().saturating_add(
2065+
compute_fees_saturating(candidate.htlc_minimum_msat(), candidate.fees()));
20642066
add_entry!(first_hop_candidate, our_node_id, intro_node_id, blinded_path_fee,
2065-
path_contribution_msat, candidate.htlc_minimum_msat(), 0_u64,
2066-
candidate.cltv_expiry_delta(),
2067+
path_contribution_msat, path_min, 0_u64, candidate.cltv_expiry_delta(),
20672068
candidate.blinded_path().map_or(1, |bp| bp.blinded_hops.len() as u8));
20682069
}
20692070
}
@@ -7192,6 +7193,10 @@ mod tests {
71927193

71937194
#[test]
71947195
fn min_htlc_overpay_violates_max_htlc() {
7196+
do_min_htlc_overpay_violates_max_htlc(true);
7197+
do_min_htlc_overpay_violates_max_htlc(false);
7198+
}
7199+
fn do_min_htlc_overpay_violates_max_htlc(blinded_payee: bool) {
71957200
// Test that if overpaying to meet a later hop's min_htlc and causes us to violate an earlier
71967201
// hop's max_htlc, we don't consider that candidate hop valid. Previously we would add this hop
71977202
// to `targets` and build an invalid path with it, and subsquently hit a debug panic asserting
@@ -7215,7 +7220,27 @@ mod tests {
72157220

72167221
let base_fee = 1_6778_3453;
72177222
let htlc_min = 2_5165_8240;
7218-
let payment_params = {
7223+
let payment_params = if blinded_payee {
7224+
let blinded_path = BlindedPath {
7225+
introduction_node_id: nodes[0],
7226+
blinding_point: ln_test_utils::pubkey(42),
7227+
blinded_hops: vec![
7228+
BlindedHop { blinded_node_id: ln_test_utils::pubkey(42 as u8), encrypted_payload: Vec::new() },
7229+
BlindedHop { blinded_node_id: ln_test_utils::pubkey(42 as u8), encrypted_payload: Vec::new() }
7230+
],
7231+
};
7232+
let blinded_payinfo = BlindedPayInfo {
7233+
fee_base_msat: base_fee,
7234+
fee_proportional_millionths: 0,
7235+
htlc_minimum_msat: htlc_min,
7236+
htlc_maximum_msat: htlc_min * 1000,
7237+
cltv_expiry_delta: 0,
7238+
features: BlindedHopFeatures::empty(),
7239+
};
7240+
let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_invoice_features(&config).to_context();
7241+
PaymentParameters::blinded(vec![(blinded_payinfo, blinded_path)])
7242+
.with_bolt12_features(bolt12_features.clone()).unwrap()
7243+
} else {
72197244
let route_hint = RouteHint(vec![RouteHintHop {
72207245
src_node_id: nodes[0],
72217246
short_channel_id: 42,
@@ -7246,6 +7271,11 @@ mod tests {
72467271

72477272
#[test]
72487273
fn previously_used_liquidity_violates_max_htlc() {
7274+
do_previously_used_liquidity_violates_max_htlc(true);
7275+
do_previously_used_liquidity_violates_max_htlc(false);
7276+
7277+
}
7278+
fn do_previously_used_liquidity_violates_max_htlc(blinded_payee: bool) {
72497279
// Test that if a candidate first_hop<>route_hint_src_node channel does not have enough
72507280
// contribution amount to cover the next hop's min_htlc plus fees, we will not consider that
72517281
// candidate. In this case, the candidate does not have enough due to a previous path taking up
@@ -7270,7 +7300,30 @@ mod tests {
72707300

72717301
let base_fees = [0, 425_9840, 0, 0];
72727302
let htlc_mins = [1_4392, 19_7401, 1027, 6_5535];
7273-
let payment_params = {
7303+
let payment_params = if blinded_payee {
7304+
let blinded_path = BlindedPath {
7305+
introduction_node_id: nodes[0],
7306+
blinding_point: ln_test_utils::pubkey(42),
7307+
blinded_hops: vec![
7308+
BlindedHop { blinded_node_id: ln_test_utils::pubkey(42 as u8), encrypted_payload: Vec::new() },
7309+
BlindedHop { blinded_node_id: ln_test_utils::pubkey(42 as u8), encrypted_payload: Vec::new() }
7310+
],
7311+
};
7312+
let mut blinded_hints = Vec::new();
7313+
for (base_fee, htlc_min) in base_fees.iter().zip(htlc_mins.iter()) {
7314+
blinded_hints.push((BlindedPayInfo {
7315+
fee_base_msat: *base_fee,
7316+
fee_proportional_millionths: 0,
7317+
htlc_minimum_msat: *htlc_min,
7318+
htlc_maximum_msat: htlc_min * 100,
7319+
cltv_expiry_delta: 10,
7320+
features: BlindedHopFeatures::empty(),
7321+
}, blinded_path.clone()));
7322+
}
7323+
let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_invoice_features(&config).to_context();
7324+
PaymentParameters::blinded(blinded_hints.clone())
7325+
.with_bolt12_features(bolt12_features.clone()).unwrap()
7326+
} else {
72747327
let mut route_hints = Vec::new();
72757328
for (idx, (base_fee, htlc_min)) in base_fees.iter().zip(htlc_mins.iter()).enumerate() {
72767329
route_hints.push(RouteHint(vec![RouteHintHop {

0 commit comments

Comments
 (0)