Skip to content

Commit 5a87041

Browse files
committed
fixup! Expose APIs to access supported feature flags
This fixup moves node feature exposure from freestanding APIs to NodeStatus, as suggested in review. Rather than exposing init_features(), channel_features(), bolt11_invoice_features(), and node_features() as separate public methods on Node, this embeds NodeFeatures in the NodeStatus struct returned by Node::status(). Additionally, channel and invoice features at node level are confusing. Users would expect negotiated per-peer/channel/invoice features, not what the node generally supports. Access to negotiated features are addressed in #841
1 parent 0c58f58 commit 5a87041

File tree

3 files changed

+14
-73
lines changed

3 files changed

+14
-73
lines changed

src/ffi/types.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub use lightning_liquidity::lsps0::ser::LSPSDateTime;
4343
pub use lightning_liquidity::lsps1::msgs::{
4444
LSPS1ChannelInfo, LSPS1OrderId, LSPS1OrderParams, LSPS1PaymentState,
4545
};
46+
use lightning_types::features::NodeFeatures;
4647
pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
4748
pub use lightning_types::string::UntrustedString;
4849
use vss_client::headers::{
@@ -1496,6 +1497,13 @@ pub enum ClosureReason {
14961497
},
14971498
}
14981499

1500+
#[cfg(feature = "uniffi")]
1501+
uniffi::custom_type!(NodeFeatures, Vec<u8>, {
1502+
remote,
1503+
try_lift: |val| Ok(NodeFeatures::from_le_bytes(val)),
1504+
lower: |obj| obj.le_flags().to_vec(),
1505+
});
1506+
14991507
#[cfg(test)]
15001508
mod tests {
15011509
use std::num::NonZeroU64;

src/lib.rs

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ use lightning_background_processor::process_events_async;
161161
pub use lightning_invoice;
162162
pub use lightning_liquidity;
163163
pub use lightning_types;
164-
use lightning_types::features::{
165-
Bolt11InvoiceFeatures, ChannelFeatures, InitFeatures, NodeFeatures,
166-
};
164+
use lightning_types::features::NodeFeatures;
167165
use liquidity::{LSPS1Liquidity, LiquiditySource};
168166
use lnurl_auth::LnurlAuth;
169167
use logger::{log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
@@ -766,6 +764,7 @@ impl Node {
766764
locked_node_metrics.latest_pathfinding_scores_sync_timestamp;
767765
let latest_node_announcement_broadcast_timestamp =
768766
locked_node_metrics.latest_node_announcement_broadcast_timestamp;
767+
let node_features = self.node_features();
769768

770769
NodeStatus {
771770
is_running,
@@ -776,6 +775,7 @@ impl Node {
776775
latest_rgs_snapshot_timestamp,
777776
latest_pathfinding_scores_sync_timestamp,
778777
latest_node_announcement_broadcast_timestamp,
778+
node_features,
779779
}
780780
}
781781

@@ -1955,7 +1955,7 @@ impl Node {
19551955
}
19561956

19571957
/// Return the features used in node announcement.
1958-
pub fn node_features(&self) -> NodeFeatures {
1958+
fn node_features(&self) -> NodeFeatures {
19591959
let gossip_features = match self.gossip_source.as_gossip_sync() {
19601960
lightning_background_processor::GossipSync::P2P(p2p_gossip_sync) => {
19611961
p2p_gossip_sync.provided_node_features()
@@ -1975,41 +1975,6 @@ impl Node {
19751975
.map(|ls| ls.liquidity_manager().provided_node_features())
19761976
.unwrap_or_else(NodeFeatures::empty)
19771977
}
1978-
1979-
/// Return the node's init features.
1980-
pub fn init_features(&self) -> InitFeatures {
1981-
let gossip_init_features = match self.gossip_source.as_gossip_sync() {
1982-
lightning_background_processor::GossipSync::P2P(p2p_gossip_sync) => {
1983-
p2p_gossip_sync.provided_init_features(self.node_id())
1984-
},
1985-
lightning_background_processor::GossipSync::Rapid(_) => InitFeatures::empty(),
1986-
lightning_background_processor::GossipSync::None => {
1987-
unreachable!("We must always have a gossip sync!")
1988-
},
1989-
};
1990-
self.channel_manager.init_features()
1991-
| self.chain_monitor.provided_init_features(self.node_id())
1992-
| self.onion_messenger.provided_init_features(self.node_id())
1993-
| gossip_init_features
1994-
| self
1995-
.liquidity_source
1996-
.as_ref()
1997-
.map(|ls| ls.liquidity_manager().provided_init_features(self.node_id()))
1998-
.unwrap_or_else(InitFeatures::empty)
1999-
}
2000-
2001-
/// Return the node's channel features.
2002-
pub fn channel_features(&self) -> ChannelFeatures {
2003-
self.channel_manager.channel_features()
2004-
}
2005-
2006-
/// Return the node's BOLT 11 invoice features.
2007-
pub fn bolt11_invoice_features(&self) -> Bolt11InvoiceFeatures {
2008-
// bolt11_invoice_features() is not public because feature
2009-
// flags can vary due to invoice type, so we convert from
2010-
// context.
2011-
self.channel_manager.init_features().to_context()
2012-
}
20131978
}
20141979

20151980
impl Drop for Node {
@@ -2053,6 +2018,8 @@ pub struct NodeStatus {
20532018
///
20542019
/// Will be `None` if we have no public channels or we haven't broadcasted yet.
20552020
pub latest_node_announcement_broadcast_timestamp: Option<u64>,
2021+
/// The features used within a node_announcement message.
2022+
pub node_features: NodeFeatures,
20562023
}
20572024

20582025
/// Status fields that are persisted across restarts.

tests/integration_tests_rust.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2805,37 +2805,3 @@ async fn splice_in_with_all_balance() {
28052805
node_a.stop().unwrap();
28062806
node_b.stop().unwrap();
28072807
}
2808-
2809-
#[test]
2810-
fn node_feature_flags() {
2811-
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
2812-
let chain_source = random_chain_source(&bitcoind, &electrsd);
2813-
let config = random_config(true);
2814-
let node = setup_node(&chain_source, config);
2815-
2816-
// NodeFeatures
2817-
let node_features = node.node_features();
2818-
assert!(node_features.supports_variable_length_onion());
2819-
assert!(node_features.supports_payment_secret());
2820-
assert!(node_features.supports_basic_mpp());
2821-
assert!(node_features.supports_keysend());
2822-
assert!(node_features.supports_onion_messages());
2823-
2824-
// InitFeatures
2825-
let init_features = node.init_features();
2826-
assert!(init_features.supports_variable_length_onion());
2827-
assert!(init_features.supports_payment_secret());
2828-
assert!(init_features.supports_basic_mpp());
2829-
assert!(init_features.supports_onion_messages());
2830-
2831-
// ChannelFeatures (non-empty)
2832-
let _channel_features = node.channel_features();
2833-
2834-
// Bolt11InvoiceFeatures
2835-
let bolt11_features = node.bolt11_invoice_features();
2836-
assert!(bolt11_features.supports_variable_length_onion());
2837-
assert!(bolt11_features.supports_payment_secret());
2838-
assert!(bolt11_features.supports_basic_mpp());
2839-
2840-
node.stop().unwrap();
2841-
}

0 commit comments

Comments
 (0)