Skip to content

Commit 2f9f232

Browse files
author
Antoine Riard
committed
Add test_static_spendable_outputs_justice_tx_revoked_htlc*
Cover both HTLC-Timeout/Success cases
1 parent f8fe241 commit 2f9f232

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
@@ -7786,4 +7786,99 @@ mod tests {
77867786
let spend_tx = check_static_output!(events, nodes, 0, 0, 1, 1);
77877787
check_spends!(spend_tx, node_txn[0].clone());
77887788
}
7789+
7790+
#[test]
7791+
fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx() {
7792+
let nodes = create_network(2);
7793+
7794+
// Create some initial channels
7795+
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
7796+
7797+
let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
7798+
let revoked_local_txn = nodes[0].node.channel_state.lock().unwrap().by_id.get(&chan_1.2).unwrap().last_local_commitment_txn.clone();
7799+
assert_eq!(revoked_local_txn[0].input.len(), 1);
7800+
assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid());
7801+
7802+
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
7803+
7804+
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
7805+
// A will generate HTLC-Timeout from revoked commitment tx
7806+
nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
7807+
let events = nodes[0].node.get_and_clear_pending_msg_events();
7808+
match events[0] {
7809+
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
7810+
_ => panic!("Unexpected event"),
7811+
}
7812+
let revoked_htlc_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
7813+
assert_eq!(revoked_htlc_txn.len(), 2);
7814+
assert_eq!(revoked_htlc_txn[0].input.len(), 1);
7815+
assert_eq!(revoked_htlc_txn[0].input[0].witness.last().unwrap().len(), 133);
7816+
check_spends!(revoked_htlc_txn[0], revoked_local_txn[0].clone());
7817+
7818+
// B will generate justice tx from A's revoked commitment/HTLC tx
7819+
nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone(), revoked_htlc_txn[0].clone()] }, 1);
7820+
let events = nodes[1].node.get_and_clear_pending_msg_events();
7821+
match events[0] {
7822+
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
7823+
_ => panic!("Unexpected event"),
7824+
}
7825+
7826+
let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
7827+
assert_eq!(node_txn.len(), 4);
7828+
assert_eq!(node_txn[3].input.len(), 1);
7829+
check_spends!(node_txn[3], revoked_htlc_txn[0].clone());
7830+
7831+
let events = nodes[1].chan_monitor.simple_monitor.get_and_clear_pending_events();
7832+
// Check B's ChannelMonitor was able to generate the right spendable output descriptor
7833+
let spend_tx = check_static_output!(events, nodes, 1, 1, 1, 1);
7834+
check_spends!(spend_tx, node_txn[3].clone());
7835+
}
7836+
7837+
#[test]
7838+
fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() {
7839+
let nodes = create_network(2);
7840+
7841+
// Create some initial channels
7842+
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
7843+
7844+
let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
7845+
let revoked_local_txn = nodes[1].node.channel_state.lock().unwrap().by_id.get(&chan_1.2).unwrap().last_local_commitment_txn.clone();
7846+
assert_eq!(revoked_local_txn[0].input.len(), 1);
7847+
assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid());
7848+
7849+
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
7850+
7851+
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
7852+
// B will generate HTLC-Success from revoked commitment tx
7853+
nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
7854+
let events = nodes[1].node.get_and_clear_pending_msg_events();
7855+
match events[0] {
7856+
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
7857+
_ => panic!("Unexpected event"),
7858+
}
7859+
let revoked_htlc_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
7860+
7861+
assert_eq!(revoked_htlc_txn.len(), 2);
7862+
assert_eq!(revoked_htlc_txn[0].input.len(), 1);
7863+
assert_eq!(revoked_htlc_txn[0].input[0].witness.last().unwrap().len(), 138);
7864+
check_spends!(revoked_htlc_txn[0], revoked_local_txn[0].clone());
7865+
7866+
// A will generate justice tx from B's revoked commitment/HTLC tx
7867+
nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone(), revoked_htlc_txn[0].clone()] }, 1);
7868+
let events = nodes[0].node.get_and_clear_pending_msg_events();
7869+
match events[0] {
7870+
MessageSendEvent::BroadcastChannelUpdate { .. } => {},
7871+
_ => panic!("Unexpected event"),
7872+
}
7873+
7874+
let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
7875+
assert_eq!(node_txn.len(), 4);
7876+
assert_eq!(node_txn[3].input.len(), 1);
7877+
check_spends!(node_txn[3], revoked_htlc_txn[0].clone());
7878+
7879+
let events = nodes[0].chan_monitor.simple_monitor.get_and_clear_pending_events();
7880+
// Check A's ChannelMonitor was able to generate the right spendable output descriptor
7881+
let spend_tx = check_static_output!(events, nodes, 1, 2, 1, 0);
7882+
check_spends!(spend_tx, node_txn[3].clone());
7883+
}
77897884
}

0 commit comments

Comments
 (0)