From: Antoine Riard Date: Tue, 9 Apr 2019 23:43:03 +0000 (-0400) Subject: Add fee estimation in check_spend_remote_htlc X-Git-Tag: v0.0.12~213^2~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=0843c22c67408b2f6b1c1f745c245a3180f6cd9d;p=rust-lightning Add fee estimation in check_spend_remote_htlc --- diff --git a/src/ln/channelmonitor.rs b/src/ln/channelmonitor.rs index 00e147549..44206458b 100644 --- a/src/ln/channelmonitor.rs +++ b/src/ln/channelmonitor.rs @@ -1500,7 +1500,7 @@ impl ChannelMonitor { } /// Attempts to claim a remote HTLC-Success/HTLC-Timeout's outputs using the revocation key - fn check_spend_remote_htlc(&self, tx: &Transaction, commitment_number: u64) -> (Option, Option) { + fn check_spend_remote_htlc(&self, tx: &Transaction, commitment_number: u64, fee_estimator: &FeeEstimator) -> (Option, Option) { if tx.input.len() != 1 || tx.output.len() != 1 { return (None, None) } @@ -1552,7 +1552,7 @@ impl ChannelMonitor { if !inputs.is_empty() { let outputs = vec!(TxOut { script_pubkey: self.destination_script.clone(), - value: amount, //TODO: - fee + value: amount }); let mut spend_tx = Transaction { @@ -1561,6 +1561,7 @@ impl ChannelMonitor { input: inputs, output: outputs, }; + 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; let sighash_parts = bip143::SighashComponents::new(&spend_tx); @@ -1792,7 +1793,7 @@ impl ChannelMonitor { } } else { if let Some(&(commitment_number, _)) = self.remote_commitment_txn_on_chain.get(&prevout.txid) { - let (tx, spendable_output) = self.check_spend_remote_htlc(tx, commitment_number); + let (tx, spendable_output) = self.check_spend_remote_htlc(tx, commitment_number, fee_estimator); if let Some(tx) = tx { txn.push(tx); }