Skip to content

Commit c14297b

Browse files
committed
Default to fallbacks for huge bogus values in fee estimation conversion
Previously, we would cast `FeeRate::to_sat_per_kwu` to `u32`, which however might result in `u32::max_value` being used if our fee estimation source delivers huge bogus data. Here, we make sure to use the fallback rate if we would do so otherwise.
1 parent 03c4ab0 commit c14297b

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/fee_estimator.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ impl FeeEstimator for OnchainFeeEstimator {
7777

7878
impl LdkFeeEstimator for OnchainFeeEstimator {
7979
fn get_est_sat_per_1000_weight(&self, confirmation_target: LdkConfirmationTarget) -> u32 {
80-
self.estimate_fee_rate(confirmation_target.into()).to_sat_per_kwu() as u32
80+
self.estimate_fee_rate(confirmation_target.into())
81+
.to_sat_per_kwu()
82+
.try_into()
83+
.unwrap_or_else(|_| get_fallback_rate_for_ldk_target(confirmation_target))
8184
}
8285
}
8386

@@ -102,16 +105,20 @@ pub(crate) fn get_fallback_rate_for_target(target: ConfirmationTarget) -> u32 {
102105
match target {
103106
ConfirmationTarget::OnchainPayment => 5000,
104107
ConfirmationTarget::ChannelFunding => 1000,
105-
ConfirmationTarget::Lightning(ldk_target) => match ldk_target {
106-
LdkConfirmationTarget::MaximumFeeEstimate => 8000,
107-
LdkConfirmationTarget::UrgentOnChainSweep => 5000,
108-
LdkConfirmationTarget::MinAllowedAnchorChannelRemoteFee => FEERATE_FLOOR_SATS_PER_KW,
109-
LdkConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => FEERATE_FLOOR_SATS_PER_KW,
110-
LdkConfirmationTarget::AnchorChannelFee => 500,
111-
LdkConfirmationTarget::NonAnchorChannelFee => 1000,
112-
LdkConfirmationTarget::ChannelCloseMinimum => 500,
113-
LdkConfirmationTarget::OutputSpendingFee => 1000,
114-
},
108+
ConfirmationTarget::Lightning(ldk_target) => get_fallback_rate_for_ldk_target(ldk_target),
109+
}
110+
}
111+
112+
pub(crate) fn get_fallback_rate_for_ldk_target(target: LdkConfirmationTarget) -> u32 {
113+
match target {
114+
LdkConfirmationTarget::MaximumFeeEstimate => 8000,
115+
LdkConfirmationTarget::UrgentOnChainSweep => 5000,
116+
LdkConfirmationTarget::MinAllowedAnchorChannelRemoteFee => FEERATE_FLOOR_SATS_PER_KW,
117+
LdkConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => FEERATE_FLOOR_SATS_PER_KW,
118+
LdkConfirmationTarget::AnchorChannelFee => 500,
119+
LdkConfirmationTarget::NonAnchorChannelFee => 1000,
120+
LdkConfirmationTarget::ChannelCloseMinimum => 500,
121+
LdkConfirmationTarget::OutputSpendingFee => 1000,
115122
}
116123
}
117124

0 commit comments

Comments
 (0)