@@ -388,6 +388,20 @@ pub struct ChannelDetails {
388
388
pub channel_value_satoshis : u64 ,
389
389
/// The user_id passed in to create_channel, or 0 if the channel was inbound.
390
390
pub user_id : u64 ,
391
+ /// The available outbound capacity for sending HTLCs to the remote peer. This does not include
392
+ /// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
393
+ /// available for inclusion in new outbound HTLCs). This further does not include any pending
394
+ /// outgoing HTLCs which are awaiting some other resolution to be sent.
395
+ pub outbound_capacity_msat : u64 ,
396
+ /// The available inbound capacity for the remote peer to send HTLCs to us. This does not
397
+ /// include any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
398
+ /// available for inclusion in new inbound HTLCs).
399
+ /// Note that there are some corner cases not fully handled here, so the actual available
400
+ /// inbound capacity may be slightly higher than this.
401
+ pub inbound_capacity_msat : u64 ,
402
+ /// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
403
+ /// the peer is connected, and (c) no monitor update failure is pending resolution.
404
+ pub is_live : bool ,
391
405
}
392
406
393
407
macro_rules! handle_error {
@@ -609,19 +623,26 @@ impl ChannelManager {
609
623
let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
610
624
let mut res = Vec :: with_capacity ( channel_state. by_id . len ( ) ) ;
611
625
for ( channel_id, channel) in channel_state. by_id . iter ( ) {
626
+ let ( inbound_capacity_msat, outbound_capacity_msat) = channel. get_inbound_outbound_available_balance_msat ( ) ;
612
627
res. push ( ChannelDetails {
613
628
channel_id : ( * channel_id) . clone ( ) ,
614
629
short_channel_id : channel. get_short_channel_id ( ) ,
615
630
remote_network_id : channel. get_their_node_id ( ) ,
616
631
channel_value_satoshis : channel. get_value_satoshis ( ) ,
632
+ inbound_capacity_msat,
633
+ outbound_capacity_msat,
617
634
user_id : channel. get_user_id ( ) ,
635
+ is_live : channel. is_live ( ) ,
618
636
} ) ;
619
637
}
620
638
res
621
639
}
622
640
623
641
/// Gets the list of usable channels, in random order. Useful as an argument to
624
642
/// Router::get_route to ensure non-announced channels are used.
643
+ ///
644
+ /// These are guaranteed to have their is_live value set to true, see the documentation for
645
+ /// ChannelDetails::is_live for more info on exactly what the criteria are.
625
646
pub fn list_usable_channels ( & self ) -> Vec < ChannelDetails > {
626
647
let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
627
648
let mut res = Vec :: with_capacity ( channel_state. by_id . len ( ) ) ;
@@ -630,12 +651,16 @@ impl ChannelManager {
630
651
// internal/external nomenclature, but that's ok cause that's probably what the user
631
652
// really wanted anyway.
632
653
if channel. is_live ( ) {
654
+ let ( inbound_capacity_msat, outbound_capacity_msat) = channel. get_inbound_outbound_available_balance_msat ( ) ;
633
655
res. push ( ChannelDetails {
634
656
channel_id : ( * channel_id) . clone ( ) ,
635
657
short_channel_id : channel. get_short_channel_id ( ) ,
636
658
remote_network_id : channel. get_their_node_id ( ) ,
637
659
channel_value_satoshis : channel. get_value_satoshis ( ) ,
660
+ inbound_capacity_msat,
661
+ outbound_capacity_msat,
638
662
user_id : channel. get_user_id ( ) ,
663
+ is_live : true ,
639
664
} ) ;
640
665
}
641
666
}
0 commit comments