From 70e1a15973fc84482f7c3bf1666a0f809b944c38 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 8 Jan 2020 19:49:50 -0700 Subject: [PATCH] Remove vote account from genesis validators --- genesis/src/genesis_accounts.rs | 20 ------ genesis/src/validators.rs | 109 ++------------------------------ 2 files changed, 6 insertions(+), 123 deletions(-) diff --git a/genesis/src/genesis_accounts.rs b/genesis/src/genesis_accounts.rs index 8edb48f885..d06e710aea 100644 --- a/genesis/src/genesis_accounts.rs +++ b/genesis/src/genesis_accounts.rs @@ -202,72 +202,52 @@ pub const VALIDATOR_INFOS: &[ValidatorInfo] = &[ ValidatorInfo { name: "01Node", node: "5n8KCdzqtvTnhkvCrFR7errH6ZUp11kL97r2awXkfzFe", - vote: "4uYMbY5Ae5ZSRNxQ3RWVyXS9rzW7E3AMZYHuUEotxu6K", node_lamports: 500 * LAMPORTS_PER_SOL, - commission: 0, }, ValidatorInfo { name: "Bison Trails", node: "7suRNpX7bJsXphHJtBv4ZsLjJZ1dTGeX256pLqJZdEAm", - vote: "DfirEZ9Up1xbE7sQji9UwtcRGe5uCcRqQtnaGpha5KNY", node_lamports: 500 * LAMPORTS_PER_SOL, - commission: 0, }, ValidatorInfo { name: "ChainFlow", node: "2te46rxywMdCNdkvjumiBBPQoVczJFxhxEaxFavQNqe3", - vote: "8bRCnytB7bySmqxodNGbZuUAtncKkB8T733DD1Dm9WMb", node_lamports: 500 * LAMPORTS_PER_SOL, - commission: 0, }, ValidatorInfo { name: "ChorusOne", node: "ChorusXqjLC2NbiStKR6k9WoD7wu6TVTtFG8qCL5XBVa", - vote: "ChorusvBuPwukqgDvYfWtEg8j4T1NcMgSTQ4b1UbAwgQ", node_lamports: 500 * LAMPORTS_PER_SOL, - commission: 0, }, ValidatorInfo { name: "Dokia Capital", node: "GeZ5PrJi9muVCJiJAaFBNGoCEdxGEqTp7L2BmT2WTTy1", - vote: "7ZdRx2EBYoRuPfyeoNbuHodMUXcAQRcC37MUw3kP6akn", node_lamports: 500 * LAMPORTS_PER_SOL, - commission: 0, }, ValidatorInfo { name: "Forbole", node: "Fe5sLQAAT7RBT8mcH1AAGCbExJQcYxcwXvp1GjrGbvxs", - vote: "Dr8MkZZuvZVQJFKtjShZYEfg6n93sc1GxevqLnGss7FW", node_lamports: 500 * LAMPORTS_PER_SOL, - commission: 0, }, ValidatorInfo { name: "P2P.ORG - Secure Non-custodial Staking", node: "44e8VyWoyZSE2oYHxMHMedAiHkGJqJgPd3tdt6iKoAFL", - vote: "BwwpzEpo1wzgV9N1987ntgNG6jLt3C9532C68pswT7Gp", node_lamports: 500 * LAMPORTS_PER_SOL, - commission: 0, }, ValidatorInfo { name: "RockX", node: "Ez4iUU87ViJLCnmSy1t1Ti3DLoysFXiBseNfnRfoehyY", - vote: "GUdGALCHQBeqkNc2ZAht3tBXab1N5u9qJC3PAzpL54r7", node_lamports: 500 * LAMPORTS_PER_SOL, - commission: 0, }, ValidatorInfo { name: "Stake Capital", node: "HavuVVDXXsJqMzPwQ4KcF5kFm2xqjbChhyi1bgGeCQif", - vote: "HswPkKj1xoLLmpM8t1vy5Pbi8zYYUs9ZawswvofKsFo1", node_lamports: 500 * LAMPORTS_PER_SOL, - commission: 0, }, ValidatorInfo { name: "Staking Facilities", node: "pbAxyqHHPMwgEjv8kmjGxysk9rhNtN7q22eAjReq6Hj", - vote: "4VZ3pJX19PpuGjoSB1qeN9sVQfrqgLVNg16is37adiFp", node_lamports: 500 * LAMPORTS_PER_SOL, - commission: 0, }, ]; diff --git a/genesis/src/validators.rs b/genesis/src/validators.rs index 60a040fbd7..6f43f69620 100644 --- a/genesis/src/validators.rs +++ b/genesis/src/validators.rs @@ -3,15 +3,12 @@ use solana_sdk::{ account::Account, genesis_config::GenesisConfig, pubkey::Pubkey, system_program, timing::years_as_slots, }; -use solana_vote_program::vote_state::{self, VoteState}; #[derive(Debug)] pub struct ValidatorInfo { pub name: &'static str, pub node: &'static str, pub node_lamports: u64, - pub vote: &'static str, - pub commission: u8, } // the node's account needs carry enough @@ -26,22 +23,19 @@ fn calculate_voting_fees(genesis_config: &GenesisConfig, years: f64) -> u64 { ) as u64 } -/// create and add vote and node id accounts for a validator +/// create accounts for a validator pub fn create_and_add_validator( genesis_config: &mut GenesisConfig, // information about this validator validator_info: &ValidatorInfo, ) -> u64 { let node: Pubkey = validator_info.node.parse().expect("invalid node"); - let vote: Pubkey = validator_info.vote.parse().expect("invalid vote"); // node is the system account from which votes will be issued let node_rent_reserve = genesis_config.rent.minimum_balance(0).max(1); let node_voting_fees = calculate_voting_fees(genesis_config, 1.0); - let vote_rent_reserve = VoteState::get_rent_exempt_reserve(&genesis_config.rent).max(1); - - let mut total_lamports = node_voting_fees + vote_rent_reserve + validator_info.node_lamports; + let mut total_lamports = node_voting_fees + validator_info.node_lamports; genesis_config .accounts @@ -52,24 +46,13 @@ pub fn create_and_add_validator( }) .lamports += node_voting_fees + validator_info.node_lamports; - assert!( - genesis_config.accounts.get(&vote).is_none(), - "{} is already in genesis", - vote - ); - - genesis_config.add_account( - vote, - vote_state::create_account(&vote, &node, validator_info.commission, vote_rent_reserve), - ); - total_lamports } #[cfg(test)] mod tests { use super::*; - use solana_sdk::{native_token::LAMPORTS_PER_SOL, rent::Rent}; + use solana_sdk::rent::Rent; fn create_and_check_validators( genesis_config: &mut GenesisConfig, @@ -112,97 +95,17 @@ mod tests { ..GenesisConfig::default() }; - let total_lamports = VoteState::get_rent_exempt_reserve(&rent) - + calculate_voting_fees(&genesis_config, 1.0) - + rent.minimum_balance(0); + let total_lamports = calculate_voting_fees(&genesis_config, 1.0) + rent.minimum_balance(0); create_and_check_validators( &mut genesis_config, &[ValidatorInfo { name: "fun", - node: "AiTDdNHW2vNtHt7PqWMHx3B8cMPRDNgc7kMiLPJM25QC", // random pubkeys + node: "AiTDdNHW2vNtHt7PqWMHx3B8cMPRDNgc7kMiLPJM25QC", // random pubkey node_lamports: 0, - vote: "77TQYZTHodhnxJcSuVjUvx8GYRCkykPyHtmFTFLjj1Rc", - commission: 50, }], total_lamports, - 2, - ); - } - - #[test] - fn test_create_one_validator_two_votes() { - let rent = Rent { - lamports_per_byte_year: 1, - exemption_threshold: 1.0, - ..Rent::default() - }; - let mut genesis_config = GenesisConfig { - rent, - ..GenesisConfig::default() - }; - let total_lamports = VoteState::get_rent_exempt_reserve(&rent) * 2 - + calculate_voting_fees(&genesis_config, 1.0) * 2 // two vote accounts - + rent.minimum_balance(0) // one node account - + 1 * LAMPORTS_PER_SOL; // 2nd vote account ask has SOL - - // weird case, just wanted to verify that the duplicated node account gets double fees - create_and_check_validators( - &mut genesis_config, - &[ - ValidatorInfo { - name: "fun", - node: "3VTm54dw8w6jTTsPH4BfoV5vo6mF985JAMtNDRYcaGFc", // random pubkeys - node_lamports: 0, - vote: "GTKWbUoLw3Bv7Ld92crhyXcEk9zUu3VEKfzeuWJZdnfW", - commission: 50, - }, - ValidatorInfo { - name: "unfun", - node: "3VTm54dw8w6jTTsPH4BfoV5vo6mF985JAMtNDRYcaGFc", // random pubkeys, same node - node_lamports: 1 * LAMPORTS_PER_SOL, - vote: "8XrFPRULg98kSm535kFaLV4GMnK5JQSuAymyrCHXsUcy", - commission: 50, - }, - ], - total_lamports, - 3, - ); - } - - #[test] - #[should_panic] - fn test_vote_collision() { - let rent = Rent { - lamports_per_byte_year: 1, - exemption_threshold: 1.0, - ..Rent::default() - }; - let mut genesis_config = GenesisConfig { - rent, - ..GenesisConfig::default() - }; - - create_and_check_validators( - &mut genesis_config, - &[ - ValidatorInfo { - name: "fun", - node: "3VTm54dw8w6jTTsPH4BfoV5vo6mF985JAMtNDRYcaGFc", // random pubkeys - node_lamports: 0, - vote: "GTKWbUoLw3Bv7Ld92crhyXcEk9zUu3VEKfzeuWJZdnfW", - commission: 50, - }, - ValidatorInfo { - name: "unfun", - node: "3VTm54dw8w6jTTsPH4BfoV5vo6mF985JAMtNDRYcaGFc", // random pubkeys, same node - node_lamports: 0, - vote: "GTKWbUoLw3Bv7Ld92crhyXcEk9zUu3VEKfzeuWJZdnfW", // duplicate vote, bad juju - commission: 50, - }, - ], - 0, - 0, + 1, ); } }