Skip to content

Commit e847e65

Browse files
committed
Add simple test for duplicate-payment_hash HTLC tracking
1 parent aabc5bf commit e847e65

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/ln/channelmanager.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,32 @@ mod tests {
30613061
}
30623062
}
30633063

3064+
#[test]
3065+
fn duplicate_htlc_test() {
3066+
// Test that we accept duplicate payment_hash HTLCs across the network and that
3067+
// claiming/failing them are all separate and don't effect each other
3068+
let mut nodes = create_network(6);
3069+
3070+
// Create some initial channels to route via 3 to 4/5 from 0/1/2
3071+
create_announced_chan_between_nodes(&nodes, 0, 3);
3072+
create_announced_chan_between_nodes(&nodes, 1, 3);
3073+
create_announced_chan_between_nodes(&nodes, 2, 3);
3074+
create_announced_chan_between_nodes(&nodes, 3, 4);
3075+
create_announced_chan_between_nodes(&nodes, 3, 5);
3076+
3077+
let (payment_preimage, payment_hash) = route_payment(&nodes[0], &vec!(&nodes[3], &nodes[4])[..], 1000000);
3078+
3079+
*nodes[0].network_payment_count.borrow_mut() -= 1;
3080+
assert_eq!(route_payment(&nodes[1], &vec!(&nodes[3])[..], 1000000).0, payment_preimage);
3081+
3082+
*nodes[0].network_payment_count.borrow_mut() -= 1;
3083+
assert_eq!(route_payment(&nodes[2], &vec!(&nodes[3], &nodes[5])[..], 1000000).0, payment_preimage);
3084+
3085+
claim_payment(&nodes[0], &vec!(&nodes[3], &nodes[4])[..], payment_preimage);
3086+
fail_payment(&nodes[2], &vec!(&nodes[3], &nodes[5])[..], payment_hash);
3087+
claim_payment(&nodes[1], &vec!(&nodes[3])[..], payment_preimage);
3088+
}
3089+
30643090
#[derive(PartialEq)]
30653091
enum HTLCType { NONE, TIMEOUT, SUCCESS }
30663092
fn test_txn_broadcast(node: &Node, chan: &(msgs::ChannelUpdate, msgs::ChannelUpdate, [u8; 32], Transaction), commitment_tx: Option<Transaction>, has_htlc_tx: HTLCType) -> Vec<Transaction> {

0 commit comments

Comments
 (0)