@@ -36,7 +36,7 @@ use lightning_net_tokio::SocketDescriptor;
3636
3737use crate :: chain:: bitcoind:: UtxoSourceClient ;
3838use crate :: chain:: ChainSource ;
39- use crate :: config:: ChannelConfig ;
39+ use crate :: config:: { AnchorChannelsConfig , ChannelConfig } ;
4040use crate :: data_store:: DataStore ;
4141use crate :: fee_estimator:: OnchainFeeEstimator ;
4242use crate :: logger:: Logger ;
@@ -399,6 +399,47 @@ pub struct ChannelCounterparty {
399399 pub outbound_htlc_maximum_msat : Option < u64 > ,
400400}
401401
402+ /// Describes the reserve behavior of a channel based on its type and trust configuration.
403+ ///
404+ /// This captures the combination of the channel's on-chain construction (anchor outputs vs legacy
405+ /// static_remote_key) and whether the counterparty is in our trusted peers list. It tells the
406+ /// user what reserve obligations exist for this channel without exposing internal protocol details.
407+ ///
408+ /// See [`AnchorChannelsConfig`] for how reserve behavior is configured.
409+ ///
410+ /// [`AnchorChannelsConfig`]: crate::config::AnchorChannelsConfig
411+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
412+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Enum ) ) ]
413+ pub enum ReserveType {
414+ /// An anchor outputs channel where we maintain a per-channel on-chain reserve for fee
415+ /// bumping force-close transactions.
416+ ///
417+ /// Anchor channels allow either party to fee-bump commitment transactions via CPFP
418+ /// at broadcast time. Because the pre-signed commitment fee may be insufficient under
419+ /// current fee conditions, the broadcaster must supply additional funds (hence adaptive)
420+ /// through an anchor output spend. The reserve ensures sufficient on-chain funds are
421+ /// available to cover this.
422+ ///
423+ /// This is the default for anchor channels when the counterparty is not in
424+ /// [`trusted_peers_no_reserve`].
425+ ///
426+ /// [`trusted_peers_no_reserve`]: crate::config::AnchorChannelsConfig::trusted_peers_no_reserve
427+ Adaptive ,
428+ /// An anchor outputs channel where we do not maintain any reserve, because the counterparty
429+ /// is in our [`trusted_peers_no_reserve`] list.
430+ ///
431+ /// In this mode, we trust the counterparty to broadcast a valid commitment transaction on
432+ /// our behalf and do not set aside funds for fee bumping.
433+ ///
434+ /// [`trusted_peers_no_reserve`]: crate::config::AnchorChannelsConfig::trusted_peers_no_reserve
435+ TrustedPeersNoReserve ,
436+ /// A legacy (pre-anchor) channel using only `option_static_remotekey`.
437+ ///
438+ /// These channels do not use anchor outputs and therefore do not require an on-chain reserve
439+ /// for fee bumping. Commitment transaction fees are pre-committed at channel open time.
440+ Legacy ,
441+ }
442+
402443/// Details of a channel as returned by [`Node::list_channels`].
403444///
404445/// When a channel is spliced, most fields continue to refer to the original pre-splice channel
@@ -559,10 +600,32 @@ pub struct ChannelDetails {
559600 pub inbound_htlc_maximum_msat : Option < u64 > ,
560601 /// Set of configurable parameters that affect channel operation.
561602 pub config : ChannelConfig ,
603+ /// The type of on-chain reserve maintained for this channel.
604+ ///
605+ /// See [`ReserveType`] for details on how reserves differ between anchor and legacy channels.
606+ pub reserve_type : ReserveType ,
562607}
563608
564- impl From < LdkChannelDetails > for ChannelDetails {
565- fn from ( value : LdkChannelDetails ) -> Self {
609+ impl ChannelDetails {
610+ pub ( crate ) fn from_ldk (
611+ value : LdkChannelDetails , anchor_channels_config : Option < & AnchorChannelsConfig > ,
612+ ) -> Self {
613+ let is_anchor_channel =
614+ value. channel_type . as_ref ( ) . map_or ( false , |ct| ct. supports_anchors_zero_fee_htlc_tx ( ) ) ;
615+
616+ let reserve_type = if is_anchor_channel {
617+ let is_trusted = anchor_channels_config. map_or ( false , |c| {
618+ c. trusted_peers_no_reserve . contains ( & value. counterparty . node_id )
619+ } ) ;
620+ if is_trusted {
621+ ReserveType :: TrustedPeersNoReserve
622+ } else {
623+ ReserveType :: Adaptive
624+ }
625+ } else {
626+ ReserveType :: Legacy
627+ } ;
628+
566629 ChannelDetails {
567630 channel_id : value. channel_id ,
568631 counterparty : ChannelCounterparty {
@@ -601,6 +664,7 @@ impl From<LdkChannelDetails> for ChannelDetails {
601664 inbound_htlc_maximum_msat : value. inbound_htlc_maximum_msat ,
602665 // unwrap safety: `config` is only `None` for LDK objects serialized prior to 0.0.109.
603666 config : value. config . map ( |c| c. into ( ) ) . unwrap ( ) ,
667+ reserve_type,
604668 }
605669 }
606670}
0 commit comments