@@ -145,8 +145,8 @@ pub struct AnchorChannelReserveContext {
145
145
///
146
146
/// [ChannelHandshakeConfig::our_max_accepted_htlcs]: crate::util::config::ChannelHandshakeConfig::our_max_accepted_htlcs
147
147
pub expected_accepted_htlcs : u16 ,
148
- /// Whether the wallet providing the anchor channel reserve uses Taproot P2TR outputs for its
149
- /// funds , or Segwit P2WPKH outputs otherwise.
148
+ /// Whether the wallet handling anchor channel reserves creates Taproot P2TR outputs for any new
149
+ /// outputs , or Segwit P2WPKH outputs otherwise.
150
150
pub taproot_wallet : bool ,
151
151
}
152
152
@@ -194,21 +194,26 @@ pub fn get_reserve_per_channel(context: &AnchorChannelReserveContext) -> Amount
194
194
pub fn get_supportable_anchor_channels (
195
195
context : & AnchorChannelReserveContext , utxos : & [ Utxo ] ,
196
196
) -> u64 {
197
- let reserve_per_channel = get_reserve_per_channel ( context) ;
197
+ // Get the reserve needed per channel, replacing the fee for an initial spend with the actual value
198
+ // below.
199
+ let default_satisfaction_fee = context. upper_bound_fee_rate . fee_wu (
200
+ Weight :: from_wu ( if context. taproot_wallet { P2TR_INPUT_WEIGHT } else { P2WPKH_INPUT_WEIGHT } )
201
+ ) . unwrap_or ( Amount :: MAX ) ;
202
+ let reserve_per_channel = get_reserve_per_channel ( context) - default_satisfaction_fee;
203
+
198
204
let mut total_fractional_amount = Amount :: from_sat ( 0 ) ;
199
205
let mut num_whole_utxos = 0 ;
200
206
for utxo in utxos {
201
- if utxo. output . value >= reserve_per_channel {
207
+ let satisfaction_fee = context
208
+ . upper_bound_fee_rate
209
+ . fee_wu ( Weight :: from_wu ( utxo. satisfaction_weight ) )
210
+ . unwrap_or ( Amount :: MAX ) ;
211
+ let amount = utxo. output . value . checked_sub ( satisfaction_fee) . unwrap_or ( Amount :: MIN ) ;
212
+ if amount >= reserve_per_channel {
202
213
num_whole_utxos += 1 ;
203
214
} else {
204
215
total_fractional_amount =
205
- total_fractional_amount. checked_add ( utxo. output . value ) . unwrap_or ( Amount :: MAX ) ;
206
- let satisfaction_fee = context
207
- . upper_bound_fee_rate
208
- . fee_wu ( Weight :: from_wu ( utxo. satisfaction_weight ) )
209
- . unwrap_or ( Amount :: MAX ) ;
210
- total_fractional_amount =
211
- total_fractional_amount. checked_sub ( satisfaction_fee) . unwrap_or ( Amount :: MIN ) ;
216
+ total_fractional_amount. checked_add ( amount) . unwrap_or ( Amount :: MAX ) ;
212
217
}
213
218
}
214
219
// We require disjoint sets of UTXOs for the reserve of each channel,
0 commit comments