Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add missing checks for the commission rate change tx and code clean-up
([\#1973](https://github.com/anoma/namada/pull/1973))
23 changes: 8 additions & 15 deletions proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2355,13 +2355,13 @@ pub fn change_validator_commission_rate<S>(
where
S: StorageRead + StorageWrite,
{
// if new_rate < Uint::zero() {
// return Err(CommissionRateChangeError::NegativeRate(
// new_rate,
// validator.clone(),
// )
// .into());
// }
if new_rate.is_negative() {
return Err(CommissionRateChangeError::NegativeRate(
new_rate,
validator.clone(),
)
.into());
}

let max_change =
read_validator_max_commission_rate_change(storage, validator)?;
Expand All @@ -2386,14 +2386,7 @@ where
.get(storage, pipeline_epoch.prev(), &params)?
.expect("Could not find a rate in given epoch");

// TODO: change this back if we use `Dec` type with a signed integer
// let change_from_prev = new_rate - rate_before_pipeline;
// if change_from_prev.abs() > max_change.unwrap() {
let change_from_prev = if new_rate > rate_before_pipeline {
new_rate - rate_before_pipeline
} else {
rate_before_pipeline - new_rate
};
let change_from_prev = new_rate.abs_diff(&rate_before_pipeline);
if change_from_prev > max_change.unwrap() {
return Err(CommissionRateChangeError::RateChangeTooLarge(
change_from_prev,
Expand Down
12 changes: 12 additions & 0 deletions shared/src/sdk/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,18 @@ pub async fn build_validator_commission_change<
commission_rate,
max_commission_change_per_epoch,
}) => {
if rate.is_negative() || rate > Dec::one() {
edisplay_line!(
IO,
"New rate is outside of the allowed range of values \
between 0.0 and 1.0."
);
if !tx_args.force {
return Err(Error::from(
TxError::InvalidCommissionRate(rate),
));
}
}
if rate.abs_diff(&commission_rate)
> max_commission_change_per_epoch
{
Expand Down