use chain::transaction::OutPoint;
use util::{transaction_utils,rng};
use util::sha2::Sha256;
-use util::logger::{Logger, Record};
+use util::logger::Logger;
use util::errors::APIError;
use std;
/// Guaranteed to return a value no larger than channel_value_satoshis
fn get_our_channel_reserve_satoshis(channel_value_satoshis: u64) -> u64 {
- cmp::min(channel_value_satoshis, 1000) //TODO
+ let (q, _) = channel_value_satoshis.overflowing_div(100);
+ cmp::min(channel_value_satoshis, cmp::max(q, 1000)) //TODO
}
fn derive_our_dust_limit_satoshis(at_open_background_feerate: u64) -> u64 {
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());
if msg.max_accepted_htlcs > 483 {
return_error_message!("max_accpted_htlcs > 483");
}
- if (msg.channel_flags & 254) != 0 {
- return Err(HandleError{err: "Unknown channel flags", action: Some(msgs::ErrorAction::IgnoreError) });
- }
// Convert things into internal flags and prep our state:
return_error_message!("max_accpted_htlcs > 483");
}
+ // TODO: Optional additional constraints mentioned in the spec
+ // MAY fail the channel if
+ // funding_satoshi is too small
+ // htlc_minimum_msat too large
+ // max_htlc_value_in_flight_msat too small
+ // channel_reserve_satoshis too large
+ // max_accepted_htlcs too small
+ // dust_limit_satoshis too small
+
self.channel_monitor.set_their_htlc_base_key(&msg.htlc_basepoint);
self.their_dust_limit_satoshis = msg.dust_limit_satoshis;