Skip to content

Commit 080d5df

Browse files
author
Antoine Riard
committed
Test htlc outputs single tx claim due to timeout case
1 parent 9de4f1a commit 080d5df

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/ln/channelmanager.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,6 +3506,58 @@ mod tests {
35063506
assert_eq!(nodes[1].node.list_channels().len(), 0);
35073507
}
35083508

3509+
#[test]
3510+
fn claim_htlc_outputs_single_tx() {
3511+
// Node revoked old state, htlcs have timed out, claim each of them in separated justice tx
3512+
3513+
let nodes = create_network(2);
3514+
3515+
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
3516+
3517+
// Rebalance the network to generate htlc in the two directions
3518+
send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000);
3519+
// node[0] is gonna to revoke an old state thus node[1] should be able to claim both offered/received HTLC outputs on top of commitment tx, but this
3520+
// time as two different claim transactions as we're gonna to timeout htlc with given a high current height
3521+
let payment_preimage_1 = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
3522+
let _payment_preimage_2 = route_payment(&nodes[1], &vec!(&nodes[0])[..], 3000000).0;
3523+
3524+
// Get the will-be-revoked local txn from node[0]
3525+
let revoked_local_txn = nodes[0].node.channel_state.lock().unwrap().by_id.get(&chan_1.2).unwrap().last_local_commitment_txn.clone();
3526+
3527+
//Revoke the old state
3528+
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage_1);
3529+
3530+
{
3531+
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
3532+
3533+
nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 200);
3534+
3535+
nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 200);
3536+
let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
3537+
assert_eq!(node_txn.len(), 10); // ChannelManager : 2, ChannelMontitor: 8 (2 revocation htlc tx, 1 local commitment tx + 1 htlc timeout tx) * 2 (block-rescan)
3538+
assert_eq!(node_txn[0].input.len(), 1);
3539+
assert_eq!(node_txn[1].input.len(), 1);
3540+
3541+
let mut revoked_tx_map = HashMap::new();
3542+
revoked_tx_map.insert(revoked_local_txn[0].txid(), revoked_local_txn[0].clone());
3543+
node_txn[0].verify(&revoked_tx_map).unwrap();
3544+
node_txn[1].verify(&revoked_tx_map).unwrap();
3545+
3546+
let witness_script_1 = node_txn[0].clone().input[0].witness.pop().unwrap();
3547+
let witness_script_2 = node_txn[1].clone().input[0].witness.pop().unwrap();
3548+
if witness_script_1.len() > 133 {
3549+
assert_eq!(witness_script_1.len(), 138);
3550+
assert_eq!(witness_script_2.len(), 133);
3551+
} else {
3552+
assert_eq!(witness_script_1.len(), 133);
3553+
assert_eq!(witness_script_2.len(), 138);
3554+
}
3555+
}
3556+
get_announce_close_broadcast_events(&nodes, 0, 1);
3557+
assert_eq!(nodes[0].node.list_channels().len(), 0);
3558+
assert_eq!(nodes[1].node.list_channels().len(), 0);
3559+
}
3560+
35093561
#[test]
35103562
fn test_htlc_ignore_latest_remote_commitment() {
35113563
// Test that HTLC transactions spending the latest remote commitment transaction are simply

src/ln/channelmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ impl ChannelMonitor {
10591059
};
10601060
let sighash_parts = bip143::SighashComponents::new(&single_htlc_tx);
10611061
sign_input!(sighash_parts, single_htlc_tx.input[0], Some(idx), htlc.amount_msat / 1000);
1062-
txn_to_broadcast.push(single_htlc_tx); // TODO: This is not yet tested in ChannelManager!
1062+
txn_to_broadcast.push(single_htlc_tx);
10631063
}
10641064
}
10651065
}

0 commit comments

Comments
 (0)