Skip to content
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

R4R: Make the simulator create the new comission rate sensibly #2682

Merged
merged 5 commits into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ FEATURES
* Gaia

* SDK
* [simulator] \#2682 MsgEditValidator now looks at the validator's max rate, thus it now succeeds a significant portion of the time

* Tendermint

Expand Down
6 changes: 2 additions & 4 deletions cmd/gaia/app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ func TestGaiaAppGenState(t *testing.T) {
func makeMsg(name string, pk crypto.PubKey) auth.StdTx {
desc := stake.NewDescription(name, "", "", "")
comm := stakeTypes.CommissionMsg{}
msg := stake.NewMsgCreateValidator(
sdk.ValAddress(pk.Address()), pk,
sdk.NewInt64Coin(bondDenom, 50), desc, comm,
)
msg := stake.NewMsgCreateValidator(sdk.ValAddress(pk.Address()), pk, sdk.NewInt64Coin(bondDenom,
50), desc, comm)
return auth.NewStdTx([]sdk.Msg{msg}, auth.StdFee{}, nil, "")
}

Expand Down
13 changes: 6 additions & 7 deletions x/stake/simulation/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func SimulateMsgCreateValidator(m auth.AccountKeeper, k stake.Keeper) simulation
Moniker: simulation.RandStringOfLength(r, 10),
}

maxCommission := sdk.NewInt(10)
maxCommission := sdk.NewDecWithPrec(r.Int63n(1000), 3)
commission := stake.NewCommissionMsg(
sdk.NewDecWithPrec(simulation.RandomAmount(r, maxCommission).Int64(), 1),
sdk.NewDecWithPrec(simulation.RandomAmount(r, maxCommission).Int64(), 1),
sdk.NewDecWithPrec(simulation.RandomAmount(r, maxCommission).Int64(), 1),
simulation.RandomDecAmount(r, maxCommission),
maxCommission,
simulation.RandomDecAmount(r, maxCommission),
)

acc := simulation.RandomAcc(r, accs)
Expand Down Expand Up @@ -85,11 +85,10 @@ func SimulateMsgEditValidator(k stake.Keeper) simulation.Operation {
Details: simulation.RandStringOfLength(r, 10),
}

maxCommission := sdk.NewInt(10)
newCommissionRate := sdk.NewDecWithPrec(simulation.RandomAmount(r, maxCommission).Int64(), 1)

val := keeper.RandomValidator(r, k, ctx)
address := val.GetOperator()
newCommissionRate := simulation.RandomDecAmount(r, val.Commission.MaxRate)

msg := stake.MsgEditValidator{
Description: description,
ValidatorAddr: address,
Expand Down
2 changes: 1 addition & 1 deletion x/stake/types/commission.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type (
// Commission defines a commission parameters for a given validator.
Commission struct {
Rate sdk.Dec `json:"rate"` // the commission rate charged to delegators
MaxRate sdk.Dec `json:"max_rate"` // maximum commission rate which validator can ever charge
MaxRate sdk.Dec `json:"max_rate"` // maximum commission rate which this validator can ever charge
MaxChangeRate sdk.Dec `json:"max_change_rate"` // maximum daily increase of the validator commission
UpdateTime time.Time `json:"update_time"` // the last time the commission rate was changed
}
Expand Down