Remove vote account from genesis validators
This commit is contained in:
		| @@ -202,72 +202,52 @@ pub const VALIDATOR_INFOS: &[ValidatorInfo] = &[ | |||||||
|     ValidatorInfo { |     ValidatorInfo { | ||||||
|         name: "01Node", |         name: "01Node", | ||||||
|         node: "5n8KCdzqtvTnhkvCrFR7errH6ZUp11kL97r2awXkfzFe", |         node: "5n8KCdzqtvTnhkvCrFR7errH6ZUp11kL97r2awXkfzFe", | ||||||
|         vote: "4uYMbY5Ae5ZSRNxQ3RWVyXS9rzW7E3AMZYHuUEotxu6K", |  | ||||||
|         node_lamports: 500 * LAMPORTS_PER_SOL, |         node_lamports: 500 * LAMPORTS_PER_SOL, | ||||||
|         commission: 0, |  | ||||||
|     }, |     }, | ||||||
|     ValidatorInfo { |     ValidatorInfo { | ||||||
|         name: "Bison Trails", |         name: "Bison Trails", | ||||||
|         node: "7suRNpX7bJsXphHJtBv4ZsLjJZ1dTGeX256pLqJZdEAm", |         node: "7suRNpX7bJsXphHJtBv4ZsLjJZ1dTGeX256pLqJZdEAm", | ||||||
|         vote: "DfirEZ9Up1xbE7sQji9UwtcRGe5uCcRqQtnaGpha5KNY", |  | ||||||
|         node_lamports: 500 * LAMPORTS_PER_SOL, |         node_lamports: 500 * LAMPORTS_PER_SOL, | ||||||
|         commission: 0, |  | ||||||
|     }, |     }, | ||||||
|     ValidatorInfo { |     ValidatorInfo { | ||||||
|         name: "ChainFlow", |         name: "ChainFlow", | ||||||
|         node: "2te46rxywMdCNdkvjumiBBPQoVczJFxhxEaxFavQNqe3", |         node: "2te46rxywMdCNdkvjumiBBPQoVczJFxhxEaxFavQNqe3", | ||||||
|         vote: "8bRCnytB7bySmqxodNGbZuUAtncKkB8T733DD1Dm9WMb", |  | ||||||
|         node_lamports: 500 * LAMPORTS_PER_SOL, |         node_lamports: 500 * LAMPORTS_PER_SOL, | ||||||
|         commission: 0, |  | ||||||
|     }, |     }, | ||||||
|     ValidatorInfo { |     ValidatorInfo { | ||||||
|         name: "ChorusOne", |         name: "ChorusOne", | ||||||
|         node: "ChorusXqjLC2NbiStKR6k9WoD7wu6TVTtFG8qCL5XBVa", |         node: "ChorusXqjLC2NbiStKR6k9WoD7wu6TVTtFG8qCL5XBVa", | ||||||
|         vote: "ChorusvBuPwukqgDvYfWtEg8j4T1NcMgSTQ4b1UbAwgQ", |  | ||||||
|         node_lamports: 500 * LAMPORTS_PER_SOL, |         node_lamports: 500 * LAMPORTS_PER_SOL, | ||||||
|         commission: 0, |  | ||||||
|     }, |     }, | ||||||
|     ValidatorInfo { |     ValidatorInfo { | ||||||
|         name: "Dokia Capital", |         name: "Dokia Capital", | ||||||
|         node: "GeZ5PrJi9muVCJiJAaFBNGoCEdxGEqTp7L2BmT2WTTy1", |         node: "GeZ5PrJi9muVCJiJAaFBNGoCEdxGEqTp7L2BmT2WTTy1", | ||||||
|         vote: "7ZdRx2EBYoRuPfyeoNbuHodMUXcAQRcC37MUw3kP6akn", |  | ||||||
|         node_lamports: 500 * LAMPORTS_PER_SOL, |         node_lamports: 500 * LAMPORTS_PER_SOL, | ||||||
|         commission: 0, |  | ||||||
|     }, |     }, | ||||||
|     ValidatorInfo { |     ValidatorInfo { | ||||||
|         name: "Forbole", |         name: "Forbole", | ||||||
|         node: "Fe5sLQAAT7RBT8mcH1AAGCbExJQcYxcwXvp1GjrGbvxs", |         node: "Fe5sLQAAT7RBT8mcH1AAGCbExJQcYxcwXvp1GjrGbvxs", | ||||||
|         vote: "Dr8MkZZuvZVQJFKtjShZYEfg6n93sc1GxevqLnGss7FW", |  | ||||||
|         node_lamports: 500 * LAMPORTS_PER_SOL, |         node_lamports: 500 * LAMPORTS_PER_SOL, | ||||||
|         commission: 0, |  | ||||||
|     }, |     }, | ||||||
|     ValidatorInfo { |     ValidatorInfo { | ||||||
|         name: "P2P.ORG - Secure Non-custodial Staking", |         name: "P2P.ORG - Secure Non-custodial Staking", | ||||||
|         node: "44e8VyWoyZSE2oYHxMHMedAiHkGJqJgPd3tdt6iKoAFL", |         node: "44e8VyWoyZSE2oYHxMHMedAiHkGJqJgPd3tdt6iKoAFL", | ||||||
|         vote: "BwwpzEpo1wzgV9N1987ntgNG6jLt3C9532C68pswT7Gp", |  | ||||||
|         node_lamports: 500 * LAMPORTS_PER_SOL, |         node_lamports: 500 * LAMPORTS_PER_SOL, | ||||||
|         commission: 0, |  | ||||||
|     }, |     }, | ||||||
|     ValidatorInfo { |     ValidatorInfo { | ||||||
|         name: "RockX", |         name: "RockX", | ||||||
|         node: "Ez4iUU87ViJLCnmSy1t1Ti3DLoysFXiBseNfnRfoehyY", |         node: "Ez4iUU87ViJLCnmSy1t1Ti3DLoysFXiBseNfnRfoehyY", | ||||||
|         vote: "GUdGALCHQBeqkNc2ZAht3tBXab1N5u9qJC3PAzpL54r7", |  | ||||||
|         node_lamports: 500 * LAMPORTS_PER_SOL, |         node_lamports: 500 * LAMPORTS_PER_SOL, | ||||||
|         commission: 0, |  | ||||||
|     }, |     }, | ||||||
|     ValidatorInfo { |     ValidatorInfo { | ||||||
|         name: "Stake Capital", |         name: "Stake Capital", | ||||||
|         node: "HavuVVDXXsJqMzPwQ4KcF5kFm2xqjbChhyi1bgGeCQif", |         node: "HavuVVDXXsJqMzPwQ4KcF5kFm2xqjbChhyi1bgGeCQif", | ||||||
|         vote: "HswPkKj1xoLLmpM8t1vy5Pbi8zYYUs9ZawswvofKsFo1", |  | ||||||
|         node_lamports: 500 * LAMPORTS_PER_SOL, |         node_lamports: 500 * LAMPORTS_PER_SOL, | ||||||
|         commission: 0, |  | ||||||
|     }, |     }, | ||||||
|     ValidatorInfo { |     ValidatorInfo { | ||||||
|         name: "Staking Facilities", |         name: "Staking Facilities", | ||||||
|         node: "pbAxyqHHPMwgEjv8kmjGxysk9rhNtN7q22eAjReq6Hj", |         node: "pbAxyqHHPMwgEjv8kmjGxysk9rhNtN7q22eAjReq6Hj", | ||||||
|         vote: "4VZ3pJX19PpuGjoSB1qeN9sVQfrqgLVNg16is37adiFp", |  | ||||||
|         node_lamports: 500 * LAMPORTS_PER_SOL, |         node_lamports: 500 * LAMPORTS_PER_SOL, | ||||||
|         commission: 0, |  | ||||||
|     }, |     }, | ||||||
| ]; | ]; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3,15 +3,12 @@ use solana_sdk::{ | |||||||
|     account::Account, genesis_config::GenesisConfig, pubkey::Pubkey, system_program, |     account::Account, genesis_config::GenesisConfig, pubkey::Pubkey, system_program, | ||||||
|     timing::years_as_slots, |     timing::years_as_slots, | ||||||
| }; | }; | ||||||
| use solana_vote_program::vote_state::{self, VoteState}; |  | ||||||
|  |  | ||||||
| #[derive(Debug)] | #[derive(Debug)] | ||||||
| pub struct ValidatorInfo { | pub struct ValidatorInfo { | ||||||
|     pub name: &'static str, |     pub name: &'static str, | ||||||
|     pub node: &'static str, |     pub node: &'static str, | ||||||
|     pub node_lamports: u64, |     pub node_lamports: u64, | ||||||
|     pub vote: &'static str, |  | ||||||
|     pub commission: u8, |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // the node's account needs carry enough | // the node's account needs carry enough | ||||||
| @@ -26,22 +23,19 @@ fn calculate_voting_fees(genesis_config: &GenesisConfig, years: f64) -> u64 { | |||||||
|         ) as 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( | pub fn create_and_add_validator( | ||||||
|     genesis_config: &mut GenesisConfig, |     genesis_config: &mut GenesisConfig, | ||||||
|     // information about this validator |     // information about this validator | ||||||
|     validator_info: &ValidatorInfo, |     validator_info: &ValidatorInfo, | ||||||
| ) -> u64 { | ) -> u64 { | ||||||
|     let node: Pubkey = validator_info.node.parse().expect("invalid node"); |     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 |     // 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_rent_reserve = genesis_config.rent.minimum_balance(0).max(1); | ||||||
|     let node_voting_fees = calculate_voting_fees(genesis_config, 1.0); |     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 + validator_info.node_lamports; | ||||||
|  |  | ||||||
|     let mut total_lamports = node_voting_fees + vote_rent_reserve + validator_info.node_lamports; |  | ||||||
|  |  | ||||||
|     genesis_config |     genesis_config | ||||||
|         .accounts |         .accounts | ||||||
| @@ -52,24 +46,13 @@ pub fn create_and_add_validator( | |||||||
|         }) |         }) | ||||||
|         .lamports += node_voting_fees + validator_info.node_lamports; |         .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 |     total_lamports | ||||||
| } | } | ||||||
|  |  | ||||||
| #[cfg(test)] | #[cfg(test)] | ||||||
| mod tests { | mod tests { | ||||||
|     use super::*; |     use super::*; | ||||||
|     use solana_sdk::{native_token::LAMPORTS_PER_SOL, rent::Rent}; |     use solana_sdk::rent::Rent; | ||||||
|  |  | ||||||
|     fn create_and_check_validators( |     fn create_and_check_validators( | ||||||
|         genesis_config: &mut GenesisConfig, |         genesis_config: &mut GenesisConfig, | ||||||
| @@ -112,97 +95,17 @@ mod tests { | |||||||
|             ..GenesisConfig::default() |             ..GenesisConfig::default() | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|         let total_lamports = VoteState::get_rent_exempt_reserve(&rent) |         let total_lamports = calculate_voting_fees(&genesis_config, 1.0) + rent.minimum_balance(0); | ||||||
|             + calculate_voting_fees(&genesis_config, 1.0) |  | ||||||
|             + rent.minimum_balance(0); |  | ||||||
|  |  | ||||||
|         create_and_check_validators( |         create_and_check_validators( | ||||||
|             &mut genesis_config, |             &mut genesis_config, | ||||||
|             &[ValidatorInfo { |             &[ValidatorInfo { | ||||||
|                 name: "fun", |                 name: "fun", | ||||||
|                 node: "AiTDdNHW2vNtHt7PqWMHx3B8cMPRDNgc7kMiLPJM25QC", // random pubkeys |                 node: "AiTDdNHW2vNtHt7PqWMHx3B8cMPRDNgc7kMiLPJM25QC", // random pubkey | ||||||
|                 node_lamports: 0, |                 node_lamports: 0, | ||||||
|                 vote: "77TQYZTHodhnxJcSuVjUvx8GYRCkykPyHtmFTFLjj1Rc", |  | ||||||
|                 commission: 50, |  | ||||||
|             }], |             }], | ||||||
|             total_lamports, |             total_lamports, | ||||||
|             2, |             1, | ||||||
|         ); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     #[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, |  | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user