Skip to content

Commit

Permalink
update to match agave genesis file format
Browse files Browse the repository at this point in the history
  • Loading branch information
gregcusack committed Jan 15, 2025
1 parent 062a21e commit 1d79dd1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

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

23 changes: 17 additions & 6 deletions src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ fn generate_filename(node_type: &NodeType, account_type: &str, index: usize) ->
}
}

#[derive(Serialize, Deserialize)]
struct ValidatorAccountsFile {
validator_accounts: Vec<ValidatorAccounts>,
}

/// A validator account where the data is encoded as a Base64 string.
/// Includes the vote account and stake account.
#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -543,8 +548,9 @@ impl Genesis {
Ok(())
}

pub fn get_bank_hash(&self) -> Result<String, Box<dyn Error>> {
let agave_output = Command::new("agave-ledger-tool")
pub fn get_bank_hash(&self, exec_path: &Path) -> Result<String, Box<dyn Error>> {
let executable_path: PathBuf = exec_path.join("agave-ledger-tool");
let agave_output = Command::new(executable_path)
.args([
"-l",
self.config_dir
Expand All @@ -561,6 +567,7 @@ impl Genesis {
"json",
])
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?
.stdout
.expect("Failed to capture agave-ledger-tool output");
Expand Down Expand Up @@ -620,16 +627,20 @@ impl Genesis {
Ok(())
}

// Creates yaml file solana-genesis can read in for `--validator-stakes-file <FILE>`
// Yaml file created with the following format dictated in agave/genesis/README.md
// See: https://github.com/anza-xyz/agave/blob/master/genesis/README.md#3-through-the-validator-accounts-file-flag
fn write_validator_genesis_accouts_to_file(&mut self) -> std::io::Result<()> {
// get ValidatorAccounts vec to write to file for solana-genesis
let validator_accounts_vec: Vec<ValidatorAccounts> =
self.validator_accounts.values().cloned().collect();
let accounts_file = ValidatorAccountsFile {
validator_accounts: self.validator_accounts.values().cloned().collect(),
};

let output_file = self.config_dir.join("validator-genesis-accounts.yml");
self.flags.validator_accounts_file = Some(output_file.clone());

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

info!("Validator genesis accounts successfully written to {output_file:?}");
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
if !skip_primordial_stakes {
genesis.create_snapshot(&exec_path)?;

let bank_hash = genesis.get_bank_hash()?;
let bank_hash = genesis.get_bank_hash(&exec_path)?;
kub_controller.set_bank_hash(bank_hash);
}
}
Expand Down

0 comments on commit 1d79dd1

Please sign in to comment.