@@ -24,7 +24,7 @@ use crate::chain::chaininterface::FeeEstimator;
2424use crate :: chain:: chainmonitor:: ChainMonitor ;
2525use crate :: chain:: chainmonitor:: Persist ;
2626use crate :: chain:: Filter ;
27- use crate :: ln:: chan_utils:: max_htlcs;
27+ use crate :: ln:: chan_utils:: { max_htlcs, BASE_INPUT_WEIGHT } ;
2828use crate :: ln:: channelmanager:: AChannelManager ;
2929use crate :: prelude:: new_hash_set;
3030use crate :: sign:: ecdsa:: EcdsaChannelSigner ;
@@ -240,11 +240,11 @@ pub fn get_supportable_anchor_channels(
240240 let mut total_fractional_amount = Amount :: from_sat ( 0 ) ;
241241 let mut num_whole_utxos = 0 ;
242242 for utxo in utxos {
243- let satisfaction_fee = context
243+ let spend_fee = context
244244 . upper_bound_fee_rate
245- . fee_wu ( Weight :: from_wu ( utxo. satisfaction_weight ) )
245+ . fee_wu ( Weight :: from_wu ( BASE_INPUT_WEIGHT + utxo. satisfaction_weight ) )
246246 . unwrap_or ( Amount :: MAX ) ;
247- let amount = utxo. output . value . checked_sub ( satisfaction_fee ) . unwrap_or ( Amount :: MIN ) ;
247+ let amount = utxo. output . value . checked_sub ( spend_fee ) . unwrap_or ( Amount :: MIN ) ;
248248 if amount >= reserve_per_channel {
249249 num_whole_utxos += 1 ;
250250 } else {
@@ -370,6 +370,15 @@ mod test {
370370 assert_eq ! ( get_supportable_anchor_channels( & context, utxos. as_slice( ) ) , 3 ) ;
371371 }
372372
373+ #[ test]
374+ fn test_get_supportable_anchor_channels_accounts_for_input_weight ( ) {
375+ let context = AnchorChannelReserveContext :: default ( ) ;
376+ let reserve = get_reserve_per_channel ( & context) ;
377+ let utxo = make_p2wpkh_utxo ( reserve - Amount :: from_sat ( 1 ) ) ;
378+
379+ assert_eq ! ( get_supportable_anchor_channels( & context, & [ utxo] ) , 0 ) ;
380+ }
381+
373382 #[ test]
374383 fn test_anchor_output_spend_transaction_weight ( ) {
375384 // Example with smaller signatures:
0 commit comments