@@ -22,7 +22,9 @@ use bitcoin::{OutPoint, ScriptBuf};
2222
2323use lightning:: chain:: chainmonitor;
2424use lightning:: impl_writeable_tlv_based;
25- use lightning:: ln:: channel_state:: { ChannelDetails as LdkChannelDetails , ChannelShutdownState } ;
25+ use lightning:: ln:: channel_state:: {
26+ ChannelDetails as LdkChannelDetails , ChannelShutdownState , CounterpartyForwardingInfo ,
27+ } ;
2628use lightning:: ln:: msgs:: { RoutingMessageHandler , SocketAddress } ;
2729use lightning:: ln:: peer_handler:: IgnoringMessageHandler ;
2830use lightning:: ln:: types:: ChannelId ;
@@ -43,11 +45,17 @@ use crate::chain::ChainSource;
4345use crate :: config:: ChannelConfig ;
4446use crate :: data_store:: DataStore ;
4547use crate :: fee_estimator:: OnchainFeeEstimator ;
48+ use crate :: ffi:: maybe_wrap;
4649use crate :: logger:: Logger ;
4750use crate :: message_handler:: NodeCustomMessageHandler ;
4851use crate :: payment:: { PaymentDetails , PendingPaymentDetails } ;
4952use crate :: runtime:: RuntimeSpawner ;
5053
54+ #[ cfg( not( feature = "uniffi" ) ) ]
55+ type InitFeatures = lightning:: types:: features:: InitFeatures ;
56+ #[ cfg( feature = "uniffi" ) ]
57+ type InitFeatures = Arc < crate :: ffi:: InitFeatures > ;
58+
5159/// A supertrait that requires that a type implements both [`KVStore`] and [`KVStoreSync`] at the
5260/// same time.
5361pub trait SyncAndAsyncKVStore : KVStore + KVStoreSync { }
@@ -416,6 +424,34 @@ impl fmt::Display for UserChannelId {
416424 }
417425}
418426
427+ /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
428+ /// to better separate parameters.
429+ #[ derive( Clone , Debug , PartialEq ) ]
430+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Record ) ) ]
431+ pub struct ChannelCounterparty {
432+ /// The node_id of our counterparty
433+ pub node_id : PublicKey ,
434+ /// The Features the channel counterparty provided upon last connection.
435+ /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
436+ /// many routing-relevant features are present in the init context.
437+ pub features : InitFeatures ,
438+ /// The value, in satoshis, that must always be held in the channel for our counterparty. This
439+ /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
440+ /// claiming at least this value on chain.
441+ ///
442+ /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
443+ ///
444+ /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
445+ pub unspendable_punishment_reserve : u64 ,
446+ /// Information on the fees and requirements that the counterparty requires when forwarding
447+ /// payments to us through this channel.
448+ pub forwarding_info : Option < CounterpartyForwardingInfo > ,
449+ /// The smallest value HTLC (in msat) the remote peer will accept, for this channel.
450+ pub outbound_htlc_minimum_msat : u64 ,
451+ /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
452+ pub outbound_htlc_maximum_msat : Option < u64 > ,
453+ }
454+
419455/// Details of a channel as returned by [`Node::list_channels`].
420456///
421457/// When a channel is spliced, most fields continue to refer to the original pre-splice channel
@@ -432,8 +468,8 @@ pub struct ChannelDetails {
432468 /// Note that this means this value is *not* persistent - it can change once during the
433469 /// lifetime of the channel.
434470 pub channel_id : ChannelId ,
435- /// The node ID of our the channel's counterparty .
436- pub counterparty_node_id : PublicKey ,
471+ /// Parameters which apply to our counterparty. See individual fields for more information .
472+ pub counterparty : ChannelCounterparty ,
437473 /// The channel's funding transaction output, if we've negotiated the funding transaction with
438474 /// our counterparty already.
439475 ///
@@ -549,28 +585,6 @@ pub struct ChannelDetails {
549585 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
550586 /// the channel.
551587 pub cltv_expiry_delta : Option < u16 > ,
552- /// The value, in satoshis, that must always be held in the channel for our counterparty. This
553- /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
554- /// claiming at least this value on chain.
555- ///
556- /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
557- ///
558- /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
559- pub counterparty_unspendable_punishment_reserve : u64 ,
560- /// The smallest value HTLC (in msat) the remote peer will accept, for this channel.
561- ///
562- /// This field is only `None` before we have received either the `OpenChannel` or
563- /// `AcceptChannel` message from the remote peer.
564- pub counterparty_outbound_htlc_minimum_msat : Option < u64 > ,
565- /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
566- pub counterparty_outbound_htlc_maximum_msat : Option < u64 > ,
567- /// Base routing fee in millisatoshis.
568- pub counterparty_forwarding_info_fee_base_msat : Option < u32 > ,
569- /// Proportional fee, in millionths of a satoshi the channel will charge per transferred satoshi.
570- pub counterparty_forwarding_info_fee_proportional_millionths : Option < u32 > ,
571- /// The minimum difference in CLTV expiry between an ingoing HTLC and its outgoing counterpart,
572- /// such that the outgoing HTLC is forwardable to this counterparty.
573- pub counterparty_forwarding_info_cltv_expiry_delta : Option < u16 > ,
574588 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
575589 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
576590 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
@@ -608,7 +622,16 @@ impl From<LdkChannelDetails> for ChannelDetails {
608622 fn from ( value : LdkChannelDetails ) -> Self {
609623 ChannelDetails {
610624 channel_id : value. channel_id ,
611- counterparty_node_id : value. counterparty . node_id ,
625+ counterparty : ChannelCounterparty {
626+ node_id : value. counterparty . node_id ,
627+ features : maybe_wrap ( value. counterparty . features ) ,
628+ unspendable_punishment_reserve : value. counterparty . unspendable_punishment_reserve ,
629+ forwarding_info : value. counterparty . forwarding_info ,
630+ // unwrap safety: This value will be `None` for objects serialized with LDK versions
631+ // prior to 0.0.115.
632+ outbound_htlc_minimum_msat : value. counterparty . outbound_htlc_minimum_msat . unwrap ( ) ,
633+ outbound_htlc_maximum_msat : value. counterparty . outbound_htlc_maximum_msat ,
634+ } ,
612635 funding_txo : value. funding_txo . map ( |o| o. into_bitcoin_outpoint ( ) ) ,
613636 funding_redeem_script : value. funding_redeem_script ,
614637 short_channel_id : value. short_channel_id ,
@@ -629,26 +652,6 @@ impl From<LdkChannelDetails> for ChannelDetails {
629652 is_usable : value. is_usable ,
630653 is_announced : value. is_announced ,
631654 cltv_expiry_delta : value. config . map ( |c| c. cltv_expiry_delta ) ,
632- counterparty_unspendable_punishment_reserve : value
633- . counterparty
634- . unspendable_punishment_reserve ,
635- counterparty_outbound_htlc_minimum_msat : value. counterparty . outbound_htlc_minimum_msat ,
636- counterparty_outbound_htlc_maximum_msat : value. counterparty . outbound_htlc_maximum_msat ,
637- counterparty_forwarding_info_fee_base_msat : value
638- . counterparty
639- . forwarding_info
640- . as_ref ( )
641- . map ( |f| f. fee_base_msat ) ,
642- counterparty_forwarding_info_fee_proportional_millionths : value
643- . counterparty
644- . forwarding_info
645- . as_ref ( )
646- . map ( |f| f. fee_proportional_millionths ) ,
647- counterparty_forwarding_info_cltv_expiry_delta : value
648- . counterparty
649- . forwarding_info
650- . as_ref ( )
651- . map ( |f| f. cltv_expiry_delta ) ,
652655 next_outbound_htlc_limit_msat : value. next_outbound_htlc_limit_msat ,
653656 next_outbound_htlc_minimum_msat : value. next_outbound_htlc_minimum_msat ,
654657 force_close_spend_delay : value. force_close_spend_delay ,
0 commit comments