Skip to content

Commit b4d4fc8

Browse files
committed
bake internal node stakes into genesis
1 parent 9c88279 commit b4d4fc8

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

Diff for: src/genesis.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ pub struct GenesisFlags {
6262
pub enable_warmup_epochs: bool,
6363
pub max_genesis_archive_unpacked_size: Option<u64>,
6464
pub cluster_type: String,
65-
pub bootstrap_validator_sol: Option<f64>,
66-
pub bootstrap_validator_stake_sol: Option<f64>,
65+
pub bootstrap_validator_sol: f64,
66+
pub bootstrap_validator_stake_sol: f64,
6767
pub commission: u8,
6868
pub internal_node_sol: f64,
6969
pub internal_node_stake_sol: f64,
@@ -180,6 +180,7 @@ impl Genesis {
180180
for (i, keypair) in keypairs.iter().enumerate() {
181181
let account_index = i / account_types.len();
182182
let account = &account_types[i % account_types.len()];
183+
info!("Account: {account}, node_type: {node_type}");
183184
let filename = match node_type {
184185
NodeType::Bootstrap => {
185186
format!("{node_type}/{account}.json")
@@ -290,19 +291,9 @@ impl Genesis {
290291
) -> Result<Vec<String>, Box<dyn Error>> {
291292
let mut args = vec![
292293
"--bootstrap-validator-lamports".to_string(),
293-
sol_to_lamports(
294-
self.flags
295-
.bootstrap_validator_sol
296-
.unwrap_or(DEFAULT_BOOTSTRAP_NODE_SOL),
297-
)
298-
.to_string(),
294+
sol_to_lamports(self.flags.bootstrap_validator_sol).to_string(),
299295
"--bootstrap-validator-stake-lamports".to_string(),
300-
sol_to_lamports(
301-
self.flags
302-
.bootstrap_validator_stake_sol
303-
.unwrap_or(DEFAULT_BOOTSTRAP_NODE_STAKE_SOL),
304-
)
305-
.to_string(),
296+
sol_to_lamports(self.flags.bootstrap_validator_stake_sol).to_string(),
306297
"--hashes-per-tick".to_string(),
307298
self.flags.hashes_per_tick.clone(),
308299
"--max-genesis-archive-unpacked-size".to_string(),
@@ -360,7 +351,7 @@ impl Genesis {
360351

361352
if !self.flags.skip_primordial_stakes {
362353
for i in 0..num_validators {
363-
args.push("--bootstrap-validator".to_string());
354+
args.push("--internal-validator".to_string());
364355
for account_type in ["identity", "vote-account", "stake-account"].iter() {
365356
let path = self
366357
.config_dir
@@ -371,6 +362,15 @@ impl Genesis {
371362
args.push(path);
372363
}
373364
}
365+
366+
// stake delegated from internal_node_sol
367+
let internal_node_lamports =
368+
self.flags.internal_node_sol - self.flags.internal_node_stake_sol;
369+
args.push("--internal-validator-lamports".to_string());
370+
args.push(sol_to_lamports(internal_node_lamports).to_string());
371+
372+
args.push("--internal-validator-stake-lamports".to_string());
373+
args.push(sol_to_lamports(self.flags.internal_node_stake_sol).to_string());
374374
}
375375

376376
if let Some(slots_per_epoch) = self.flags.slots_per_epoch {

Diff for: src/main.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ fn parse_matches() -> clap::ArgMatches {
238238
.long("internal-node-sol")
239239
.takes_value(true)
240240
.default_value(&DEFAULT_INTERNAL_NODE_SOL.to_string())
241-
.help("Amount to fund internal nodes in genesis config."),
241+
.help("Amount to fund internal nodes in genesis"),
242242
)
243243
.arg(
244244
Arg::with_name("internal_node_stake_sol")
245245
.long("internal-node-stake-sol")
246246
.takes_value(true)
247247
.default_value(&DEFAULT_INTERNAL_NODE_STAKE_SOL.to_string())
248-
.help("Amount to stake internal nodes (Sol)."),
248+
.help("Amount to stake internal nodes (Sol) in genesis"),
249249
)
250250
.arg(
251251
Arg::with_name("skip_primordial_stakes")
@@ -594,19 +594,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
594594
.value_of("cluster_type")
595595
.unwrap_or_default()
596596
.to_string(),
597-
bootstrap_validator_sol: matches
598-
.value_of("bootstrap_validator_sol")
599-
.map(|value_str| {
600-
value_str
601-
.parse()
602-
.expect("Invalid value for bootstrap_validator_sol")
603-
}),
604-
bootstrap_validator_stake_sol: matches.value_of("bootstrap_validator_stake_sol").map(
605-
|value_str| {
606-
value_str
607-
.parse()
608-
.expect("Invalid value for bootstrap_validator_stake_sol")
609-
},
597+
bootstrap_validator_sol: value_t_or_exit!(matches, "bootstrap_validator_sol", f64),
598+
bootstrap_validator_stake_sol: value_t_or_exit!(
599+
matches,
600+
"bootstrap_validator_stake_sol",
601+
f64
610602
),
611603
commission,
612604
internal_node_sol,

Diff for: src/startup_scripts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ run_delegate_stake() {
597597
fi
598598
fi
599599
echo "created stake account"
600-
600+
601601
if [ "$stake_account_already_exists" != true ]; then
602602
echo "stake account does not exist. so lets deligate"
603603
if ! run_solana_command "solana delegate-stake validator-accounts/stake.json validator-accounts/vote.json --force -k $IDENTITY_FILE" "Delegate Stake"; then

0 commit comments

Comments
 (0)