Skip to content

Commit

Permalink
update yaml format add long-help in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
gregcusack committed Jan 7, 2025
1 parent 65dd851 commit 8ec7ec7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ pub struct Base64Account {
pub executable: bool,
}

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

/// A validator account where the data is encoded as a Base64 string.
/// Includes the vote account and stake account.
#[derive(Serialize, Deserialize, Debug)]
Expand Down
23 changes: 19 additions & 4 deletions genesis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use {
solana_entry::poh::compute_hashes_per_tick,
solana_genesis::{
genesis_accounts::add_genesis_accounts, Base64Account, Base64ValidatorAccount,
ValidatorAccountsFile,
},
solana_ledger::{blockstore::create_new_ledger, blockstore_options::LedgerColumnOptions},
solana_rpc_client::rpc_client::RpcClient,
Expand Down Expand Up @@ -123,8 +124,9 @@ pub fn load_validator_accounts(
) -> io::Result<()> {
let accounts_file = File::open(file)?;
let validator_genesis_accounts: Vec<Base64ValidatorAccount> =
serde_yaml::from_reader(accounts_file)
.map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{err:?}")))?;
serde_yaml::from_reader::<_, ValidatorAccountsFile>(accounts_file)
.map_err(|err| io::Error::new(io::ErrorKind::Other, format!("{err:?}")))?
.validator_accounts;

for account_details in validator_genesis_accounts {
let pubkeys = [
Expand Down Expand Up @@ -549,7 +551,20 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.value_name("FILENAME")
.takes_value(true)
.multiple(true)
.help("The location of identity, vote, and stake pubkeys and balances for validator accounts"),
.help("The location of identity, vote, and stake pubkeys and balances for validator accounts to bake into genesis")
.long_help(
"Each file should have the following YAML format:\n\
\n\
validator_accounts:\n\
- balance_lamports: <balance-lamports-0>\n\
\x20\x20stake_lamports: <stake-lamports-0>\n\
\x20\x20identity_account: <identity-pubkey-0>\n\
\x20\x20vote_account: <vote-pubkey-0>\n\
\x20\x20stake_account: <stake-pubkey-0>\n\
- balance_lamports: <balance-lamports-1>\n\
\x20\x20stake_lamports: <stake-lamports-1>\n\
...\n"
)
)
.arg(
Arg::with_name("cluster_type")
Expand Down Expand Up @@ -1284,7 +1299,7 @@ mod tests {
// write accounts to file
let path = Path::new("test_append_validator_accounts_to_genesis.yml");
let mut file = File::create(path).unwrap();
file.write_all(b"---\n").unwrap();
file.write_all(b"validator_accounts:\n").unwrap();
file.write_all(serialized.as_bytes()).unwrap();

load_validator_accounts(
Expand Down

0 comments on commit 8ec7ec7

Please sign in to comment.