@@ -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};
@@ -4475,7 +4476,6 @@ pub(super) fn calculate_our_funding_satoshis(
4475
4476
holder_dust_limit_satoshis: u64,
4476
4477
) -> Result<u64, APIError> {
4477
4478
let mut total_input_satoshis = 0u64;
4478
- let mut our_contributed_weight = 0u64;
4479
4479
4480
4480
for (idx, input) in funding_inputs.iter().enumerate() {
4481
4481
if let Some(output) = input.1.as_transaction().output.get(input.0.previous_output.vout as usize) {
@@ -4486,6 +4486,9 @@ pub(super) fn calculate_our_funding_satoshis(
4486
4486
input.1.as_transaction().compute_txid(), input.0.previous_output.vout, idx) });
4487
4487
}
4488
4488
}
4489
+ // inputs:
4490
+ let mut our_contributed_weight = (funding_inputs.len() as u64) * BASE_INPUT_WEIGHT;
4491
+ // witnesses:
4489
4492
our_contributed_weight = our_contributed_weight.saturating_add(total_witness_weight.to_wu());
4490
4493
4491
4494
// If we are the initiator, we must pay for weight of all common fields in the funding transaction.
@@ -12268,25 +12271,25 @@ mod tests {
12268
12271
assert_eq!(
12269
12272
calculate_our_funding_satoshis(true, &inputs_2, witness_weight, 2000, 1000)
12270
12273
.unwrap(),
12271
- 298972
12274
+ 298332
12272
12275
);
12273
12276
12274
12277
assert_eq!(
12275
12278
calculate_our_funding_satoshis(true, &inputs_1, witness_weight, 2000, 1000)
12276
12279
.unwrap(),
12277
- 18972
12280
+ 18652
12278
12281
);
12279
12282
12280
12283
assert_eq!(
12281
12284
calculate_our_funding_satoshis(true, &inputs_1, Weight::from_wu(0), 2000, 1000)
12282
12285
.unwrap(),
12283
- 19572
12286
+ 19252
12284
12287
);
12285
12288
12286
12289
assert_eq!(
12287
12290
calculate_our_funding_satoshis(false, &inputs_1, Weight::from_wu(0), 2000, 1000)
12288
12291
.unwrap(),
12289
- 20000
12292
+ 19680
12290
12293
);
12291
12294
12292
12295
// below dust limit
0 commit comments