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