@@ -10518,28 +10518,37 @@ fn test_max_dust_htlc_exposure() {
10518
10518
}
10519
10519
10520
10520
#[test]
10521
- fn test_nondust_htlc_fees_are_dust() {
10522
- // Test that the transaction fees paid in nondust HTLCs count towards our dust limit
10521
+ fn test_nondust_htlc_excess_fees_are_dust() {
10522
+ // Test that the excess transaction fees paid in nondust HTLCs count towards our dust limit
10523
+ const DEFAULT_FEERATE: u32 = 253;
10524
+ const HIGH_FEERATE: u32 = 275;
10525
+ const EXCESS_FEERATE: u32 = HIGH_FEERATE - DEFAULT_FEERATE;
10523
10526
let chanmon_cfgs = create_chanmon_cfgs(3);
10527
+ {
10528
+ // Set the feerate of the channel funder above the `dust_exposure_limiting_feerate` of
10529
+ // the fundee. This delta means that the fundee will add the mining fees of the commitment and
10530
+ // htlc transactions in excess of its `dust_exposure_limiting_feerate` to its total dust htlc
10531
+ // exposure.
10532
+ let mut feerate_lock = chanmon_cfgs[1].fee_estimator.sat_per_kw.lock().unwrap();
10533
+ *feerate_lock = HIGH_FEERATE;
10534
+ }
10524
10535
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
10525
10536
10526
10537
let mut config = test_default_channel_config();
10527
10538
// Set the dust limit to the default value
10528
10539
config.channel_config.max_dust_htlc_exposure =
10529
10540
MaxDustHTLCExposure::FeeRateMultiplier(10_000);
10530
10541
// Make sure the HTLC limits don't get in the way
10531
- config.channel_handshake_limits.min_max_accepted_htlcs = 400 ;
10532
- config.channel_handshake_config.our_max_accepted_htlcs = 400 ;
10542
+ config.channel_handshake_limits.min_max_accepted_htlcs = chan_utils::MAX_HTLCS ;
10543
+ config.channel_handshake_config.our_max_accepted_htlcs = chan_utils::MAX_HTLCS ;
10533
10544
config.channel_handshake_config.our_htlc_minimum_msat = 1;
10545
+ config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
10534
10546
10535
10547
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(config), Some(config), Some(config)]);
10536
10548
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
10537
10549
10538
- // Create a channel from 1 -> 0 but immediately push all of the funds towards 0
10539
- let chan_id_1 = create_announced_chan_between_nodes(&nodes, 1, 0).2;
10540
- while nodes[1].node.list_channels()[0].next_outbound_htlc_limit_msat > 0 {
10541
- send_payment(&nodes[1], &[&nodes[0]], nodes[1].node.list_channels()[0].next_outbound_htlc_limit_msat);
10542
- }
10550
+ // Leave enough on the funder side to let it pay the mining fees for a commit tx with tons of htlcs
10551
+ let chan_id_1 = create_announced_chan_between_nodes_with_value(&nodes, 1, 0, 1_000_000, 750_000_000).2;
10543
10552
10544
10553
// First get the channel one HTLC_VALUE HTLC away from the dust limit by sending dust HTLCs
10545
10554
// repeatedly until we run out of space.
@@ -10561,14 +10570,13 @@ fn test_nondust_htlc_fees_are_dust() {
10561
10570
10562
10571
// At this point we have somewhere between dust_limit and dust_limit * 2 left in our dust
10563
10572
// exposure limit, and we want to max that out using non-dust HTLCs.
10564
- let commitment_tx_per_htlc_cost =
10565
- htlc_success_tx_weight(&ChannelTypeFeatures::empty()) * 253;
10573
+ let commitment_tx_per_htlc_cost = chan_utils::per_outbound_htlc_counterparty_commit_tx_fee_msat(EXCESS_FEERATE, &ChannelTypeFeatures::empty());
10566
10574
let max_htlcs_remaining = dust_limit * 2 / commitment_tx_per_htlc_cost;
10567
- assert!(max_htlcs_remaining < 30 ,
10575
+ assert!(max_htlcs_remaining < chan_utils::MAX_HTLCS.into() ,
10568
10576
"We should be able to fill our dust limit without too many HTLCs");
10569
10577
for i in 0..max_htlcs_remaining + 1 {
10570
10578
assert_ne!(i, max_htlcs_remaining);
10571
- if nodes[0].node.list_channels()[0].next_outbound_htlc_limit_msat < dust_limit {
10579
+ if nodes[0].node.list_channels()[0].next_outbound_htlc_limit_msat <= dust_limit {
10572
10580
// We found our limit, and it was less than max_htlcs_remaining!
10573
10581
// At this point we can only send dust HTLCs as any non-dust HTLCs will overuse our
10574
10582
// remaining dust exposure.
0 commit comments