Skip to content

Commit ae8d479

Browse files
committed
update to match agave genesis file format
1 parent a5587aa commit ae8d479

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/genesis.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,15 @@ fn generate_filename(node_type: &NodeType, account_type: &str, index: usize) ->
4545
}
4646
}
4747

48-
/// A validator account where the data is encoded as a Base64 string.
49-
/// Includes the vote account and stake account.
48+
#[derive(Serialize, Deserialize)]
49+
struct ValidatorAccountsFile {
50+
validator_accounts: Vec<StakedValidatorAccountInfo>,
51+
}
52+
53+
/// Info needed to create a staked validator account,
54+
/// including relevant balances and vote- and stake-account addresses
5055
#[derive(Serialize, Deserialize, Debug, Clone)]
51-
pub struct ValidatorAccounts {
56+
pub struct StakedValidatorAccountInfo {
5257
pub balance_lamports: u64,
5358
pub stake_lamports: u64,
5459
pub identity_account: String,
@@ -130,7 +135,7 @@ pub struct Genesis {
130135
config_dir: PathBuf,
131136
key_generator: GenKeys,
132137
pub validator_stakes_file: Option<PathBuf>,
133-
validator_accounts: HashMap<String, ValidatorAccounts>,
138+
validator_accounts: HashMap<String, StakedValidatorAccountInfo>,
134139
pub flags: GenesisFlags,
135140
}
136141

@@ -208,7 +213,6 @@ impl Genesis {
208213
}
209214

210215
self.write_accounts_to_file(&node_type, &account_types, &keypairs)?;
211-
// self.initialize_validator_accounts(&keypairs);
212216

213217
Ok(())
214218
}
@@ -273,7 +277,7 @@ impl Genesis {
273277
let vote_account = account_type_keypair[1].pubkey().to_string();
274278
let stake_account = account_type_keypair[2].pubkey().to_string();
275279

276-
let validator_account = ValidatorAccounts {
280+
let validator_account = StakedValidatorAccountInfo {
277281
balance_lamports: 0,
278282
stake_lamports: 0,
279283
identity_account,
@@ -543,8 +547,9 @@ impl Genesis {
543547
Ok(())
544548
}
545549

546-
pub fn get_bank_hash(&self) -> Result<String, Box<dyn Error>> {
547-
let agave_output = Command::new("agave-ledger-tool")
550+
pub fn get_bank_hash(&self, exec_path: &Path) -> Result<String, Box<dyn Error>> {
551+
let executable_path: PathBuf = exec_path.join("agave-ledger-tool");
552+
let agave_output = Command::new(executable_path)
548553
.args([
549554
"-l",
550555
self.config_dir
@@ -561,6 +566,7 @@ impl Genesis {
561566
"json",
562567
])
563568
.stdout(Stdio::piped())
569+
.stderr(Stdio::piped())
564570
.spawn()?
565571
.stdout
566572
.expect("Failed to capture agave-ledger-tool output");
@@ -603,7 +609,7 @@ impl Genesis {
603609
));
604610
}
605611

606-
// match `validator_stakes` with corresponding `ValidatorAccounts` and update balance and stake
612+
// match `validator_stakes` with corresponding `StakedValidatorAccountInfo` and update balance and stake
607613
for (key, stake) in validator_stakes {
608614
if let Some(validator_account) = self.validator_accounts.get_mut(&key) {
609615
validator_account.balance_lamports = stake.balance_lamports;
@@ -620,16 +626,19 @@ impl Genesis {
620626
Ok(())
621627
}
622628

629+
// Creates yaml file solana-genesis can read in for `--validator-stakes-file <FILE>`
630+
// Yaml file created with the following format dictated in agave/genesis/README.md
631+
// See: https://github.com/anza-xyz/agave/blob/master/genesis/README.md#3-through-the-validator-accounts-file-flag
623632
fn write_validator_genesis_accouts_to_file(&mut self) -> std::io::Result<()> {
624-
// get ValidatorAccounts vec to write to file for solana-genesis
625-
let validator_accounts_vec: Vec<ValidatorAccounts> =
626-
self.validator_accounts.values().cloned().collect();
633+
let accounts_file = ValidatorAccountsFile {
634+
validator_accounts: self.validator_accounts.values().cloned().collect(),
635+
};
636+
627637
let output_file = self.config_dir.join("validator-genesis-accounts.yml");
628638
self.flags.validator_accounts_file = Some(output_file.clone());
629639

630-
// write ValidatorAccouns to yaml file for solana-genesis
631640
let file = File::create(&output_file)?;
632-
serde_yaml::to_writer(file, &validator_accounts_vec)
641+
serde_yaml::to_writer(file, &accounts_file)
633642
.map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{err:?}")))?;
634643

635644
info!("Validator genesis accounts successfully written to {output_file:?}");

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
728728
if !skip_primordial_stakes {
729729
genesis.create_snapshot(&exec_path)?;
730730

731-
let bank_hash = genesis.get_bank_hash()?;
731+
let bank_hash = genesis.get_bank_hash(&exec_path)?;
732732
kub_controller.set_bank_hash(bank_hash);
733733
}
734734
}

0 commit comments

Comments
 (0)