-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MinCommissionRate param #9245
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,12 +58,14 @@ func migrateValidatorsByPowerIndexKey(store sdk.KVStore) { | |
func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) { | ||
paramstore.WithKeyTable(types.ParamKeyTable()) | ||
paramstore.Set(ctx, types.KeyPowerReduction, sdk.DefaultPowerReduction) | ||
paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate) | ||
} | ||
|
||
// MigrateStore performs in-place store migrations from v0.40 to v0.43. The | ||
// migration includes: | ||
// | ||
// - Setting the Power Reduction param in the paramstore | ||
// - Setting the MinCommissionRate param in the paramstore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. migrations look good, but now they need to go to a 0.44 folder There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AmauryM now, 0.45 folder? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! |
||
func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, paramstore paramtypes.Subspace) error { | ||
store := ctx.KVStore(storeKey) | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,13 +32,19 @@ const ( | |||||
DefaultHistoricalEntries uint32 = 10000 | ||||||
) | ||||||
|
||||||
var ( | ||||||
// DefaultMinCommissionRate is set to 0% | ||||||
DefaultMinCommissionRate = sdk.ZeroDec() | ||||||
) | ||||||
|
||||||
var ( | ||||||
KeyUnbondingTime = []byte("UnbondingTime") | ||||||
KeyMaxValidators = []byte("MaxValidators") | ||||||
KeyMaxEntries = []byte("MaxEntries") | ||||||
KeyBondDenom = []byte("BondDenom") | ||||||
KeyHistoricalEntries = []byte("HistoricalEntries") | ||||||
KeyPowerReduction = []byte("PowerReduction") | ||||||
KeyMinCommissionRate = []byte("MinCommissionRate") | ||||||
) | ||||||
|
||||||
var _ paramtypes.ParamSet = (*Params)(nil) | ||||||
|
@@ -49,14 +55,15 @@ func ParamKeyTable() paramtypes.KeyTable { | |||||
} | ||||||
|
||||||
// NewParams creates a new Params instance | ||||||
func NewParams(unbondingTime time.Duration, maxValidators, maxEntries, historicalEntries uint32, bondDenom string, powerReduction sdk.Int) Params { | ||||||
func NewParams(unbondingTime time.Duration, maxValidators, maxEntries, historicalEntries uint32, bondDenom string, powerReduction sdk.Int, minCommissionRate sdk.Dec) Params { | ||||||
return Params{ | ||||||
UnbondingTime: unbondingTime, | ||||||
MaxValidators: maxValidators, | ||||||
MaxEntries: maxEntries, | ||||||
HistoricalEntries: historicalEntries, | ||||||
BondDenom: bondDenom, | ||||||
PowerReduction: powerReduction, | ||||||
MinCommissionRate: minCommissionRate, | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -69,6 +76,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { | |||||
paramtypes.NewParamSetPair(KeyHistoricalEntries, &p.HistoricalEntries, validateHistoricalEntries), | ||||||
paramtypes.NewParamSetPair(KeyBondDenom, &p.BondDenom, validateBondDenom), | ||||||
paramtypes.NewParamSetPair(KeyPowerReduction, &p.PowerReduction, ValidatePowerReduction), | ||||||
paramtypes.NewParamSetPair(KeyMinCommissionRate, &p.MinCommissionRate, validateMinCommissionRate), | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -81,6 +89,7 @@ func DefaultParams() Params { | |||||
DefaultHistoricalEntries, | ||||||
sdk.DefaultBondDenom, | ||||||
sdk.DefaultPowerReduction, | ||||||
DefaultMinCommissionRate, | ||||||
) | ||||||
} | ||||||
|
||||||
|
@@ -128,6 +137,14 @@ func (p Params) Validate() error { | |||||
return err | ||||||
} | ||||||
|
||||||
if err := ValidatePowerReduction(p.PowerReduction); err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
if err := validateMinCommissionRate(p.MinCommissionRate); err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
return nil | ||||||
} | ||||||
|
||||||
|
@@ -208,3 +225,19 @@ func ValidatePowerReduction(i interface{}) error { | |||||
|
||||||
return nil | ||||||
} | ||||||
|
||||||
func validateMinCommissionRate(i interface{}) error { | ||||||
v, ok := i.(sdk.Dec) | ||||||
if !ok { | ||||||
return fmt.Errorf("invalid parameter type: %T", i) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
if v.IsNegative() { | ||||||
return fmt.Errorf("minimum commission rate cannot be negative: %s", v) | ||||||
} | ||||||
if v.GT(sdk.OneDec()) { | ||||||
return fmt.Errorf("minimum commission rate cannot be greater than 100%%: %s", v) | ||||||
} | ||||||
|
||||||
return nil | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a description here?