@@ -422,6 +422,11 @@ pub struct ChannelDetails {
422422 pub short_channel_id : Option < u64 > ,
423423 /// The node_id of our counterparty
424424 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 : Features < FeatureContextInit > ,
425430 /// The value, in satoshis, of this channel as appears in the funding output
426431 pub channel_value_satoshis : u64 ,
427432 /// The user_id passed in to create_channel, or 0 if the channel was inbound.
@@ -694,50 +699,70 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
694699 /// Gets the list of open channels, in random order. See ChannelDetail field documentation for
695700 /// more information.
696701 pub fn list_channels ( & self ) -> Vec < ChannelDetails > {
697- let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
698- let mut res = Vec :: with_capacity ( channel_state. by_id . len ( ) ) ;
699- for ( channel_id, channel) in channel_state. by_id . iter ( ) {
700- let ( inbound_capacity_msat, outbound_capacity_msat) = channel. get_inbound_outbound_available_balance_msat ( ) ;
701- res. push ( ChannelDetails {
702- channel_id : ( * channel_id) . clone ( ) ,
703- short_channel_id : channel. get_short_channel_id ( ) ,
704- remote_network_id : channel. get_their_node_id ( ) ,
705- channel_value_satoshis : channel. get_value_satoshis ( ) ,
706- inbound_capacity_msat,
707- outbound_capacity_msat,
708- user_id : channel. get_user_id ( ) ,
709- is_live : channel. is_live ( ) ,
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 channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
722- let mut res = Vec :: with_capacity ( channel_state. by_id . len ( ) ) ;
723- for ( channel_id, channel) in channel_state. by_id . iter ( ) {
724- // Note we use is_live here instead of usable which leads to somewhat confused
725- // internal/external nomenclature, but that's ok cause that's probably what the user
726- // really wanted anyway.
727- if channel. is_live ( ) {
702+ let mut res = Vec :: new ( ) ;
703+ {
704+ let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
705+ res. reserve ( channel_state. by_id . len ( ) ) ;
706+ for ( channel_id, channel) in channel_state. by_id . iter ( ) {
728707 let ( inbound_capacity_msat, outbound_capacity_msat) = channel. get_inbound_outbound_available_balance_msat ( ) ;
729708 res. push ( ChannelDetails {
730709 channel_id : ( * channel_id) . clone ( ) ,
731710 short_channel_id : channel. get_short_channel_id ( ) ,
732711 remote_network_id : channel. get_their_node_id ( ) ,
712+ remote_node_features : Features :: empty ( ) ,
733713 channel_value_satoshis : channel. get_value_satoshis ( ) ,
734714 inbound_capacity_msat,
735715 outbound_capacity_msat,
736716 user_id : channel. get_user_id ( ) ,
737- is_live : true ,
717+ is_live : channel . is_live ( ) ,
738718 } ) ;
739719 }
740720 }
721+ let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
722+ for chan in res. iter_mut ( ) {
723+ if let Some ( peer_state) = per_peer_state. get ( & chan. remote_network_id ) {
724+ chan. remote_node_features = peer_state. lock ( ) . unwrap ( ) . latest_features . clone ( ) ;
725+ }
726+ }
727+ res
728+ }
729+
730+ /// Gets the list of usable channels, in random order. Useful as an argument to
731+ /// Router::get_route to ensure non-announced channels are used.
732+ ///
733+ /// These are guaranteed to have their is_live value set to true, see the documentation for
734+ /// ChannelDetails::is_live for more info on exactly what the criteria are.
735+ pub fn list_usable_channels ( & self ) -> Vec < ChannelDetails > {
736+ let mut res = Vec :: new ( ) ;
737+ {
738+ let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
739+ res. reserve ( channel_state. by_id . len ( ) ) ;
740+ for ( channel_id, channel) in channel_state. by_id . iter ( ) {
741+ // Note we use is_live here instead of usable which leads to somewhat confused
742+ // internal/external nomenclature, but that's ok cause that's probably what the user
743+ // really wanted anyway.
744+ if channel. is_live ( ) {
745+ let ( inbound_capacity_msat, outbound_capacity_msat) = channel. get_inbound_outbound_available_balance_msat ( ) ;
746+ res. push ( ChannelDetails {
747+ channel_id : ( * channel_id) . clone ( ) ,
748+ short_channel_id : channel. get_short_channel_id ( ) ,
749+ remote_network_id : channel. get_their_node_id ( ) ,
750+ remote_node_features : Features :: empty ( ) ,
751+ channel_value_satoshis : channel. get_value_satoshis ( ) ,
752+ inbound_capacity_msat,
753+ outbound_capacity_msat,
754+ user_id : channel. get_user_id ( ) ,
755+ is_live : true ,
756+ } ) ;
757+ }
758+ }
759+ }
760+ let per_peer_state = self . per_peer_state . read ( ) . unwrap ( ) ;
761+ for chan in res. iter_mut ( ) {
762+ if let Some ( peer_state) = per_peer_state. get ( & chan. remote_network_id ) {
763+ chan. remote_node_features = peer_state. lock ( ) . unwrap ( ) . latest_features . clone ( ) ;
764+ }
765+ }
741766 res
742767 }
743768
0 commit comments