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