Skip to content
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
4 changes: 2 additions & 2 deletions programs/stake/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ pub fn create_account(lamports: u64, config: &Config) -> AccountSharedData {
#[allow(deprecated)]
pub fn add_genesis_account(genesis_config: &mut GenesisConfig) -> u64 {
let mut account = create_config_account(vec![], &Config::default(), 0);
let lamports = genesis_config.rent.minimum_balance(account.data().len());
let lamports = std::cmp::max(genesis_config.rent.minimum_balance(account.data().len()), 1);

account.set_lamports(lamports.max(1));
account.set_lamports(lamports);

genesis_config.add_account(solana_stake_interface::config::id(), account);

Expand Down
21 changes: 21 additions & 0 deletions programs/stake/src/epoch_rewards.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Creates the initial empty EpochRewards sysvar
use {
solana_account::{AccountSharedData, WritableAccount},
solana_genesis_config::GenesisConfig,
solana_sdk_ids::sysvar,
solana_sysvar::{
epoch_rewards::{self, EpochRewards},
Sysvar,
},
};

pub fn add_genesis_account(genesis_config: &mut GenesisConfig) -> u64 {
let data = vec![0; EpochRewards::size_of()];
let lamports = std::cmp::max(genesis_config.rent.minimum_balance(data.len()), 1);

let account = AccountSharedData::create(lamports, data, sysvar::id(), false, u64::MAX);

genesis_config.add_account(epoch_rewards::id(), account);

lamports
}
5 changes: 4 additions & 1 deletion programs/stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ pub use solana_sdk_ids::stake::{check_id, id};
use {solana_genesis_config::GenesisConfig, solana_native_token::LAMPORTS_PER_SOL};

pub mod config;
pub mod epoch_rewards;
#[deprecated(since = "2.2.0")]
pub mod points;
pub mod stake_instruction;
pub mod stake_state;

pub fn add_genesis_accounts(genesis_config: &mut GenesisConfig) -> u64 {
config::add_genesis_account(genesis_config)
let config_lamports = config::add_genesis_account(genesis_config);
let rewards_lamports = epoch_rewards::add_genesis_account(genesis_config);
config_lamports.saturating_add(rewards_lamports)
}

/// The minimum stake amount that can be delegated, in lamports.
Expand Down
11 changes: 1 addition & 10 deletions runtime/src/bank/partitioned_epoch_rewards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,7 @@ mod tests {
);

assert!(curr_bank.is_calculated());

if slot == SLOTS_PER_EPOCH {
// cap should increase because of new epoch rewards
assert!(post_cap > pre_cap);
} else {
assert_eq!(post_cap, pre_cap);
}
Comment on lines -615 to -620

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! It's great to get rid of these hacks

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it.

assert_eq!(post_cap, pre_cap);
} else if slot == SLOTS_PER_EPOCH + 1 {
// 1. when curr_slot == SLOTS_PER_EPOCH + 1, the 2nd block of
// epoch 1, reward distribution should happen in this block.
Expand Down Expand Up @@ -694,9 +688,6 @@ mod tests {

// calculation block, state should be calculated.
assert!(curr_bank.is_calculated());

// cap should increase because of new epoch rewards
assert!(post_cap > pre_cap);
} else if slot == SLOTS_PER_EPOCH + 1 {
// When curr_slot == SLOTS_PER_EPOCH + 1, the 2nd block of
// epoch 1, reward distribution should happen in this block. The
Expand Down
Loading