Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/src/test_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use crate::{
validator::{Validator, ValidatorConfig},
};
use solana_ledger::create_new_tmp_ledger;
use solana_runtime::genesis_utils::{
bootstrap_validator_stake_lamports, BOOTSTRAP_VALIDATOR_LAMPORTS,
};
use solana_sdk::{
clock::DEFAULT_DEV_SLOTS_PER_EPOCH,
hash::Hash,
Expand All @@ -31,7 +34,6 @@ pub struct TestValidatorOptions {

impl Default for TestValidatorOptions {
fn default() -> Self {
use solana_ledger::genesis_utils::BOOTSTRAP_VALIDATOR_LAMPORTS;
TestValidatorOptions {
fees: 0,
bootstrap_validator_lamports: BOOTSTRAP_VALIDATOR_LAMPORTS,
Expand Down Expand Up @@ -94,7 +96,7 @@ impl TestValidator {
&contact_info.id,
&Keypair::new(),
&solana_sdk::pubkey::new_rand(),
42,
bootstrap_validator_stake_lamports(),
bootstrap_validator_lamports,
solana_sdk::genesis_config::ClusterType::Development,
);
Expand Down
6 changes: 3 additions & 3 deletions ledger/src/genesis_utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use solana_runtime::genesis_utils::{
create_genesis_config_with_leader, create_genesis_config_with_leader_ex, GenesisConfigInfo,
BOOTSTRAP_VALIDATOR_LAMPORTS,
bootstrap_validator_stake_lamports, create_genesis_config_with_leader,
create_genesis_config_with_leader_ex, GenesisConfigInfo,
};

// same as genesis_config::create_genesis_config, but with bootstrap_validator staking logic
Expand All @@ -9,6 +9,6 @@ pub fn create_genesis_config(mint_lamports: u64) -> GenesisConfigInfo {
create_genesis_config_with_leader(
mint_lamports,
&solana_sdk::pubkey::new_rand(),
BOOTSTRAP_VALIDATOR_LAMPORTS,
bootstrap_validator_stake_lamports(),
)
}
13 changes: 7 additions & 6 deletions ledger/src/leader_schedule_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,14 @@ mod tests {
use crate::{
blockstore::make_slot_entries,
genesis_utils::{
create_genesis_config, create_genesis_config_with_leader, GenesisConfigInfo,
BOOTSTRAP_VALIDATOR_LAMPORTS,
bootstrap_validator_stake_lamports, create_genesis_config,
create_genesis_config_with_leader, GenesisConfigInfo,
},
get_tmp_ledger_path,
staking_utils::tests::setup_vote_and_stake_accounts,
};
use solana_runtime::bank::Bank;
use solana_runtime::genesis_utils::BOOTSTRAP_VALIDATOR_LAMPORTS;
use solana_sdk::clock::NUM_CONSECUTIVE_LEADER_SLOTS;
use solana_sdk::epoch_schedule::{
EpochSchedule, DEFAULT_LEADER_SCHEDULE_SLOT_OFFSET, DEFAULT_SLOTS_PER_EPOCH,
Expand Down Expand Up @@ -382,7 +383,7 @@ mod tests {
let mut genesis_config = create_genesis_config_with_leader(
BOOTSTRAP_VALIDATOR_LAMPORTS,
&pubkey,
BOOTSTRAP_VALIDATOR_LAMPORTS,
bootstrap_validator_stake_lamports(),
)
.genesis_config;
genesis_config.epoch_schedule = EpochSchedule::custom(
Expand Down Expand Up @@ -435,7 +436,7 @@ mod tests {
let mut genesis_config = create_genesis_config_with_leader(
BOOTSTRAP_VALIDATOR_LAMPORTS,
&pubkey,
BOOTSTRAP_VALIDATOR_LAMPORTS,
bootstrap_validator_stake_lamports(),
)
.genesis_config;
genesis_config.epoch_schedule.warmup = false;
Expand Down Expand Up @@ -519,7 +520,7 @@ mod tests {
mut genesis_config,
mint_keypair,
..
} = create_genesis_config(10_000);
} = create_genesis_config(10_000 * bootstrap_validator_stake_lamports());
genesis_config.epoch_schedule.warmup = false;

let bank = Bank::new(&genesis_config);
Expand All @@ -533,7 +534,7 @@ mod tests {
&mint_keypair,
&vote_account,
&validator_identity,
BOOTSTRAP_VALIDATOR_LAMPORTS,
bootstrap_validator_stake_lamports(),
);
let node_pubkey = validator_identity.pubkey();

Expand Down
7 changes: 4 additions & 3 deletions ledger/src/leader_schedule_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ fn sort_stakes(stakes: &mut Vec<(Pubkey, u64)>) {
mod tests {
use super::*;
use solana_runtime::genesis_utils::{
create_genesis_config_with_leader, BOOTSTRAP_VALIDATOR_LAMPORTS,
bootstrap_validator_stake_lamports, create_genesis_config_with_leader,
BOOTSTRAP_VALIDATOR_LAMPORTS,
};

#[test]
fn test_leader_schedule_via_bank() {
let pubkey = solana_sdk::pubkey::new_rand();
let genesis_config =
create_genesis_config_with_leader(0, &pubkey, BOOTSTRAP_VALIDATOR_LAMPORTS)
create_genesis_config_with_leader(0, &pubkey, bootstrap_validator_stake_lamports())
.genesis_config;
let bank = Bank::new(&genesis_config);

Expand All @@ -86,7 +87,7 @@ mod tests {
let genesis_config = create_genesis_config_with_leader(
BOOTSTRAP_VALIDATOR_LAMPORTS,
&pubkey,
BOOTSTRAP_VALIDATOR_LAMPORTS,
bootstrap_validator_stake_lamports(),
)
.genesis_config;
let bank = Bank::new(&genesis_config);
Expand Down
8 changes: 4 additions & 4 deletions ledger/src/staking_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ where
pub(crate) mod tests {
use super::*;
use crate::genesis_utils::{
create_genesis_config, GenesisConfigInfo, BOOTSTRAP_VALIDATOR_LAMPORTS,
bootstrap_validator_stake_lamports, create_genesis_config, GenesisConfigInfo,
};
use solana_sdk::{
account::from_account,
Expand Down Expand Up @@ -178,10 +178,10 @@ pub(crate) mod tests {
#[test]
fn test_epoch_stakes_and_lockouts() {
solana_logger::setup();
let stake = BOOTSTRAP_VALIDATOR_LAMPORTS * 100;
let stake = bootstrap_validator_stake_lamports();
let leader_stake = Stake {
delegation: Delegation {
stake: BOOTSTRAP_VALIDATOR_LAMPORTS,
stake: bootstrap_validator_stake_lamports(),
activation_epoch: std::u64::MAX, // mark as bootstrap
..Delegation::default()
},
Expand All @@ -194,7 +194,7 @@ pub(crate) mod tests {
genesis_config,
mint_keypair,
..
} = create_genesis_config(10_000);
} = create_genesis_config(10_000 * bootstrap_validator_stake_lamports());

let bank = Bank::new(&genesis_config);
let vote_account = Keypair::new();
Expand Down
12 changes: 6 additions & 6 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4357,9 +4357,9 @@ pub(crate) mod tests {
use crate::{
accounts_index::{AccountMap, Ancestors, ITER_BATCH_SIZE},
genesis_utils::{
activate_all_features, create_genesis_config_with_leader,
create_genesis_config_with_vote_accounts, GenesisConfigInfo, ValidatorVoteKeypairs,
BOOTSTRAP_VALIDATOR_LAMPORTS,
activate_all_features, bootstrap_validator_stake_lamports,
create_genesis_config_with_leader, create_genesis_config_with_vote_accounts,
GenesisConfigInfo, ValidatorVoteKeypairs,
},
native_loader::NativeLoaderError,
status_cache::MAX_CACHE_ENTRIES,
Expand Down Expand Up @@ -4427,7 +4427,7 @@ pub(crate) mod tests {
#[allow(clippy::float_cmp)]
fn test_bank_new() {
let dummy_leader_pubkey = solana_sdk::pubkey::new_rand();
let dummy_leader_lamports = BOOTSTRAP_VALIDATOR_LAMPORTS;
let dummy_leader_stake_lamports = bootstrap_validator_stake_lamports();
let mint_lamports = 10_000;
let GenesisConfigInfo {
mut genesis_config,
Expand All @@ -4437,7 +4437,7 @@ pub(crate) mod tests {
} = create_genesis_config_with_leader(
mint_lamports,
&dummy_leader_pubkey,
dummy_leader_lamports,
dummy_leader_stake_lamports,
);

genesis_config.rent = Rent {
Expand All @@ -4450,7 +4450,7 @@ pub(crate) mod tests {
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), mint_lamports);
assert_eq!(
bank.get_balance(&voting_keypair.pubkey()),
dummy_leader_lamports /* 1 token goes to the vote account associated with dummy_leader_lamports */
dummy_leader_stake_lamports /* 1 token goes to the vote account associated with dummy_leader_lamports */
);

let rent_account = bank.get_account(&sysvar::rent::id()).unwrap();
Expand Down
6 changes: 6 additions & 0 deletions runtime/src/genesis_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ use solana_sdk::{
system_program,
};
use solana_stake_program::stake_state;
use solana_stake_program::stake_state::StakeState;
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;

// fun fact: rustc is very close to make this const fn.
pub fn bootstrap_validator_stake_lamports() -> u64 {
StakeState::get_rent_exempt_reserve(&Rent::default())
}

pub struct ValidatorVoteKeypairs {
pub node_keypair: Keypair,
pub vote_keypair: Keypair,
Expand Down