Skip to content

Commit b2c4dd2

Browse files
committed
backward compatible new, burn check, bool >1 handling for active
1 parent 77a7601 commit b2c4dd2

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

epoch-rewards/src/lib.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,23 @@ impl EpochRewards {
8080
}
8181

8282
pub fn active(&self) -> bool {
83-
self.active != 0
83+
match self.active {
84+
0 => false,
85+
1 => true,
86+
_ => panic!("invalid active value"),
87+
}
8488
}
8589

8690
pub fn new(
87-
distribution_starting_block_height: u64,
88-
num_partitions: u64,
89-
parent_blockhash: Hash,
90-
total_points: u128,
9191
total_rewards: u64,
9292
distributed_rewards: u64,
93-
active: bool,
93+
distribution_starting_block_height: u64,
9494
) -> Self {
9595
Self {
9696
distribution_starting_block_height: distribution_starting_block_height.to_le_bytes(),
97-
num_partitions: num_partitions.to_le_bytes(),
98-
parent_blockhash,
99-
total_points: total_points.to_le_bytes(),
10097
total_rewards: total_rewards.to_le_bytes(),
10198
distributed_rewards: distributed_rewards.to_le_bytes(),
102-
active: active as u8,
99+
..Self::default()
103100
}
104101
}
105102

@@ -116,7 +113,7 @@ mod tests {
116113

117114
#[test]
118115
fn test_epoch_rewards_distribute() {
119-
let mut epoch_rewards = EpochRewards::new(64, 0, Hash::default(), 0, 100, 0, false);
116+
let mut epoch_rewards = EpochRewards::new(100, 0, 64);
120117
epoch_rewards.distribute(100);
121118

122119
assert_eq!(epoch_rewards.total_rewards(), 100);
@@ -126,7 +123,7 @@ mod tests {
126123
#[test]
127124
#[should_panic(expected = "new_distributed_rewards <= self.total_rewards")]
128125
fn test_epoch_rewards_distribute_panic() {
129-
let mut epoch_rewards = EpochRewards::new(64, 0, Hash::default(), 0, 100, 0, false);
126+
let mut epoch_rewards = EpochRewards::new(100, 0, 64);
130127
epoch_rewards.distribute(200);
131128
}
132129
}

rent/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,16 @@ impl Rent {
9393
self.burn_percent
9494
}
9595

96+
/// Creates a new `Rent` with the given parameters.
97+
///
98+
/// # Panics
99+
///
100+
/// Panics if `burn_percent` is not in the range [0, 100].
96101
pub fn new(lamports_per_byte_year: u64, exemption_threshold: f64, burn_percent: u8) -> Self {
102+
assert!(
103+
burn_percent <= 100,
104+
"burn_percent must be in range [0, 100]"
105+
);
97106
Self {
98107
lamports_per_byte_year: lamports_per_byte_year.to_le_bytes(),
99108
exemption_threshold: exemption_threshold.to_le_bytes(),

sysvar/src/epoch_rewards.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@
4747
//! }
4848
//! #
4949
//! # use solana_sysvar_id::SysvarId;
50-
//! # use solana_hash::Hash;
5150
//! # let p = EpochRewards::id();
5251
//! # let l = &mut 1559040;
53-
//! # let epoch_rewards = EpochRewards::new(42, 0, Hash::default(), 0, 100, 10, true);
52+
//! # let epoch_rewards = EpochRewards::new(100, 10, 42);
5453
//! # let mut d: Vec<u8> = bincode::serialize(&epoch_rewards).unwrap();
5554
//! # let a = AccountInfo::new(&p, false, false, l, &mut d, &p, false);
5655
//! # let accounts = &[a.clone(), a];
@@ -90,10 +89,9 @@
9089
//! }
9190
//! #
9291
//! # use solana_sysvar_id::SysvarId;
93-
//! # use solana_hash::Hash;
9492
//! # let p = EpochRewards::id();
9593
//! # let l = &mut 1559040;
96-
//! # let epoch_rewards = EpochRewards::new(42, 0, Hash::default(), 0, 100, 10, true);
94+
//! # let epoch_rewards = EpochRewards::new(100, 10, 42);
9795
//! # let mut d: Vec<u8> = bincode::serialize(&epoch_rewards).unwrap();
9896
//! # let a = AccountInfo::new(&p, false, false, l, &mut d, &p, false);
9997
//! # let accounts = &[a.clone(), a];
@@ -117,8 +115,7 @@
117115
//! # use anyhow::Result;
118116
//! #
119117
//! fn print_sysvar_epoch_rewards(client: &RpcClient) -> Result<()> {
120-
//! # use solana_hash::Hash;
121-
//! # let epoch_rewards = EpochRewards::new(42, 0, Hash::default(), 0, 100, 10, true);
118+
//! # let epoch_rewards = EpochRewards::new(100, 10, 42);
122119
//! # let data: Vec<u8> = bincode::serialize(&epoch_rewards)?;
123120
//! # client.set_get_account_response(epoch_rewards::ID, Account {
124121
//! # lamports: 1120560,
@@ -162,15 +159,7 @@ mod tests {
162159
#[serial]
163160
#[cfg(feature = "bincode")]
164161
fn test_epoch_rewards_get() {
165-
let expected = EpochRewards::new(
166-
42,
167-
7,
168-
solana_hash::Hash::new_unique(),
169-
1234567890,
170-
100,
171-
10,
172-
true,
173-
);
162+
let expected = EpochRewards::new(100, 10, 42);
174163

175164
let data = bincode::serialize(&expected).unwrap();
176165
assert_eq!(data.len(), 81);

0 commit comments

Comments
 (0)