@@ -1251,7 +1251,7 @@ impl Node {
12511251 FundingAmount :: Exact { amount_sats } => {
12521252 // Check funds availability after connection (includes anchor reserve
12531253 // calculation).
1254- self . check_sufficient_funds_for_channel ( amount_sats, & peer_info. node_id ) ?;
1254+ self . check_sufficient_onchain_funds ( amount_sats, & peer_info. node_id , true ) ?;
12551255 amount_sats
12561256 } ,
12571257 FundingAmount :: Max => {
@@ -1357,33 +1357,37 @@ impl Node {
13571357 Ok ( new_channel_anchor_reserve_sats ( & self . config , peer_node_id, anchor_channel) )
13581358 }
13591359
1360- fn check_sufficient_funds_for_channel (
1361- & self , amount_sats : u64 , peer_node_id : & PublicKey ,
1360+ fn check_sufficient_onchain_funds (
1361+ & self , amount_sats : u64 , peer_node_id : & PublicKey , for_new_channel : bool ,
13621362 ) -> Result < ( ) , Error > {
1363+ let action_str = if for_new_channel { "create channel" } else { "splice-in" } ;
13631364 let cur_anchor_reserve_sats =
13641365 total_anchor_channels_reserve_sats ( & self . channel_manager , & self . config ) ;
13651366 let spendable_amount_sats =
13661367 self . wallet . get_spendable_amount_sats ( cur_anchor_reserve_sats) . unwrap_or ( 0 ) ;
13671368
1368- // Fail early if we have less than the channel value available.
13691369 if spendable_amount_sats < amount_sats {
1370- log_error ! ( self . logger,
1371- "Unable to create channel due to insufficient funds. Available: {}sats, Required: {}sats" ,
1372- spendable_amount_sats, amount_sats
1370+ log_error ! (
1371+ self . logger,
1372+ "Unable to {} due to insufficient funds. Available: {}sats, Required: {}sats" ,
1373+ action_str,
1374+ spendable_amount_sats,
1375+ amount_sats
13731376 ) ;
13741377 return Err ( Error :: InsufficientFunds ) ;
13751378 }
13761379
1377- // Fail if we have less than the channel value + anchor reserve available (if applicable).
1378- let required_funds_sats =
1379- amount_sats + self . new_channel_anchor_reserve_sats ( peer_node_id) ?;
1380+ if for_new_channel {
1381+ let required_funds_sats =
1382+ amount_sats + self . new_channel_anchor_reserve_sats ( peer_node_id) ?;
13801383
1381- if spendable_amount_sats < required_funds_sats {
1382- log_error ! ( self . logger,
1383- "Unable to create channel due to insufficient funds. Available: {}sats, Required: {}sats" ,
1384- spendable_amount_sats, required_funds_sats
1385- ) ;
1386- return Err ( Error :: InsufficientFunds ) ;
1384+ if spendable_amount_sats < required_funds_sats {
1385+ log_error ! ( self . logger,
1386+ "Unable to create channel due to insufficient funds. Available: {}sats, Required: {}sats" ,
1387+ spendable_amount_sats, required_funds_sats
1388+ ) ;
1389+ return Err ( Error :: InsufficientFunds ) ;
1390+ }
13871391 }
13881392
13891393 Ok ( ( ) )
@@ -1659,7 +1663,7 @@ impl Node {
16591663 } ,
16601664 } ;
16611665
1662- self . check_sufficient_funds_for_channel ( splice_amount_sats, & counterparty_node_id) ?;
1666+ self . check_sufficient_onchain_funds ( splice_amount_sats, & counterparty_node_id, false ) ?;
16631667
16641668 let funding_template = self
16651669 . channel_manager
0 commit comments