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