Skip to content

Commit 5b76e6b

Browse files
authored
Merge pull request #4670 from tnull/2026-06-anchor-reserve-input-weight
Account for UTXO base weight in anchor reserve checks
2 parents dd32fe7 + 5e7b7d3 commit 5b76e6b

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

lightning/src/util/anchor_channel_reserves.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::chain::chaininterface::FeeEstimator;
2424
use crate::chain::chainmonitor::ChainMonitor;
2525
use crate::chain::chainmonitor::Persist;
2626
use crate::chain::Filter;
27-
use crate::ln::chan_utils::max_htlcs;
27+
use crate::ln::chan_utils::{max_htlcs, BASE_INPUT_WEIGHT};
2828
use crate::ln::channelmanager::AChannelManager;
2929
use crate::prelude::new_hash_set;
3030
use 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

Comments
 (0)