@@ -3061,6 +3061,32 @@ mod tests {
3061
3061
}
3062
3062
}
3063
3063
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
+
3064
3090
#[ derive( PartialEq ) ]
3065
3091
enum HTLCType { NONE , TIMEOUT , SUCCESS }
3066
3092
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