@@ -16,6 +16,7 @@ use bitcoin_payment_instructions::onion_message_resolver::LDKOnionMessageDNSSECH
1616use lightning:: chain:: chainmonitor;
1717use lightning:: impl_writeable_tlv_based;
1818use lightning:: ln:: channel_state:: ChannelDetails as LdkChannelDetails ;
19+ use lightning:: ln:: channel_state:: CounterpartyForwardingInfo ;
1920use lightning:: ln:: msgs:: { RoutingMessageHandler , SocketAddress } ;
2021use lightning:: ln:: peer_handler:: IgnoringMessageHandler ;
2122use lightning:: ln:: types:: ChannelId ;
@@ -35,11 +36,17 @@ use crate::chain::ChainSource;
3536use crate :: config:: ChannelConfig ;
3637use crate :: data_store:: DataStore ;
3738use crate :: fee_estimator:: OnchainFeeEstimator ;
39+ use crate :: ffi:: maybe_wrap;
3840use crate :: logger:: Logger ;
3941use crate :: message_handler:: NodeCustomMessageHandler ;
4042use crate :: payment:: { PaymentDetails , PendingPaymentDetails } ;
4143use crate :: runtime:: RuntimeSpawner ;
4244
45+ #[ cfg( not( feature = "uniffi" ) ) ]
46+ type InitFeatures = lightning:: types:: features:: InitFeatures ;
47+ #[ cfg( feature = "uniffi" ) ]
48+ type InitFeatures = Arc < crate :: ffi:: InitFeatures > ;
49+
4350/// A supertrait that requires that a type implements both [`KVStore`] and [`KVStoreSync`] at the
4451/// same time.
4552pub trait SyncAndAsyncKVStore : KVStore + KVStoreSync { }
@@ -376,6 +383,34 @@ impl fmt::Display for UserChannelId {
376383 }
377384}
378385
386+ /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
387+ /// to better separate parameters.
388+ #[ derive( Clone , Debug , PartialEq ) ]
389+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Record ) ) ]
390+ pub struct ChannelCounterparty {
391+ /// The node_id of our counterparty
392+ pub node_id : PublicKey ,
393+ /// The Features the channel counterparty provided upon last connection.
394+ /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
395+ /// many routing-relevant features are present in the init context.
396+ pub features : InitFeatures ,
397+ /// The value, in satoshis, that must always be held in the channel for our counterparty. This
398+ /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
399+ /// claiming at least this value on chain.
400+ ///
401+ /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
402+ ///
403+ /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
404+ pub unspendable_punishment_reserve : u64 ,
405+ /// Information on the fees and requirements that the counterparty requires when forwarding
406+ /// payments to us through this channel.
407+ pub forwarding_info : Option < CounterpartyForwardingInfo > ,
408+ /// The smallest value HTLC (in msat) the remote peer will accept, for this channel.
409+ pub outbound_htlc_minimum_msat : u64 ,
410+ /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
411+ pub outbound_htlc_maximum_msat : Option < u64 > ,
412+ }
413+
379414/// Details of a channel as returned by [`Node::list_channels`].
380415///
381416/// When a channel is spliced, most fields continue to refer to the original pre-splice channel
@@ -392,8 +427,8 @@ pub struct ChannelDetails {
392427 /// Note that this means this value is *not* persistent - it can change once during the
393428 /// lifetime of the channel.
394429 pub channel_id : ChannelId ,
395- /// The node ID of our the channel's counterparty .
396- pub counterparty_node_id : PublicKey ,
430+ /// Parameters which apply to our counterparty. See individual fields for more information .
431+ pub counterparty : ChannelCounterparty ,
397432 /// The channel's funding transaction output, if we've negotiated the funding transaction with
398433 /// our counterparty already.
399434 ///
@@ -509,28 +544,6 @@ pub struct ChannelDetails {
509544 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
510545 /// the channel.
511546 pub cltv_expiry_delta : Option < u16 > ,
512- /// The value, in satoshis, that must always be held in the channel for our counterparty. This
513- /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
514- /// claiming at least this value on chain.
515- ///
516- /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
517- ///
518- /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
519- pub counterparty_unspendable_punishment_reserve : u64 ,
520- /// The smallest value HTLC (in msat) the remote peer will accept, for this channel.
521- ///
522- /// This field is only `None` before we have received either the `OpenChannel` or
523- /// `AcceptChannel` message from the remote peer.
524- pub counterparty_outbound_htlc_minimum_msat : Option < u64 > ,
525- /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
526- pub counterparty_outbound_htlc_maximum_msat : Option < u64 > ,
527- /// Base routing fee in millisatoshis.
528- pub counterparty_forwarding_info_fee_base_msat : Option < u32 > ,
529- /// Proportional fee, in millionths of a satoshi the channel will charge per transferred satoshi.
530- pub counterparty_forwarding_info_fee_proportional_millionths : Option < u32 > ,
531- /// The minimum difference in CLTV expiry between an ingoing HTLC and its outgoing counterpart,
532- /// such that the outgoing HTLC is forwardable to this counterparty.
533- pub counterparty_forwarding_info_cltv_expiry_delta : Option < u16 > ,
534547 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
535548 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
536549 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
@@ -564,7 +577,16 @@ impl From<LdkChannelDetails> for ChannelDetails {
564577 fn from ( value : LdkChannelDetails ) -> Self {
565578 ChannelDetails {
566579 channel_id : value. channel_id ,
567- counterparty_node_id : value. counterparty . node_id ,
580+ counterparty : ChannelCounterparty {
581+ node_id : value. counterparty . node_id ,
582+ features : maybe_wrap ( value. counterparty . features ) ,
583+ unspendable_punishment_reserve : value. counterparty . unspendable_punishment_reserve ,
584+ forwarding_info : value. counterparty . forwarding_info ,
585+ // unwrap safety: This value will be `None` for objects serialized with LDK versions
586+ // prior to 0.0.115.
587+ outbound_htlc_minimum_msat : value. counterparty . outbound_htlc_minimum_msat . unwrap ( ) ,
588+ outbound_htlc_maximum_msat : value. counterparty . outbound_htlc_maximum_msat ,
589+ } ,
568590 funding_txo : value. funding_txo . map ( |o| o. into_bitcoin_outpoint ( ) ) ,
569591 funding_redeem_script : value. funding_redeem_script ,
570592 short_channel_id : value. short_channel_id ,
@@ -585,26 +607,6 @@ impl From<LdkChannelDetails> for ChannelDetails {
585607 is_usable : value. is_usable ,
586608 is_announced : value. is_announced ,
587609 cltv_expiry_delta : value. config . map ( |c| c. cltv_expiry_delta ) ,
588- counterparty_unspendable_punishment_reserve : value
589- . counterparty
590- . unspendable_punishment_reserve ,
591- counterparty_outbound_htlc_minimum_msat : value. counterparty . outbound_htlc_minimum_msat ,
592- counterparty_outbound_htlc_maximum_msat : value. counterparty . outbound_htlc_maximum_msat ,
593- counterparty_forwarding_info_fee_base_msat : value
594- . counterparty
595- . forwarding_info
596- . as_ref ( )
597- . map ( |f| f. fee_base_msat ) ,
598- counterparty_forwarding_info_fee_proportional_millionths : value
599- . counterparty
600- . forwarding_info
601- . as_ref ( )
602- . map ( |f| f. fee_proportional_millionths ) ,
603- counterparty_forwarding_info_cltv_expiry_delta : value
604- . counterparty
605- . forwarding_info
606- . as_ref ( )
607- . map ( |f| f. cltv_expiry_delta ) ,
608610 next_outbound_htlc_limit_msat : value. next_outbound_htlc_limit_msat ,
609611 next_outbound_htlc_minimum_msat : value. next_outbound_htlc_minimum_msat ,
610612 force_close_spend_delay : value. force_close_spend_delay ,
0 commit comments