@@ -404,6 +404,11 @@ pub struct ChannelDetails {
404
404
pub short_channel_id : Option < u64 > ,
405
405
/// The node_id of our counterparty
406
406
pub remote_network_id : PublicKey ,
407
+ /// The Features this node provided us opon our last connection with them.
408
+ /// This is particularly useful for routing as many node_announcement-context features are also
409
+ /// set in the init-context, and we should almost certainly consider the init-context version
410
+ /// to be the latest copy.
411
+ pub remote_node_features : InitFeatures ,
407
412
/// The value, in satoshis, of this channel as appears in the funding output
408
413
pub channel_value_satoshis : u64 ,
409
414
/// The user_id passed in to create_channel, or 0 if the channel was inbound.
@@ -679,50 +684,70 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
679
684
/// Gets the list of open channels, in random order. See ChannelDetail field documentation for
680
685
/// more information.
681
686
pub fn list_channels ( & self ) -> Vec < ChannelDetails > {
682
- let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
683
- let mut res = Vec :: with_capacity ( channel_state. by_id . len ( ) ) ;
684
- for ( channel_id, channel) in channel_state. by_id . iter ( ) {
685
- let ( inbound_capacity_msat, outbound_capacity_msat) = channel. get_inbound_outbound_available_balance_msat ( ) ;
686
- res. push ( ChannelDetails {
687
- channel_id : ( * channel_id) . clone ( ) ,
688
- short_channel_id : channel. get_short_channel_id ( ) ,
689
- remote_network_id : channel. get_their_node_id ( ) ,
690
- channel_value_satoshis : channel. get_value_satoshis ( ) ,
691
- inbound_capacity_msat,
692
- outbound_capacity_msat,
693
- user_id : channel. get_user_id ( ) ,
694
- is_live : channel. is_live ( ) ,
695
- } ) ;
696
- }
697
- res
698
- }
699
-
700
- /// Gets the list of usable channels, in random order. Useful as an argument to
701
- /// Router::get_route to ensure non-announced channels are used.
702
- ///
703
- /// These are guaranteed to have their is_live value set to true, see the documentation for
704
- /// ChannelDetails::is_live for more info on exactly what the criteria are.
705
- pub fn list_usable_channels ( & self ) -> Vec < ChannelDetails > {
706
- let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
707
- let mut res = Vec :: with_capacity ( channel_state. by_id . len ( ) ) ;
708
- for ( channel_id, channel) in channel_state. by_id . iter ( ) {
709
- // Note we use is_live here instead of usable which leads to somewhat confused
710
- // internal/external nomenclature, but that's ok cause that's probably what the user
711
- // really wanted anyway.
712
- if channel. is_live ( ) {
687
+ let mut res = Vec :: new ( ) ;
688
+ {
689
+ let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
690
+ res. reserve ( channel_state. by_id . len ( ) ) ;
691
+ for ( channel_id, channel) in channel_state. by_id . iter ( ) {
713
692
let ( inbound_capacity_msat, outbound_capacity_msat) = channel. get_inbound_outbound_available_balance_msat ( ) ;
714
693
res. push ( ChannelDetails {
715
694
channel_id : ( * channel_id) . clone ( ) ,
716
695
short_channel_id : channel. get_short_channel_id ( ) ,
717
696
remote_network_id : channel. get_their_node_id ( ) ,
697
+ remote_node_features : InitFeatures :: empty ( ) ,
718
698
channel_value_satoshis : channel. get_value_satoshis ( ) ,
719
699
inbound_capacity_msat,
720
700
outbound_capacity_msat,
721
701
user_id : channel. get_user_id ( ) ,
722
- is_live : true ,
702
+ is_live : channel . is_live ( ) ,
723
703
} ) ;
724
704
}
725
705
}
706
+ let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
707
+ for chan in res. iter_mut ( ) {
708
+ if let Some ( peer_state) = per_peer_state. get ( & chan. remote_network_id ) {
709
+ chan. remote_node_features = peer_state. lock ( ) . unwrap ( ) . latest_features . clone ( ) ;
710
+ }
711
+ }
712
+ res
713
+ }
714
+
715
+ /// Gets the list of usable channels, in random order. Useful as an argument to
716
+ /// Router::get_route to ensure non-announced channels are used.
717
+ ///
718
+ /// These are guaranteed to have their is_live value set to true, see the documentation for
719
+ /// ChannelDetails::is_live for more info on exactly what the criteria are.
720
+ pub fn list_usable_channels ( & self ) -> Vec < ChannelDetails > {
721
+ let mut res = Vec :: new ( ) ;
722
+ {
723
+ let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
724
+ res. reserve ( channel_state. by_id . len ( ) ) ;
725
+ for ( channel_id, channel) in channel_state. by_id . iter ( ) {
726
+ // Note we use is_live here instead of usable which leads to somewhat confused
727
+ // internal/external nomenclature, but that's ok cause that's probably what the user
728
+ // really wanted anyway.
729
+ if channel. is_live ( ) {
730
+ let ( inbound_capacity_msat, outbound_capacity_msat) = channel. get_inbound_outbound_available_balance_msat ( ) ;
731
+ res. push ( ChannelDetails {
732
+ channel_id : ( * channel_id) . clone ( ) ,
733
+ short_channel_id : channel. get_short_channel_id ( ) ,
734
+ remote_network_id : channel. get_their_node_id ( ) ,
735
+ remote_node_features : InitFeatures :: empty ( ) ,
736
+ channel_value_satoshis : channel. get_value_satoshis ( ) ,
737
+ inbound_capacity_msat,
738
+ outbound_capacity_msat,
739
+ user_id : channel. get_user_id ( ) ,
740
+ is_live : true ,
741
+ } ) ;
742
+ }
743
+ }
744
+ }
745
+ let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
746
+ for chan in res. iter_mut ( ) {
747
+ if let Some ( peer_state) = per_peer_state. get ( & chan. remote_network_id ) {
748
+ chan. remote_node_features = peer_state. lock ( ) . unwrap ( ) . latest_features . clone ( ) ;
749
+ }
750
+ }
726
751
res
727
752
}
728
753
0 commit comments