Skip to content

Commit 32e2b7a

Browse files
author
Antoine Riard
committed
Add fee estimation in check_spend_remote_htlc
1 parent a5aae94 commit 32e2b7a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ln/channelmonitor.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ impl ChannelMonitor {
15001500
}
15011501

15021502
/// Attempts to claim a remote HTLC-Success/HTLC-Timeout's outputs using the revocation key
1503-
fn check_spend_remote_htlc(&self, tx: &Transaction, commitment_number: u64) -> (Option<Transaction>, Option<SpendableOutputDescriptor>) {
1503+
fn check_spend_remote_htlc(&self, tx: &Transaction, commitment_number: u64, fee_estimator: &FeeEstimator) -> (Option<Transaction>, Option<SpendableOutputDescriptor>) {
15041504
if tx.input.len() != 1 || tx.output.len() != 1 {
15051505
return (None, None)
15061506
}
@@ -1552,7 +1552,7 @@ impl ChannelMonitor {
15521552
if !inputs.is_empty() {
15531553
let outputs = vec!(TxOut {
15541554
script_pubkey: self.destination_script.clone(),
1555-
value: amount, //TODO: - fee
1555+
value: amount
15561556
});
15571557

15581558
let mut spend_tx = Transaction {
@@ -1561,6 +1561,7 @@ impl ChannelMonitor {
15611561
input: inputs,
15621562
output: outputs,
15631563
};
1564+
spend_tx.output[0].value -= fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::HighPriority) * (spend_tx.get_weight() + Self::get_witnesses_weight(&vec![InputDescriptors::RevokedOutput])) / 1000;
15641565

15651566
let sighash_parts = bip143::SighashComponents::new(&spend_tx);
15661567

@@ -1792,7 +1793,7 @@ impl ChannelMonitor {
17921793
}
17931794
} else {
17941795
if let Some(&(commitment_number, _)) = self.remote_commitment_txn_on_chain.get(&prevout.txid) {
1795-
let (tx, spendable_output) = self.check_spend_remote_htlc(tx, commitment_number);
1796+
let (tx, spendable_output) = self.check_spend_remote_htlc(tx, commitment_number, fee_estimator);
17961797
if let Some(tx) = tx {
17971798
txn.push(tx);
17981799
}

0 commit comments

Comments
 (0)