Add UserConfig::manually_handle_bolt12_invoices
[rust-lightning] / lightning / src / routing / router.rs
index 28101991cf700c35fab7e781e7389979564a0361..5b202604e371a5624a5cce671f2ec3fbe44a7eab 100644 (file)
@@ -15,7 +15,8 @@ use crate::blinded_path::{BlindedHop, BlindedPath, Direction, IntroductionNode};
 use crate::blinded_path::message;
 use crate::blinded_path::payment::{ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs, self};
 use crate::ln::{PaymentHash, PaymentPreimage};
-use crate::ln::channelmanager::{ChannelDetails, PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA, RecipientOnionFields};
+use crate::ln::channel_state::ChannelDetails;
+use crate::ln::channelmanager::{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;
@@ -35,6 +36,11 @@ use core::{cmp, fmt};
 use core::ops::Deref;
 
 /// A [`Router`] implemented using [`find_route`].
+///
+/// # Privacy
+///
+/// Implements [`MessageRouter`] by delegating to [`DefaultMessageRouter`]. See those docs for
+/// privacy implications.
 pub struct DefaultRouter<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref, SP: Sized, Sc: ScoreLookUp<ScoreParams = SP>> where
        L::Target: Logger,
        S::Target: for <'a> LockableScore<'a, ScoreLookUp = Sc>,
@@ -172,10 +178,18 @@ impl< G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
        fn create_blinded_paths<
                T: secp256k1::Signing + secp256k1::Verification
        > (
-               &self, recipient: PublicKey, peers: Vec<message::ForwardNode>, secp_ctx: &Secp256k1<T>,
+               &self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
                self.message_router.create_blinded_paths(recipient, peers, secp_ctx)
        }
+
+       fn create_compact_blinded_paths<
+               T: secp256k1::Signing + secp256k1::Verification
+       > (
+               &self, recipient: PublicKey, peers: Vec<message::ForwardNode>, secp_ctx: &Secp256k1<T>,
+       ) -> Result<Vec<BlindedPath>, ()> {
+               self.message_router.create_compact_blinded_paths(recipient, peers, secp_ctx)
+       }
 }
 
 /// A trait defining behavior for routing a payment.
@@ -2009,7 +2023,7 @@ where L::Target: Logger {
                true
        } else if let Some(payee) = payee_node_id_opt {
                network_nodes.get(&payee).map_or(false, |node| node.announcement_info.as_ref().map_or(false,
-                       |info| info.features.supports_basic_mpp()))
+                       |info| info.features().supports_basic_mpp()))
        } else { false };
 
        let max_total_routing_fee_msat = route_params.max_total_routing_fee_msat.unwrap_or(u64::max_value());
@@ -2499,7 +2513,7 @@ where L::Target: Logger {
                                }
 
                                let features = if let Some(node_info) = $node.announcement_info.as_ref() {
-                                       &node_info.features
+                                       &node_info.features()
                                } else {
                                        &default_node_features
                                };
@@ -2828,7 +2842,7 @@ where L::Target: Logger {
                                        if !features_set {
                                                if let Some(node) = network_nodes.get(&target) {
                                                        if let Some(node_info) = node.announcement_info.as_ref() {
-                                                               ordered_hops.last_mut().unwrap().1 = node_info.features.clone();
+                                                               ordered_hops.last_mut().unwrap().1 = node_info.features().clone();
                                                        } else {
                                                                ordered_hops.last_mut().unwrap().1 = default_node_features.clone();
                                                        }
@@ -3321,6 +3335,7 @@ mod tests {
        use crate::routing::test_utils::{add_channel, add_or_update_node, build_graph, build_line_graph, id_to_feature_flags, get_nodes, update_channel};
        use crate::chain::transaction::OutPoint;
        use crate::sign::EntropySource;
+       use crate::ln::channel_state::{ChannelCounterparty, ChannelDetails, ChannelShutdownState};
        use crate::ln::types::ChannelId;
        use crate::ln::features::{BlindedHopFeatures, ChannelFeatures, InitFeatures, NodeFeatures};
        use crate::ln::msgs::{ErrorAction, LightningError, UnsignedChannelUpdate, MAX_VALUE_MSAT};
@@ -3349,10 +3364,10 @@ mod tests {
        use crate::sync::Arc;
 
        fn get_channel_details(short_channel_id: Option<u64>, node_id: PublicKey,
-                       features: InitFeatures, outbound_capacity_msat: u64) -> channelmanager::ChannelDetails {
-               channelmanager::ChannelDetails {
+                       features: InitFeatures, outbound_capacity_msat: u64) -> ChannelDetails {
+               ChannelDetails {
                        channel_id: ChannelId::new_zero(),
-                       counterparty: channelmanager::ChannelCounterparty {
+                       counterparty: ChannelCounterparty {
                                features,
                                node_id,
                                unspendable_punishment_reserve: 0,
@@ -3382,7 +3397,7 @@ mod tests {
                        inbound_htlc_maximum_msat: None,
                        config: None,
                        feerate_sat_per_1000_weight: None,
-                       channel_shutdown_state: Some(channelmanager::ChannelShutdownState::NotShuttingDown),
+                       channel_shutdown_state: Some(ChannelShutdownState::NotShuttingDown),
                        pending_inbound_htlcs: Vec::new(),
                        pending_outbound_htlcs: Vec::new(),
                }
@@ -8504,8 +8519,9 @@ pub(crate) mod bench_utils {
        use crate::chain::transaction::OutPoint;
        use crate::routing::scoring::ScoreUpdate;
        use crate::sign::KeysManager;
+       use crate::ln::channel_state::{ChannelCounterparty, ChannelShutdownState};
+       use crate::ln::channelmanager;
        use crate::ln::types::ChannelId;
-       use crate::ln::channelmanager::{self, ChannelCounterparty};
        use crate::util::config::UserConfig;
        use crate::util::test_utils::TestLogger;
 
@@ -8590,7 +8606,7 @@ pub(crate) mod bench_utils {
                        inbound_htlc_maximum_msat: None,
                        config: None,
                        feerate_sat_per_1000_weight: None,
-                       channel_shutdown_state: Some(channelmanager::ChannelShutdownState::NotShuttingDown),
+                       channel_shutdown_state: Some(ChannelShutdownState::NotShuttingDown),
                        pending_inbound_htlcs: Vec::new(),
                        pending_outbound_htlcs: Vec::new(),
                }