From 6f6e0861964f7bc2bd83e4d765ad7d111d216e4f Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 1 Sep 2023 09:38:44 -0500 Subject: [PATCH] BOLT12 invoice_feature methods for ChannelManager --- lightning/src/ln/blinded_payment_tests.rs | 5 ++--- lightning/src/ln/channelmanager.rs | 14 +++++++++++- lightning/src/routing/router.rs | 26 +++++++++++------------ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs index 6a3b20fef..e8b6bfd67 100644 --- a/lightning/src/ln/blinded_payment_tests.rs +++ b/lightning/src/ln/blinded_payment_tests.rs @@ -13,7 +13,6 @@ use crate::blinded_path::payment::{PaymentConstraints, ReceiveTlvs}; use crate::events::MessageSendEventsProvider; use crate::ln::channelmanager; use crate::ln::channelmanager::{PaymentId, RecipientOnionFields}; -use crate::ln::features::Bolt12InvoiceFeatures; use crate::ln::functional_test_utils::*; use crate::ln::outbound_payment::Retry; use crate::prelude::*; @@ -88,8 +87,8 @@ fn mpp_to_one_hop_blinded_path() { nodes[3].node.get_our_node_id(), payee_tlvs, &chanmon_cfgs[3].keys_manager, &secp_ctx ).unwrap(); - let bolt12_features: Bolt12InvoiceFeatures = - channelmanager::provided_bolt11_invoice_features(&UserConfig::default()).to_context(); + let bolt12_features = + channelmanager::provided_bolt12_invoice_features(&UserConfig::default()); let route_params = RouteParameters::from_payment_params_and_value( PaymentParameters::blinded(vec![blinded_path]).with_bolt12_features(bolt12_features).unwrap(), amt_msat, diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 2aa2aab2a..4400bde20 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -43,7 +43,7 @@ use crate::events::{Event, EventHandler, EventsProvider, MessageSendEvent, Messa // construct one themselves. use crate::ln::{inbound_payment, ChannelId, PaymentHash, PaymentPreimage, PaymentSecret}; use crate::ln::channel::{Channel, ChannelPhase, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UnfundedChannelContext, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel}; -use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures}; +use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures}; #[cfg(any(feature = "_test_utils", test))] use crate::ln::features::Bolt11InvoiceFeatures; use crate::routing::gossip::NetworkGraph; @@ -8260,6 +8260,12 @@ where provided_bolt11_invoice_features(&self.default_configuration) } + /// Fetches the set of [`Bolt12InvoiceFeatures`] flags that are provided by or required by + /// [`ChannelManager`]. + fn bolt12_invoice_features(&self) -> Bolt12InvoiceFeatures { + provided_bolt12_invoice_features(&self.default_configuration) + } + /// Fetches the set of [`ChannelFeatures`] flags which are provided by or required by /// [`ChannelManager`]. pub fn channel_features(&self) -> ChannelFeatures { @@ -8821,6 +8827,12 @@ pub(crate) fn provided_bolt11_invoice_features(config: &UserConfig) -> Bolt11Inv provided_init_features(config).to_context() } +/// Fetches the set of [`Bolt12InvoiceFeatures`] flags that are provided by or required by +/// [`ChannelManager`]. +pub(crate) fn provided_bolt12_invoice_features(config: &UserConfig) -> Bolt12InvoiceFeatures { + provided_init_features(config).to_context() +} + /// Fetches the set of [`ChannelFeatures`] flags which are provided by or required by /// [`ChannelManager`]. pub(crate) fn provided_channel_features(config: &UserConfig) -> ChannelFeatures { diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index cce62b5dd..fe73b37cf 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -2818,7 +2818,7 @@ mod tests { use crate::chain::transaction::OutPoint; use crate::sign::EntropySource; use crate::ln::ChannelId; - use crate::ln::features::{BlindedHopFeatures, Bolt12InvoiceFeatures, ChannelFeatures, InitFeatures, NodeFeatures}; + use crate::ln::features::{BlindedHopFeatures, ChannelFeatures, InitFeatures, NodeFeatures}; use crate::ln::msgs::{ErrorAction, LightningError, UnsignedChannelUpdate, MAX_VALUE_MSAT}; use crate::ln::channelmanager; use crate::offers::invoice::BlindedPayInfo; @@ -4674,7 +4674,7 @@ mod tests { do_simple_mpp_route_test(clear_payment_params); // MPP to a 1-hop blinded path for nodes[2] - let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_bolt11_invoice_features(&config).to_context(); + let bolt12_features = channelmanager::provided_bolt12_invoice_features(&config); let blinded_path = BlindedPath { introduction_node_id: nodes[2], blinding_point: ln_test_utils::pubkey(42), @@ -6795,7 +6795,7 @@ mod tests { cltv_expiry_delta: 10, features: BlindedHopFeatures::empty(), }; - let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_bolt11_invoice_features(&config).to_context(); + let bolt12_features = channelmanager::provided_bolt12_invoice_features(&config); let payment_params = PaymentParameters::blinded(vec![ (blinded_payinfo.clone(), blinded_path.clone()), (blinded_payinfo.clone(), blinded_path.clone())]) @@ -7104,7 +7104,7 @@ mod tests { let random_seed_bytes = keys_manager.get_secure_random_bytes(); let config = UserConfig::default(); - let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_bolt11_invoice_features(&config).to_context(); + let bolt12_features = channelmanager::provided_bolt12_invoice_features(&config); let blinded_path_1 = BlindedPath { introduction_node_id: nodes[2], blinding_point: ln_test_utils::pubkey(42), @@ -7132,7 +7132,7 @@ mod tests { (blinded_payinfo_2.clone(), blinded_path_2.clone()), ]; let payment_params = PaymentParameters::blinded(blinded_hints.clone()) - .with_bolt12_features(bolt12_features.clone()).unwrap(); + .with_bolt12_features(bolt12_features).unwrap(); let mut route_params = RouteParameters::from_payment_params_and_value(payment_params, 100_000); route_params.max_total_routing_fee_msat = Some(100_000); @@ -7297,9 +7297,9 @@ mod tests { blinded_hints[1].0.htlc_maximum_msat = 2_8089_0861_1584_0000; blinded_hints[1].0.cltv_expiry_delta = 0; - let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_bolt11_invoice_features(&config).to_context(); + let bolt12_features = channelmanager::provided_bolt12_invoice_features(&config); let payment_params = PaymentParameters::blinded(blinded_hints.clone()) - .with_bolt12_features(bolt12_features.clone()).unwrap(); + .with_bolt12_features(bolt12_features).unwrap(); let netgraph = network_graph.read_only(); let route_params = RouteParameters::from_payment_params_and_value( @@ -7349,7 +7349,7 @@ mod tests { ]; blinded_hints[1].1.introduction_node_id = nodes[6]; - let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_bolt11_invoice_features(&config).to_context(); + let bolt12_features = channelmanager::provided_bolt12_invoice_features(&config); let payment_params = PaymentParameters::blinded(blinded_hints.clone()) .with_bolt12_features(bolt12_features.clone()).unwrap(); @@ -7406,7 +7406,7 @@ mod tests { blinded_hints[2].1.introduction_node_id = nodes[6]; - let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_bolt11_invoice_features(&config).to_context(); + let bolt12_features = channelmanager::provided_bolt12_invoice_features(&config); let payment_params = PaymentParameters::blinded(blinded_hints.clone()) .with_bolt12_features(bolt12_features.clone()).unwrap(); @@ -7466,7 +7466,7 @@ mod tests { cltv_expiry_delta: 0, features: BlindedHopFeatures::empty(), }; - let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_bolt11_invoice_features(&config).to_context(); + let bolt12_features = channelmanager::provided_bolt12_invoice_features(&config); PaymentParameters::blinded(vec![(blinded_payinfo, blinded_path)]) .with_bolt12_features(bolt12_features.clone()).unwrap() } else { @@ -7549,7 +7549,7 @@ mod tests { features: BlindedHopFeatures::empty(), }, blinded_path.clone())); } - let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_bolt11_invoice_features(&config).to_context(); + let bolt12_features = channelmanager::provided_bolt12_invoice_features(&config); PaymentParameters::blinded(blinded_hints.clone()) .with_bolt12_features(bolt12_features.clone()).unwrap() } else { @@ -7640,7 +7640,7 @@ mod tests { ], }) ]; - let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_bolt11_invoice_features(&config).to_context(); + let bolt12_features = channelmanager::provided_bolt12_invoice_features(&config); let payment_params = PaymentParameters::blinded(blinded_hints.clone()) .with_bolt12_features(bolt12_features.clone()).unwrap(); let route_params = RouteParameters::from_payment_params_and_value( @@ -7700,7 +7700,7 @@ mod tests { features: BlindedHopFeatures::empty(), }, blinded_path.clone())); } - let bolt12_features: Bolt12InvoiceFeatures = channelmanager::provided_bolt11_invoice_features(&config).to_context(); + let bolt12_features = channelmanager::provided_bolt12_invoice_features(&config); PaymentParameters::blinded(blinded_hints.clone()) .with_bolt12_features(bolt12_features.clone()).unwrap() }; -- 2.39.5