@@ -944,21 +944,6 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
944944 return Err ( Error :: InsufficientFunds ) ;
945945 }
946946
947- let peer_info = PeerInfo { node_id, address } ;
948-
949- let con_node_id = peer_info. node_id ;
950- let con_addr = peer_info. address . clone ( ) ;
951- let con_logger = Arc :: clone ( & self . logger ) ;
952- let con_pm = Arc :: clone ( & self . peer_manager ) ;
953-
954- // We need to use our main runtime here as a local runtime might not be around to poll
955- // connection futures going forward.
956- tokio:: task:: block_in_place ( move || {
957- runtime. block_on ( async move {
958- connect_peer_if_necessary ( con_node_id, con_addr, con_pm, con_logger) . await
959- } )
960- } ) ?;
961-
962947 let channel_config = ( * ( channel_config. unwrap_or_default ( ) ) ) . clone ( ) . into ( ) ;
963948 let user_config = UserConfig {
964949 channel_handshake_limits : Default :: default ( ) ,
@@ -972,14 +957,41 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
972957
973958 let push_msat = push_to_counterparty_msat. unwrap_or ( 0 ) ;
974959 let user_channel_id: u128 = rand:: thread_rng ( ) . gen :: < u128 > ( ) ;
960+ self . internal_connect_open_channel (
961+ node_id,
962+ channel_amount_sats,
963+ push_msat,
964+ user_channel_id,
965+ address,
966+ Some ( user_config) ,
967+ runtime,
968+ )
969+ }
970+
971+ fn internal_connect_open_channel (
972+ & self , node_id : PublicKey , channel_amount_sats : u64 , push_msat : u64 , user_channel_id : u128 ,
973+ address : SocketAddress , user_config : Option < UserConfig > , runtime : & tokio:: runtime:: Runtime ,
974+ ) -> Result < UserChannelId , Error > {
975+ let peer_info = PeerInfo { node_id, address } ;
976+ let con_node_id = peer_info. node_id ;
977+ let con_addr = peer_info. address . clone ( ) ;
978+ let con_logger = Arc :: clone ( & self . logger ) ;
979+ let con_pm = Arc :: clone ( & self . peer_manager ) ;
980+ // We need to use our main runtime here as a local runtime might not be around to poll
981+ // connection futures going forward.
982+ tokio:: task:: block_in_place ( move || {
983+ runtime. block_on ( async move {
984+ connect_peer_if_necessary ( con_node_id, con_addr, con_pm, con_logger) . await
985+ } )
986+ } ) ?;
975987
976988 match self . channel_manager . create_channel (
977989 peer_info. node_id ,
978990 channel_amount_sats,
979991 push_msat,
980992 user_channel_id,
981993 None ,
982- Some ( user_config) ,
994+ user_config,
983995 ) {
984996 Ok ( _) => {
985997 log_info ! (
0 commit comments