From 1c839ff1035eea3b01f5f9c258826d867e04af24 Mon Sep 17 00:00:00 2001 From: Yuntai Kyong Date: Fri, 17 Aug 2018 12:57:51 +0900 Subject: [PATCH] Add checking locally derived reserve and dust limit --- src/ln/channel.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ln/channel.rs b/src/ln/channel.rs index f3455a9f5..e2749ffff 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -391,8 +391,13 @@ impl Channel { return Err(APIError::APIMisuseError{err: "push value > channel value"}); } - let feerate = fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Normal); + let background_feerate = fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Background); + if Channel::get_our_channel_reserve_satoshis(channel_value_satoshis) < Channel::derive_our_dust_limit_satoshis(background_feerate) { + return Err(APIError::FeeRateTooHigh{err: format!("Not enough reserve above dust limit can be found at current fee rate({})", background_feerate), feerate: background_feerate}); + } + + let feerate = fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::Normal); let secp_ctx = Secp256k1::new(); let our_channel_monitor_claim_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&secp_ctx, &chan_keys.channel_monitor_claim_key).unwrap().serialize()); -- 2.39.5