Skip to content

Commit 3e8833a

Browse files
author
Antoine Riard
committed
Add test_static_spendable_outputs_justice_tx_revoked_htlc*
Cover both HTLC-Timeout/Success cases
1 parent 2817ecc commit 3e8833a

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

src/ln/channelmanager.rs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7831,4 +7831,99 @@ mod tests {
78317831
let spend_tx = check_static_output!(events, nodes, 0, 0, 1, 1);
78327832
check_spends!(spend_tx, node_txn[0].clone());
78337833
}
7834+
7835+
#[test]
7836+
fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx() {
7837+
let nodes = create_network(2);
7838+
7839+
// Create some initial channels
7840+
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
7841+
7842+
let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
7843+
let revoked_local_txn = nodes[0].node.channel_state.lock().unwrap().by_id.get(&chan_1.2).unwrap().last_local_commitment_txn.clone();
7844+
assert_eq!(revoked_local_txn[0].input.len(), 1);
7845+
assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid());
7846+
7847+
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
7848+
7849+
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
7850+
// A will generate HTLC-Timeout from revoked commitment tx
7851+
nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
7852+
let events = nodes[0].node.get_and_clear_pending_msg_events();
7853+
match events[0] {
7854+
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
7855+
_ => panic!("Unexpected event"),
7856+
}
7857+
let revoked_htlc_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
7858+
assert_eq!(revoked_htlc_txn.len(), 2);
7859+
assert_eq!(revoked_htlc_txn[0].input.len(), 1);
7860+
assert_eq!(revoked_htlc_txn[0].input[0].witness.last().unwrap().len(), 133);
7861+
check_spends!(revoked_htlc_txn[0], revoked_local_txn[0].clone());
7862+
7863+
// B will generate justice tx from A's revoked commitment/HTLC tx
7864+
nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone(), revoked_htlc_txn[0].clone()] }, 1);
7865+
let events = nodes[1].node.get_and_clear_pending_msg_events();
7866+
match events[0] {
7867+
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
7868+
_ => panic!("Unexpected event"),
7869+
}
7870+
7871+
let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
7872+
assert_eq!(node_txn.len(), 4);
7873+
assert_eq!(node_txn[3].input.len(), 1);
7874+
check_spends!(node_txn[3], revoked_htlc_txn[0].clone());
7875+
7876+
let events = nodes[1].chan_monitor.simple_monitor.get_and_clear_pending_events();
7877+
// Check B's ChannelMonitor was able to generate the right spendable output descriptor
7878+
let spend_tx = check_static_output!(events, nodes, 1, 1, 1, 1);
7879+
check_spends!(spend_tx, node_txn[3].clone());
7880+
}
7881+
7882+
#[test]
7883+
fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() {
7884+
let nodes = create_network(2);
7885+
7886+
// Create some initial channels
7887+
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
7888+
7889+
let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
7890+
let revoked_local_txn = nodes[1].node.channel_state.lock().unwrap().by_id.get(&chan_1.2).unwrap().last_local_commitment_txn.clone();
7891+
assert_eq!(revoked_local_txn[0].input.len(), 1);
7892+
assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid());
7893+
7894+
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
7895+
7896+
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
7897+
// B will generate HTLC-Success from revoked commitment tx
7898+
nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
7899+
let events = nodes[1].node.get_and_clear_pending_msg_events();
7900+
match events[0] {
7901+
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
7902+
_ => panic!("Unexpected event"),
7903+
}
7904+
let revoked_htlc_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
7905+
7906+
assert_eq!(revoked_htlc_txn.len(), 2);
7907+
assert_eq!(revoked_htlc_txn[0].input.len(), 1);
7908+
assert_eq!(revoked_htlc_txn[0].input[0].witness.last().unwrap().len(), 138);
7909+
check_spends!(revoked_htlc_txn[0], revoked_local_txn[0].clone());
7910+
7911+
// A will generate justice tx from B's revoked commitment/HTLC tx
7912+
nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone(), revoked_htlc_txn[0].clone()] }, 1);
7913+
let events = nodes[0].node.get_and_clear_pending_msg_events();
7914+
match events[0] {
7915+
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
7916+
_ => panic!("Unexpected event"),
7917+
}
7918+
7919+
let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
7920+
assert_eq!(node_txn.len(), 4);
7921+
assert_eq!(node_txn[3].input.len(), 1);
7922+
check_spends!(node_txn[3], revoked_htlc_txn[0].clone());
7923+
7924+
let events = nodes[0].chan_monitor.simple_monitor.get_and_clear_pending_events();
7925+
// Check A's ChannelMonitor was able to generate the right spendable output descriptor
7926+
let spend_tx = check_static_output!(events, nodes, 1, 2, 1, 0);
7927+
check_spends!(spend_tx, node_txn[3].clone());
7928+
}
78347929
}

0 commit comments

Comments
 (0)