Skip to content

Commit 7e2fd5a

Browse files
author
Antoine Riard
committed
Test htlc outputs single tx claim due to timeout case
1 parent 7ac8af5 commit 7e2fd5a

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/ln/channelmanager.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3444,7 +3444,7 @@ mod tests {
34443444
#[test]
34453445
fn channel_monitor_claim_revoked_commitment_tx() {
34463446

3447-
let nodes = create_network(2);
3447+
let nodes = create_network(4);
34483448

34493449
// Create some new channel:
34503450
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
@@ -3479,6 +3479,42 @@ mod tests {
34793479
get_announce_close_broadcast_events(&nodes, 0, 1);
34803480
assert_eq!(nodes[0].node.list_channels().len(), 0);
34813481
assert_eq!(nodes[1].node.list_channels().len(), 0);
3482+
3483+
let chan_2 = create_announced_chan_between_nodes(&nodes, 2, 3);
3484+
3485+
// Rebalance the network to generate htlc in the two directions
3486+
send_payment(&nodes[2], &vec!(&nodes[3])[..], 8000000);
3487+
// node[2] is gonna to revoke an old state thus node[3] should be able to claim both offered/received HTLC outputs on top of commitment tx, but this
3488+
// time as two different claim transactions as we're gonna to timeout htlc with given a high current heigh
3489+
let payment_preimage_3 = route_payment(&nodes[2], &vec!(&nodes[3])[..], 3000000).0;
3490+
let _payment_preimage_4 = route_payment(&nodes[3], &vec!(&nodes[2])[..], 3000000).0;
3491+
3492+
// Get the will-be-revoked local txn from node[2]
3493+
let revoked_local_txn = nodes[2].node.channel_state.lock().unwrap().by_id.iter().next().unwrap().1.last_local_commitment_txn.clone();
3494+
3495+
//Revoke the old state
3496+
claim_payment(&nodes[2], &vec!(&nodes[3])[..], payment_preimage_3);
3497+
3498+
{
3499+
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
3500+
3501+
nodes[2].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 200);
3502+
test_txn_broadcast(&nodes[2], &chan_2, Some(revoked_local_txn[0].clone()), HTLCType::TIMEOUT);
3503+
3504+
nodes[3].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 200);
3505+
let node_txn = nodes[3].tx_broadcaster.txn_broadcasted.lock().unwrap();
3506+
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)
3507+
assert_eq!(node_txn[0].input.len(), 1);
3508+
assert_eq!(node_txn[1].input.len(), 1);
3509+
3510+
let mut funding_tx_map = HashMap::new();
3511+
funding_tx_map.insert(revoked_local_txn[0].txid(), revoked_local_txn[0].clone());
3512+
node_txn[0].verify(&funding_tx_map).unwrap();
3513+
}
3514+
get_announce_close_broadcast_events(&nodes, 2, 3);
3515+
assert_eq!(nodes[2].node.list_channels().len(), 0);
3516+
assert_eq!(nodes[3].node.list_channels().len(), 0);
3517+
34823518
}
34833519

34843520
#[test]

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)