Skip to content

Commit

Permalink
Add option to wait for a specific epoch length to bench-tps
Browse files Browse the repository at this point in the history
  • Loading branch information
sakridge committed May 16, 2020
1 parent 9222bc2 commit e684b00
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 36 deletions.
21 changes: 21 additions & 0 deletions bench-tps/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ where
duration,
tx_count,
sustained,
target_slots_per_epoch,
..
} = config;

Expand Down Expand Up @@ -163,6 +164,26 @@ where
})
.collect();

if target_slots_per_epoch != 0 {
info!(
"Waiting until epochs are {} slots long..",
target_slots_per_epoch
);
loop {
if let Ok(epoch_info) = client.get_epoch_info() {
if epoch_info.slots_in_epoch >= target_slots_per_epoch {
info!("Done epoch_info: {:?}", epoch_info);
break;
}
info!(
"Waiting for epoch: {} now: {}",
target_slots_per_epoch, epoch_info.slots_in_epoch
);
}
sleep(Duration::from_millis(1));
}
}

// generate and send transactions for the specified duration
let start = Instant::now();
let keypair_chunks = source_keypair_chunks.len();
Expand Down
18 changes: 18 additions & 0 deletions bench-tps/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct Config {
pub multi_client: bool,
pub use_move: bool,
pub num_lamports_per_account: u64,
pub target_slots_per_epoch: u64,
}

impl Default for Config {
Expand All @@ -47,6 +48,7 @@ impl Default for Config {
multi_client: true,
use_move: false,
num_lamports_per_account: NUM_LAMPORTS_PER_ACCOUNT_DEFAULT,
target_slots_per_epoch: 0,
}
}
}
Expand Down Expand Up @@ -172,6 +174,15 @@ pub fn build_args<'a, 'b>(version: &'b str) -> App<'a, 'b> {
"Number of lamports per account.",
),
)
.arg(
Arg::with_name("target_slots_per_epoch")
.long("target-slots-per-epoch")
.value_name("SLOTS")
.takes_value(true)
.help(
"Wait until epochs are this many slots long.",
),
)
}

/// Parses a clap `ArgMatches` structure into a `Config`
Expand Down Expand Up @@ -259,5 +270,12 @@ pub fn extract_args<'a>(matches: &ArgMatches<'a>) -> Config {
args.num_lamports_per_account = v.to_string().parse().expect("can't parse lamports");
}

if let Some(t) = matches.value_of("target_slots_per_epoch") {
args.target_slots_per_epoch = t
.to_string()
.parse()
.expect("can't parse target slots per epoch");
}

args
}
9 changes: 5 additions & 4 deletions cli/src/cli_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use inflector::cases::titlecase::to_title_case;
use serde::Serialize;
use serde_json::{Map, Value};
use solana_client::rpc_response::{
RpcAccountBalance, RpcEpochInfo, RpcKeyedAccount, RpcSupply, RpcVoteAccountInfo,
RpcAccountBalance, RpcKeyedAccount, RpcSupply, RpcVoteAccountInfo,
};
use solana_sdk::{
clock::{self, Epoch, Slot, UnixTimestamp},
epoch_info::EpochInfo,
native_token::lamports_to_sol,
stake_history::StakeHistoryEntry,
};
Expand Down Expand Up @@ -186,11 +187,11 @@ pub struct CliSlotStatus {
#[serde(rename_all = "camelCase")]
pub struct CliEpochInfo {
#[serde(flatten)]
pub epoch_info: RpcEpochInfo,
pub epoch_info: EpochInfo,
}

impl From<RpcEpochInfo> for CliEpochInfo {
fn from(epoch_info: RpcEpochInfo) -> Self {
impl From<EpochInfo> for CliEpochInfo {
fn from(epoch_info: EpochInfo) -> Self {
Self { epoch_info }
}
}
Expand Down
5 changes: 3 additions & 2 deletions client/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use solana_sdk::{
MAX_HASH_AGE_IN_SECONDS,
},
commitment_config::CommitmentConfig,
epoch_info::EpochInfo,
epoch_schedule::EpochSchedule,
fee_calculator::{FeeCalculator, FeeRateGovernor},
hash::Hash,
Expand Down Expand Up @@ -296,14 +297,14 @@ impl RpcClient {
.map_err(|err| err.into_with_request(request))?
}

pub fn get_epoch_info(&self) -> ClientResult<RpcEpochInfo> {
pub fn get_epoch_info(&self) -> ClientResult<EpochInfo> {
self.get_epoch_info_with_commitment(CommitmentConfig::default())
}

pub fn get_epoch_info_with_commitment(
&self,
commitment_config: CommitmentConfig,
) -> ClientResult<RpcEpochInfo> {
) -> ClientResult<EpochInfo> {
self.send(RpcRequest::GetEpochInfo, json!([commitment_config]), 0)
}

Expand Down
16 changes: 0 additions & 16 deletions client/src/rpc_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,6 @@ pub struct RpcContactInfo {
/// Map of leader base58 identity pubkeys to the slot indices relative to the first epoch slot
pub type RpcLeaderSchedule = HashMap<String, Vec<usize>>;

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RpcEpochInfo {
/// The current epoch
pub epoch: Epoch,

/// The current slot, relative to the start of the current epoch
pub slot_index: u64,

/// The number of slots in this epoch
pub slots_in_epoch: u64,

/// The absolute current slot
pub absolute_slot: Slot,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
pub struct RpcVersionInfo {
Expand Down
5 changes: 5 additions & 0 deletions client/src/thin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use solana_sdk::{
client::{AsyncClient, Client, SyncClient},
clock::MAX_PROCESSING_AGE,
commitment_config::CommitmentConfig,
epoch_info::EpochInfo,
fee_calculator::{FeeCalculator, FeeRateGovernor},
hash::Hash,
instruction::Instruction,
Expand Down Expand Up @@ -518,6 +519,10 @@ impl SyncClient for ThinClient {
Ok(slot)
}

fn get_epoch_info(&self) -> TransportResult<EpochInfo> {
self.rpc_client().get_epoch_info().map_err(|e| e.into())
}

fn get_transaction_count(&self) -> TransportResult<u64> {
let index = self.optimizer.experiment();
let now = Instant::now();
Expand Down
16 changes: 4 additions & 12 deletions core/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use solana_runtime::{accounts::AccountAddressFilter, bank::Bank};
use solana_sdk::{
clock::{Slot, UnixTimestamp},
commitment_config::{CommitmentConfig, CommitmentLevel},
epoch_info::EpochInfo,
epoch_schedule::EpochSchedule,
hash::Hash,
inflation::Inflation,
Expand Down Expand Up @@ -744,7 +745,7 @@ pub trait RpcSol {
&self,
meta: Self::Metadata,
commitment: Option<CommitmentConfig>,
) -> Result<RpcEpochInfo>;
) -> Result<EpochInfo>;

#[rpc(meta, name = "getBlockCommitment")]
fn get_block_commitment(
Expand Down Expand Up @@ -1035,18 +1036,9 @@ impl RpcSol for RpcSolImpl {
&self,
meta: Self::Metadata,
commitment: Option<CommitmentConfig>,
) -> Result<RpcEpochInfo> {
) -> Result<EpochInfo> {
let bank = meta.request_processor.read().unwrap().bank(commitment)?;
let epoch_schedule = bank.epoch_schedule();

let slot = bank.slot();
let (epoch, slot_index) = epoch_schedule.get_epoch_and_slot_index(slot);
Ok(RpcEpochInfo {
epoch,
slot_index,
slots_in_epoch: epoch_schedule.get_slots_in_epoch(epoch),
absolute_slot: slot,
})
Ok(bank.get_epoch_info())
}

fn get_block_commitment(
Expand Down
5 changes: 3 additions & 2 deletions ramp-tps/src/stake.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::utils;
use log::*;
use solana_client::{rpc_client::RpcClient, rpc_response::RpcEpochInfo};
use solana_client::rpc_client::RpcClient;
use solana_sdk::{
clock::Epoch,
epoch_info::EpochInfo,
genesis_config::GenesisConfig,
stake_history::StakeHistoryEntry,
sysvar::{
Expand Down Expand Up @@ -60,7 +61,7 @@ fn stake_history_entry(epoch: Epoch, rpc_client: &RpcClient) -> Option<StakeHist
/// Wait until stake warms up and return the current epoch
pub fn wait_for_warm_up(
activation_epoch: Epoch,
mut epoch_info: RpcEpochInfo,
mut epoch_info: EpochInfo,
rpc_client: &RpcClient,
stake_config: &StakeConfig,
genesis_config: &GenesisConfig,
Expand Down
13 changes: 13 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use solana_sdk::{
Epoch, Slot, SlotCount, SlotIndex, UnixTimestamp, DEFAULT_TICKS_PER_SECOND,
MAX_PROCESSING_AGE, MAX_RECENT_BLOCKHASHES, SECONDS_PER_DAY,
},
epoch_info::EpochInfo,
epoch_schedule::EpochSchedule,
fee_calculator::{FeeCalculator, FeeRateGovernor},
genesis_config::{GenesisConfig, OperatingMode},
Expand Down Expand Up @@ -2495,6 +2496,18 @@ impl Bank {
self.epoch_schedule.get_epoch_and_slot_index(slot)
}

pub fn get_epoch_info(&self) -> EpochInfo {
let absolute_slot = self.slot();
let (epoch, slot_index) = self.get_epoch_and_slot_index(absolute_slot);
let slots_in_epoch = self.get_slots_in_epoch(epoch);
EpochInfo {
epoch,
slot_index,
slots_in_epoch,
absolute_slot,
}
}

pub fn is_empty(&self) -> bool {
!self.is_delta.load(Ordering::Relaxed)
}
Expand Down
5 changes: 5 additions & 0 deletions runtime/src/bank_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use solana_sdk::{
account::Account,
client::{AsyncClient, Client, SyncClient},
commitment_config::CommitmentConfig,
epoch_info::EpochInfo,
fee_calculator::{FeeCalculator, FeeRateGovernor},
hash::Hash,
instruction::Instruction,
Expand Down Expand Up @@ -241,6 +242,10 @@ impl SyncClient for BankClient {
)))
}
}

fn get_epoch_info(&self) -> Result<EpochInfo> {
Ok(self.bank.get_epoch_info())
}
}

impl BankClient {
Expand Down
3 changes: 3 additions & 0 deletions sdk/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
account::Account,
clock::Slot,
commitment_config::CommitmentConfig,
epoch_info::EpochInfo,
fee_calculator::{FeeCalculator, FeeRateGovernor},
hash::Hash,
instruction::Instruction,
Expand Down Expand Up @@ -106,6 +107,8 @@ pub trait SyncClient {
commitment_config: CommitmentConfig,
) -> Result<u64>;

fn get_epoch_info(&self) -> Result<EpochInfo>;

/// Poll until the signature has been confirmed by at least `min_confirmed_blocks`
fn poll_for_signature_confirmation(
&self,
Expand Down
17 changes: 17 additions & 0 deletions sdk/src/epoch_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::clock::{Epoch, Slot};

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct EpochInfo {
/// The current epoch
pub epoch: Epoch,

/// The current slot, relative to the start of the current epoch
pub slot_index: u64,

/// The number of slots in this epoch
pub slots_in_epoch: u64,

/// The absolute current slot
pub absolute_slot: Slot,
}
1 change: 1 addition & 0 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod bpf_loader;
pub mod clock;
pub mod commitment_config;
pub mod entrypoint_native;
pub mod epoch_info;
pub mod epoch_schedule;
pub mod fee_calculator;
pub mod hash;
Expand Down

0 comments on commit e684b00

Please sign in to comment.