Speed up local cluster partitioning tests (#11177)
* Fix long local cluster partition tests by skipping slot warmup Co-authored-by: Carl <carl@solana.com>
This commit is contained in:
@ -2,15 +2,12 @@ use crate::{
|
||||
bank::Bank,
|
||||
genesis_utils::{self, GenesisConfigInfo, ValidatorVoteKeypairs},
|
||||
};
|
||||
use solana_sdk::{
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
};
|
||||
use solana_sdk::{pubkey::Pubkey, signature::Signer};
|
||||
|
||||
pub fn setup_bank_and_vote_pubkeys(num_vote_accounts: usize, stake: u64) -> (Bank, Vec<Pubkey>) {
|
||||
// Create some voters at genesis
|
||||
let validator_voting_keypairs: Vec<_> = (0..num_vote_accounts)
|
||||
.map(|_| ValidatorVoteKeypairs::new(Keypair::new(), Keypair::new(), Keypair::new()))
|
||||
.map(|_| ValidatorVoteKeypairs::new_rand())
|
||||
.collect();
|
||||
|
||||
let vote_pubkeys: Vec<_> = validator_voting_keypairs
|
||||
@ -21,7 +18,7 @@ pub fn setup_bank_and_vote_pubkeys(num_vote_accounts: usize, stake: u64) -> (Ban
|
||||
genesis_utils::create_genesis_config_with_vote_accounts(
|
||||
10_000,
|
||||
&validator_voting_keypairs,
|
||||
stake,
|
||||
vec![stake; validator_voting_keypairs.len()],
|
||||
);
|
||||
let bank = Bank::new(&genesis_config);
|
||||
(bank, vote_pubkeys)
|
||||
|
@ -9,19 +9,23 @@ use solana_sdk::{
|
||||
};
|
||||
use solana_stake_program::stake_state;
|
||||
use solana_vote_program::vote_state;
|
||||
use std::borrow::Borrow;
|
||||
use std::{borrow::Borrow, sync::Arc};
|
||||
|
||||
// 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,
|
||||
pub node_keypair: Arc<Keypair>,
|
||||
pub vote_keypair: Arc<Keypair>,
|
||||
pub stake_keypair: Arc<Keypair>,
|
||||
}
|
||||
|
||||
impl ValidatorVoteKeypairs {
|
||||
pub fn new(node_keypair: Keypair, vote_keypair: Keypair, stake_keypair: Keypair) -> Self {
|
||||
pub fn new(
|
||||
node_keypair: Arc<Keypair>,
|
||||
vote_keypair: Arc<Keypair>,
|
||||
stake_keypair: Arc<Keypair>,
|
||||
) -> Self {
|
||||
Self {
|
||||
node_keypair,
|
||||
vote_keypair,
|
||||
@ -31,9 +35,9 @@ impl ValidatorVoteKeypairs {
|
||||
|
||||
pub fn new_rand() -> Self {
|
||||
Self {
|
||||
node_keypair: Keypair::new(),
|
||||
vote_keypair: Keypair::new(),
|
||||
stake_keypair: Keypair::new(),
|
||||
node_keypair: Arc::new(Keypair::new()),
|
||||
vote_keypair: Arc::new(Keypair::new()),
|
||||
stake_keypair: Arc::new(Keypair::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -41,7 +45,7 @@ impl ValidatorVoteKeypairs {
|
||||
pub struct GenesisConfigInfo {
|
||||
pub genesis_config: GenesisConfig,
|
||||
pub mint_keypair: Keypair,
|
||||
pub voting_keypair: Keypair,
|
||||
pub voting_keypair: Arc<Keypair>,
|
||||
}
|
||||
|
||||
pub fn create_genesis_config(mint_lamports: u64) -> GenesisConfigInfo {
|
||||
@ -51,15 +55,26 @@ pub fn create_genesis_config(mint_lamports: u64) -> GenesisConfigInfo {
|
||||
pub fn create_genesis_config_with_vote_accounts(
|
||||
mint_lamports: u64,
|
||||
voting_keypairs: &[impl Borrow<ValidatorVoteKeypairs>],
|
||||
stake: u64,
|
||||
stakes: Vec<u64>,
|
||||
) -> GenesisConfigInfo {
|
||||
let mut genesis_config_info = create_genesis_config(mint_lamports);
|
||||
for validator_voting_keypairs in voting_keypairs {
|
||||
assert_eq!(voting_keypairs.len(), stakes.len());
|
||||
|
||||
let mut genesis_config_info = create_genesis_config_with_leader_ex(
|
||||
mint_lamports,
|
||||
&voting_keypairs[0].borrow().node_keypair.pubkey(),
|
||||
voting_keypairs[0].borrow().vote_keypair.clone(),
|
||||
voting_keypairs[0].borrow().stake_keypair.clone(),
|
||||
stakes[0],
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
);
|
||||
|
||||
for (validator_voting_keypairs, stake) in voting_keypairs.iter().zip(stakes) {
|
||||
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 node_account = Account::new(BOOTSTRAP_VALIDATOR_LAMPORTS, 0, &system_program::id());
|
||||
let vote_account = vote_state::create_account(&vote_pubkey, &node_pubkey, 0, stake);
|
||||
let stake_account = stake_state::create_account(
|
||||
&stake_pubkey,
|
||||
@ -71,7 +86,8 @@ pub fn create_genesis_config_with_vote_accounts(
|
||||
|
||||
// Put newly created accounts into genesis
|
||||
genesis_config_info.genesis_config.accounts.extend(vec![
|
||||
(vote_pubkey, vote_account.clone()),
|
||||
(node_pubkey, node_account),
|
||||
(vote_pubkey, vote_account),
|
||||
(stake_pubkey, stake_account),
|
||||
]);
|
||||
}
|
||||
@ -87,6 +103,8 @@ pub fn create_genesis_config_with_leader(
|
||||
create_genesis_config_with_leader_ex(
|
||||
mint_lamports,
|
||||
bootstrap_validator_pubkey,
|
||||
Arc::new(Keypair::new()),
|
||||
Arc::new(Keypair::new()),
|
||||
bootstrap_validator_stake_lamports,
|
||||
BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||
)
|
||||
@ -95,13 +113,12 @@ pub fn create_genesis_config_with_leader(
|
||||
pub fn create_genesis_config_with_leader_ex(
|
||||
mint_lamports: u64,
|
||||
bootstrap_validator_pubkey: &Pubkey,
|
||||
bootstrap_validator_voting_keypair: Arc<Keypair>,
|
||||
bootstrap_validator_staking_keypair: Arc<Keypair>,
|
||||
bootstrap_validator_stake_lamports: u64,
|
||||
bootstrap_validator_lamports: u64,
|
||||
) -> GenesisConfigInfo {
|
||||
let mint_keypair = Keypair::new();
|
||||
let bootstrap_validator_voting_keypair = Keypair::new();
|
||||
let bootstrap_validator_staking_keypair = Keypair::new();
|
||||
|
||||
let bootstrap_validator_vote_account = vote_state::create_account(
|
||||
&bootstrap_validator_voting_keypair.pubkey(),
|
||||
&bootstrap_validator_pubkey,
|
||||
|
Reference in New Issue
Block a user