Skip to content

Commit 0b36513

Browse files
committed
Adjust HTLC_{SUCCESS,TIMEOUT}_TX_WEIGHT when anchors used
1 parent 658960a commit 0b36513

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ pub(crate) const MAX_HTLCS: u16 = 483;
4545
pub(super) const HTLC_SUCCESS_TX_WEIGHT: u64 = 703;
4646
pub(super) const HTLC_TIMEOUT_TX_WEIGHT: u64 = 663;
4747

48+
#[inline]
49+
pub fn htlc_success_tx_weight(opt_anchors: bool) -> u64 {
50+
const HTLC_SUCCESS_ANCHOR_TX_WEIGHT: u64 = 706;
51+
if opt_anchors { HTLC_SUCCESS_ANCHOR_TX_WEIGHT } else { HTLC_SUCCESS_TX_WEIGHT }
52+
}
53+
54+
#[inline]
55+
pub fn htlc_timeout_tx_weight(opt_anchors: bool) -> u64 {
56+
const HTLC_TIMEOUT_ANCHOR_TX_WEIGHT: u64 = 666;
57+
if opt_anchors { HTLC_TIMEOUT_ANCHOR_TX_WEIGHT } else { HTLC_TIMEOUT_TX_WEIGHT }
58+
}
59+
4860
#[derive(PartialEq)]
4961
pub(crate) enum HTLCType {
5062
AcceptedHTLC,
@@ -598,11 +610,12 @@ pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, conte
598610
witness: Vec::new(),
599611
});
600612

601-
let total_fee = if htlc.offered {
602-
feerate_per_kw as u64 * HTLC_TIMEOUT_TX_WEIGHT / 1000
603-
} else {
604-
feerate_per_kw as u64 * HTLC_SUCCESS_TX_WEIGHT / 1000
605-
};
613+
let weight = if htlc.offered {
614+
htlc_timeout_tx_weight(opt_anchors)
615+
} else {
616+
htlc_success_tx_weight(opt_anchors)
617+
};
618+
let total_fee = feerate_per_kw as u64 * weight / 1000;
606619

607620
let mut txouts: Vec<TxOut> = Vec::new();
608621
txouts.push(TxOut {

0 commit comments

Comments
 (0)