Skip to content

Commit

Permalink
wip. getting error
Browse files Browse the repository at this point in the history
  • Loading branch information
gregcusack committed May 20, 2024
1 parent 004e615 commit 341c2d1
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 112 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"

[dependencies]
bzip2 = "0.4.4"
clap = { version = "3.2.22", features = ["cargo"] }
clap = { version = "3.2.22", features = ["cargo"] }
console = "0.15.8"
git2 = "0.18.3"
indicatif = "0.17.8"
Expand All @@ -20,6 +20,7 @@ rand = "0.8.5"
reqwest = { version = "0.11.23", features = ["blocking", "brotli", "deflate", "gzip", "rustls-tls", "json"] }
rustls = { version = "0.21.11", default-features = false, features = ["quic"] }
solana-accounts-db = "1.18.8"
solana-clap-v3-utils = "1.18.8"
solana-core = "1.18.8"
solana-ledger = "1.18.8"
solana-logger = "1.18.8"
Expand Down
6 changes: 3 additions & 3 deletions src/client_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub struct ClientConfig {
pub client_type: String,
pub client_to_run: String,
pub bench_tps_args: Vec<String>,
pub target_node: Option<Pubkey>,
pub duration: u64,
pub num_nodes: Option<u64>,
pub client_target_node: Option<Pubkey>,
pub client_duration_seconds: u64,
pub client_wait_for_n_nodes: Option<u64>,
}
23 changes: 9 additions & 14 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ impl DockerConfig {
return Err(output.status.to_string().into());
}
progress_bar.finish_and_clear();
info!("{validator_type} image build complete");

Ok(())
}
Expand Down Expand Up @@ -193,18 +192,14 @@ USER solana
COPY --chown=solana:solana {startup_script_directory} /home/solana/k8s-cluster-scripts
RUN chmod +x /home/solana/k8s-cluster-scripts/*
COPY --chown=solana:solana ./config-k8s/bootstrap-validator /home/solana/ledger
COPY --chown=solana:solana ./{solana_build_directory}/bin/ /home/solana/bin/
COPY --chown=solana:solana ./{solana_build_directory}/bin/ /home/solana/.cargo/bin/
COPY --chown=solana:solana ./{solana_build_directory}/version.yml /home/solana/
ENV PATH="/home/solana/bin:${{PATH}}"
ENV PATH="/home/solana/.cargo/bin:${{PATH}}"
WORKDIR /home/solana
{}
"#,
self.base_image
);

let dockerfile = format!(
"{dockerfile}\n{}",
self.insert_client_accounts_if_present(solana_root_path, validator_type)?,
self.base_image, self.insert_client_accounts_if_present(solana_root_path, validator_type)?
);

debug!("dockerfile: {dockerfile:?}");
Expand All @@ -228,10 +223,10 @@ WORKDIR /home/solana
Ok(format!(
r#"
COPY --chown=solana:solana ./config-k8s/bench-tps-{index}.yml /home/solana/client-accounts.yml
"#,
))
"#
))
} else {
Err(format!("{:?} does not exist!", bench_tps_path).into())
Err(format!("{bench_tps_path:?} does not exist!").into())
}
}
ValidatorType::Bootstrap => {
Expand All @@ -240,9 +235,9 @@ COPY --chown=solana:solana ./config-k8s/bench-tps-{index}.yml /home/solana/clien
Ok(r#"
COPY --chown=solana:solana ./config-k8s/client-accounts.yml /home/solana
"#
.to_string())
.to_string())
} else {
Err(format!("{:?} does not exist!", client_accounts_path).into())
Err(format!("{client_accounts_path:?} does not exist!").into())
}
}
ValidatorType::Standard | ValidatorType::RPC => Ok("".to_string()),
Expand Down
84 changes: 39 additions & 45 deletions src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,24 @@ impl std::fmt::Display for GenesisFlags {
}

fn append_client_accounts_to_file(
in_file: &PathBuf, //bench-tps-i.yml
out_file: &PathBuf, //client-accounts.yml
bench_tps_account_path: &PathBuf, //bench-tps-i.yml
client_accounts_path: &PathBuf, //client-accounts.yml
) -> io::Result<()> {
// Open the bench-tps-i.yml file for reading.
let input = File::open(in_file)?;
let input = File::open(bench_tps_account_path)?;
let reader = io::BufReader::new(input);

// Open (or create) client-accounts.yml
let output = OpenOptions::new()
.create(true)
.append(true)
.open(out_file)?;
.open(client_accounts_path)?;
let mut writer = BufWriter::new(output);

// Enumerate the lines of the input file, starting from 1.
for (index, line) in reader.lines().enumerate().map(|(i, l)| (i + 1, l)) {
// Skip first line since it is a header aka "---" in a yaml
for line in reader.lines().skip(1) {
let line = line?;

// Skip first line since it is a header aka "---" in a yaml
if (index as u64) > 1 {
writeln!(writer, "{line}")?;
}
writeln!(writer, "{line}")?;
}

Ok(())
Expand Down Expand Up @@ -159,10 +155,6 @@ impl Genesis {
validator_type: ValidatorType,
number_of_accounts: usize,
) -> Result<(), Box<dyn Error>> {
if let ValidatorType::Client(_) = validator_type {
return Err("Client valdiator_type in generate_accounts not allowed".into());
}

info!("generating {number_of_accounts} {validator_type} accounts...");

let account_types = match validator_type {
Expand All @@ -172,7 +164,7 @@ impl Genesis {
ValidatorType::RPC => {
vec!["identity"] // no vote or stake account for RPC
}
ValidatorType::Client(_) => panic!("Client type not supported"),
ValidatorType::Client(_) => return Err("Client valdiator_type in generate_accounts not allowed".into()),
};

let total_accounts_to_generate = number_of_accounts * account_types.len();
Expand Down Expand Up @@ -222,36 +214,16 @@ impl Genesis {
if number_of_clients == 0 {
return Ok(());
}

let client_accounts_file = config_dir.join("client-accounts.yml");

let progress_bar = new_spinner_progress_bar();
progress_bar.set_message(format!("{WRITING}Creating and writing client accounts..."));

info!("generating {number_of_clients} client account(s)...");

let children: Result<Vec<_>, _> = (0..number_of_clients)
.map(|i| {
info!("client account: {i}");
let mut args = Vec::new();
let account_path = config_dir.join(format!("bench-tps-{i}.yml"));
args.push("--write-client-keys".to_string());
args.push(account_path.into_os_string().into_string().map_err(|err| {
std::io::Error::new(
std::io::ErrorKind::InvalidData,
format!("Invalid Unicode data in path: {:?}", err),
)
})?);
args.push("--target-lamports-per-signature".to_string());
args.push(target_lamports_per_signature.to_string());

if !bench_tps_args.is_empty() {
args.extend(bench_tps_args.to_owned());
}

let executable_path = if let DeployMethod::ReleaseChannel(_) = deploy_method {
solana_root_path.join("solana-release/bin/solana-bench-tps")
} else {
solana_root_path.join("farf/bin/solana-bench-tps")
};

Self::create_client_account(&args, &executable_path)
Self::create_client_account(i, config_dir, target_lamports_per_signature, bench_tps_args, deploy_method, solana_root_path)
})
.collect();

Expand All @@ -262,8 +234,6 @@ impl Genesis {
}
}

let progress_bar = new_spinner_progress_bar();
progress_bar.set_message(format!("{WRITING}Writing client accounts..."));
for i in 0..number_of_clients {
let account_path = config_dir.join(format!("bench-tps-{i}.yml"));
append_client_accounts_to_file(&account_path, &client_accounts_file)?;
Expand All @@ -275,9 +245,33 @@ impl Genesis {
}

fn create_client_account(
args: &Vec<String>,
executable_path: &PathBuf,
client_index: usize,
config_dir: &Path,
target_lamports_per_signature: u64,
bench_tps_args: &[String],
deploy_method: &DeployMethod,
solana_root_path: &Path,
) -> Result<Child, Box<dyn Error>> {
info!("client account: {client_index}");
let mut args = Vec::new();
let account_path = config_dir.join(format!("bench-tps-{client_index}.yml"));
args.push("--write-client-keys".to_string());
args.push(account_path.into_os_string().into_string().map_err(|err| {
std::io::Error::new(
std::io::ErrorKind::InvalidData,
format!("Invalid Unicode data in path: {:?}", err),
)
})?);
args.push("--target-lamports-per-signature".to_string());
args.push(target_lamports_per_signature.to_string());

args.extend_from_slice(bench_tps_args);

let executable_path = if let DeployMethod::ReleaseChannel(_) = deploy_method {
solana_root_path.join("solana-release/bin/solana-bench-tps")
} else {
solana_root_path.join("farf/bin/solana-bench-tps")
};
let child = Command::new(executable_path)
.args(args)
.stdout(Stdio::null())
Expand Down
6 changes: 3 additions & 3 deletions src/kubernetes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,15 @@ impl<'a> Kubernetes<'a> {

flags.push(self.client_config.client_type.clone());

if let Some(target_node) = self.client_config.target_node {
if let Some(target_node) = self.client_config.client_target_node {
flags.push("--target-node".to_string());
flags.push(target_node.to_string());
}

flags.push("--duration".to_string());
flags.push(self.client_config.duration.to_string());
flags.push(self.client_config.client_duration_seconds.to_string());

if let Some(num_nodes) = self.client_config.num_nodes {
if let Some(num_nodes) = self.client_config.client_wait_for_n_nodes {
flags.push("--num-nodes".to_string());
flags.push(num_nodes.to_string());
}
Expand Down
2 changes: 0 additions & 2 deletions src/ledger_helper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use {
crate::genesis::DEFAULT_MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
log::*,
solana_accounts_db::hardened_unpack::open_genesis_config,
solana_sdk::shred_version::compute_shred_version,
std::{error::Error, path::Path},
Expand All @@ -25,7 +24,6 @@ impl LedgerHelper {
let genesis_config =
open_genesis_config(ledger_dir, DEFAULT_MAX_GENESIS_ARCHIVE_UNPACKED_SIZE);
let shred_version = compute_shred_version(&genesis_config?.hash(), None);
info!("Shred Version: {}", shred_version);
Ok(shred_version)
}
}
Loading

0 comments on commit 341c2d1

Please sign in to comment.