@@ -1508,6 +1508,41 @@ fn test_chan_reserve_dust_inbound_htlcs_outbound_chan() {
1508
1508
assert_eq!( err, "Cannot send value that would put counterparty balance under holder-announced channel reserve value" ) ) ;
1509
1509
}
1510
1510
1511
+ #[ test]
1512
+ fn test_chan_init_feerate_unaffordability ( ) {
1513
+ // Test that we will reject channel opens which do not leave enough to pay for any HTLCs due to
1514
+ // channel reserve and feerate requirements.
1515
+ let mut chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1516
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1517
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1518
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1519
+
1520
+ // Set the push_msat amount such that nodes[0] will not be able to afford to add even a single
1521
+ // HTLC.
1522
+ let feerate_per_kw = 253 ;
1523
+ let mut push_amt = 100_000_000 ;
1524
+ push_amt -= feerate_per_kw as u64 * ( COMMITMENT_TX_BASE_WEIGHT + 4 * COMMITMENT_TX_WEIGHT_PER_HTLC ) / 1000 * 1000 ;
1525
+ assert_eq ! ( nodes[ 0 ] . node. create_channel( nodes[ 1 ] . node. get_our_node_id( ) , 100_000 , push_amt + 1 , 42 , None ) . unwrap_err( ) ,
1526
+ APIError :: APIMisuseError { err: "Funding amount (356) can't even pay fee for initial commitment transaction fee of 357." . to_string( ) } ) ;
1527
+
1528
+ // During open, we don't have a "counterparty channel reserve" to check against, so that
1529
+ // requirement only comes into play on the open_channel handling side.
1530
+ push_amt -= Channel :: < EnforcingSigner > :: get_holder_selected_channel_reserve_satoshis ( 100_000 ) * 1000 ;
1531
+ nodes[ 0 ] . node . create_channel ( nodes[ 1 ] . node . get_our_node_id ( ) , 100_000 , push_amt, 42 , None ) . unwrap ( ) ;
1532
+ let mut open_channel_msg = get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendOpenChannel , nodes[ 1 ] . node. get_our_node_id( ) ) ;
1533
+ open_channel_msg. push_msat += 1 ;
1534
+ nodes[ 1 ] . node . handle_open_channel ( & nodes[ 0 ] . node . get_our_node_id ( ) , InitFeatures :: known ( ) , & open_channel_msg) ;
1535
+
1536
+ let msg_events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
1537
+ assert_eq ! ( msg_events. len( ) , 1 ) ;
1538
+ match msg_events[ 0 ] {
1539
+ MessageSendEvent :: HandleError { action : ErrorAction :: SendErrorMessage { ref msg } , node_id : _ } => {
1540
+ assert_eq ! ( msg. data, "Insufficient funding amount for initial reserve" ) ;
1541
+ } ,
1542
+ _ => panic ! ( "Unexpected event" ) ,
1543
+ }
1544
+ }
1545
+
1511
1546
#[ test]
1512
1547
fn test_chan_reserve_dust_inbound_htlcs_inbound_chan ( ) {
1513
1548
// Test that if we receive many dust HTLCs over an inbound channel, they don't count when
0 commit comments