Skip to content

Commit 94235ea

Browse files
author
Antoine Riard
committed
Add channel_monitor_claim_revoked_commitment_tx test
Test htlc outputs shared claim case Modify comment test
1 parent 97488ad commit 94235ea

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

src/ln/channelmanager.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,8 +3215,8 @@ mod tests {
32153215
res
32163216
}
32173217

3218-
/// Tests that the given node has broadcast a claim transaction against the provided revoked
3219-
/// HTLC transaction.
3218+
/// Tests that the given node has broadcast a claim transaction against the provided
3219+
/// HTLC transaction issued from a revoked commitment tx
32203220
fn test_revoked_htlc_claim_txn_broadcast(node: &Node, revoked_tx: Transaction) {
32213221
let mut node_txn = node.tx_broadcaster.txn_broadcasted.lock().unwrap();
32223222
assert_eq!(node_txn.len(), 1);
@@ -3441,6 +3441,46 @@ mod tests {
34413441
assert_eq!(nodes[1].node.list_channels().len(), 0);
34423442
}
34433443

3444+
#[test]
3445+
fn channel_monitor_claim_revoked_commitment_tx() {
3446+
3447+
let nodes = create_network(2);
3448+
3449+
// Create some new channel:
3450+
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
3451+
3452+
// Rebalance the network to generate htlc in the two directions
3453+
send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000);
3454+
// 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
3455+
let payment_preimage_1 = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
3456+
let _payment_preimage_2 = route_payment(&nodes[1], &vec!(&nodes[0])[..], 3000000).0;
3457+
3458+
// Get the will-be-revoked local txn from node[0]
3459+
let revoked_local_txn = nodes[0].node.channel_state.lock().unwrap().by_id.iter().next().unwrap().1.last_local_commitment_txn.clone();
3460+
3461+
//Revoke the old state
3462+
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage_1);
3463+
3464+
{
3465+
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
3466+
3467+
nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
3468+
test_txn_broadcast(&nodes[0], &chan_1, Some(revoked_local_txn[0].clone()), HTLCType::TIMEOUT);
3469+
3470+
nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
3471+
let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
3472+
assert_eq!(node_txn.len(), 4); // ChannelManager is broadcasting last_local_commitment_txn.. and revocation tx is broacasted twice as block has been re-scanned.
3473+
assert_eq!(node_txn[0].input.len(), 2); //TODO: really should be 4 when we implement to_local and to_remote via revocation key claiming
3474+
3475+
let mut funding_tx_map = HashMap::new();
3476+
funding_tx_map.insert(revoked_local_txn[0].txid(), revoked_local_txn[0].clone());
3477+
node_txn[0].verify(&funding_tx_map).unwrap();
3478+
}
3479+
get_announce_close_broadcast_events(&nodes, 0, 1);
3480+
assert_eq!(nodes[0].node.list_channels().len(), 0);
3481+
assert_eq!(nodes[1].node.list_channels().len(), 0);
3482+
}
3483+
34443484
#[test]
34453485
fn test_htlc_ignore_latest_remote_commitment() {
34463486
// Test that HTLC transactions spending the latest remote commitment transaction are simply

0 commit comments

Comments
 (0)