Skip to content

Commit

Permalink
working. but should do a last check
Browse files Browse the repository at this point in the history
  • Loading branch information
greg committed Aug 22, 2024
1 parent 3439520 commit 58543d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 107 deletions.
94 changes: 9 additions & 85 deletions src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ pub struct GenesisFlags {
pub enable_warmup_epochs: bool,
pub max_genesis_archive_unpacked_size: Option<u64>,
pub cluster_type: String,
pub bootstrap_validator_sol: Option<f64>,
pub bootstrap_validator_stake_sol: Option<f64>,
pub bootstrap_validator_sol: f64,
pub bootstrap_validator_stake_sol: f64,
pub commission: u8,
pub internal_node_sol: f64,
pub internal_node_stake_sol: f64,
Expand Down Expand Up @@ -98,7 +98,6 @@ pub struct Genesis {
config_dir: PathBuf,
key_generator: GenKeys,
pub flags: GenesisFlags,
validator_accounts_file: PathBuf,
}

impl Genesis {
Expand All @@ -114,19 +113,10 @@ impl Genesis {

let seed: [u8; 32] = rand::thread_rng().gen();

let validator_accounts_file = config_dir.join("validator-accounts.yml");
if validator_accounts_file.exists() {
fs::remove_file(&validator_accounts_file).expect("failed to rm file");
}
// Create a new file and add "---" at the top
let mut file = File::create(&validator_accounts_file).expect("failed to create file");
writeln!(file, "---").expect("failed to write to file");

Self {
config_dir,
key_generator: GenKeys::new(seed),
flags,
validator_accounts_file,
}
}

Expand Down Expand Up @@ -187,7 +177,6 @@ impl Genesis {
account_types: &[String],
keypairs: &[Keypair],
) -> Result<(), Box<dyn Error>> {

for (i, keypair) in keypairs.iter().enumerate() {
let account_index = i / account_types.len();
let account = &account_types[i % account_types.len()];
Expand All @@ -201,54 +190,8 @@ impl Genesis {
}
NodeType::Client(_, _) => panic!("Client type not supported"),
};

let outfile = self.config_dir.join(&filename);
write_keypair_file(keypair, outfile)?;

// match node_type {
// &NodeType::Standard => {
// let mut owner = "11111111111111111111111111111111";
// let mut internal_node_sol: u64 = 12345678900000; //self.flags.internal_node_sol;
// if account.contains("stake") {
// continue;
// // owner = "Stake11111111111111111111111111111111111111";
// // internal_node_sol = internal_node_sol/10;
// } else if account.contains("vote") {
// continue;
// // owner = "Vote111111111111111111111111111111111111111";
// // internal_node_sol = internal_node_sol/10;
// };
// info!("greg: got standard and identity");
// // Open the validator_accounts_file in append mode
// let mut file = OpenOptions::new()
// .write(true)
// .append(true)
// .open(&self.validator_accounts_file)?;
// // create validator_accounts_file here
// // and add "---" at the top of the file
// // Delete the file if it exists


// // let internal_node_sol: u64 = 123456789000; //self.flags.internal_node_sol;
// let pubkey = keypair.pubkey().to_string();
// // Append to validator_accounts_file here
// // in the following format:
// /*
// $pubkey:
// balance: $internal_node_sol
// owner: 11111111111111111111111111111111
// data:
// executable: false
// */
// // Append the necessary data to the validator_accounts_file
// writeln!(file, "{pubkey}:")?;
// writeln!(file, " balance: {internal_node_sol}")?;
// writeln!(file, " owner: {owner}")?;
// writeln!(file, " data:")?;
// writeln!(file, " executable: false")?;
// }
// _ => info!("diff noad type: {}", node_type),
// }
}
Ok(())
}
Expand Down Expand Up @@ -347,19 +290,9 @@ impl Genesis {
) -> Result<Vec<String>, Box<dyn Error>> {
let mut args = vec![
"--bootstrap-validator-lamports".to_string(),
sol_to_lamports(
self.flags
.bootstrap_validator_sol
.unwrap_or(DEFAULT_BOOTSTRAP_NODE_SOL),
)
.to_string(),
sol_to_lamports(self.flags.bootstrap_validator_sol).to_string(),
"--bootstrap-validator-stake-lamports".to_string(),
sol_to_lamports(
self.flags
.bootstrap_validator_stake_sol
.unwrap_or(DEFAULT_BOOTSTRAP_NODE_STAKE_SOL),
)
.to_string(),
sol_to_lamports(self.flags.bootstrap_validator_stake_sol).to_string(),
"--hashes-per-tick".to_string(),
self.flags.hashes_per_tick.clone(),
"--max-genesis-archive-unpacked-size".to_string(),
Expand Down Expand Up @@ -428,22 +361,13 @@ impl Genesis {
args.push(path);
}
}

args.push("--validator-lamports".to_string());
args.push(sol_to_lamports(self.flags.internal_node_sol).to_string());

args.push("--validator-stake-lamports".to_string());
args.push("123456789000".to_string());
args.push(sol_to_lamports(self.flags.internal_node_stake_sol).to_string());
}
// if self.flags.skip_primordial_stakes {
// args.push("--validator".to_string());
// for account_type in ["identity", "vote-account", "stake-account"].iter() {
// let path = self
// .config_dir
// .join(format!("validator-{account_type}-{image_tag}-0.json"))
// .into_os_string()
// .into_string()
// .map_err(|_| "Failed to convert path to string")?;
// args.push(path);
// }
// args.push(path);
// }

if let Some(slots_per_epoch) = self.flags.slots_per_epoch {
args.push("--slots-per-epoch".to_string());
Expand Down
25 changes: 9 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ fn parse_matches() -> clap::ArgMatches {
.long("internal-node-sol")
.takes_value(true)
.default_value(&DEFAULT_INTERNAL_NODE_SOL.to_string())
.help("Amount to fund internal nodes in genesis config."),
.help("Amount to fund internal nodes in genesis"),
)
.arg(
Arg::with_name("internal_node_stake_sol")
.long("internal-node-stake-sol")
.takes_value(true)
.default_value(&DEFAULT_INTERNAL_NODE_STAKE_SOL.to_string())
.help("Amount to stake internal nodes (Sol)."),
.help("Amount to stake internal nodes (Sol) in genesis"),
)
.arg(
Arg::with_name("skip_primordial_stakes")
Expand Down Expand Up @@ -558,6 +558,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let internal_node_sol =
value_t_or_exit!(matches, "internal_node_sol", f64) + internal_node_stake_sol;

let bootstrap_validator_stake_sol =
value_t_or_exit!(matches, "bootstrap_validator_stake_sol", f64);
let bootstrap_validator_sol =
value_t_or_exit!(matches, "bootstrap_validator_sol", f64) + bootstrap_validator_stake_sol;

let skip_primordial_stakes = matches.is_present("skip_primordial_stakes");

let genesis_flags = GenesisFlags {
Expand Down Expand Up @@ -594,20 +599,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.value_of("cluster_type")
.unwrap_or_default()
.to_string(),
bootstrap_validator_sol: matches
.value_of("bootstrap_validator_sol")
.map(|value_str| {
value_str
.parse()
.expect("Invalid value for bootstrap_validator_sol")
}),
bootstrap_validator_stake_sol: matches.value_of("bootstrap_validator_stake_sol").map(
|value_str| {
value_str
.parse()
.expect("Invalid value for bootstrap_validator_stake_sol")
},
),
bootstrap_validator_sol,
bootstrap_validator_stake_sol,
commission,
internal_node_sol,
internal_node_stake_sol,
Expand Down
6 changes: 0 additions & 6 deletions src/startup_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,6 @@ run_delegate_stake() {
solana --keypair $IDENTITY_FILE stake-account validator-accounts/stake.json
}
#echo "create vote account"
#setup_validator
#echo "create delegate stake"
#run_delegate_stake
if $run_validator_stake_setup; then
echo "get airdrop and create vote account"
setup_validator
Expand Down

0 comments on commit 58543d8

Please sign in to comment.