Skip to content

Commit

Permalink
check if rate > 1 in lib code
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Oct 11, 2023
1 parent 2e84ddc commit 66a7567
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ pub enum SlashError {
pub enum CommissionRateChangeError {
#[error("Unexpected negative commission rate {0} for validator {1}")]
NegativeRate(Dec, Address),
#[error(
"Unexpected commission rate {0} larger than 1.0 for validator {1}"
)]
LargerThanOne(Dec, Address),
#[error("Rate change of {0} is too large for validator {1}")]
RateChangeTooLarge(Dec, Address),
#[error(
Expand Down Expand Up @@ -2363,6 +2367,14 @@ where
.into());
}

if new_rate > Dec::one() {
return Err(CommissionRateChangeError::LargerThanOne(
new_rate,
validator.clone(),
)
.into());
}

let max_change =
read_validator_max_commission_rate_change(storage, validator)?;
if max_change.is_none() {
Expand Down

0 comments on commit 66a7567

Please sign in to comment.