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
1 changed files with 13 additions and 2 deletions

View File

@ -14,7 +14,7 @@ use {
solana_sdk::{
account::AccountSharedData,
clock::Slot,
epoch_schedule::EpochSchedule,
epoch_schedule::{EpochSchedule, MINIMUM_SLOTS_PER_EPOCH},
native_token::sol_to_lamports,
pubkey::Pubkey,
rpc_port,
@ -151,7 +151,18 @@ fn main() {
Arg::with_name("slots_per_epoch")
.long("slots-per-epoch")
.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)
.help(
"Override the number of slots in an epoch. \