File tree Expand file tree Collapse file tree 5 files changed +35
-16
lines changed
.changelog/unreleased/improvements
wasm_for_tests/wasm_source Expand file tree Collapse file tree 5 files changed +35
-16
lines changed Original file line number Diff line number Diff line change 1+ - Add missing checks for the commission rate change tx and code clean-up
2+ ([ \# 1973] ( https://github.com/anoma/namada/pull/1973 ) )
Original file line number Diff line number Diff line change @@ -97,6 +97,10 @@ pub enum SlashError {
9797pub enum CommissionRateChangeError {
9898 #[ error( "Unexpected negative commission rate {0} for validator {1}" ) ]
9999 NegativeRate ( Dec , Address ) ,
100+ #[ error(
101+ "Unexpected commission rate {0} larger than 1.0 for validator {1}"
102+ ) ]
103+ LargerThanOne ( Dec , Address ) ,
100104 #[ error( "Rate change of {0} is too large for validator {1}" ) ]
101105 RateChangeTooLarge ( Dec , Address ) ,
102106 #[ error(
Original file line number Diff line number Diff line change @@ -2996,13 +2996,21 @@ pub fn change_validator_commission_rate<S>(
29962996where
29972997 S : StorageRead + StorageWrite ,
29982998{
2999- // if new_rate < Uint::zero() {
3000- // return Err(CommissionRateChangeError::NegativeRate(
3001- // new_rate,
3002- // validator.clone(),
3003- // )
3004- // .into());
3005- // }
2999+ if new_rate. is_negative ( ) {
3000+ return Err ( CommissionRateChangeError :: NegativeRate (
3001+ new_rate,
3002+ validator. clone ( ) ,
3003+ )
3004+ . into ( ) ) ;
3005+ }
3006+
3007+ if new_rate > Dec :: one ( ) {
3008+ return Err ( CommissionRateChangeError :: LargerThanOne (
3009+ new_rate,
3010+ validator. clone ( ) ,
3011+ )
3012+ . into ( ) ) ;
3013+ }
30063014
30073015 let max_change =
30083016 read_validator_max_commission_rate_change ( storage, validator) ?;
@@ -3027,14 +3035,7 @@ where
30273035 . get ( storage, pipeline_epoch. prev ( ) , & params) ?
30283036 . expect ( "Could not find a rate in given epoch" ) ;
30293037
3030- // TODO: change this back if we use `Dec` type with a signed integer
3031- // let change_from_prev = new_rate - rate_before_pipeline;
3032- // if change_from_prev.abs() > max_change.unwrap() {
3033- let change_from_prev = if new_rate > rate_before_pipeline {
3034- new_rate - rate_before_pipeline
3035- } else {
3036- rate_before_pipeline - new_rate
3037- } ;
3038+ let change_from_prev = new_rate. abs_diff ( & rate_before_pipeline) ;
30383039 if change_from_prev > max_change. unwrap ( ) {
30393040 return Err ( CommissionRateChangeError :: RateChangeTooLarge (
30403041 change_from_prev,
Original file line number Diff line number Diff line change @@ -544,6 +544,18 @@ pub async fn build_validator_commission_change<'a>(
544544 commission_rate,
545545 max_commission_change_per_epoch,
546546 } ) => {
547+ if rate. is_negative ( ) || * rate > Dec :: one ( ) {
548+ edisplay_line ! (
549+ context. io( ) ,
550+ "New rate is outside of the allowed range of values \
551+ between 0.0 and 1.0."
552+ ) ;
553+ if !tx_args. force {
554+ return Err ( Error :: from (
555+ TxError :: InvalidCommissionRate ( * rate) ,
556+ ) ) ;
557+ }
558+ }
547559 if rate. abs_diff ( & commission_rate)
548560 > max_commission_change_per_epoch
549561 {
You can’t perform that action at this time.
0 commit comments