Skip to content

Commit 33079be

Browse files
committed
Fix incorrect weight estimation for splice shared input
The splice shared input weight should always be composed of the base input weight (prevout & sequence), an empty `script_sig` weight, and the multisig channel-type specific witness weight.
1 parent d4bba8a commit 33079be

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,10 @@ impl InputOwned {
16391639
fn estimate_input_weight(&self) -> Weight {
16401640
match self {
16411641
InputOwned::Single(single) => estimate_input_weight(&single.prev_output),
1642-
InputOwned::Shared(shared) => estimate_input_weight(&shared.prev_output),
1642+
// TODO(taproot): Needs to consider different weights based on channel type
1643+
InputOwned::Shared(_) => Weight::from_wu(
1644+
BASE_INPUT_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT + FUNDING_TRANSACTION_WITNESS_WEIGHT,
1645+
),
16431646
}
16441647
}
16451648

@@ -2156,6 +2159,8 @@ pub(super) fn calculate_change_output_value(
21562159
weight = weight.saturating_add(TX_COMMON_FIELDS_WEIGHT);
21572160
if is_splice {
21582161
// TODO(taproot): Needs to consider different weights based on channel type
2162+
weight = weight.saturating_add(BASE_INPUT_WEIGHT);
2163+
weight = weight.saturating_add(EMPTY_SCRIPT_SIG_WEIGHT);
21592164
weight = weight.saturating_add(FUNDING_TRANSACTION_WITNESS_WEIGHT);
21602165
}
21612166
}
@@ -3147,7 +3152,7 @@ mod tests {
31473152
// Provide and expect a shared input
31483153
do_test_interactive_tx_constructor(TestSession {
31493154
description: "Provide and expect a shared input",
3150-
inputs_a: generate_inputs(&[TestOutput::P2WPKH(50_000)]),
3155+
inputs_a: generate_inputs(&[TestOutput::P2WPKH(100_000)]),
31513156
a_shared_input: Some(generate_shared_input(&prev_funding_tx_1, 0, 60_000)),
31523157
shared_output_a: generate_funding_txout(108_000, 108_000),
31533158
outputs_a: vec![],

lightning/src/ln/splicing_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn test_v1_splice_in() {
235235
assert_eq!(tx_add_output_msg.sats, post_splice_channel_value);
236236
} else {
237237
assert!(tx_add_output_msg.script.is_p2wpkh());
238-
assert_eq!(tx_add_output_msg.sats, 14146); // extra_splice_funding_input_sats - splice_in_sats
238+
assert_eq!(tx_add_output_msg.sats, 13979); // extra_splice_funding_input_sats - splice_in_sats
239239
}
240240

241241
let _res = acceptor_node

0 commit comments

Comments
 (0)