Skip to content

Commit f61676e

Browse files
committed
Dont broadcast HTLC-Timeouts when closing a channel until locktime
1 parent 00bbc51 commit f61676e

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,32 +1899,40 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18991899
self.holder_tx_signed = true;
19001900
let commitment_tx = self.onchain_tx_handler.get_fully_signed_holder_tx(&self.funding_redeemscript);
19011901
let txid = commitment_tx.txid();
1902-
let mut res = vec![commitment_tx];
1902+
let mut holder_transactions = vec![commitment_tx];
19031903
for htlc in self.current_holder_commitment_tx.htlc_outputs.iter() {
19041904
if let Some(vout) = htlc.0.transaction_output_index {
19051905
let preimage = if !htlc.0.offered {
19061906
if let Some(preimage) = self.payment_preimages.get(&htlc.0.payment_hash) { Some(preimage.clone()) } else {
19071907
// We can't build an HTLC-Success transaction without the preimage
19081908
continue;
19091909
}
1910+
} else if htlc.0.cltv_expiry > self.best_block.height() + 1 {
1911+
// Don't broadcast HTLC-Timeout transactions immediately as they don't meet the
1912+
// current locktime requirements on-chain. We will broadcast them in
1913+
// `block_confirmed` when `would_broadcast_at_height` returns true.
1914+
// Note that we add + 1 as transactions are broadcastable when they can be
1915+
// confirmed in the next block.
1916+
continue;
19101917
} else { None };
19111918
if let Some(htlc_tx) = self.onchain_tx_handler.get_fully_signed_htlc_tx(
19121919
&::bitcoin::OutPoint { txid, vout }, &preimage) {
1913-
res.push(htlc_tx);
1920+
holder_transactions.push(htlc_tx);
19141921
}
19151922
}
19161923
}
19171924
// We throw away the generated waiting_first_conf data as we aren't (yet) confirmed and we don't actually know what the caller wants to do.
19181925
// The data will be re-generated and tracked in check_spend_holder_transaction if we get a confirmation.
1919-
return res;
1926+
holder_transactions
19201927
}
19211928

19221929
#[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
1930+
/// Note that this includes possibly-locktimed-in-the-future transactions!
19231931
fn unsafe_get_latest_holder_commitment_txn<L: Deref>(&mut self, logger: &L) -> Vec<Transaction> where L::Target: Logger {
19241932
log_trace!(logger, "Getting signed copy of latest holder commitment transaction!");
19251933
let commitment_tx = self.onchain_tx_handler.get_fully_signed_copy_holder_tx(&self.funding_redeemscript);
19261934
let txid = commitment_tx.txid();
1927-
let mut res = vec![commitment_tx];
1935+
let mut holder_transactions = vec![commitment_tx];
19281936
for htlc in self.current_holder_commitment_tx.htlc_outputs.iter() {
19291937
if let Some(vout) = htlc.0.transaction_output_index {
19301938
let preimage = if !htlc.0.offered {
@@ -1935,11 +1943,11 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
19351943
} else { None };
19361944
if let Some(htlc_tx) = self.onchain_tx_handler.unsafe_get_fully_signed_htlc_tx(
19371945
&::bitcoin::OutPoint { txid, vout }, &preimage) {
1938-
res.push(htlc_tx);
1946+
holder_transactions.push(htlc_tx);
19391947
}
19401948
}
19411949
}
1942-
return res
1950+
holder_transactions
19431951
}
19441952

19451953
pub fn block_connected<B: Deref, F: Deref, L: Deref>(&mut self, header: &BlockHeader, txdata: &TransactionData, height: u32, broadcaster: B, fee_estimator: F, logger: L) -> Vec<TransactionOutputs>

0 commit comments

Comments
 (0)