@@ -15,7 +15,9 @@ use bitcoin::{OutPoint, ScriptBuf};
1515use bitcoin_payment_instructions:: onion_message_resolver:: LDKOnionMessageDNSSECHrnResolver ;
1616use lightning:: chain:: chainmonitor;
1717use lightning:: impl_writeable_tlv_based;
18- use lightning:: ln:: channel_state:: { ChannelDetails as LdkChannelDetails , ChannelShutdownState } ;
18+ use lightning:: ln:: channel_state:: {
19+ ChannelDetails as LdkChannelDetails , ChannelShutdownState , CounterpartyForwardingInfo ,
20+ } ;
1921use lightning:: ln:: msgs:: { RoutingMessageHandler , SocketAddress } ;
2022use lightning:: ln:: peer_handler:: IgnoringMessageHandler ;
2123use lightning:: ln:: types:: ChannelId ;
@@ -35,11 +37,17 @@ use crate::chain::ChainSource;
3537use crate :: config:: ChannelConfig ;
3638use crate :: data_store:: DataStore ;
3739use crate :: fee_estimator:: OnchainFeeEstimator ;
40+ use crate :: ffi:: maybe_wrap;
3841use crate :: logger:: Logger ;
3942use crate :: message_handler:: NodeCustomMessageHandler ;
4043use crate :: payment:: { PaymentDetails , PendingPaymentDetails } ;
4144use crate :: runtime:: RuntimeSpawner ;
4245
46+ #[ cfg( not( feature = "uniffi" ) ) ]
47+ type InitFeatures = lightning:: types:: features:: InitFeatures ;
48+ #[ cfg( feature = "uniffi" ) ]
49+ type InitFeatures = Arc < crate :: ffi:: InitFeatures > ;
50+
4351/// A supertrait that requires that a type implements both [`KVStore`] and [`KVStoreSync`] at the
4452/// same time.
4553pub trait SyncAndAsyncKVStore : KVStore + KVStoreSync { }
@@ -376,6 +384,34 @@ impl fmt::Display for UserChannelId {
376384 }
377385}
378386
387+ /// Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
388+ /// to better separate parameters.
389+ #[ derive( Clone , Debug , PartialEq ) ]
390+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Record ) ) ]
391+ pub struct ChannelCounterparty {
392+ /// The node_id of our counterparty
393+ pub node_id : PublicKey ,
394+ /// The Features the channel counterparty provided upon last connection.
395+ /// Useful for routing as it is the most up-to-date copy of the counterparty's features and
396+ /// many routing-relevant features are present in the init context.
397+ pub features : InitFeatures ,
398+ /// The value, in satoshis, that must always be held in the channel for our counterparty. This
399+ /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by
400+ /// claiming at least this value on chain.
401+ ///
402+ /// This value is not included in [`inbound_capacity_msat`] as it can never be spent.
403+ ///
404+ /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
405+ pub unspendable_punishment_reserve : u64 ,
406+ /// Information on the fees and requirements that the counterparty requires when forwarding
407+ /// payments to us through this channel.
408+ pub forwarding_info : Option < CounterpartyForwardingInfo > ,
409+ /// The smallest value HTLC (in msat) the remote peer will accept, for this channel.
410+ pub outbound_htlc_minimum_msat : u64 ,
411+ /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
412+ pub outbound_htlc_maximum_msat : Option < u64 > ,
413+ }
414+
379415/// Details of a channel as returned by [`Node::list_channels`].
380416///
381417/// When a channel is spliced, most fields continue to refer to the original pre-splice channel
@@ -392,8 +428,8 @@ pub struct ChannelDetails {
392428 /// Note that this means this value is *not* persistent - it can change once during the
393429 /// lifetime of the channel.
394430 pub channel_id : ChannelId ,
395- /// The node ID of our the channel's counterparty .
396- pub counterparty_node_id : PublicKey ,
431+ /// Parameters which apply to our counterparty. See individual fields for more information .
432+ pub counterparty : ChannelCounterparty ,
397433 /// The channel's funding transaction output, if we've negotiated the funding transaction with
398434 /// our counterparty already.
399435 ///
@@ -509,28 +545,6 @@ pub struct ChannelDetails {
509545 /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over
510546 /// the channel.
511547 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 > ,
534548 /// The available outbound capacity for sending a single HTLC to the remote peer. This is
535549 /// similar to [`ChannelDetails::outbound_capacity_msat`] but it may be further restricted by
536550 /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us
@@ -568,7 +582,16 @@ impl From<LdkChannelDetails> for ChannelDetails {
568582 fn from ( value : LdkChannelDetails ) -> Self {
569583 ChannelDetails {
570584 channel_id : value. channel_id ,
571- counterparty_node_id : value. counterparty . node_id ,
585+ counterparty : ChannelCounterparty {
586+ node_id : value. counterparty . node_id ,
587+ features : maybe_wrap ( value. counterparty . features ) ,
588+ unspendable_punishment_reserve : value. counterparty . unspendable_punishment_reserve ,
589+ forwarding_info : value. counterparty . forwarding_info ,
590+ // unwrap safety: This value will be `None` for objects serialized with LDK versions
591+ // prior to 0.0.115.
592+ outbound_htlc_minimum_msat : value. counterparty . outbound_htlc_minimum_msat . unwrap ( ) ,
593+ outbound_htlc_maximum_msat : value. counterparty . outbound_htlc_maximum_msat ,
594+ } ,
572595 funding_txo : value. funding_txo . map ( |o| o. into_bitcoin_outpoint ( ) ) ,
573596 funding_redeem_script : value. funding_redeem_script ,
574597 short_channel_id : value. short_channel_id ,
@@ -589,26 +612,6 @@ impl From<LdkChannelDetails> for ChannelDetails {
589612 is_usable : value. is_usable ,
590613 is_announced : value. is_announced ,
591614 cltv_expiry_delta : value. config . map ( |c| c. cltv_expiry_delta ) ,
592- counterparty_unspendable_punishment_reserve : value
593- . counterparty
594- . unspendable_punishment_reserve ,
595- counterparty_outbound_htlc_minimum_msat : value. counterparty . outbound_htlc_minimum_msat ,
596- counterparty_outbound_htlc_maximum_msat : value. counterparty . outbound_htlc_maximum_msat ,
597- counterparty_forwarding_info_fee_base_msat : value
598- . counterparty
599- . forwarding_info
600- . as_ref ( )
601- . map ( |f| f. fee_base_msat ) ,
602- counterparty_forwarding_info_fee_proportional_millionths : value
603- . counterparty
604- . forwarding_info
605- . as_ref ( )
606- . map ( |f| f. fee_proportional_millionths ) ,
607- counterparty_forwarding_info_cltv_expiry_delta : value
608- . counterparty
609- . forwarding_info
610- . as_ref ( )
611- . map ( |f| f. cltv_expiry_delta ) ,
612615 next_outbound_htlc_limit_msat : value. next_outbound_htlc_limit_msat ,
613616 next_outbound_htlc_minimum_msat : value. next_outbound_htlc_minimum_msat ,
614617 force_close_spend_delay : value. force_close_spend_delay ,
0 commit comments