Skip to content

Commit 2044411

Browse files
author
Antoine Riard
committed
Delay failure of non-dust HTLC-outputs until solving timeout tx matures
Fix tests broken by introduced change
1 parent d6f984b commit 2044411

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/ln/channelmonitor.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,7 @@ impl ChannelMonitor {
17861786
// While all commitment/HTLC-Success/HTLC-Timeout transactions have one input, HTLCs
17871787
// can also be resolved in a few other ways which can have more than one output. Thus,
17881788
// we call is_resolving_htlc_output here outside of the tx.input.len() == 1 check.
1789-
let mut updated = self.is_resolving_htlc_output(tx);
1789+
let mut updated = self.is_resolving_htlc_output(tx, height);
17901790
if updated.len() > 0 {
17911791
htlc_updated.append(&mut updated);
17921792
}
@@ -1904,7 +1904,7 @@ impl ChannelMonitor {
19041904

19051905
/// Check if any transaction broadcasted is resolving HTLC output by a success or timeout on a local
19061906
/// or remote commitment tx, if so send back the source, preimage if found and payment_hash of resolved HTLC
1907-
fn is_resolving_htlc_output(&mut self, tx: &Transaction) -> Vec<(HTLCSource, Option<PaymentPreimage>, PaymentHash)> {
1907+
fn is_resolving_htlc_output(&mut self, tx: &Transaction, height: u32) -> Vec<(HTLCSource, Option<PaymentPreimage>, PaymentHash)> {
19081908
let mut htlc_updated = Vec::new();
19091909

19101910
'outer_loop: for input in &tx.input {
@@ -1984,7 +1984,15 @@ impl ChannelMonitor {
19841984
payment_preimage.0.copy_from_slice(&input.witness[1]);
19851985
htlc_updated.push((source, Some(payment_preimage), payment_hash));
19861986
} else {
1987-
htlc_updated.push((source, None, payment_hash));
1987+
log_info!(self, "Failing HTLC with payment_hash {} timeout by a spend tx, waiting confirmation until {} height", log_bytes!(payment_hash.0), height + HTLC_FAIL_ANTI_REORG_DELAY - 1);
1988+
match self.htlc_updated_waiting_threshold_conf.entry(height + HTLC_FAIL_ANTI_REORG_DELAY - 1) {
1989+
hash_map::Entry::Occupied(mut entry) => {
1990+
entry.get_mut().push((source, None, payment_hash));
1991+
}
1992+
hash_map::Entry::Vacant(entry) => {
1993+
entry.insert(vec![(source, None, payment_hash)]);
1994+
}
1995+
}
19881996
}
19891997
}
19901998
}

src/ln/functional_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,7 @@ fn test_htlc_on_chain_timeout() {
20932093
}
20942094

20952095
nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![timeout_tx]}, 1);
2096+
connect_blocks(&nodes[1].chain_monitor, HTLC_FAIL_ANTI_REORG_DELAY, 1, true, header.bitcoin_hash());
20962097
check_added_monitors!(nodes[1], 0);
20972098
check_closed_broadcast!(nodes[1]);
20982099

@@ -3750,6 +3751,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
37503751
check_spends!(htlc_success_txn[1], commitment_txn[0].clone());
37513752

37523753
nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![htlc_timeout_tx] }, 200);
3754+
connect_blocks(&nodes[1].chain_monitor, HTLC_FAIL_ANTI_REORG_DELAY, 200, true, header.bitcoin_hash());
37533755
expect_pending_htlcs_forwardable!(nodes[1]);
37543756
let htlc_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
37553757
assert!(htlc_updates.update_add_htlcs.is_empty());

0 commit comments

Comments
 (0)