Avoid a panic when --slots-per-epoch is less than MINIMUM_SLOTS_PER_EPOCH

This commit is contained in:
Michael Vines
2021-03-17 21:16:04 -07:00
committed by mergify[bot]
parent 7f500d610c
commit 4ab98fff02

View File

@ -14,7 +14,7 @@ use {
solana_sdk::{ solana_sdk::{
account::AccountSharedData, account::AccountSharedData,
clock::Slot, clock::Slot,
epoch_schedule::EpochSchedule, epoch_schedule::{EpochSchedule, MINIMUM_SLOTS_PER_EPOCH},
native_token::sol_to_lamports, native_token::sol_to_lamports,
pubkey::Pubkey, pubkey::Pubkey,
rpc_port, rpc_port,
@ -151,7 +151,18 @@ fn main() {
Arg::with_name("slots_per_epoch") Arg::with_name("slots_per_epoch")
.long("slots-per-epoch") .long("slots-per-epoch")
.value_name("SLOTS") .value_name("SLOTS")
.validator(is_slot) .validator(|value| {
value
.parse::<Slot>()
.map_err(|err| format!("error parsing '{}': {}", value, err))
.and_then(|slot| {
if slot < MINIMUM_SLOTS_PER_EPOCH {
Err(format!("value must be >= {}", MINIMUM_SLOTS_PER_EPOCH))
} else {
Ok(())
}
})
})
.takes_value(true) .takes_value(true)
.help( .help(
"Override the number of slots in an epoch. \ "Override the number of slots in an epoch. \