X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=lightning%2Fsrc%2Frouting%2Frouter.rs;h=8f68ebfb02dce2abe494a655463246e7b9fe8943;hb=3cc673bec27703bbd7ed4a60421e10a85a01569c;hp=81312980a5a1550137078ab69506c894c6d35c69;hpb=c07245f1292b1679e7bb36a1bfae1517bfe36451;p=rust-lightning diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 81312980..8f68ebfb 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -13,10 +13,11 @@ use bitcoin::secp256k1::{PublicKey, Secp256k1, self}; use crate::blinded_path::{BlindedHop, BlindedPath, Direction, IntroductionNode}; use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs}; -use crate::ln::types::PaymentHash; -use crate::ln::channelmanager::{ChannelDetails, PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA}; +use crate::ln::{PaymentHash, PaymentPreimage}; +use crate::ln::channelmanager::{ChannelDetails, PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA, RecipientOnionFields}; use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures}; use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT}; +use crate::ln::onion_utils; use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice}; use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath}; use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId, RoutingFees}; @@ -603,6 +604,17 @@ impl RouteParameters { pub fn from_payment_params_and_value(payment_params: PaymentParameters, final_value_msat: u64) -> Self { Self { payment_params, final_value_msat, max_total_routing_fee_msat: Some(final_value_msat / 100 + 50_000) } } + + /// Sets the maximum number of hops that can be included in a payment path, based on the provided + /// [`RecipientOnionFields`] and blinded paths. + pub fn set_max_path_length( + &mut self, recipient_onion: &RecipientOnionFields, is_keysend: bool, best_block_height: u32 + ) -> Result<(), ()> { + let keysend_preimage_opt = is_keysend.then(|| PaymentPreimage([42; 32])); + onion_utils::set_max_path_length( + self, recipient_onion, keysend_preimage_opt, best_block_height + ) + } } impl Writeable for RouteParameters {