Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions bindings/python/src/ldk_node/test_ldk_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,29 @@ def expect_event(node, expected_event_type):
return event


def assert_feature_helpers_return_bool(test_case, features):
feature_methods = [
method_name for method_name in dir(features)
if method_name.startswith("supports_") or method_name.startswith("requires_")
]

test_case.assertGreater(len(feature_methods), 0)
for method_name in feature_methods:
with test_case.subTest(method_name=method_name):
test_case.assertIsInstance(getattr(features, method_name)(), bool)


def node_features_exposed(test_case, node_features):
test_case.assertIsInstance(node_features, NodeFeatures)
assert_feature_helpers_return_bool(test_case, node_features)


def init_features_exposed(test_case, init_features):
test_case.assertIsInstance(init_features, InitFeatures)
assert_feature_helpers_return_bool(test_case, init_features)
test_case.assertIsInstance(init_features.initial_routing_sync(), bool)



class TestLdkNode(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -153,6 +176,10 @@ def test_channel_full_cycle(self):
node_id_2 = node_2.node_id()
print("Node ID 2:", node_id_2)

# Check node-announcement features exposed through NodeStatus.
for node in [node_1, node_2]:
node_features_exposed(self, node.status().node_features)

address_1 = node_1.onchain_payment().new_address()
txid_1 = send_to_address(address_1, 100000)
address_2 = node_2.onchain_payment().new_address()
Expand Down Expand Up @@ -200,6 +227,10 @@ def test_channel_full_cycle(self):

channel_ready_event_2 = expect_event(node_2, Event.CHANNEL_READY)

# Check negotiated init features exposed through ChannelDetails.
for channel in [node_1.list_channels()[0], node_2.list_channels()[0]]:
init_features_exposed(self, channel.counterparty.features)

description = Bolt11InvoiceDescription.DIRECT("asdf")
invoice = node_2.bolt11_payment().receive(2500000, description, 9217)
node_1.bolt11_payment().send(invoice, None)
Expand Down
297 changes: 295 additions & 2 deletions src/ffi/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub use bitcoin::{Address, BlockHash, Network, OutPoint, ScriptBuf, Txid};
pub use lightning::chain::channelmonitor::BalanceSource;
use lightning::events::PaidBolt12Invoice as LdkPaidBolt12Invoice;
pub use lightning::events::{ClosureReason, PaymentFailureReason};
use lightning::ln::channel_state::ChannelShutdownState;
use lightning::ln::channel_state::{ChannelShutdownState, CounterpartyForwardingInfo};
use lightning::ln::channelmanager::PaymentId;
use lightning::ln::msgs::DecodeError;
pub use lightning::ln::types::ChannelId;
Expand All @@ -44,7 +44,7 @@ pub use lightning_liquidity::lsps0::ser::LSPSDateTime;
pub use lightning_liquidity::lsps1::msgs::{
LSPS1ChannelInfo, LSPS1OrderId, LSPS1OrderParams, LSPS1PaymentState,
};
use lightning_types::features::NodeFeatures as LdkNodeFeatures;
use lightning_types::features::{InitFeatures as LdkInitFeatures, NodeFeatures as LdkNodeFeatures};
pub use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
pub use lightning_types::string::UntrustedString;
use vss_client::headers::{
Expand Down Expand Up @@ -1526,6 +1526,7 @@ pub struct NodeFeatures {
pub(crate) inner: LdkNodeFeatures,
}

#[uniffi::export]
impl NodeFeatures {
/// Constructs node features from big-endian BOLT 9 encoded bytes.
#[uniffi::constructor]
Expand Down Expand Up @@ -1815,6 +1816,298 @@ impl From<LdkNodeFeatures> for NodeFeatures {
}
}

#[derive(Debug, Clone, PartialEq, Eq, uniffi::Object)]
#[uniffi::export(Debug, Eq)]
pub struct InitFeatures {
pub(crate) inner: LdkInitFeatures,
}

#[uniffi::export]
impl InitFeatures {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be missing #[uniffi::export]?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been added.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the one you added is also fine to keep, but we'll also need to add uniffi::export to the impl block, as otherwise the methods won't be available in bindings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. I've added this and extended the coverage in the python test to check the now-exposed methods. I noticed NodeFeatures had the same issue, so I fixed and covered that as well.

/// Constructs init features from big-endian BOLT 9 encoded bytes.
#[uniffi::constructor]
pub fn from_bytes(bytes: &[u8]) -> Self {
Self { inner: LdkInitFeatures::from_be_bytes(bytes.to_vec()).into() }
}

/// Returns the BOLT 9 big-endian encoded representation of these features.
pub fn to_bytes(&self) -> Vec<u8> {
self.inner.encode()
}

/// Whether the peer's `init` message advertises support for `option_static_remotekey`.
pub fn supports_static_remote_key(&self) -> bool {
Comment thread
enigbe marked this conversation as resolved.
self.inner.supports_static_remote_key()
}

/// Whether the peer's `init` message requires `option_static_remotekey`.
pub fn requires_static_remote_key(&self) -> bool {
self.inner.requires_static_remote_key()
}

/// Whether the peer's `init` message advertises support for `option_anchors_zero_fee_htlc_tx`.
pub fn supports_anchors_zero_fee_htlc_tx(&self) -> bool {
self.inner.supports_anchors_zero_fee_htlc_tx()
}

/// Whether the peer's `init` message requires `option_anchors_zero_fee_htlc_tx`.
pub fn requires_anchors_zero_fee_htlc_tx(&self) -> bool {
self.inner.requires_anchors_zero_fee_htlc_tx()
}

/// Whether the peer's `init` message advertises support for `option_anchors_nonzero_fee_htlc_tx`.
pub fn supports_anchors_nonzero_fee_htlc_tx(&self) -> bool {
self.inner.supports_anchors_nonzero_fee_htlc_tx()
}

/// Whether the peer's `init` message requires `option_anchors_nonzero_fee_htlc_tx`.
pub fn requires_anchors_nonzero_fee_htlc_tx(&self) -> bool {
self.inner.requires_anchors_nonzero_fee_htlc_tx()
}

/// Whether the peer's `init` message advertises support for `option_support_large_channel`.
pub fn supports_wumbo(&self) -> bool {
self.inner.supports_wumbo()
}

/// Whether the peer's `init` message requires `option_support_large_channel`.
pub fn requires_wumbo(&self) -> bool {
self.inner.requires_wumbo()
}

/// Whether the peer's `init` message advertises support for `option_route_blinding`.
pub fn supports_route_blinding(&self) -> bool {
self.inner.supports_route_blinding()
}

/// Whether the peer's `init` message requires `option_route_blinding`.
pub fn requires_route_blinding(&self) -> bool {
self.inner.requires_route_blinding()
}

/// Whether the peer's `init` message advertises support for `option_onion_messages`.
pub fn supports_onion_messages(&self) -> bool {
self.inner.supports_onion_messages()
}

/// Whether the peer's `init` message requires `option_onion_messages`.
pub fn requires_onion_messages(&self) -> bool {
self.inner.requires_onion_messages()
}

/// Whether the peer's `init` message advertises support for `option_scid_alias`.
pub fn supports_scid_privacy(&self) -> bool {
self.inner.supports_scid_privacy()
}

/// Whether the peer's `init` message requires `option_scid_alias`.
pub fn requires_scid_privacy(&self) -> bool {
self.inner.requires_scid_privacy()
}

/// Whether the peer's `init` message advertises support for `option_zeroconf`.
pub fn supports_zero_conf(&self) -> bool {
self.inner.supports_zero_conf()
}

/// Whether the peer's `init` message requires `option_zeroconf`.
pub fn requires_zero_conf(&self) -> bool {
Comment thread
enigbe marked this conversation as resolved.
self.inner.requires_zero_conf()
}

/// Whether the peer's `init` message advertises support for `option_dual_fund`.
pub fn supports_dual_fund(&self) -> bool {
self.inner.supports_dual_fund()
}

/// Whether the peer's `init` message requires `option_dual_fund`.
pub fn requires_dual_fund(&self) -> bool {
self.inner.requires_dual_fund()
}

/// Whether the peer's `init` message advertises support for `option_quiesce`.
pub fn supports_quiescence(&self) -> bool {
self.inner.supports_quiescence()
}

/// Whether the peer's `init` message requires `option_quiesce`.
pub fn requires_quiescence(&self) -> bool {
self.inner.requires_quiescence()
}

/// Whether the peer's `init` message advertises support for `option_data_loss_protect`.
pub fn supports_data_loss_protect(&self) -> bool {
self.inner.supports_data_loss_protect()
}

/// Whether the peer's `init` message requires `option_data_loss_protect`.
pub fn requires_data_loss_protect(&self) -> bool {
self.inner.requires_data_loss_protect()
}

/// Whether the peer's `init` message advertises support for `option_upfront_shutdown_script`.
pub fn supports_upfront_shutdown_script(&self) -> bool {
self.inner.supports_upfront_shutdown_script()
}

/// Whether the peer's `init` message requires `option_upfront_shutdown_script`.
pub fn requires_upfront_shutdown_script(&self) -> bool {
self.inner.requires_upfront_shutdown_script()
}

/// Whether the peer's `init` message advertises support for `gossip_queries`.
pub fn supports_gossip_queries(&self) -> bool {
self.inner.supports_gossip_queries()
}

/// Whether the peer's `init` message requires `gossip_queries`.
pub fn requires_gossip_queries(&self) -> bool {
self.inner.requires_gossip_queries()
}

/// Whether the peer's `init` message advertises support for `var_onion_optin`.
pub fn supports_variable_length_onion(&self) -> bool {
self.inner.supports_variable_length_onion()
}

/// Whether the peer's `init` message requires `var_onion_optin`.
pub fn requires_variable_length_onion(&self) -> bool {
self.inner.requires_variable_length_onion()
}

/// Whether the peer's `init` message advertises support for `payment_secret`.
pub fn supports_payment_secret(&self) -> bool {
self.inner.supports_payment_secret()
}

/// Whether the peer's `init` message requires `payment_secret`.
pub fn requires_payment_secret(&self) -> bool {
self.inner.requires_payment_secret()
}

/// Whether the peer's `init` message advertises support for `basic_mpp`.
pub fn supports_basic_mpp(&self) -> bool {
self.inner.supports_basic_mpp()
}

/// Whether the peer's `init` message requires `basic_mpp`.
pub fn requires_basic_mpp(&self) -> bool {
self.inner.requires_basic_mpp()
}

/// Whether the peer's `init` message advertises support for `opt_shutdown_anysegwit`.
pub fn supports_shutdown_anysegwit(&self) -> bool {
self.inner.supports_shutdown_anysegwit()
}

/// Whether the peer's `init` message requires `opt_shutdown_anysegwit`.
pub fn requires_shutdown_anysegwit(&self) -> bool {
self.inner.requires_shutdown_anysegwit()
}

/// Whether the peer's `init` message advertises support for `option_channel_type`.
pub fn supports_channel_type(&self) -> bool {
self.inner.supports_channel_type()
}

/// Whether the peer's `init` message requires `option_channel_type`.
pub fn requires_channel_type(&self) -> bool {
self.inner.requires_channel_type()
}

/// Whether the peer's `init` message advertises support for `option_trampoline`.
pub fn supports_trampoline_routing(&self) -> bool {
self.inner.supports_trampoline_routing()
}

/// Whether the peer's `init` message requires `option_trampoline`.
pub fn requires_trampoline_routing(&self) -> bool {
self.inner.requires_trampoline_routing()
}

/// Whether the peer's `init` message advertises support for `option_simple_close`.
pub fn supports_simple_close(&self) -> bool {
self.inner.supports_simple_close()
}

/// Whether the peer's `init` message requires `option_simple_close`.
pub fn requires_simple_close(&self) -> bool {
self.inner.requires_simple_close()
}

/// Whether the peer's `init` message advertises support for `option_splice`.
pub fn supports_splicing(&self) -> bool {
self.inner.supports_splicing()
}

/// Whether the peer's `init` message requires `option_splice`.
pub fn requires_splicing(&self) -> bool {
self.inner.requires_splicing()
}

/// Whether the peer's `init` message advertises support for `option_provide_storage`.
pub fn supports_provide_storage(&self) -> bool {
self.inner.supports_provide_storage()
}

/// Whether the peer's `init` message requires `option_provide_storage`.
pub fn requires_provide_storage(&self) -> bool {
self.inner.requires_provide_storage()
}

/// Whether the peer's `init` message set `initial_routing_sync`.
pub fn initial_routing_sync(&self) -> bool {
self.inner.initial_routing_sync()
}

/// Whether the peer's `init` message advertises support for `option_taproot`.
pub fn supports_taproot(&self) -> bool {
self.inner.supports_taproot()
}

/// Whether the peer's `init` message requires `option_taproot`.
pub fn requires_taproot(&self) -> bool {
self.inner.requires_taproot()
}

/// Whether the peer's `init` message advertises support for `option_zero_fee_commitments`.
pub fn supports_anchor_zero_fee_commitments(&self) -> bool {
self.inner.supports_anchor_zero_fee_commitments()
}

/// Whether the peer's `init` message requires `option_zero_fee_commitments`.
pub fn requires_anchor_zero_fee_commitments(&self) -> bool {
self.inner.requires_anchor_zero_fee_commitments()
}

/// Whether the peer's `init` message advertises support for HTLC hold.
pub fn supports_htlc_hold(&self) -> bool {
self.inner.supports_htlc_hold()
}

/// Whether the peer's `init` message requires HTLC hold.
pub fn requires_htlc_hold(&self) -> bool {
self.inner.requires_htlc_hold()
}
}

impl From<LdkInitFeatures> for InitFeatures {
fn from(ldk_init: LdkInitFeatures) -> Self {
Self { inner: ldk_init }
}
}
/// Information needed for constructing an invoice route hint for this channel.
#[uniffi::remote(Record)]
pub struct CounterpartyForwardingInfo {
/// Base routing fee in millisatoshis.
pub fee_base_msat: u32,
/// Amount in millionths of a satoshi the channel will charge per transferred satoshi.
pub fee_proportional_millionths: u32,
/// The minimum difference in cltv_expiry between an ingoing HTLC and its outgoing counterpart,
/// such that the outgoing HTLC is forwardable to this counterparty.
pub cltv_expiry_delta: u16,
}

#[cfg(test)]
mod tests {
use std::num::NonZeroU64;
Expand Down
Loading