Skip to content

Commit 30e08c5

Browse files
committed
Fix cmp::max execution in ChannelContext::get_dust_buffer_feerate
The current `cmp::max` doesnt align with the function comment, ie its comparing 2530 and `feerate_plus_quarter` instead of `feerate_per_kw + 2530` and `feerate_plus_quarter` which is fixed in this commit
1 parent 68d5e88 commit 30e08c5

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2699,7 +2699,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
26992699
feerate_per_kw = cmp::max(feerate_per_kw, feerate);
27002700
}
27012701
let feerate_plus_quarter = feerate_per_kw.checked_mul(1250).map(|v| v / 1000);
2702-
cmp::max(2530, feerate_plus_quarter.unwrap_or(u32::max_value()))
2702+
cmp::max(feerate_per_kw + 2530, feerate_plus_quarter.unwrap_or(u32::max_value()))
27032703
}
27042704

27052705
/// Get forwarding information for the counterparty.

lightning/src/ln/functional_tests.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9891,8 +9891,8 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
98919891
// Default test fee estimator rate is 253 sat/kw, so we set the multiplier to 5_000_000 / 253
98929892
// to get roughly the same initial value as the default setting when this test was
98939893
// originally written.
9894-
MaxDustHTLCExposure::FeeRateMultiplier(5_000_000 / 253)
9895-
} else { MaxDustHTLCExposure::FixedLimitMsat(5_000_000) }; // initial default setting value
9894+
MaxDustHTLCExposure::FeeRateMultiplier(6_000_000 / 253)
9895+
} else { MaxDustHTLCExposure::FixedLimitMsat(6_000_000) }; // initial default setting value
98969896
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
98979897
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(config), None]);
98989898
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
@@ -9901,6 +9901,8 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
99019901
let mut open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
99029902
open_channel.common_fields.max_htlc_value_in_flight_msat = 50_000_000;
99039903
open_channel.common_fields.max_accepted_htlcs = 60;
9904+
// --
9905+
99049906
if on_holder_tx {
99059907
open_channel.common_fields.dust_limit_satoshis = 546;
99069908
}
@@ -9935,18 +9937,21 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
99359937
let (channel_ready, channel_id) = create_chan_between_nodes_with_value_confirm(&nodes[0], &nodes[1], &tx);
99369938
let (announcement, as_update, bs_update) = create_chan_between_nodes_with_value_b(&nodes[0], &nodes[1], &channel_ready);
99379939
update_nodes_with_chan_announce(&nodes, 0, 1, &announcement, &as_update, &bs_update);
9940+
// Node A < - > Node B channel is now established
99389941

99399942
// Fetch a route in advance as we will be unable to once we're unable to send.
99409943
let (mut route, payment_hash, _, payment_secret) =
99419944
get_route_and_payment_hash!(nodes[0], nodes[1], 1000);
99429945

9946+
99439947
let (dust_buffer_feerate, max_dust_htlc_exposure_msat) = {
99449948
let per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
99459949
let chan_lock = per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
99469950
let chan = chan_lock.channel_by_id.get(&channel_id).unwrap();
99479951
(chan.context().get_dust_buffer_feerate(None) as u64,
99489952
chan.context().get_max_dust_htlc_exposure_msat(&LowerBoundedFeeEstimator(nodes[0].fee_estimator)))
99499953
};
9954+
99509955
let dust_outbound_htlc_on_holder_tx_msat: u64 = (dust_buffer_feerate * htlc_timeout_tx_weight(&channel_type_features) / 1000 + open_channel.common_fields.dust_limit_satoshis - 1) * 1000;
99519956
let dust_outbound_htlc_on_holder_tx: u64 = max_dust_htlc_exposure_msat / dust_outbound_htlc_on_holder_tx_msat;
99529957

@@ -10032,7 +10037,7 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
1003210037
// For the multiplier dust exposure limit, since it scales with feerate,
1003310038
// we need to add a lot of HTLCs that will become dust at the new feerate
1003410039
// to cross the threshold.
10035-
for _ in 0..20 {
10040+
for _ in 0..30 {
1003610041
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[1], Some(1_000), None);
1003710042
nodes[0].node.send_payment_with_route(&route, payment_hash,
1003810043
RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0)).unwrap();
@@ -10054,12 +10059,12 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
1005410059
fn do_test_max_dust_htlc_exposure_by_threshold_type(multiplier_dust_limit: bool) {
1005510060
do_test_max_dust_htlc_exposure(true, ExposureEvent::AtHTLCForward, true, multiplier_dust_limit);
1005610061
do_test_max_dust_htlc_exposure(false, ExposureEvent::AtHTLCForward, true, multiplier_dust_limit);
10062+
do_test_max_dust_htlc_exposure(false, ExposureEvent::AtHTLCForward, false, multiplier_dust_limit);
10063+
do_test_max_dust_htlc_exposure(true, ExposureEvent::AtHTLCForward, false, multiplier_dust_limit);
1005710064
do_test_max_dust_htlc_exposure(false, ExposureEvent::AtHTLCReception, true, multiplier_dust_limit);
1005810065
do_test_max_dust_htlc_exposure(false, ExposureEvent::AtHTLCReception, false, multiplier_dust_limit);
10059-
do_test_max_dust_htlc_exposure(true, ExposureEvent::AtHTLCForward, false, multiplier_dust_limit);
1006010066
do_test_max_dust_htlc_exposure(true, ExposureEvent::AtHTLCReception, false, multiplier_dust_limit);
1006110067
do_test_max_dust_htlc_exposure(true, ExposureEvent::AtHTLCReception, true, multiplier_dust_limit);
10062-
do_test_max_dust_htlc_exposure(false, ExposureEvent::AtHTLCForward, false, multiplier_dust_limit);
1006310068
do_test_max_dust_htlc_exposure(true, ExposureEvent::AtUpdateFeeOutbound, true, multiplier_dust_limit);
1006410069
do_test_max_dust_htlc_exposure(true, ExposureEvent::AtUpdateFeeOutbound, false, multiplier_dust_limit);
1006510070
do_test_max_dust_htlc_exposure(false, ExposureEvent::AtUpdateFeeOutbound, false, multiplier_dust_limit);
@@ -10068,7 +10073,7 @@ fn do_test_max_dust_htlc_exposure_by_threshold_type(multiplier_dust_limit: bool)
1006810073

1006910074
#[test]
1007010075
fn test_max_dust_htlc_exposure() {
10071-
do_test_max_dust_htlc_exposure_by_threshold_type(false);
10076+
do_test_max_dust_htlc_exposure_by_threshold_type(false);
1007210077
do_test_max_dust_htlc_exposure_by_threshold_type(true);
1007310078
}
1007410079

0 commit comments

Comments
 (0)