Skip to content

Commit 5bb9292

Browse files
committed
Test for failing channel after local commitment dust HTLC timeout
1 parent ad238e2 commit 5bb9292

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/ln/channelmonitor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,6 @@ impl ChannelMonitor {
17941794
// to the source, and if we don't fail the channel we will have to ensure that the next
17951795
// updates that peer sends us are update_fails, failing the channel if not. It's probably
17961796
// easier to just fail the channel as this case should be rare enough anyway.
1797-
// TODO: Test below dust HTLC channel failing
17981797
if let Some(ref cur_local_tx) = self.current_local_signed_commitment_tx {
17991798
for &(ref htlc, _, _) in cur_local_tx.htlc_outputs.iter() {
18001799
// For inbound HTLCs which we know the preimage for, we have to ensure we hit the

src/ln/functional_tests.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ use std::sync::atomic::Ordering;
5050
use std::time::Instant;
5151
use std::mem;
5252

53+
const CHAN_CONFIRM_DEPTH: u32 = 100;
5354
fn confirm_transaction(chain: &chaininterface::ChainWatchInterfaceUtil, tx: &Transaction, chan_id: u32) {
5455
assert!(chain.does_match_tx(tx));
5556
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
5657
chain.block_connected_checked(&header, 1, &[tx; 1], &[chan_id; 1]);
57-
for i in 2..100 {
58+
for i in 2..CHAN_CONFIRM_DEPTH {
5859
header = BlockHeader { version: 0x20000000, prev_blockhash: header.bitcoin_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
5960
chain.block_connected_checked(&header, i, &[tx; 0], &[0; 0]);
6061
}
@@ -6046,6 +6047,49 @@ fn test_static_output_closing_tx() {
60466047
check_spends!(spend_txn[0], closing_tx);
60476048
}
60486049

6050+
fn do_htlc_claim_local_commitment_only(use_dust: bool) {
6051+
let nodes = create_network(2);
6052+
let chan = create_announced_chan_between_nodes(&nodes, 0, 1);
6053+
6054+
let (our_payment_preimage, _) = route_payment(&nodes[0], &[&nodes[1]], if use_dust { 50000 } else { 3000000 });
6055+
6056+
// Claim the payment, but don't deliver A's commitment_signed, resulting in the HTLC only being
6057+
// present in B's local commitment transaction, but none of A's commitment transactions.
6058+
assert!(nodes[1].node.claim_funds(our_payment_preimage));
6059+
check_added_monitors!(nodes[1], 1);
6060+
6061+
let bs_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
6062+
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]).unwrap();
6063+
let events = nodes[0].node.get_and_clear_pending_events();
6064+
assert_eq!(events.len(), 1);
6065+
match events[0] {
6066+
Event::PaymentSent { payment_preimage } => {
6067+
assert_eq!(payment_preimage, our_payment_preimage);
6068+
},
6069+
_ => panic!("Unexpected event"),
6070+
}
6071+
6072+
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_updates.commitment_signed).unwrap();
6073+
check_added_monitors!(nodes[0], 1);
6074+
let as_updates = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id());
6075+
nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_updates.0).unwrap();
6076+
check_added_monitors!(nodes[1], 1);
6077+
6078+
let mut header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
6079+
for i in 1..TEST_FINAL_CLTV - CLTV_CLAIM_BUFFER + CHAN_CONFIRM_DEPTH + 1 {
6080+
nodes[1].chain_monitor.block_connected_checked(&header, i, &Vec::new(), &Vec::new());
6081+
header.prev_blockhash = header.bitcoin_hash();
6082+
}
6083+
test_txn_broadcast(&nodes[1], &chan, None, if use_dust { HTLCType::NONE } else { HTLCType::SUCCESS });
6084+
check_closed_broadcast!(nodes[1]);
6085+
}
6086+
6087+
#[test]
6088+
fn htlc_claim_local_commitment_only() {
6089+
do_htlc_claim_local_commitment_only(true);
6090+
do_htlc_claim_local_commitment_only(false);
6091+
}
6092+
60496093
fn run_onion_failure_test<F1,F2>(_name: &str, test_case: u8, nodes: &Vec<Node>, route: &Route, payment_hash: &PaymentHash, callback_msg: F1, callback_node: F2, expected_retryable: bool, expected_error_code: Option<u16>, expected_channel_update: Option<HTLCFailChannelUpdate>)
60506094
where F1: for <'a> FnMut(&'a mut msgs::UpdateAddHTLC),
60516095
F2: FnMut(),

0 commit comments

Comments
 (0)