@@ -5486,7 +5486,6 @@ fn bolt2_open_channel_sending_node_checks_part2() {
5486
5486
5487
5487
#[ test]
5488
5488
fn test_update_add_htlc_bolt2_sender_value_below_minimum_msat ( ) {
5489
- //BOLT2 Requirement: MUST offer amount_msat greater than 0.
5490
5489
//BOLT2 Requirement: MUST NOT offer amount_msat below the receiving node's htlc_minimum_msat (same validation check catches both of these)
5491
5490
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
5492
5491
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
@@ -5496,7 +5495,7 @@ fn test_update_add_htlc_bolt2_sender_value_below_minimum_msat() {
5496
5495
let mut route = nodes[ 0 ] . router . get_route ( & nodes[ 1 ] . node . get_our_node_id ( ) , None , & [ ] , 100000 , TEST_FINAL_CLTV ) . unwrap ( ) ;
5497
5496
let ( _, our_payment_hash) = get_payment_preimage_hash ! ( nodes[ 0 ] ) ;
5498
5497
5499
- route. hops [ 0 ] . fee_msat = 0 ;
5498
+ route. hops [ 0 ] . fee_msat = 100 ;
5500
5499
5501
5500
let err = nodes[ 0 ] . node . send_payment ( route, our_payment_hash) ;
5502
5501
@@ -5509,6 +5508,51 @@ fn test_update_add_htlc_bolt2_sender_value_below_minimum_msat() {
5509
5508
nodes[ 0 ] . logger . assert_log ( "lightning::ln::channelmanager" . to_string ( ) , "Cannot send less than their minimum HTLC value" . to_string ( ) , 1 ) ;
5510
5509
}
5511
5510
5511
+ #[ test]
5512
+ fn test_update_add_htlc_bolt2_sender_zero_value_msat ( ) {
5513
+ //BOLT2 Requirement: MUST offer amount_msat greater than 0.
5514
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
5515
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
5516
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
5517
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
5518
+ let _chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 95000000 , InitFeatures :: supported ( ) , InitFeatures :: supported ( ) ) ;
5519
+ let mut route = nodes[ 0 ] . router . get_route ( & nodes[ 1 ] . node . get_our_node_id ( ) , None , & [ ] , 100000 , TEST_FINAL_CLTV ) . unwrap ( ) ;
5520
+ let ( _, our_payment_hash) = get_payment_preimage_hash ! ( nodes[ 0 ] ) ;
5521
+
5522
+ route. hops [ 0 ] . fee_msat = 0 ;
5523
+
5524
+ let err = nodes[ 0 ] . node . send_payment ( route, our_payment_hash) ;
5525
+
5526
+ if let Err ( APIError :: ChannelUnavailable { err} ) = err {
5527
+ assert_eq ! ( err, "Cannot send 0-msat HTLC" ) ;
5528
+ } else {
5529
+ assert ! ( false ) ;
5530
+ }
5531
+ assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
5532
+ nodes[ 0 ] . logger . assert_log ( "lightning::ln::channelmanager" . to_string ( ) , "Cannot send 0-msat HTLC" . to_string ( ) , 1 ) ;
5533
+ }
5534
+
5535
+ #[ test]
5536
+ fn test_update_add_htlc_bolt2_receiver_zero_value_msat ( ) {
5537
+ //BOLT2 Requirement: MUST offer amount_msat greater than 0.
5538
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
5539
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
5540
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
5541
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
5542
+ let _chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 95000000 , InitFeatures :: supported ( ) , InitFeatures :: supported ( ) ) ;
5543
+ let route = nodes[ 0 ] . router . get_route ( & nodes[ 1 ] . node . get_our_node_id ( ) , None , & [ ] , 100000 , TEST_FINAL_CLTV ) . unwrap ( ) ;
5544
+ let ( _, our_payment_hash) = get_payment_preimage_hash ! ( nodes[ 0 ] ) ;
5545
+
5546
+ nodes[ 0 ] . node . send_payment ( route, our_payment_hash) ;
5547
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
5548
+ let mut updates = get_htlc_update_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
5549
+ updates. update_add_htlcs [ 0 ] . amount_msat = 0 ;
5550
+
5551
+ nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & updates. update_add_htlcs [ 0 ] ) ;
5552
+ nodes[ 1 ] . logger . assert_log ( "lightning::ln::channelmanager" . to_string ( ) , "Remote side tried to send a 0-msat HTLC" . to_string ( ) , 1 ) ;
5553
+ check_closed_broadcast ! ( nodes[ 1 ] , true ) . unwrap ( ) ;
5554
+ }
5555
+
5512
5556
#[ test]
5513
5557
fn test_update_add_htlc_bolt2_sender_cltv_expiry_too_high ( ) {
5514
5558
//BOLT 2 Requirement: MUST set cltv_expiry less than 500000000.
@@ -7271,3 +7315,21 @@ fn test_override_channel_config() {
7271
7315
assert_eq ! ( res. channel_flags, 0 ) ;
7272
7316
assert_eq ! ( res. to_self_delay, 200 ) ;
7273
7317
}
7318
+
7319
+ #[ test]
7320
+ fn test_override_0msat_htlc_minimum ( ) {
7321
+ let mut zero_config = UserConfig :: default ( ) ;
7322
+ zero_config. own_channel_config . our_htlc_minimum_msat = 0 ;
7323
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
7324
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
7325
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , Some ( zero_config. clone ( ) ) ] ) ;
7326
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
7327
+
7328
+ nodes[ 0 ] . node . create_channel ( nodes[ 1 ] . node . get_our_node_id ( ) , 16_000_000 , 12_000_000 , 42 , Some ( zero_config) ) . unwrap ( ) ;
7329
+ let res = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendOpenChannel , nodes[ 1 ] . node. get_our_node_id( ) ) ;
7330
+ assert_eq ! ( res. htlc_minimum_msat, 1 ) ;
7331
+
7332
+ nodes[ 1 ] . node . handle_open_channel ( & nodes[ 0 ] . node . get_our_node_id ( ) , InitFeatures :: supported ( ) , & res) ;
7333
+ let res = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendAcceptChannel , nodes[ 0 ] . node. get_our_node_id( ) ) ;
7334
+ assert_eq ! ( res. htlc_minimum_msat, 1 ) ;
7335
+ }
0 commit comments