Skip to content

Commit 6622736

Browse files
Add public util on RouteParameters for setting max path length.
1 parent d198828 commit 6622736

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lightning/src/routing/router.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ use bitcoin::secp256k1::{PublicKey, Secp256k1, self};
1313

1414
use crate::blinded_path::{BlindedHop, BlindedPath, Direction, IntroductionNode};
1515
use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs};
16-
use crate::ln::types::PaymentHash;
17-
use crate::ln::channelmanager::{ChannelDetails, PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA};
16+
use crate::ln::{PaymentHash, PaymentPreimage};
17+
use crate::ln::channelmanager::{ChannelDetails, PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA, RecipientOnionFields};
1818
use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures};
1919
use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
20+
use crate::ln::onion_utils;
2021
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice};
2122
use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath};
2223
use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId, RoutingFees};
@@ -603,6 +604,17 @@ impl RouteParameters {
603604
pub fn from_payment_params_and_value(payment_params: PaymentParameters, final_value_msat: u64) -> Self {
604605
Self { payment_params, final_value_msat, max_total_routing_fee_msat: Some(final_value_msat / 100 + 50_000) }
605606
}
607+
608+
/// Sets the maximum number of hops that can be included in a payment path, based on the provided
609+
/// [`RecipientOnionFields`] and blinded paths.
610+
pub fn set_max_path_length(
611+
&mut self, recipient_onion: &RecipientOnionFields, is_keysend: bool, best_block_height: u32
612+
) -> Result<(), ()> {
613+
let keysend_preimage_opt = is_keysend.then(|| PaymentPreimage([42; 32]));
614+
onion_utils::set_max_path_length(
615+
self, recipient_onion, keysend_preimage_opt, best_block_height
616+
)
617+
}
606618
}
607619

608620
impl Writeable for RouteParameters {

0 commit comments

Comments
 (0)