Skip to content

Commit

Permalink
Merge PR cosmos#4466: Lazy commission validation
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner authored and alexanderbez committed Jun 3, 2019
1 parent 59ac148 commit 9c04932
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 74 deletions.
1 change: 1 addition & 0 deletions .pending/improvements/sdk/4466-Commission-vali
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4466 Commission validation added to validate basic of MsgCreateValidator by changing CommissionMsg to CommissionRates
12 changes: 6 additions & 6 deletions x/distribution/keeper/allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) {
sh := staking.NewHandler(sk)

// create validator with 50% commission
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
require.True(t, sh(ctx, msg).IsOK())
Expand All @@ -42,13 +42,13 @@ func TestAllocateTokensToManyValidators(t *testing.T) {
sh := staking.NewHandler(sk)

// create validator with 50% commission
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
require.True(t, sh(ctx, msg).IsOK())

// create second validator with 0% commission
commission = staking.NewCommissionMsg(sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0))
commission = staking.NewCommissionRates(sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0))
msg = staking.NewMsgCreateValidator(valOpAddr2, valConsPk2,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
require.True(t, sh(ctx, msg).IsOK())
Expand Down Expand Up @@ -109,19 +109,19 @@ func TestAllocateTokensTruncation(t *testing.T) {
sh := staking.NewHandler(sk)

// create validator with 10% commission
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(110)), staking.Description{}, commission, sdk.OneInt())
require.True(t, sh(ctx, msg).IsOK())

// create second validator with 10% commission
commission = staking.NewCommissionMsg(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
commission = staking.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
msg = staking.NewMsgCreateValidator(valOpAddr2, valConsPk2,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
require.True(t, sh(ctx, msg).IsOK())

// create third validator with 10% commission
commission = staking.NewCommissionMsg(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
commission = staking.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
msg = staking.NewMsgCreateValidator(valOpAddr3, valConsPk3,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
require.True(t, sh(ctx, msg).IsOK())
Expand Down
16 changes: 8 additions & 8 deletions x/distribution/keeper/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestCalculateRewardsBasic(t *testing.T) {
sh := staking.NewHandler(sk)

// create validator with 50% commission
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
require.True(t, sh(ctx, msg).IsOK())
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) {
sh := staking.NewHandler(sk)

// create validator with 50% commission
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
valPower := int64(100)
valTokens := sdk.TokensFromTendermintPower(valPower)
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) {
// create validator with 50% commission
power := int64(100)
valTokens := sdk.TokensFromTendermintPower(power)
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
sdk.NewCoin(sdk.DefaultBondDenom, valTokens), staking.Description{}, commission, sdk.OneInt())
require.True(t, sh(ctx, msg).IsOK())
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) {
sh := staking.NewHandler(sk)

// create validator with 50% commission
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
require.True(t, sh(ctx, msg).IsOK())
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) {
// create validator with 50% commission
power := int64(100)
valTokens := sdk.TokensFromTendermintPower(power)
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
msg := staking.NewMsgCreateValidator(
valOpAddr1, valConsPk1,
sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
Expand Down Expand Up @@ -335,7 +335,7 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) {
// create validator with 50% commission
power := int64(100)
valTokens := sdk.TokensFromTendermintPower(power)
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
sdk.NewCoin(sdk.DefaultBondDenom, valTokens), staking.Description{}, commission, sdk.OneInt())
require.True(t, sh(ctx, msg).IsOK())
Expand Down Expand Up @@ -400,7 +400,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) {
sh := staking.NewHandler(sk)

// create validator with 50% commission
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
power := int64(100)
valTokens := sdk.TokensFromTendermintPower(power)
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
Expand Down Expand Up @@ -479,7 +479,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
tokens := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDec(initial))}

// create validator with 50% commission
commission := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
commission := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, commission, sdk.OneInt())
require.True(t, sh(ctx, msg).IsOK())
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func TestQueries(t *testing.T) {

// test delegation rewards query
sh := staking.NewHandler(sk)
comm := staking.NewCommissionMsg(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
comm := staking.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
msg := staking.NewMsgCreateValidator(valOpAddr1, valConsPk1,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)), staking.Description{}, comm, sdk.OneInt())
require.True(t, sh(ctx, msg).IsOK())
Expand Down
2 changes: 1 addition & 1 deletion x/genutil/genesis_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
func TestValidateGenesisMultipleMessages(t *testing.T) {

desc := staking.NewDescription("testname", "", "", "")
comm := staking.CommissionMsg{}
comm := staking.CommissionRates{}

msg1 := staking.NewMsgCreateValidator(sdk.ValAddress(pk1.Address()), pk1,
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, sdk.OneInt())
Expand Down
6 changes: 3 additions & 3 deletions x/gov/tally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,19 +502,19 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {

valTokens1 := sdk.TokensFromTendermintPower(25)
val1CreateMsg := staking.NewMsgCreateValidator(
sdk.ValAddress(input.addrs[0]), ed25519.GenPrivKey().PubKey(), sdk.NewCoin(sdk.DefaultBondDenom, valTokens1), testDescription, testCommissionMsg, sdk.OneInt(),
sdk.ValAddress(input.addrs[0]), ed25519.GenPrivKey().PubKey(), sdk.NewCoin(sdk.DefaultBondDenom, valTokens1), testDescription, testCommissionRates, sdk.OneInt(),
)
stakingHandler(ctx, val1CreateMsg)

valTokens2 := sdk.TokensFromTendermintPower(6)
val2CreateMsg := staking.NewMsgCreateValidator(
sdk.ValAddress(input.addrs[1]), ed25519.GenPrivKey().PubKey(), sdk.NewCoin(sdk.DefaultBondDenom, valTokens2), testDescription, testCommissionMsg, sdk.OneInt(),
sdk.ValAddress(input.addrs[1]), ed25519.GenPrivKey().PubKey(), sdk.NewCoin(sdk.DefaultBondDenom, valTokens2), testDescription, testCommissionRates, sdk.OneInt(),
)
stakingHandler(ctx, val2CreateMsg)

valTokens3 := sdk.TokensFromTendermintPower(7)
val3CreateMsg := staking.NewMsgCreateValidator(
sdk.ValAddress(input.addrs[2]), ed25519.GenPrivKey().PubKey(), sdk.NewCoin(sdk.DefaultBondDenom, valTokens3), testDescription, testCommissionMsg, sdk.OneInt(),
sdk.ValAddress(input.addrs[2]), ed25519.GenPrivKey().PubKey(), sdk.NewCoin(sdk.DefaultBondDenom, valTokens3), testDescription, testCommissionRates, sdk.OneInt(),
)
stakingHandler(ctx, val3CreateMsg)

Expand Down
6 changes: 3 additions & 3 deletions x/gov/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ var (
ed25519.GenPrivKey().PubKey(),
}

testDescription = staking.NewDescription("T", "E", "S", "T")
testCommissionMsg = staking.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
testDescription = staking.NewDescription("T", "E", "S", "T")
testCommissionRates = staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
)

func createValidators(t *testing.T, stakingHandler sdk.Handler, ctx sdk.Context, addrs []sdk.ValAddress, powerAmt []int64) {
Expand All @@ -203,7 +203,7 @@ func createValidators(t *testing.T, stakingHandler sdk.Handler, ctx sdk.Context,
valTokens := sdk.TokensFromTendermintPower(powerAmt[i])
valCreateMsg := staking.NewMsgCreateValidator(
addrs[i], pubkeys[i], sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
testDescription, testCommissionMsg, sdk.OneInt(),
testDescription, testCommissionRates, sdk.OneInt(),
)

res := stakingHandler(ctx, valCreateMsg)
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestSlashingMsgs(t *testing.T) {
mock.SetGenesis(mapp, accs)

description := staking.NewDescription("foo_moniker", "", "", "")
commission := staking.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
commission := staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())

createValidatorMsg := staking.NewMsgCreateValidator(
sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commission, sdk.OneInt(),
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func testAddr(addr string) sdk.AccAddress {
}

func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) staking.MsgCreateValidator {
commission := staking.NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
commission := staking.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
return staking.NewMsgCreateValidator(
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt),
staking.Description{}, commission, sdk.OneInt(),
Expand Down
4 changes: 2 additions & 2 deletions x/staking/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var (
NewQueryRedelegationParams = querier.NewQueryRedelegationParams
NewQueryValidatorsParams = querier.NewQueryValidatorsParams
RegisterCodec = types.RegisterCodec
NewCommissionMsg = types.NewCommissionMsg
NewCommissionRates = types.NewCommissionRates
NewCommission = types.NewCommission
NewCommissionWithTime = types.NewCommissionWithTime
NewDelegation = types.NewDelegation
Expand Down Expand Up @@ -222,7 +222,7 @@ type (
QueryRedelegationParams = querier.QueryRedelegationParams
QueryValidatorsParams = querier.QueryValidatorsParams
Commission = types.Commission
CommissionMsg = types.CommissionMsg
CommissionRates = types.CommissionRates
DVPair = types.DVPair
DVVTriplet = types.DVVTriplet
Delegation = types.Delegation
Expand Down
2 changes: 1 addition & 1 deletion x/staking/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestStakingMsgs(t *testing.T) {
// create validator
description := NewDescription("foo_moniker", "", "", "")
createValidatorMsg := NewMsgCreateValidator(
sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commissionMsg, sdk.OneInt(),
sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commissionRates, sdk.OneInt(),
)

header := abci.Header{Height: mApp.LastBlockHeight() + 1}
Expand Down
4 changes: 2 additions & 2 deletions x/staking/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func BuildCreateValidatorMsg(cliCtx context.CLIContext, txBldr authtxb.TxBuilder
rateStr := viper.GetString(FlagCommissionRate)
maxRateStr := viper.GetString(FlagCommissionMaxRate)
maxChangeRateStr := viper.GetString(FlagCommissionMaxChangeRate)
commissionMsg, err := buildCommissionMsg(rateStr, maxRateStr, maxChangeRateStr)
commissionRates, err := buildCommissionRates(rateStr, maxRateStr, maxChangeRateStr)
if err != nil {
return txBldr, nil, err
}
Expand All @@ -359,7 +359,7 @@ func BuildCreateValidatorMsg(cliCtx context.CLIContext, txBldr authtxb.TxBuilder
}

msg := types.NewMsgCreateValidator(
sdk.ValAddress(valAddr), pk, amount, description, commissionMsg, minSelfDelegation,
sdk.ValAddress(valAddr), pk, amount, description, commissionRates, minSelfDelegation,
)

if viper.GetBool(client.FlagGenerateOnly) {
Expand Down
4 changes: 2 additions & 2 deletions x/staking/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

func buildCommissionMsg(rateStr, maxRateStr, maxChangeRateStr string) (commission types.CommissionMsg, err error) {
func buildCommissionRates(rateStr, maxRateStr, maxChangeRateStr string) (commission types.CommissionRates, err error) {
if rateStr == "" || maxRateStr == "" || maxChangeRateStr == "" {
return commission, errors.New("must specify all validator commission parameters")
}
Expand All @@ -27,6 +27,6 @@ func buildCommissionMsg(rateStr, maxRateStr, maxChangeRateStr string) (commissio
return commission, err
}

commission = types.NewCommissionMsg(rate, maxRate, maxChangeRate)
commission = types.NewCommissionRates(rate, maxRate, maxChangeRate)
return commission, nil
}
2 changes: 1 addition & 1 deletion x/staking/simulation/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func SimulateMsgCreateValidator(m auth.AccountKeeper, k staking.Keeper) simulati
}

maxCommission := sdk.NewDecWithPrec(r.Int63n(1000), 3)
commission := staking.NewCommissionMsg(
commission := staking.NewCommissionRates(
simulation.RandomDecAmount(r, maxCommission),
maxCommission,
simulation.RandomDecAmount(r, maxCommission),
Expand Down
8 changes: 4 additions & 4 deletions x/staking/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ var (
sdk.Coins{sdk.NewCoin("foocoin", sdk.NewInt(0))},
)

commissionMsg = NewCommissionMsg(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
commissionRates = NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
)

func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey crypto.PubKey, amt sdk.Int) MsgCreateValidator {
return types.NewMsgCreateValidator(
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), Description{}, commissionMsg, sdk.OneInt(),
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), Description{}, commissionRates, sdk.OneInt(),
)
}

func NewTestMsgCreateValidatorWithCommission(address sdk.ValAddress, pubKey crypto.PubKey,
amt sdk.Int, commissionRate sdk.Dec) MsgCreateValidator {

commission := NewCommissionMsg(commissionRate, sdk.OneDec(), sdk.ZeroDec())
commission := NewCommissionRates(commissionRate, sdk.OneDec(), sdk.ZeroDec())

return types.NewMsgCreateValidator(
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), Description{}, commission, sdk.OneInt(),
Expand All @@ -46,7 +46,7 @@ func NewTestMsgCreateValidatorWithMinSelfDelegation(address sdk.ValAddress, pubK
amt sdk.Int, minSelfDelegation sdk.Int) MsgCreateValidator {

return types.NewMsgCreateValidator(
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), Description{}, commissionMsg, minSelfDelegation,
address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), Description{}, commissionRates, minSelfDelegation,
)
}

Expand Down
30 changes: 12 additions & 18 deletions x/staking/types/commission.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,22 @@ import (
type (
// Commission defines a commission parameters for a given validator.
Commission struct {
Rate sdk.Dec `json:"rate"` // the commission rate charged to delegators, as a fraction
MaxRate sdk.Dec `json:"max_rate"` // maximum commission rate which this validator can ever charge, as a fraction
MaxChangeRate sdk.Dec `json:"max_change_rate"` // maximum daily increase of the validator commission, as a fraction
UpdateTime time.Time `json:"update_time"` // the last time the commission rate was changed
CommissionRates
UpdateTime time.Time `json:"update_time"` // the last time the commission rate was changed
}

// CommissionMsg defines a commission message to be used for creating a
// CommissionRates defines the initial commission rates to be used for creating a
// validator.
CommissionMsg struct {
CommissionRates struct {
Rate sdk.Dec `json:"rate"` // the commission rate charged to delegators, as a fraction
MaxRate sdk.Dec `json:"max_rate"` // maximum commission rate which validator can ever charge, as a fraction
MaxChangeRate sdk.Dec `json:"max_change_rate"` // maximum daily increase of the validator commission, as a fraction
}
)

// NewCommissionMsg returns an initialized validator commission message.
func NewCommissionMsg(rate, maxRate, maxChangeRate sdk.Dec) CommissionMsg {
return CommissionMsg{
// NewCommissionRates returns an initialized validator commission rates.
func NewCommissionRates(rate, maxRate, maxChangeRate sdk.Dec) CommissionRates {
return CommissionRates{
Rate: rate,
MaxRate: maxRate,
MaxChangeRate: maxChangeRate,
Expand All @@ -37,21 +35,17 @@ func NewCommissionMsg(rate, maxRate, maxChangeRate sdk.Dec) CommissionMsg {
// NewCommission returns an initialized validator commission.
func NewCommission(rate, maxRate, maxChangeRate sdk.Dec) Commission {
return Commission{
Rate: rate,
MaxRate: maxRate,
MaxChangeRate: maxChangeRate,
UpdateTime: time.Unix(0, 0).UTC(),
CommissionRates: NewCommissionRates(rate, maxRate, maxChangeRate),
UpdateTime: time.Unix(0, 0).UTC(),
}
}

// NewCommission returns an initialized validator commission with a specified
// update time which should be the current block BFT time.
func NewCommissionWithTime(rate, maxRate, maxChangeRate sdk.Dec, updatedAt time.Time) Commission {
return Commission{
Rate: rate,
MaxRate: maxRate,
MaxChangeRate: maxChangeRate,
UpdateTime: updatedAt,
CommissionRates: NewCommissionRates(rate, maxRate, maxChangeRate),
UpdateTime: updatedAt,
}
}

Expand All @@ -73,7 +67,7 @@ func (c Commission) String() string {

// Validate performs basic sanity validation checks of initial commission
// parameters. If validation fails, an SDK error is returned.
func (c Commission) Validate() sdk.Error {
func (c CommissionRates) Validate() sdk.Error {
switch {
case c.MaxRate.LT(sdk.ZeroDec()):
// max rate cannot be negative
Expand Down
Loading

0 comments on commit 9c04932

Please sign in to comment.