@@ -39,9 +39,7 @@ fn do_test_counterparty_no_reserve(send_from_initiator: bool) {
3939 // in normal testing, we test it explicitly here.
4040 let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
4141 let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
42- let legacy_cfg = test_legacy_channel_config ( ) ;
43- let node_chanmgrs =
44- create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( legacy_cfg. clone ( ) ) , Some ( legacy_cfg) ] ) ;
42+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
4543 let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
4644
4745 let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
@@ -52,13 +50,14 @@ fn do_test_counterparty_no_reserve(send_from_initiator: bool) {
5250 // Have node0 initiate a channel to node1 with aforementioned parameters
5351 let mut push_amt = 100_000_000 ;
5452 let feerate_per_kw = 253 ;
55- let channel_type_features = ChannelTypeFeatures :: only_static_remote_key ( ) ;
53+ let channel_type_features = ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) ;
5654 push_amt -= feerate_per_kw as u64
5755 * ( commitment_tx_base_weight ( & channel_type_features) + 4 * COMMITMENT_TX_WEIGHT_PER_HTLC )
5856 / 1000 * 1000 ;
5957 push_amt -= get_holder_selected_channel_reserve_satoshis ( 100_000 , 0 , & default_config, false )
6058 . unwrap ( )
6159 * 1000 ;
60+ push_amt -= 2 * 330_000 ;
6261
6362 let push = if send_from_initiator { 0 } else { push_amt } ;
6463 let temp_channel_id =
@@ -109,10 +108,8 @@ fn do_test_counterparty_no_reserve(send_from_initiator: bool) {
109108 & nodes[ 0 ] ,
110109 & [ & nodes[ 1 ] ] ,
111110 100_000_000
112- // Note that for outbound channels we have to consider the commitment tx fee and the
113- // "fee spike buffer", which is currently a multiple of the total commitment tx fee as
114- // well as an additional HTLC.
115- - FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE * commit_tx_fee_msat ( feerate_per_kw, 2 , & channel_type_features) ,
111+ - commit_tx_fee_msat ( feerate_per_kw, 2 , & channel_type_features)
112+ - 2 * 330_000 ,
116113 ) ;
117114 } else {
118115 send_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , push_amt) ;
@@ -2358,12 +2355,6 @@ pub fn do_test_dust_limit_fee_accounting(can_afford: bool) {
23582355fn test_create_channel_to_trusted_peer_0reserve ( ) {
23592356 let mut config = test_default_channel_config ( ) ;
23602357
2361- // Legacy channels
2362- config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = false ;
2363- config. channel_handshake_config . negotiate_anchor_zero_fee_commitments = false ;
2364- let channel_type = do_test_create_channel_to_trusted_peer_0reserve ( config. clone ( ) ) ;
2365- assert_eq ! ( channel_type, ChannelTypeFeatures :: only_static_remote_key( ) ) ;
2366-
23672358 // Anchor channels
23682359 config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = true ;
23692360 config. channel_handshake_config . negotiate_anchor_zero_fee_commitments = false ;
@@ -2416,14 +2407,8 @@ fn do_test_create_channel_to_trusted_peer_0reserve(mut config: UserConfig) -> Ch
24162407 } else {
24172408 0
24182409 } ;
2419- let spike_multiple = if channel_type == ChannelTypeFeatures :: only_static_remote_key ( ) {
2420- FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE as u32
2421- } else {
2422- 1
2423- } ;
2424- let spiked_feerate = spike_multiple * feerate_per_kw;
24252410 let reserved_commit_tx_fee_sat = chan_utils:: commit_tx_fee_sat (
2426- spiked_feerate ,
2411+ feerate_per_kw ,
24272412 2 , // We reserve space for two HTLCs, the next outbound non-dust HTLC, and the fee spike buffer HTLC
24282413 & channel_type,
24292414 ) ;
@@ -2446,12 +2431,6 @@ fn do_test_create_channel_to_trusted_peer_0reserve(mut config: UserConfig) -> Ch
24462431fn test_accept_inbound_channel_from_trusted_peer_0reserve ( ) {
24472432 let mut config = test_default_channel_config ( ) ;
24482433
2449- // Legacy channels
2450- config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = false ;
2451- config. channel_handshake_config . negotiate_anchor_zero_fee_commitments = false ;
2452- let channel_type = do_test_accept_inbound_channel_from_trusted_peer_0reserve ( config. clone ( ) ) ;
2453- assert_eq ! ( channel_type, ChannelTypeFeatures :: only_static_remote_key( ) ) ;
2454-
24552434 // Anchor channels
24562435 config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = true ;
24572436 config. channel_handshake_config . negotiate_anchor_zero_fee_commitments = false ;
@@ -2539,14 +2518,8 @@ fn do_test_accept_inbound_channel_from_trusted_peer_0reserve(
25392518 } else {
25402519 0
25412520 } ;
2542- let spike_multiple = if channel_type == ChannelTypeFeatures :: only_static_remote_key ( ) {
2543- FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE as u32
2544- } else {
2545- 1
2546- } ;
2547- let spiked_feerate = spike_multiple * feerate_per_kw;
25482521 let reserved_commit_tx_fee_sat = chan_utils:: commit_tx_fee_sat (
2549- spiked_feerate ,
2522+ feerate_per_kw ,
25502523 2 , // We reserve space for two HTLCs, the next outbound non-dust HTLC, and the fee spike buffer HTLC
25512524 & channel_type,
25522525 ) ;
@@ -2565,20 +2538,8 @@ fn do_test_accept_inbound_channel_from_trusted_peer_0reserve(
25652538 channel_type
25662539}
25672540
2568- enum LegacyChannelsNoOutputs {
2569- PaymentSucceeds ,
2570- FailsReceiverUpdateAddHTLC ,
2571- FailsReceiverCanAcceptHTLCA ,
2572- FailsReceiverCanAcceptHTLCB ,
2573- }
2574-
25752541#[ xtest( feature = "_externalize_tests" ) ]
25762542fn test_0reserve_no_outputs ( ) {
2577- do_test_0reserve_no_outputs_legacy ( LegacyChannelsNoOutputs :: PaymentSucceeds ) ;
2578- do_test_0reserve_no_outputs_legacy ( LegacyChannelsNoOutputs :: FailsReceiverCanAcceptHTLCA ) ;
2579- do_test_0reserve_no_outputs_legacy ( LegacyChannelsNoOutputs :: FailsReceiverCanAcceptHTLCB ) ;
2580- do_test_0reserve_no_outputs_legacy ( LegacyChannelsNoOutputs :: FailsReceiverUpdateAddHTLC ) ;
2581-
25822543 do_test_0reserve_no_outputs_keyed_anchors ( true ) ;
25832544 do_test_0reserve_no_outputs_keyed_anchors ( false ) ;
25842545
@@ -2678,189 +2639,6 @@ pub(crate) fn setup_0reserve_no_outputs_channels<'a, 'b, 'c, 'd>(
26782639 ( channel_id, tx)
26792640}
26802641
2681- fn do_test_0reserve_no_outputs_legacy ( no_outputs_case : LegacyChannelsNoOutputs ) {
2682- let mut config = test_default_channel_config ( ) ;
2683- config. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = false ;
2684- config. channel_handshake_config . negotiate_anchor_zero_fee_commitments = false ;
2685-
2686- let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
2687- let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
2688- config. channel_handshake_config . announced_channel_max_inbound_htlc_value_in_flight_percentage =
2689- 100 ;
2690-
2691- let channel_type = ChannelTypeFeatures :: only_static_remote_key ( ) ;
2692-
2693- let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( config. clone ( ) ) , Some ( config) ] ) ;
2694- let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2695-
2696- let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
2697- let _node_b_id = nodes[ 1 ] . node . get_our_node_id ( ) ;
2698-
2699- let feerate_per_kw = 253 ;
2700- let spike_multiple = FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE as u32 ;
2701- let dust_limit_satoshis: u64 = 546 ;
2702- let channel_value_sat = 1000 ;
2703-
2704- let ( channel_id, _funding_tx) =
2705- setup_0reserve_no_outputs_channels ( & nodes, channel_value_sat, dust_limit_satoshis) ;
2706- assert_eq ! ( nodes[ 0 ] . node. list_channels( ) [ 0 ] . channel_type. as_ref( ) . unwrap( ) , & channel_type) ;
2707-
2708- // Sending the biggest dust HTLC possible trims our balance output!
2709- let ( timeout_tx_fee_sat, success_tx_fee_sat) =
2710- second_stage_tx_fees_sat ( & channel_type, spike_multiple * feerate_per_kw) ;
2711- let max_dust_htlc_sat = dust_limit_satoshis + success_tx_fee_sat - 1 ;
2712- assert ! (
2713- channel_value_sat
2714- . saturating_sub( commit_tx_fee_sat( feerate_per_kw, 0 , & channel_type) )
2715- . saturating_sub( max_dust_htlc_sat)
2716- < dust_limit_satoshis
2717- ) ;
2718-
2719- // We can't afford the fee for an additional non-dust HTLC + the fee spike HTLC, so we can only send
2720- // dust HTLCs...
2721- let min_local_nondust_htlc_sat = dust_limit_satoshis + timeout_tx_fee_sat;
2722- assert ! (
2723- channel_value_sat - commit_tx_fee_sat( spike_multiple * feerate_per_kw, 2 , & channel_type)
2724- < min_local_nondust_htlc_sat
2725- ) ;
2726-
2727- // We cannot trim our own balance output, otherwise we'd have no outputs on the commitment. We must
2728- // also reserve enough fees to pay for an incoming non-dust HTLC, aka the fee spike buffer HTLC.
2729- let min_value_sat = core:: cmp:: max (
2730- commit_tx_fee_sat ( spike_multiple * feerate_per_kw, 0 , & channel_type) + dust_limit_satoshis,
2731- commit_tx_fee_sat ( spike_multiple * feerate_per_kw, 1 , & channel_type) ,
2732- ) ;
2733- // At this point the tighter requirement is "must have an output"
2734- assert ! (
2735- commit_tx_fee_sat( spike_multiple * feerate_per_kw, 0 , & channel_type) + dust_limit_satoshis
2736- > commit_tx_fee_sat( spike_multiple * feerate_per_kw, 1 , & channel_type)
2737- ) ;
2738- // But say at 9sat/vb with default dust limit,
2739- // the tighter requirement is actually "must have funds for an inbound HTLC" !
2740- assert ! (
2741- commit_tx_fee_sat( 9 * 250 , 0 , & channel_type) + 354
2742- < commit_tx_fee_sat( 9 * 250 , 1 , & channel_type)
2743- ) ;
2744- let sender_amount_msat = ( channel_value_sat - min_value_sat) * 1000 ;
2745- let details_0 = & nodes[ 0 ] . node . list_channels ( ) [ 0 ] ;
2746- assert_eq ! ( details_0. next_outbound_htlc_minimum_msat, 1000 ) ;
2747- assert_eq ! ( details_0. next_outbound_htlc_limit_msat, sender_amount_msat) ;
2748- assert ! ( details_0. next_outbound_htlc_limit_msat > details_0. next_outbound_htlc_minimum_msat) ;
2749-
2750- let ( sender_amount_msat, receiver_amount_msat) = match no_outputs_case {
2751- LegacyChannelsNoOutputs :: PaymentSucceeds => ( sender_amount_msat, sender_amount_msat) ,
2752- LegacyChannelsNoOutputs :: FailsReceiverCanAcceptHTLCA => {
2753- // A dust HTLC with 1msat added to it will break counterparty `can_accept_incoming_htlc`
2754- // validation, as this dust HTLC would push the holder's balance output below the
2755- // dust limit at the spike multiple feerate.
2756- ( sender_amount_msat, sender_amount_msat + 1 )
2757- } ,
2758- LegacyChannelsNoOutputs :: FailsReceiverCanAcceptHTLCB => {
2759- // In `validate_update_add_htlc`, we check that there is still some output present on
2760- // the commitment given the *current* set of HTLCs, and the *current* feerate. So this
2761- // HTLC will pass at `validate_update_add_htlc`, but will fail in
2762- // `can_accept_incoming_htlc` due to failed fee spike buffer checks.
2763- let receiver_amount_msat = ( channel_value_sat
2764- - commit_tx_fee_sat ( feerate_per_kw, 0 , & channel_type)
2765- - dust_limit_satoshis)
2766- * 1000 ;
2767- ( sender_amount_msat, receiver_amount_msat)
2768- } ,
2769- LegacyChannelsNoOutputs :: FailsReceiverUpdateAddHTLC => {
2770- // Same value as above, just add 1msat, and this fails at `validate_update_add_htlc`
2771- let receiver_amount_msat = ( channel_value_sat
2772- - commit_tx_fee_sat ( feerate_per_kw, 0 , & channel_type)
2773- - dust_limit_satoshis)
2774- * 1000 ;
2775- ( sender_amount_msat, receiver_amount_msat + 1 )
2776- } ,
2777- } ;
2778-
2779- if let LegacyChannelsNoOutputs :: PaymentSucceeds = no_outputs_case {
2780- send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , sender_amount_msat) ;
2781- // Node 1 the fundee has 0-reserve too, so whatever they receive, they can send right back!
2782- // Node 0 should *always* have the funds to cover the fee of a single non-dust HTLC from node 1.
2783- assert_eq ! (
2784- nodes[ 1 ] . node. list_channels( ) [ 0 ] . next_outbound_htlc_limit_msat,
2785- sender_amount_msat
2786- ) ;
2787- send_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , sender_amount_msat) ;
2788- } else {
2789- let ( route, payment_hash, _, payment_secret) =
2790- get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , sender_amount_msat) ;
2791- let secp_ctx = Secp256k1 :: new ( ) ;
2792- let session_priv = SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
2793- let cur_height = nodes[ 0 ] . node . best_block . read ( ) . unwrap ( ) . height + 1 ;
2794- let onion_keys =
2795- onion_utils:: construct_onion_keys ( & secp_ctx, & route. paths [ 0 ] , & session_priv) ;
2796- let recipient_onion_fields =
2797- RecipientOnionFields :: secret_only ( payment_secret, sender_amount_msat) ;
2798- let ( onion_payloads, htlc_msat, htlc_cltv) = onion_utils:: test_build_onion_payloads (
2799- & route. paths [ 0 ] ,
2800- & recipient_onion_fields,
2801- cur_height,
2802- & None ,
2803- None ,
2804- None ,
2805- )
2806- . unwrap ( ) ;
2807- assert_eq ! ( htlc_msat, sender_amount_msat) ;
2808- let onion_packet =
2809- onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash)
2810- . unwrap ( ) ;
2811- let msg = msgs:: UpdateAddHTLC {
2812- channel_id,
2813- htlc_id : 0 ,
2814- amount_msat : receiver_amount_msat,
2815- payment_hash,
2816- cltv_expiry : htlc_cltv,
2817- onion_routing_packet : onion_packet,
2818- skimmed_fee_msat : None ,
2819- blinding_point : None ,
2820- hold_htlc : None ,
2821- accountable : None ,
2822- } ;
2823-
2824- nodes[ 1 ] . node . handle_update_add_htlc ( node_a_id, & msg) ;
2825-
2826- if let LegacyChannelsNoOutputs :: FailsReceiverUpdateAddHTLC = no_outputs_case {
2827- nodes[ 1 ] . logger . assert_log_contains (
2828- "lightning::ln::channelmanager" ,
2829- "Remote HTLC add would overdraw remaining funds" ,
2830- 3 ,
2831- ) ;
2832- assert_eq ! ( nodes[ 1 ] . node. list_channels( ) . len( ) , 0 ) ;
2833- let err_msg = check_closed_broadcast ( & nodes[ 1 ] , 1 , true ) . pop ( ) . unwrap ( ) ;
2834- assert_eq ! ( err_msg. data, "Remote HTLC add would overdraw remaining funds" ) ;
2835- let reason = ClosureReason :: ProcessingError {
2836- err : "Remote HTLC add would overdraw remaining funds" . to_string ( ) ,
2837- } ;
2838- check_added_monitors ( & nodes[ 1 ] , 1 ) ;
2839- check_closed_event ( & nodes[ 1 ] , 1 , reason, & [ node_a_id] , channel_value_sat) ;
2840-
2841- return ;
2842- }
2843-
2844- let htlcs_in_commitment = vec ! [ HTLCOutputInCommitment {
2845- offered: false ,
2846- amount_msat: receiver_amount_msat,
2847- cltv_expiry: htlc_cltv,
2848- payment_hash,
2849- transaction_output_index: Some ( 1 ) ,
2850- } ] ;
2851-
2852- manually_trigger_update_fail_htlc (
2853- & nodes,
2854- channel_id,
2855- channel_value_sat * 1000 ,
2856- dust_limit_satoshis,
2857- payment_hash,
2858- htlcs_in_commitment,
2859- false ,
2860- ) ;
2861- }
2862- }
2863-
28642642fn manually_trigger_update_fail_htlc < ' a , ' b , ' c , ' d > (
28652643 nodes : & ' a Vec < Node < ' b , ' c , ' d > > , channel_id : ChannelId , value_to_self_msat : u64 ,
28662644 dust_limit_satoshis : u64 , payment_hash : PaymentHash ,
0 commit comments