@@ -57,6 +57,7 @@ use crate::chain::transaction::{OutPoint, TransactionData};
57
57
use crate::sign::ecdsa::EcdsaChannelSigner;
58
58
use crate::sign::{EntropySource, ChannelSigner, SignerProvider, NodeSigner, Recipient};
59
59
use crate::events::{ClosureReason, Event};
60
+ use crate::events::bump_transaction::BASE_INPUT_WEIGHT;
60
61
use crate::routing::gossip::NodeId;
61
62
use crate::util::ser::{Readable, ReadableArgs, TransactionU16LenLimited, Writeable, Writer};
62
63
use crate::util::logger::{Logger, Record, WithContext};
@@ -4354,7 +4355,6 @@ pub(super) fn calculate_our_funding_satoshis(
4354
4355
holder_dust_limit_satoshis: u64,
4355
4356
) -> Result<u64, APIError> {
4356
4357
let mut total_input_satoshis = 0u64;
4357
- let mut our_contributed_weight = 0u64;
4358
4358
4359
4359
for (idx, input) in funding_inputs.iter().enumerate() {
4360
4360
if let Some(output) = input.1.as_transaction().output.get(input.0.previous_output.vout as usize) {
@@ -4365,6 +4365,9 @@ pub(super) fn calculate_our_funding_satoshis(
4365
4365
input.1.as_transaction().compute_txid(), input.0.previous_output.vout, idx) });
4366
4366
}
4367
4367
}
4368
+ // inputs:
4369
+ let mut our_contributed_weight = (funding_inputs.len() as u64) * BASE_INPUT_WEIGHT;
4370
+ // witnesses:
4368
4371
our_contributed_weight = our_contributed_weight.saturating_add(total_witness_weight.to_wu());
4369
4372
4370
4373
// If we are the initiator, we must pay for weight of all common fields in the funding transaction.
@@ -12242,25 +12245,25 @@ mod tests {
12242
12245
assert_eq!(
12243
12246
calculate_our_funding_satoshis(true, &inputs_2, witness_weight, 2000, 1000)
12244
12247
.unwrap(),
12245
- 298972
12248
+ 298332
12246
12249
);
12247
12250
12248
12251
assert_eq!(
12249
12252
calculate_our_funding_satoshis(true, &inputs_1, witness_weight, 2000, 1000)
12250
12253
.unwrap(),
12251
- 18972
12254
+ 18652
12252
12255
);
12253
12256
12254
12257
assert_eq!(
12255
12258
calculate_our_funding_satoshis(true, &inputs_1, Weight::from_wu(0), 2000, 1000)
12256
12259
.unwrap(),
12257
- 19572
12260
+ 19252
12258
12261
);
12259
12262
12260
12263
assert_eq!(
12261
12264
calculate_our_funding_satoshis(false, &inputs_1, Weight::from_wu(0), 2000, 1000)
12262
12265
.unwrap(),
12263
- 20000
12266
+ 19680
12264
12267
);
12265
12268
12266
12269
// below dust limit
0 commit comments