add partitioned rewards sysvar fns (#32128)
This commit is contained in:
parent
ae65b35d9b
commit
00b5c40122
|
@ -3934,6 +3934,72 @@ impl Bank {
|
|||
.test_enable_partitioned_rewards
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Helper fn to log epoch_rewards sysvar
|
||||
fn log_epoch_rewards_sysvar(&self, prefix: &str) {
|
||||
if let Some(account) = self.get_account(&sysvar::epoch_rewards::id()) {
|
||||
let epoch_rewards: sysvar::epoch_rewards::EpochRewards =
|
||||
from_account(&account).unwrap();
|
||||
info!(
|
||||
"{prefix} epoch_rewards sysvar: {:?}",
|
||||
(account.lamports(), epoch_rewards)
|
||||
);
|
||||
} else {
|
||||
info!("{prefix} epoch_rewards sysvar: none");
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Create EpochRewards syavar with calculated rewards
|
||||
fn create_epoch_rewards_sysvar(
|
||||
&self,
|
||||
total_rewards: u64,
|
||||
distributed_rewards: u64,
|
||||
distribution_complete_block_height: u64,
|
||||
) {
|
||||
assert!(self.is_partitioned_rewards_code_enabled());
|
||||
|
||||
let epoch_rewards = sysvar::epoch_rewards::EpochRewards {
|
||||
total_rewards,
|
||||
distributed_rewards,
|
||||
distribution_complete_block_height,
|
||||
};
|
||||
|
||||
self.update_sysvar_account(&sysvar::epoch_rewards::id(), |account| {
|
||||
let mut inherited_account_fields =
|
||||
self.inherit_specially_retained_account_fields(account);
|
||||
|
||||
assert!(total_rewards >= distributed_rewards);
|
||||
// set the account lamports to the undistributed rewards
|
||||
inherited_account_fields.0 = total_rewards - distributed_rewards;
|
||||
create_account(&epoch_rewards, inherited_account_fields)
|
||||
});
|
||||
|
||||
self.log_epoch_rewards_sysvar("create");
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Update EpochRewards sysvar with distributed rewards
|
||||
fn update_epoch_rewards_sysvar(&self, distributed: u64) {
|
||||
assert!(self.is_partitioned_rewards_code_enabled());
|
||||
|
||||
let mut epoch_rewards: sysvar::epoch_rewards::EpochRewards =
|
||||
from_account(&self.get_account(&sysvar::epoch_rewards::id()).unwrap()).unwrap();
|
||||
epoch_rewards.distribute(distributed);
|
||||
|
||||
self.update_sysvar_account(&sysvar::epoch_rewards::id(), |account| {
|
||||
let mut inherited_account_fields =
|
||||
self.inherit_specially_retained_account_fields(account);
|
||||
|
||||
let lamports = inherited_account_fields.0;
|
||||
assert!(lamports >= distributed);
|
||||
inherited_account_fields.0 = lamports - distributed;
|
||||
create_account(&epoch_rewards, inherited_account_fields)
|
||||
});
|
||||
|
||||
self.log_epoch_rewards_sysvar("update");
|
||||
}
|
||||
|
||||
fn update_recent_blockhashes_locked(&self, locked_blockhash_queue: &BlockhashQueue) {
|
||||
#[allow(deprecated)]
|
||||
self.update_sysvar_account(&sysvar::recent_blockhashes::id(), |account| {
|
||||
|
|
Loading…
Reference in New Issue