Skip to content
Merged
Changes from 1 commit
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 sdk/program/src/epoch_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! [`sysvar::epoch_rewards`]: crate::sysvar::epoch_rewards

use {crate::hash::Hash, solana_sdk_macro::CloneZeroed, std::ops::AddAssign};
use {crate::hash::Hash, solana_sdk_macro::CloneZeroed};

#[repr(C, align(16))]
#[cfg_attr(feature = "frozen-abi", derive(AbiExample))]
Expand Down Expand Up @@ -44,7 +44,7 @@ impl EpochRewards {
pub fn distribute(&mut self, amount: u64) {
assert!(self.distributed_rewards.saturating_add(amount) <= self.total_rewards);

self.distributed_rewards.add_assign(amount);
self.distributed_rewards = self.distributed_rewards.saturating_add(amount);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The lint seems unnecessary here, but the change to saturating add is innocuous. I don't think we need to do the addition multiple times, though
How about this:

pub fn distribute(&mut self, amount: u64) {
    let new_distributed_rewards = self.distributed_rewards.saturating_add(amount);
    assert!(new_distributed_rewards <= self.total_rewards);
    self.distributed_rewards = new_distributed_rewards;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thank you for the insight! yeah, good catch! just fixed it! 34f81e7

}
}

Expand Down