Skip to content

Commit bb3eeed

Browse files
committed
Adjust the weight of htlc success and timeout witnesses in 0FC channels
1 parent 67ed89d commit bb3eeed

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

lightning/src/events/bump_transaction/mod.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use crate::io_extras::sink;
2424
use crate::ln::chan_utils;
2525
use crate::ln::chan_utils::{
2626
shared_anchor_script_pubkey, HTLCOutputInCommitment, ANCHOR_INPUT_WITNESS_WEIGHT,
27-
HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT, HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT,
27+
HTLC_SUCCESS_INPUT_KEYED_ANCHOR_WITNESS_WEIGHT, HTLC_SUCCESS_INPUT_P2A_ANCHOR_WITNESS_WEIGHT,
28+
HTLC_TIMEOUT_INPUT_KEYED_ANCHOR_WITNESS_WEIGHT, HTLC_TIMEOUT_INPUT_P2A_ANCHOR_WITNESS_WEIGHT,
2829
P2A_ANCHOR_INPUT_WITNESS_WEIGHT,
2930
};
3031
use crate::ln::types::ChannelId;
@@ -864,16 +865,30 @@ where
864865
output: vec![],
865866
};
866867
let mut must_spend = Vec::with_capacity(htlc_descriptors.len());
868+
let (htlc_success_witness_weight, htlc_timeout_witness_weight) =
869+
if channel_type.supports_anchor_zero_fee_commitments() {
870+
(
871+
HTLC_SUCCESS_INPUT_P2A_ANCHOR_WITNESS_WEIGHT,
872+
HTLC_TIMEOUT_INPUT_P2A_ANCHOR_WITNESS_WEIGHT,
873+
)
874+
} else if channel_type.supports_anchors_zero_fee_htlc_tx() {
875+
(
876+
HTLC_SUCCESS_INPUT_KEYED_ANCHOR_WITNESS_WEIGHT,
877+
HTLC_TIMEOUT_INPUT_KEYED_ANCHOR_WITNESS_WEIGHT,
878+
)
879+
} else {
880+
panic!("channel type should be either zero-fee HTLCs, or zero-fee commitments");
881+
};
867882
for htlc_descriptor in htlc_descriptors {
868883
let htlc_input = htlc_descriptor.unsigned_tx_input();
869884
must_spend.push(Input {
870885
outpoint: htlc_input.previous_output.clone(),
871886
previous_utxo: htlc_descriptor.previous_utxo(&self.secp),
872887
satisfaction_weight: EMPTY_SCRIPT_SIG_WEIGHT
873888
+ if htlc_descriptor.preimage.is_some() {
874-
HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT
889+
htlc_success_witness_weight
875890
} else {
876-
HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT
891+
htlc_timeout_witness_weight
877892
},
878893
});
879894
htlc_tx.input.push(htlc_input);

lightning/src/ln/chan_utils.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,16 @@ pub const P2A_ANCHOR_INPUT_WITNESS_WEIGHT: u64 = 1;
9595
/// The maximum value of a P2A anchor.
9696
pub const P2A_MAX_VALUE: u64 = 240;
9797

98-
/// The upper bound weight of an HTLC timeout input from a commitment transaction with anchor
99-
/// outputs.
100-
pub const HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT: u64 = 288;
101-
/// The upper bound weight of an HTLC success input from a commitment transaction with anchor
102-
/// outputs.
103-
pub const HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT: u64 = 327;
98+
/// The upper bound weight of an HTLC timeout input from a commitment transaction with keyed anchor outputs.
99+
pub const HTLC_TIMEOUT_INPUT_KEYED_ANCHOR_WITNESS_WEIGHT: u64 = 288;
100+
/// The upper bound weight of an HTLC timeout input from a commitment transaction with a p2a anchor output.
101+
/// Note the corresponding outputs no longer have the 1 CSV lock.
102+
pub const HTLC_TIMEOUT_INPUT_P2A_ANCHOR_WITNESS_WEIGHT: u64 = 285;
103+
/// The upper bound weight of an HTLC success input from a commitment transaction with keyed anchor outputs.
104+
pub const HTLC_SUCCESS_INPUT_KEYED_ANCHOR_WITNESS_WEIGHT: u64 = 327;
105+
/// The upper bound weight of an HTLC success input from a commitment transaction with a p2a anchor output.
106+
/// Note the corresponding outputs no longer have the 1 CSV lock.
107+
pub const HTLC_SUCCESS_INPUT_P2A_ANCHOR_WITNESS_WEIGHT: u64 = 324;
104108

105109
/// The size of the 2-of-2 multisig script
106110
const MULTISIG_SCRIPT_SIZE: u64 = 1 + // OP_2

0 commit comments

Comments
 (0)