Skip to content

Commit

Permalink
bake internal node stakes into genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
gregcusack committed Aug 22, 2024
1 parent 9c88279 commit b4d4fc8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
30 changes: 15 additions & 15 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 @@ -180,6 +180,7 @@ impl Genesis {
for (i, keypair) in keypairs.iter().enumerate() {
let account_index = i / account_types.len();
let account = &account_types[i % account_types.len()];
info!("Account: {account}, node_type: {node_type}");
let filename = match node_type {
NodeType::Bootstrap => {
format!("{node_type}/{account}.json")
Expand Down Expand Up @@ -290,19 +291,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 @@ -360,7 +351,7 @@ impl Genesis {

if !self.flags.skip_primordial_stakes {
for i in 0..num_validators {
args.push("--bootstrap-validator".to_string());
args.push("--internal-validator".to_string());
for account_type in ["identity", "vote-account", "stake-account"].iter() {
let path = self
.config_dir
Expand All @@ -371,6 +362,15 @@ impl Genesis {
args.push(path);
}
}

// stake delegated from internal_node_sol
let internal_node_lamports =
self.flags.internal_node_sol - self.flags.internal_node_stake_sol;
args.push("--internal-validator-lamports".to_string());
args.push(sol_to_lamports(internal_node_lamports).to_string());

args.push("--internal-validator-stake-lamports".to_string());
args.push(sol_to_lamports(self.flags.internal_node_stake_sol).to_string());
}

if let Some(slots_per_epoch) = self.flags.slots_per_epoch {
Expand Down
22 changes: 7 additions & 15 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 @@ -594,19 +594,11 @@ 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: value_t_or_exit!(matches, "bootstrap_validator_sol", f64),
bootstrap_validator_stake_sol: value_t_or_exit!(
matches,
"bootstrap_validator_stake_sol",
f64
),
commission,
internal_node_sol,
Expand Down
2 changes: 1 addition & 1 deletion src/startup_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ run_delegate_stake() {
fi
fi
echo "created stake account"
if [ "$stake_account_already_exists" != true ]; then
echo "stake account does not exist. so lets deligate"
if ! run_solana_command "solana delegate-stake validator-accounts/stake.json validator-accounts/vote.json --force -k $IDENTITY_FILE" "Delegate Stake"; then
Expand Down

0 comments on commit b4d4fc8

Please sign in to comment.