Skip to content

Commit d558879

Browse files
committed
rework sysvars to byte arrays and accessors
1 parent fa5db38 commit d558879

File tree

4 files changed

+13
-28
lines changed

4 files changed

+13
-28
lines changed

epoch-schedule/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ mod tests {
295295

296296
#[test]
297297
fn test_clone() {
298-
let epoch_schedule = EpochSchedule::custom(1, 2, true);
298+
let epoch_schedule = EpochSchedule::custom(MINIMUM_SLOTS_PER_EPOCH, MINIMUM_SLOTS_PER_EPOCH, true);
299299
#[allow(clippy::clone_on_copy)]
300300
let cloned_epoch_schedule = epoch_schedule.clone();
301301
assert_eq!(cloned_epoch_schedule, epoch_schedule);

genesis-config/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ impl fmt::Display for GenesisConfig {
244244
self.ticks_per_slot,
245245
self.poh_config.hashes_per_tick,
246246
self.poh_config.target_tick_duration,
247-
self.epoch_schedule.slots_per_epoch,
248-
if self.epoch_schedule.warmup {
247+
self.epoch_schedule.slots_per_epoch(),
248+
if self.epoch_schedule.warmup() {
249249
"en"
250250
} else {
251251
"dis"

rent/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ impl Default for Rent {
8181
}
8282

8383
impl Rent {
84-
/// Calculate how much rent to burn from the collected rent.
85-
///
86-
/// The first value returned is the amount burned. The second is the amount
87-
/// to distribute to validators.
8884
pub fn lamports_per_byte_year(&self) -> u64 {
8985
u64::from_le_bytes(self.lamports_per_byte_year)
9086
}
@@ -105,6 +101,10 @@ impl Rent {
105101
}
106102
}
107103

104+
/// Calculate how much rent to burn from the collected rent.
105+
///
106+
/// The first value returned is the amount burned. The second is the amount
107+
/// to distribute to validators.
108108
pub fn calculate_burn(&self, rent_collected: u64) -> (u64, u64) {
109109
let burned_portion = (rent_collected * u64::from(self.burn_percent)) / 100;
110110
(burned_portion, rent_collected - burned_portion)

sysvar/src/epoch_rewards.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,10 @@
4747
//! }
4848
//! #
4949
//! # use solana_sysvar_id::SysvarId;
50+
//! # use solana_hash::Hash;
5051
//! # let p = EpochRewards::id();
5152
//! # let l = &mut 1559040;
52-
//! # let epoch_rewards = EpochRewards {
53-
//! # distribution_starting_block_height: 42,
54-
//! # total_rewards: 100,
55-
//! # distributed_rewards: 10,
56-
//! # active: true,
57-
//! # ..EpochRewards::default()
58-
//! # };
53+
//! # let epoch_rewards = EpochRewards::new(42, 0, Hash::default(), 0, 100, 10, true);
5954
//! # let mut d: Vec<u8> = bincode::serialize(&epoch_rewards).unwrap();
6055
//! # let a = AccountInfo::new(&p, false, false, l, &mut d, &p, false);
6156
//! # let accounts = &[a.clone(), a];
@@ -95,15 +90,10 @@
9590
//! }
9691
//! #
9792
//! # use solana_sysvar_id::SysvarId;
93+
//! # use solana_hash::Hash;
9894
//! # let p = EpochRewards::id();
9995
//! # let l = &mut 1559040;
100-
//! # let epoch_rewards = EpochRewards {
101-
//! # distribution_starting_block_height: 42,
102-
//! # total_rewards: 100,
103-
//! # distributed_rewards: 10,
104-
//! # active: true,
105-
//! # ..EpochRewards::default()
106-
//! # };
96+
//! # let epoch_rewards = EpochRewards::new(42, 0, Hash::default(), 0, 100, 10, true);
10797
//! # let mut d: Vec<u8> = bincode::serialize(&epoch_rewards).unwrap();
10898
//! # let a = AccountInfo::new(&p, false, false, l, &mut d, &p, false);
10999
//! # let accounts = &[a.clone(), a];
@@ -127,13 +117,8 @@
127117
//! # use anyhow::Result;
128118
//! #
129119
//! fn print_sysvar_epoch_rewards(client: &RpcClient) -> Result<()> {
130-
//! # let epoch_rewards = EpochRewards {
131-
//! # distribution_starting_block_height: 42,
132-
//! # total_rewards: 100,
133-
//! # distributed_rewards: 10,
134-
//! # active: true,
135-
//! # ..EpochRewards::default()
136-
//! # };
120+
//! # use solana_hash::Hash;
121+
//! # let epoch_rewards = EpochRewards::new(42, 0, Hash::default(), 0, 100, 10, true);
137122
//! # let data: Vec<u8> = bincode::serialize(&epoch_rewards)?;
138123
//! # client.set_get_account_response(epoch_rewards::ID, Account {
139124
//! # lamports: 1120560,

0 commit comments

Comments
 (0)