Add checking locally derived reserve and dust limit
authorYuntai Kyong <yuntai.kyong@gmail.com>
Fri, 17 Aug 2018 03:57:51 +0000 (12:57 +0900)
committerMatt Corallo <git@bluematt.me>
Fri, 17 Aug 2018 17:18:28 +0000 (13:18 -0400)
src/ln/channel.rs

index f3455a9f5c71eef0642e15a8101c9ba2888ba023..e2749ffffb94ba150c7a5c6947b136cef4281f35 100644 (file)
@@ -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());