Skip to content

Commit 3cf25dd

Browse files
author
Antoine Riard
committed
Fail back dust HTLC of local commitment tx after maturation
1 parent 2044411 commit 3cf25dd

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/ln/channelmonitor.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,14 +1648,32 @@ impl ChannelMonitor {
16481648
/// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
16491649
/// revoked using data in local_claimable_outpoints.
16501650
/// Should not be used if check_spend_revoked_transaction succeeds.
1651-
fn check_spend_local_transaction(&self, tx: &Transaction, _height: u32) -> (Vec<Transaction>, Vec<SpendableOutputDescriptor>, (Sha256dHash, Vec<TxOut>)) {
1651+
fn check_spend_local_transaction(&mut self, tx: &Transaction, height: u32) -> (Vec<Transaction>, Vec<SpendableOutputDescriptor>, (Sha256dHash, Vec<TxOut>)) {
16521652
let commitment_txid = tx.txid();
1653-
// TODO: If we find a match here we need to fail back HTLCs that weren't included in the
1654-
// broadcast commitment transaction, either because they didn't meet dust or because they
1655-
// weren't yet included in our commitment transaction(s).
1653+
1654+
macro_rules! wait_threshold_conf {
1655+
($height: expr, $update: expr) => {
1656+
match self.htlc_updated_waiting_threshold_conf.entry($height + HTLC_FAIL_ANTI_REORG_DELAY - 1) {
1657+
hash_map::Entry::Occupied(mut entry) => {
1658+
entry.get_mut().push($update);
1659+
}
1660+
hash_map::Entry::Vacant(entry) => {
1661+
entry.insert(vec![($update)]);
1662+
}
1663+
}
1664+
}
1665+
}
1666+
16561667
if let &Some(ref local_tx) = &self.current_local_signed_commitment_tx {
16571668
if local_tx.txid == commitment_txid {
16581669
log_trace!(self, "Got latest local commitment tx broadcast, searching for available HTLCs to claim");
1670+
for (ref htlc, _, ref source) in &local_tx.htlc_outputs {
1671+
if htlc.transaction_output_index.is_none() {
1672+
if let Some(source) = source {
1673+
wait_threshold_conf!(height, (source.clone(), None, htlc.payment_hash.clone()));
1674+
}
1675+
}
1676+
}
16591677
match self.key_storage {
16601678
Storage::Local { ref delayed_payment_base_key, ref latest_per_commitment_point, .. } => {
16611679
let (local_txn, spendable_outputs, watch_outputs) = self.broadcast_by_local_state(local_tx, latest_per_commitment_point, &Some(*delayed_payment_base_key));
@@ -1671,6 +1689,13 @@ impl ChannelMonitor {
16711689
if let &Some(ref local_tx) = &self.prev_local_signed_commitment_tx {
16721690
if local_tx.txid == commitment_txid {
16731691
log_trace!(self, "Got previous local commitment tx broadcast, searching for available HTLCs to claim");
1692+
for (ref htlc, _, ref source) in &local_tx.htlc_outputs {
1693+
if htlc.transaction_output_index.is_none() {
1694+
if let Some(source) = source {
1695+
wait_threshold_conf!(height, (source.clone(), None, htlc.payment_hash.clone()));
1696+
}
1697+
}
1698+
}
16741699
match self.key_storage {
16751700
Storage::Local { ref delayed_payment_base_key, ref prev_latest_per_commitment_point, .. } => {
16761701
let (local_txn, spendable_outputs, watch_outputs) = self.broadcast_by_local_state(local_tx, prev_latest_per_commitment_point, &Some(*delayed_payment_base_key));

0 commit comments

Comments
 (0)