Skip to content

Commit a59bcf6

Browse files
committed
Include base input fee in fee, in calculate_our_funding_satoshis
1 parent 0917689 commit a59bcf6

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};
@@ -4354,7 +4355,6 @@ pub(super) fn calculate_our_funding_satoshis(
43544355
holder_dust_limit_satoshis: u64,
43554356
) -> Result<u64, APIError> {
43564357
let mut total_input_satoshis = 0u64;
4357-
let mut our_contributed_weight = 0u64;
43584358

43594359
for (idx, input) in funding_inputs.iter().enumerate() {
43604360
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(
43654365
input.1.as_transaction().compute_txid(), input.0.previous_output.vout, idx) });
43664366
}
43674367
}
4368+
// inputs:
4369+
let mut our_contributed_weight = (funding_inputs.len() as u64) * BASE_INPUT_WEIGHT;
4370+
// witnesses:
43684371
our_contributed_weight = our_contributed_weight.saturating_add(total_witness_weight.to_wu());
43694372

43704373
// If we are the initiator, we must pay for weight of all common fields in the funding transaction.
@@ -12242,25 +12245,25 @@ mod tests {
1224212245
assert_eq!(
1224312246
calculate_our_funding_satoshis(true, &inputs_2, witness_weight, 2000, 1000)
1224412247
.unwrap(),
12245-
298972
12248+
298332
1224612249
);
1224712250

1224812251
assert_eq!(
1224912252
calculate_our_funding_satoshis(true, &inputs_1, witness_weight, 2000, 1000)
1225012253
.unwrap(),
12251-
18972
12254+
18652
1225212255
);
1225312256

1225412257
assert_eq!(
1225512258
calculate_our_funding_satoshis(true, &inputs_1, Weight::from_wu(0), 2000, 1000)
1225612259
.unwrap(),
12257-
19572
12260+
19252
1225812261
);
1225912262

1226012263
assert_eq!(
1226112264
calculate_our_funding_satoshis(false, &inputs_1, Weight::from_wu(0), 2000, 1000)
1226212265
.unwrap(),
12263-
20000
12266+
19680
1226412267
);
1226512268

1226612269
// below dust limit

0 commit comments

Comments
 (0)