From ebd6fe7acb63170433ef1e75e77a928ccc1961cb Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 18 Mar 2021 07:17:50 +0000 Subject: [PATCH] Avoid a panic when --slots-per-epoch is less than MINIMUM_SLOTS_PER_EPOCH (#15975) (cherry picked from commit 4ab98fff02a069b0ca564894ec5e71a634d6deea) Co-authored-by: Michael Vines --- validator/src/bin/solana-test-validator.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/validator/src/bin/solana-test-validator.rs b/validator/src/bin/solana-test-validator.rs index fd2e3fec9f..85cd93cc90 100644 --- a/validator/src/bin/solana-test-validator.rs +++ b/validator/src/bin/solana-test-validator.rs @@ -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::() + .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. \