X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Frouter.rs;h=1b52af8815624e3c4e3e3d9a400577875cfa8869;hb=5b36449c5950a78ae1857985c8ce309cdf091cc9;hp=d6aef902f0c1f28bddd8ad23279324410cd988d6;hpb=756bcbc66763abddf864490e1581c9a890435cbb;p=rust-lightning diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index d6aef902..1b52af88 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -670,6 +670,9 @@ where L::Target: Logger { } } } + if payment_params.max_total_cltv_expiry_delta <= final_cltv_expiry_delta { + return Err(LightningError{err: "Can't find a route where the maximum total CLTV expiry delta is below the final CLTV expiry.".to_owned(), action: ErrorAction::IgnoreError}); + } // The general routing idea is the following: // 1. Fill first/last hops communicated by the caller. @@ -866,9 +869,9 @@ where L::Target: Logger { // In order to already account for some of the privacy enhancing random CLTV // expiry delta offset we add on top later, we subtract a rough estimate // (2*MEDIAN_HOP_CLTV_EXPIRY_DELTA) here. - let max_total_cltv_expiry_delta = payment_params.max_total_cltv_expiry_delta + let max_total_cltv_expiry_delta = (payment_params.max_total_cltv_expiry_delta - final_cltv_expiry_delta) .checked_sub(2*MEDIAN_HOP_CLTV_EXPIRY_DELTA) - .unwrap_or(payment_params.max_total_cltv_expiry_delta); + .unwrap_or(payment_params.max_total_cltv_expiry_delta - final_cltv_expiry_delta); let hop_total_cltv_delta = ($next_hops_cltv_delta as u32) .checked_add($candidate.cltv_expiry_delta()) .unwrap_or(u32::max_value()); @@ -1668,6 +1671,7 @@ mod tests { }, funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }), short_channel_id, + inbound_scid_alias: None, channel_value_satoshis: 0, user_channel_id: 0, balance_msat: 0, @@ -2487,7 +2491,8 @@ mod tests { let random_seed_bytes = keys_manager.get_secure_random_bytes(); // Disable nodes 1, 2, and 8 by requiring unknown feature bits - let unknown_features = NodeFeatures::known().set_unknown_feature_required(); + let mut unknown_features = NodeFeatures::known(); + unknown_features.set_unknown_feature_required(); add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[0], unknown_features.clone(), 1); add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[1], unknown_features.clone(), 1); add_or_update_node(&net_graph_msg_handler, &secp_ctx, &privkeys[7], unknown_features.clone(), 1); @@ -5091,7 +5096,7 @@ mod tests { .with_max_total_cltv_expiry_delta(feasible_max_total_cltv_delta); let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet); let random_seed_bytes = keys_manager.get_secure_random_bytes(); - let route = get_route(&our_id, &feasible_payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap(); + let route = get_route(&our_id, &feasible_payment_params, &network_graph, None, 100, 0, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap(); let path = route.paths[0].iter().map(|hop| hop.short_channel_id).collect::>(); assert_ne!(path.len(), 0); @@ -5099,7 +5104,7 @@ mod tests { let fail_max_total_cltv_delta = 23; let fail_payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes)) .with_max_total_cltv_expiry_delta(fail_max_total_cltv_delta); - match get_route(&our_id, &fail_payment_params, &network_graph, None, 100, 42, Arc::clone(&logger), &scorer, &random_seed_bytes) + match get_route(&our_id, &fail_payment_params, &network_graph, None, 100, 0, Arc::clone(&logger), &scorer, &random_seed_bytes) { Err(LightningError { err, .. } ) => { assert_eq!(err, "Failed to find a path to the given destination"); @@ -5362,6 +5367,7 @@ mod benches { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }), short_channel_id: Some(1), + inbound_scid_alias: None, channel_value_satoshis: 10_000_000, user_channel_id: 0, balance_msat: 10_000_000, @@ -5433,7 +5439,7 @@ mod benches { let mut routes = Vec::new(); let mut route_endpoints = Vec::new(); let mut seed: usize = 0xdeadbeef; - 'load_endpoints: for _ in 0..100 { + 'load_endpoints: for _ in 0..150 { loop { seed *= 0xdeadbeef; let src = PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap(); @@ -5465,6 +5471,15 @@ mod benches { } } + // Because we've changed channel scores, its possible we'll take different routes to the + // selected destinations, possibly causing us to fail because, eg, the newly-selected path + // requires a too-high CLTV delta. + route_endpoints.retain(|(first_hop, params, amt)| { + get_route(&payer, params, &graph.read_only(), Some(&[first_hop]), *amt, 42, &DummyLogger{}, &scorer, &random_seed_bytes).is_ok() + }); + route_endpoints.truncate(100); + assert_eq!(route_endpoints.len(), 100); + // ...then benchmark finding paths between the nodes we learned. let mut idx = 0; bench.iter(|| {