Skip to content

Commit 3206408

Browse files
committed
f - use witness_weight
1 parent 8f7aa25 commit 3206408

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,7 @@ pub(super) fn calculate_change_output_value(
20762076

20772077
let mut total_input_satoshis = 0u64;
20782078
let mut our_funding_inputs_weight = 0u64;
2079-
for FundingTxInput { txin, prevtx, .. } in context.our_funding_inputs.iter() {
2079+
for FundingTxInput { txin, prevtx, witness_weight } in context.our_funding_inputs.iter() {
20802080
let txid = prevtx.compute_txid();
20812081
if txin.previous_output.txid != txid {
20822082
return Err(AbortReason::PrevTxOutInvalid);
@@ -2086,7 +2086,8 @@ pub(super) fn calculate_change_output_value(
20862086
.get(txin.previous_output.vout as usize)
20872087
.ok_or(AbortReason::PrevTxOutInvalid)?;
20882088
total_input_satoshis = total_input_satoshis.saturating_add(output.value.to_sat());
2089-
let weight = estimate_input_weight(output).to_wu();
2089+
2090+
let weight = BASE_INPUT_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT + witness_weight.to_wu();
20902091
our_funding_inputs_weight = our_funding_inputs_weight.saturating_add(weight);
20912092
}
20922093

@@ -2157,7 +2158,8 @@ mod tests {
21572158
use super::{
21582159
get_output_weight, AddingRole, ConstructedTransaction, InteractiveTxOutput,
21592160
InteractiveTxSigningSession, NegotiatedTxInput, OutputOwned, P2TR_INPUT_WEIGHT_LOWER_BOUND,
2160-
P2WPKH_INPUT_WEIGHT_LOWER_BOUND, P2WSH_INPUT_WEIGHT_LOWER_BOUND, TX_COMMON_FIELDS_WEIGHT,
2161+
P2WPKH_INPUT_WEIGHT_LOWER_BOUND, P2WPKH_WITNESS_WEIGHT, P2WSH_INPUT_WEIGHT_LOWER_BOUND,
2162+
TX_COMMON_FIELDS_WEIGHT,
21612163
};
21622164

21632165
const TEST_FEERATE_SATS_PER_KW: u32 = FEERATE_FLOOR_SATS_PER_KW * 10;
@@ -3162,7 +3164,7 @@ mod tests {
31623164
sequence: Sequence::ZERO,
31633165
witness: Witness::new(),
31643166
};
3165-
let witness_weight = Weight::ZERO;
3167+
let witness_weight = Weight::from_wu(P2WPKH_WITNESS_WEIGHT);
31663168
FundingTxInput { txin, prevtx, witness_weight }
31673169
})
31683170
.collect();

0 commit comments

Comments
 (0)