diff --git a/src/event.rs b/src/event.rs index 05b7fa6d6..c92661af4 100644 --- a/src/event.rs +++ b/src/event.rs @@ -292,6 +292,7 @@ where // channel. let confirmation_target = ConfirmationTarget::Normal; + // We set nLockTime to the current height to discourage fee sniping. let cur_height = self.channel_manager.current_best_block().height(); let locktime = LockTime::from_height(cur_height).unwrap_or(LockTime::ZERO); @@ -569,6 +570,7 @@ where Some(locktime), &Secp256k1::new(), ); + match res { Ok(spending_tx) => self.wallet.broadcast_transactions(&[&spending_tx]), Err(err) => { diff --git a/src/wallet.rs b/src/wallet.rs index 50b60b7ea..57dd4dc38 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -22,7 +22,7 @@ use bitcoin::bech32::u5; use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature}; use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, Signing}; -use bitcoin::{PackedLockTime, LockTime, Script, Transaction, TxOut, Txid}; +use bitcoin::{LockTime, PackedLockTime, Script, Transaction, TxOut, Txid}; use std::collections::HashMap; use std::sync::{Arc, Condvar, Mutex, RwLock}; @@ -156,14 +156,19 @@ where } pub(crate) fn create_funding_transaction( - &self, output_script: Script, value_sats: u64, confirmation_target: ConfirmationTarget, locktime: LockTime, + &self, output_script: Script, value_sats: u64, confirmation_target: ConfirmationTarget, + locktime: LockTime, ) -> Result { let fee_rate = self.estimate_fee_rate(confirmation_target); let locked_wallet = self.inner.lock().unwrap(); let mut tx_builder = locked_wallet.build_tx(); - tx_builder.add_recipient(output_script, value_sats).fee_rate(fee_rate).nlocktime(locktime).enable_rbf(); + tx_builder + .add_recipient(output_script, value_sats) + .fee_rate(fee_rate) + .nlocktime(locktime) + .enable_rbf(); let mut psbt = match tx_builder.finish() { Ok((psbt, _)) => {