Skip to content

Commit 9e44479

Browse files
committed
Add a further test of HTLC failure after a claim occurrs.
This adds a further test of 7e78fa6 which I had lying around in my TODO list for a while.
1 parent 2ced708 commit 9e44479

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use bitcoin::blockdata::block::{Block, BlockHeader};
1616
use bitcoin::blockdata::constants::genesis_block;
1717
use bitcoin::hash_types::BlockHash;
1818
use bitcoin::network::constants::Network;
19-
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr};
19+
use chain::channelmonitor::{ANTI_REORG_DELAY, ChannelMonitor, ChannelMonitorUpdateErr};
2020
use chain::transaction::OutPoint;
2121
use chain::Listen;
2222
use chain::Watch;
@@ -2146,6 +2146,48 @@ fn test_pending_update_fee_ack_on_reconnect() {
21462146
claim_payment(&nodes[1], &[&nodes[0]], payment_preimage);
21472147
}
21482148

2149+
#[test]
2150+
fn test_fail_htlc_on_broadcast_after_claim() {
2151+
// In an earlier version of 7e78fa660cec8a73286c94c1073ee588140e7a01 we'd also fail the inbound
2152+
// channel backwards if we received an HTLC failure after a HTLC fulfillment. Here we test a
2153+
// specific case of that by having the HTLC failure come from the channelmonitor after a dust
2154+
// HTLC was not included in a confirmed commitment transaction.
2155+
//
2156+
// We first forward a payment, then claim it with an update_fulfill_htlc message, closing the
2157+
// channel immediately before commitment occurs. After the commitment transaction reaches
2158+
// ANTI_REORG_DELAY confirmations, will will try to fail the HTLC which was already fulfilled.
2159+
let chanmon_cfgs = create_chanmon_cfgs(3);
2160+
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
2161+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
2162+
let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs);
2163+
2164+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
2165+
let chan_id_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()).2;
2166+
2167+
let payment_preimage = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 2000).0;
2168+
2169+
let bs_txn = get_local_commitment_txn!(nodes[2], chan_id_2);
2170+
assert_eq!(bs_txn.len(), 1);
2171+
2172+
nodes[2].node.claim_funds(payment_preimage);
2173+
check_added_monitors!(nodes[2], 1);
2174+
let cs_updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
2175+
nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]);
2176+
let bs_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
2177+
check_added_monitors!(nodes[1], 1);
2178+
expect_payment_forwarded!(nodes[1], Some(1000), false);
2179+
2180+
mine_transaction(&nodes[1], &bs_txn[0]);
2181+
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
2182+
check_closed_broadcast!(nodes[1], true);
2183+
check_added_monitors!(nodes[1], 1);
2184+
expect_pending_htlcs_forwardable!(nodes[1]);
2185+
2186+
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]);
2187+
expect_payment_sent!(nodes[0], payment_preimage);
2188+
commitment_signed_dance!(nodes[0], nodes[1], bs_updates.commitment_signed, true, true);
2189+
}
2190+
21492191
fn do_update_fee_resend_test(deliver_update: bool, parallel_updates: bool) {
21502192
// In early versions we did not handle resending of update_fee on reconnect correctly. The
21512193
// chanmon_consistency fuzz target, of course, immediately found it, but we test a few cases

0 commit comments

Comments
 (0)