Skip to content

Commit 217293c

Browse files
committed
Include base input fee in fee, in calculate_our_funding_satoshis
1 parent 4459d20 commit 217293c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use crate::chain::transaction::{OutPoint, TransactionData};
5757
use crate::sign::ecdsa::EcdsaChannelSigner;
5858
use crate::sign::{EntropySource, ChannelSigner, SignerProvider, NodeSigner, Recipient};
5959
use crate::events::{ClosureReason, Event};
60+
use crate::events::bump_transaction::BASE_INPUT_WEIGHT;
6061
use crate::routing::gossip::NodeId;
6162
use crate::util::ser::{Readable, ReadableArgs, TransactionU16LenLimited, Writeable, Writer};
6263
use crate::util::logger::{Logger, Record, WithContext};
@@ -4475,7 +4476,6 @@ pub(super) fn calculate_our_funding_satoshis(
44754476
holder_dust_limit_satoshis: u64,
44764477
) -> Result<u64, APIError> {
44774478
let mut total_input_satoshis = 0u64;
4478-
let mut our_contributed_weight = 0u64;
44794479

44804480
for (idx, input) in funding_inputs.iter().enumerate() {
44814481
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(
44864486
input.1.as_transaction().compute_txid(), input.0.previous_output.vout, idx) });
44874487
}
44884488
}
4489+
// inputs:
4490+
let mut our_contributed_weight = (funding_inputs.len() as u64) * BASE_INPUT_WEIGHT;
4491+
// witnesses:
44894492
our_contributed_weight = our_contributed_weight.saturating_add(total_witness_weight.to_wu());
44904493

44914494
// If we are the initiator, we must pay for weight of all common fields in the funding transaction.
@@ -12268,25 +12271,25 @@ mod tests {
1226812271
assert_eq!(
1226912272
calculate_our_funding_satoshis(true, &inputs_2, witness_weight, 2000, 1000)
1227012273
.unwrap(),
12271-
298972
12274+
298332
1227212275
);
1227312276

1227412277
assert_eq!(
1227512278
calculate_our_funding_satoshis(true, &inputs_1, witness_weight, 2000, 1000)
1227612279
.unwrap(),
12277-
18972
12280+
18652
1227812281
);
1227912282

1228012283
assert_eq!(
1228112284
calculate_our_funding_satoshis(true, &inputs_1, Weight::from_wu(0), 2000, 1000)
1228212285
.unwrap(),
12283-
19572
12286+
19252
1228412287
);
1228512288

1228612289
assert_eq!(
1228712290
calculate_our_funding_satoshis(false, &inputs_1, Weight::from_wu(0), 2000, 1000)
1228812291
.unwrap(),
12289-
20000
12292+
19680
1229012293
);
1229112294

1229212295
// below dust limit

0 commit comments

Comments
 (0)