From e3ac6fac1e379a4cfd60ac7b370026efb647285f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 18 Feb 2020 13:12:53 -0800 Subject: [PATCH] Factor out creating genesis with vote accounts into a utility function (bp #8315) (#8317) automerge --- runtime/src/genesis_utils.rs | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/runtime/src/genesis_utils.rs b/runtime/src/genesis_utils.rs index ed975c2d4f..e361fda9fb 100644 --- a/runtime/src/genesis_utils.rs +++ b/runtime/src/genesis_utils.rs @@ -9,10 +9,27 @@ use solana_sdk::{ }; use solana_stake_program::stake_state; use solana_vote_program::vote_state; +use std::borrow::Borrow; // The default stake placed with the bootstrap validator pub const BOOTSTRAP_VALIDATOR_LAMPORTS: u64 = 42; +pub struct ValidatorVoteKeypairs { + pub node_keypair: Keypair, + pub vote_keypair: Keypair, + pub stake_keypair: Keypair, +} + +impl ValidatorVoteKeypairs { + pub fn new(node_keypair: Keypair, vote_keypair: Keypair, stake_keypair: Keypair) -> Self { + Self { + node_keypair, + vote_keypair, + stake_keypair, + } + } +} + pub struct GenesisConfigInfo { pub genesis_config: GenesisConfig, pub mint_keypair: Keypair, @@ -23,6 +40,36 @@ pub fn create_genesis_config(mint_lamports: u64) -> GenesisConfigInfo { create_genesis_config_with_leader(mint_lamports, &Pubkey::new_rand(), 0) } +pub fn create_genesis_config_with_vote_accounts( + mint_lamports: u64, + voting_keypairs: &[impl Borrow], +) -> GenesisConfigInfo { + let mut genesis_config_info = create_genesis_config(mint_lamports); + for validator_voting_keypairs in voting_keypairs { + let node_pubkey = validator_voting_keypairs.borrow().node_keypair.pubkey(); + let vote_pubkey = validator_voting_keypairs.borrow().vote_keypair.pubkey(); + let stake_pubkey = validator_voting_keypairs.borrow().stake_keypair.pubkey(); + + // Create accounts + let vote_account = vote_state::create_account(&vote_pubkey, &node_pubkey, 0, 100); + let stake_account = stake_state::create_account( + &stake_pubkey, + &vote_pubkey, + &vote_account, + &genesis_config_info.genesis_config.rent, + 100, + ); + + // Put newly created accounts into genesis + genesis_config_info.genesis_config.accounts.extend(vec![ + (vote_pubkey, vote_account.clone()), + (stake_pubkey, stake_account), + ]); + } + + genesis_config_info +} + pub fn create_genesis_config_with_leader( mint_lamports: u64, bootstrap_validator_pubkey: &Pubkey,