Skip to content

Commit 9322e5a

Browse files
committed
Adjust HTLC_{SUCCESS,TIMEOUT}_TX_WEIGHT when anchors used
1 parent af21b3c commit 9322e5a

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ 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+
/// Gets the weight for an HTLC-Success transaction.
49+
#[inline]
50+
pub fn htlc_success_tx_weight(opt_anchors: bool) -> u64 {
51+
const HTLC_SUCCESS_ANCHOR_TX_WEIGHT: u64 = 706;
52+
if opt_anchors { HTLC_SUCCESS_ANCHOR_TX_WEIGHT } else { HTLC_SUCCESS_TX_WEIGHT }
53+
}
54+
55+
/// Gets the weight for an HTLC-Timeout transaction.
56+
#[inline]
57+
pub fn htlc_timeout_tx_weight(opt_anchors: bool) -> u64 {
58+
const HTLC_TIMEOUT_ANCHOR_TX_WEIGHT: u64 = 666;
59+
if opt_anchors { HTLC_TIMEOUT_ANCHOR_TX_WEIGHT } else { HTLC_TIMEOUT_TX_WEIGHT }
60+
}
61+
4862
#[derive(PartialEq)]
4963
pub(crate) enum HTLCType {
5064
AcceptedHTLC,
@@ -598,11 +612,12 @@ pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, conte
598612
witness: Vec::new(),
599613
});
600614

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-
};
615+
let weight = if htlc.offered {
616+
htlc_timeout_tx_weight(opt_anchors)
617+
} else {
618+
htlc_success_tx_weight(opt_anchors)
619+
};
620+
let total_fee = feerate_per_kw as u64 * weight / 1000;
606621

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

0 commit comments

Comments
 (0)