@@ -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,31 @@ 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
200
+ . upper_bound_fee_rate
201
+ . fee_wu ( Weight :: from_wu ( if context. taproot_wallet {
202
+ P2TR_INPUT_WEIGHT
203
+ } else {
204
+ P2WPKH_INPUT_WEIGHT
205
+ } ) )
206
+ . unwrap_or ( Amount :: MAX ) ;
207
+ let reserve_per_channel = get_reserve_per_channel ( context) - default_satisfaction_fee;
208
+
198
209
let mut total_fractional_amount = Amount :: from_sat ( 0 ) ;
199
210
let mut num_whole_utxos = 0 ;
200
211
for utxo in utxos {
201
- if utxo. output . value >= reserve_per_channel {
212
+ let satisfaction_fee = context
213
+ . upper_bound_fee_rate
214
+ . fee_wu ( Weight :: from_wu ( utxo. satisfaction_weight ) )
215
+ . unwrap_or ( Amount :: MAX ) ;
216
+ let amount = utxo. output . value . checked_sub ( satisfaction_fee) . unwrap_or ( Amount :: MIN ) ;
217
+ if amount >= reserve_per_channel {
202
218
num_whole_utxos += 1 ;
203
219
} else {
204
220
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 ) ;
221
+ total_fractional_amount. checked_add ( amount) . unwrap_or ( Amount :: MAX ) ;
212
222
}
213
223
}
214
224
// We require disjoint sets of UTXOs for the reserve of each channel,
0 commit comments