enforce proper range for rent burn_percent (#7217)
* enforce proper range for burn_percent
This commit is contained in:
parent
d5c8b26a45
commit
ba688cf629
|
@ -97,3 +97,24 @@ pub fn is_port(port: String) -> Result<(), String> {
|
|||
.map(|_| ())
|
||||
.map_err(|e| format!("{:?}", e))
|
||||
}
|
||||
|
||||
pub fn is_valid_percentage(percentage: String) -> Result<(), String> {
|
||||
percentage
|
||||
.parse::<u8>()
|
||||
.map_err(|e| {
|
||||
format!(
|
||||
"Unable to parse input percentage, provided: {}, err: {:?}",
|
||||
percentage, e
|
||||
)
|
||||
})
|
||||
.and_then(|v| {
|
||||
if v > 100 {
|
||||
Err(format!(
|
||||
"Percentage must be in range of 0 to 100, provided: {}",
|
||||
v
|
||||
))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ mod unlocks;
|
|||
use crate::genesis_accounts::add_genesis_accounts;
|
||||
use clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg, ArgMatches};
|
||||
use solana_clap_utils::input_parsers::pubkey_of;
|
||||
use solana_clap_utils::input_validators::is_valid_percentage;
|
||||
use solana_genesis::Base64Account;
|
||||
use solana_ledger::{blocktree::create_new_ledger, poh::compute_hashes_per_tick};
|
||||
use solana_sdk::{
|
||||
|
@ -249,7 +250,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
.value_name("NUMBER")
|
||||
.takes_value(true)
|
||||
.default_value(default_rent_burn_percentage)
|
||||
.help("amount of rent to burn, as a fraction of std::u8::MAX."),
|
||||
.help("percentage of collected rent to burn")
|
||||
.validator(is_valid_percentage),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("target_signatures_per_slot")
|
||||
|
|
|
@ -1394,7 +1394,7 @@ mod tests {
|
|||
&Rent {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
}
|
||||
},
|
||||
),
|
||||
Err(InstructionError::InsufficientFunds)
|
||||
);
|
||||
|
|
|
@ -1706,6 +1706,7 @@ mod tests {
|
|||
&dummy_leader_pubkey,
|
||||
dummy_leader_lamports,
|
||||
);
|
||||
|
||||
genesis_config.rent = Rent {
|
||||
lamports_per_byte_year: 5,
|
||||
exemption_threshold: 1.2,
|
||||
|
|
|
@ -23,8 +23,8 @@ pub const DEFAULT_LAMPORTS_PER_BYTE_YEAR: u64 = 0; //1_000_000_000 / 100 * 365 /
|
|||
/// default amount of time (in years) the balance has to include rent for
|
||||
pub const DEFAULT_EXEMPTION_THRESHOLD: f64 = 2.0;
|
||||
|
||||
/// default amount of rent to burn, as a fraction of std::u8::MAX
|
||||
pub const DEFAULT_BURN_PERCENT: u8 = ((50usize * std::u8::MAX as usize) / 100usize) as u8;
|
||||
/// default percentage of rent to burn (Valid values are 0 to 100)
|
||||
pub const DEFAULT_BURN_PERCENT: u8 = 100;
|
||||
|
||||
/// account storage overhead for calculation of base rent
|
||||
pub const ACCOUNT_STORAGE_OVERHEAD: u64 = 128;
|
||||
|
|
Loading…
Reference in New Issue