@@ -256,6 +256,66 @@ pub fn test_insane_channel_opens() {
256
256
} ) ;
257
257
}
258
258
259
+ #[ test]
260
+ fn test_insane_zero_fee_channel_open ( ) {
261
+ let mut cfg = UserConfig :: default ( ) ;
262
+ cfg. manually_accept_inbound_channels = true ;
263
+ cfg. channel_handshake_config . negotiate_anchor_zero_fee_commitments = true ;
264
+
265
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
266
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
267
+ let node_chanmgrs =
268
+ create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( cfg. clone ( ) ) , Some ( cfg. clone ( ) ) ] ) ;
269
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
270
+
271
+ let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
272
+ let node_b_id = nodes[ 1 ] . node . get_our_node_id ( ) ;
273
+
274
+ nodes[ 0 ] . node . create_channel ( node_b_id, 100_000 , 0 , 42 , None , None ) . unwrap ( ) ;
275
+
276
+ let open_channel_message =
277
+ get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendOpenChannel , node_b_id) ;
278
+
279
+ let insane_open_helper =
280
+ |expected_error_str : & str , message_mutator : fn ( msgs:: OpenChannel ) -> msgs:: OpenChannel | {
281
+ let open_channel_mutated = message_mutator ( open_channel_message. clone ( ) ) ;
282
+ nodes[ 1 ] . node . handle_open_channel ( node_a_id, & open_channel_mutated) ;
283
+
284
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
285
+ match events[ 0 ] {
286
+ Event :: OpenChannelRequest { temporary_channel_id, .. } => {
287
+ match nodes[ 1 ] . node . accept_inbound_channel (
288
+ & temporary_channel_id,
289
+ & nodes[ 0 ] . node . get_our_node_id ( ) ,
290
+ 23 ,
291
+ None ,
292
+ ) {
293
+ Ok ( _) => panic ! ( "Unexpected successful channel accept" ) ,
294
+ Err ( e) => assert ! ( format!( "{:?}" , e) . contains( expected_error_str) ) ,
295
+ }
296
+ } ,
297
+ _ => panic ! ( "Unexpected event" ) ,
298
+ }
299
+
300
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
301
+ assert_eq ! ( events. len( ) , 1 ) ;
302
+ assert ! ( matches!( events[ 0 ] , MessageSendEvent :: HandleError { .. } ) ) ;
303
+ } ;
304
+
305
+ insane_open_helper (
306
+ "max_accepted_htlcs was 115. It must not be larger than 114" . into ( ) ,
307
+ |mut msg| {
308
+ msg. common_fields . max_accepted_htlcs = 115 ;
309
+ msg
310
+ } ,
311
+ ) ;
312
+
313
+ insane_open_helper ( "Zero Fee Channels must never attempt to use a fee" . into ( ) , |mut msg| {
314
+ msg. common_fields . commitment_feerate_sat_per_1000_weight = 123 ;
315
+ msg
316
+ } ) ;
317
+ }
318
+
259
319
#[ xtest( feature = "_externalize_tests" ) ]
260
320
pub fn test_funding_exceeds_no_wumbo_limit ( ) {
261
321
// Test that if a peer does not support wumbo channels, we'll refuse to open a wumbo channel to
0 commit comments