@@ -889,14 +889,20 @@ where
889889 total_anchor_channels_reserve_sats ( & self . channel_manager , & self . config ) ;
890890 let w = Arc :: clone ( & self . wallet ) ;
891891 let spendable_amount_sats = tokio:: task:: spawn_blocking ( move || {
892- w. get_spendable_amount_sats ( cur_anchor_reserve_sats)
892+ w. get_spendable_amount_sats ( cur_anchor_reserve_sats, "lsps2_open_channel" )
893893 } )
894894 . await
895895 . unwrap_or_else ( |e| {
896896 log_error ! ( self . logger, "Failed to get spendable amount: {}" , e) ;
897897 Err ( Error :: WalletOperationFailed )
898898 } )
899899 . unwrap_or ( 0 ) ;
900+ log_info ! (
901+ self . logger,
902+ "LSPS2 OpenChannel wallet check returned spendable_amount_sats={} for peer {}" ,
903+ spendable_amount_sats,
904+ their_network_key,
905+ ) ;
900906 let required_funds_sats = channel_amount_sats
901907 + self . config . anchor_channels_config . as_ref ( ) . map_or ( 0 , |c| {
902908 if init_features. requires_anchors_zero_fee_htlc_tx ( )
@@ -1200,6 +1206,14 @@ where
12001206 amt_to_forward_msat,
12011207 channel_count
12021208 } ) => {
1209+ log_info ! (
1210+ self . logger,
1211+ "Handling LSPS4 OpenChannel for peer {} (amt_to_forward_msat={}, channel_count={}, thread_id={:?})" ,
1212+ their_network_key,
1213+ amt_to_forward_msat,
1214+ channel_count,
1215+ std:: thread:: current( ) . id( ) ,
1216+ ) ;
12031217 if self . liquidity_manager . lsps4_service_handler ( ) . is_none ( ) {
12041218 log_error ! ( self . logger, "Failed to handle LSPS4ServiceEvent as LSPS4 liquidity service was not configured." , ) ;
12051219 return ;
@@ -1236,6 +1250,11 @@ where
12361250 log_error ! ( self . logger, "Failed to handle LSPS4ServiceEvent as peer manager isn't available. This should never happen." , ) ;
12371251 return ;
12381252 } ;
1253+ log_info ! (
1254+ self . logger,
1255+ "LSPS4 OpenChannel peer {} is connected; computing channel size" ,
1256+ their_network_key,
1257+ ) ;
12391258
12401259 // Fail if we have insufficient onchain funds available.
12411260 let over_provisioning_msat = ( amt_to_forward_msat
@@ -1256,18 +1275,63 @@ where
12561275 channel_amount_sats = channel_amount_sats. max ( tier_value_sats) ;
12571276 }
12581277 }
1278+ log_info ! (
1279+ self . logger,
1280+ "LSPS4 OpenChannel peer {} computed channel_amount_sats={} (amt_to_forward_msat={}, over_provisioning_ppm={}, min_channel_size_msat={}, tier_count={})" ,
1281+ their_network_key,
1282+ channel_amount_sats,
1283+ amt_to_forward_msat,
1284+ service_config. channel_over_provisioning_ppm,
1285+ service_config. min_channel_size_msat,
1286+ service_config. channel_size_tiers. len( ) ,
1287+ ) ;
12591288 let cur_anchor_reserve_sats =
12601289 total_anchor_channels_reserve_sats ( & self . channel_manager , & self . config ) ;
12611290 let w = Arc :: clone ( & self . wallet ) ;
1262- let spendable_amount_sats = tokio:: task:: spawn_blocking ( move || {
1263- w. get_spendable_amount_sats ( cur_anchor_reserve_sats)
1291+ let wallet_check_peer = their_network_key;
1292+ log_info ! (
1293+ self . logger,
1294+ "LSPS4 OpenChannel spawning wallet check for peer {} (reserve_sats={}, thread_id={:?})" ,
1295+ wallet_check_peer,
1296+ cur_anchor_reserve_sats,
1297+ std:: thread:: current( ) . id( ) ,
1298+ ) ;
1299+ let spendable_amount_result = tokio:: task:: spawn_blocking ( move || {
1300+ let blocking_thread_id = format ! ( "{:?}" , std:: thread:: current( ) . id( ) ) ;
1301+ let result = w. get_spendable_amount_sats ( cur_anchor_reserve_sats, "lsps4_open_channel" ) ;
1302+ ( blocking_thread_id, result)
12641303 } )
1265- . await
1266- . unwrap_or_else ( |e| {
1304+ . await ;
1305+ log_info ! (
1306+ self . logger,
1307+ "LSPS4 OpenChannel wallet check join completed for peer {} (join_ok={}, thread_id={:?})" ,
1308+ their_network_key,
1309+ spendable_amount_result. is_ok( ) ,
1310+ std:: thread:: current( ) . id( ) ,
1311+ ) ;
1312+ let ( blocking_thread_id, spendable_amount_result) = spendable_amount_result
1313+ . unwrap_or_else ( |e| {
1314+ log_error ! ( self . logger, "Failed to get spendable amount: {}" , e) ;
1315+ ( format ! ( "{:?}" , std:: thread:: current( ) . id( ) ) , Err ( Error :: WalletOperationFailed ) )
1316+ } ) ;
1317+ log_info ! (
1318+ self . logger,
1319+ "LSPS4 OpenChannel wallet check blocking task returned for peer {} (blocking_thread_id={}, result={:?})" ,
1320+ their_network_key,
1321+ blocking_thread_id,
1322+ spendable_amount_result,
1323+ ) ;
1324+ let spendable_amount_sats = spendable_amount_result. unwrap_or_else ( |e| {
12671325 log_error ! ( self . logger, "Failed to get spendable amount: {}" , e) ;
1268- Err ( Error :: WalletOperationFailed )
1326+ 0
12691327 } )
1270- . unwrap_or ( 0 ) ;
1328+ ;
1329+ log_info ! (
1330+ self . logger,
1331+ "LSPS4 OpenChannel wallet check returned spendable_amount_sats={} for peer {}" ,
1332+ spendable_amount_sats,
1333+ their_network_key,
1334+ ) ;
12711335 let required_funds_sats = channel_amount_sats
12721336 + self . config . anchor_channels_config . as_ref ( ) . map_or ( 0 , |c| {
12731337 if init_features. requires_anchors_zero_fee_htlc_tx ( )
@@ -1278,16 +1342,32 @@ where
12781342 0
12791343 }
12801344 } ) ;
1345+ log_info ! (
1346+ self . logger,
1347+ "LSPS4 OpenChannel peer {} computed required_funds_sats={} (channel_amount_sats={}, anchor_reserve_applied={})" ,
1348+ their_network_key,
1349+ required_funds_sats,
1350+ channel_amount_sats,
1351+ required_funds_sats. saturating_sub( channel_amount_sats) ,
1352+ ) ;
12811353 if spendable_amount_sats < required_funds_sats {
12821354 log_error ! ( self . logger,
1283- "Unable to create channel due to insufficient funds. Available: {}sats, Required: {}sats" ,
1284- spendable_amount_sats, channel_amount_sats
1355+ "Unable to create channel due to insufficient funds. Available: {}sats, Required: {}sats, Peer: {} " ,
1356+ spendable_amount_sats, required_funds_sats , their_network_key
12851357 ) ;
12861358 // TODO: We just silently fail here. Eventually we will need to remember
12871359 // the pending requests and regularly retry opening the channel until we
12881360 // succeed.
12891361 return ;
12901362 }
1363+ log_info ! (
1364+ self . logger,
1365+ "LSPS4 OpenChannel peer {} passed funding checks (channel_amount_sats={}, required_funds_sats={}, spendable_amount_sats={})" ,
1366+ their_network_key,
1367+ channel_amount_sats,
1368+ required_funds_sats,
1369+ spendable_amount_sats,
1370+ ) ;
12911371
12921372 let mut config = self . channel_manager . get_current_config ( ) . clone ( ) ;
12931373
@@ -1311,6 +1391,13 @@ where
13111391
13121392 // TODO: does LSPS4 service need to track this? seems like no?
13131393 let user_channel_id = 0 ;
1394+ log_info ! (
1395+ self . logger,
1396+ "Calling create_channel for LSPS4 peer {} (channel_amount_sats={}, user_channel_id={})" ,
1397+ their_network_key,
1398+ channel_amount_sats,
1399+ user_channel_id,
1400+ ) ;
13141401
13151402 match self . channel_manager . create_channel (
13161403 their_network_key,
@@ -1320,7 +1407,14 @@ where
13201407 None ,
13211408 Some ( config) ,
13221409 ) {
1323- Ok ( _) => { } ,
1410+ Ok ( _) => {
1411+ log_info ! (
1412+ self . logger,
1413+ "LSPS4 create_channel accepted for peer {} (channel_amount_sats={})" ,
1414+ their_network_key,
1415+ channel_amount_sats,
1416+ ) ;
1417+ } ,
13241418 Err ( e) => {
13251419 // TODO: We just silently fail here. Eventually we will need to remember
13261420 // the pending requests and regularly retry opening the channel until we
@@ -2111,6 +2205,14 @@ where
21112205 & self , their_network_key : PublicKey , amt_to_forward_msat : u64 ,
21122206 channel_count : usize ,
21132207 ) -> Result < ( ) , Error > {
2208+ log_info ! (
2209+ self . logger,
2210+ "Entering open_channel_for_lsps4 for peer {} (amt_to_forward_msat={}, channel_count={}, thread_id={:?})" ,
2211+ their_network_key,
2212+ amt_to_forward_msat,
2213+ channel_count,
2214+ std:: thread:: current( ) . id( ) ,
2215+ ) ;
21142216 let service_config = if let Some ( service_config) =
21152217 self . lsps4_service . as_ref ( ) . map ( |s| s. service_config . clone ( ) )
21162218 {
@@ -2156,10 +2258,32 @@ where
21562258 channel_amount_sats = channel_amount_sats. max ( tier_value_sats) ;
21572259 }
21582260 }
2261+ log_info ! (
2262+ self . logger,
2263+ "open_channel_for_lsps4 peer {} computed channel_amount_sats={} (amt_to_forward_msat={}, over_provisioning_ppm={}, min_channel_size_msat={}, tier_count={})" ,
2264+ their_network_key,
2265+ channel_amount_sats,
2266+ amt_to_forward_msat,
2267+ service_config. channel_over_provisioning_ppm,
2268+ service_config. min_channel_size_msat,
2269+ service_config. channel_size_tiers. len( ) ,
2270+ ) ;
21592271 let cur_anchor_reserve_sats =
21602272 total_anchor_channels_reserve_sats ( & self . channel_manager , & self . config ) ;
2273+ log_info ! (
2274+ self . logger,
2275+ "open_channel_for_lsps4 peer {} fetching spendable_amount_sats with reserve_sats={}" ,
2276+ their_network_key,
2277+ cur_anchor_reserve_sats,
2278+ ) ;
21612279 let spendable_amount_sats =
2162- self . wallet . get_spendable_amount_sats ( cur_anchor_reserve_sats) . unwrap_or ( 0 ) ;
2280+ self . wallet . get_spendable_amount_sats ( cur_anchor_reserve_sats, "lsps4_fallback" ) . unwrap_or ( 0 ) ;
2281+ log_info ! (
2282+ self . logger,
2283+ "open_channel_for_lsps4 peer {} wallet returned spendable_amount_sats={}" ,
2284+ their_network_key,
2285+ spendable_amount_sats,
2286+ ) ;
21632287 let required_funds_sats = channel_amount_sats
21642288 + self . config . anchor_channels_config . as_ref ( ) . map_or ( 0 , |c| {
21652289 if init_features. requires_anchors_zero_fee_htlc_tx ( )
@@ -2170,13 +2294,29 @@ where
21702294 0
21712295 }
21722296 } ) ;
2297+ log_info ! (
2298+ self . logger,
2299+ "open_channel_for_lsps4 peer {} computed required_funds_sats={} (channel_amount_sats={}, anchor_reserve_applied={})" ,
2300+ their_network_key,
2301+ required_funds_sats,
2302+ channel_amount_sats,
2303+ required_funds_sats. saturating_sub( channel_amount_sats) ,
2304+ ) ;
21732305 if spendable_amount_sats < required_funds_sats {
21742306 log_error ! ( self . logger,
2175- "Unable to create channel due to insufficient funds. Available: {}sats, Required: {}sats" ,
2176- spendable_amount_sats, channel_amount_sats
2307+ "Unable to create channel due to insufficient funds. Available: {}sats, Required: {}sats, Peer: {} " ,
2308+ spendable_amount_sats, required_funds_sats , their_network_key
21772309 ) ;
21782310 return Err ( Error :: InsufficientFunds ) ;
21792311 }
2312+ log_info ! (
2313+ self . logger,
2314+ "open_channel_for_lsps4 peer {} passed funding checks (channel_amount_sats={}, required_funds_sats={}, spendable_amount_sats={})" ,
2315+ their_network_key,
2316+ channel_amount_sats,
2317+ required_funds_sats,
2318+ spendable_amount_sats,
2319+ ) ;
21802320
21812321 let mut config = self . channel_manager . get_current_config ( ) . clone ( ) ;
21822322 debug_assert_eq ! (
@@ -2192,6 +2332,13 @@ where
21922332 config. channel_handshake_config . their_channel_reserve_proportional_millionths = 0 ;
21932333
21942334 let user_channel_id = 0 ;
2335+ log_info ! (
2336+ self . logger,
2337+ "open_channel_for_lsps4 calling create_channel for peer {} (channel_amount_sats={}, user_channel_id={})" ,
2338+ their_network_key,
2339+ channel_amount_sats,
2340+ user_channel_id,
2341+ ) ;
21952342
21962343 self . channel_manager
21972344 . create_channel (
@@ -2202,7 +2349,14 @@ where
22022349 None ,
22032350 Some ( config) ,
22042351 )
2205- . map ( |_| ( ) )
2352+ . map ( |_| {
2353+ log_info ! (
2354+ self . logger,
2355+ "open_channel_for_lsps4 create_channel accepted for peer {} (channel_amount_sats={})" ,
2356+ their_network_key,
2357+ channel_amount_sats,
2358+ ) ;
2359+ } )
22062360 . map_err ( |e| {
22072361 log_error ! (
22082362 self . logger,
0 commit comments