From f0024e1a73f65781ef3745887c25a0dd13533454 Mon Sep 17 00:00:00 2001 From: ValarDragon Date: Sun, 4 Nov 2018 15:52:13 -0800 Subject: [PATCH 1/2] Make the simulator create the new comission rate sensibly --- PENDING.md | 1 + x/stake/simulation/msgs.go | 13 ++++++------- x/stake/types/commission.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/PENDING.md b/PENDING.md index 84a08a5abe26..cf2eaefd5f57 100644 --- a/PENDING.md +++ b/PENDING.md @@ -28,6 +28,7 @@ FEATURES * SDK * (#1336) Mechanism for SDK Users to configure their own Bech32 prefixes instead of using the default cosmos prefixes. + * [simulator] \#2682 MsgEditValidator now looks at the validator's max rate, thus it now succeeds a significant portion of the time * Tendermint diff --git a/x/stake/simulation/msgs.go b/x/stake/simulation/msgs.go index ec2dffd9277b..dda344ffbd78 100644 --- a/x/stake/simulation/msgs.go +++ b/x/stake/simulation/msgs.go @@ -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) @@ -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, diff --git a/x/stake/types/commission.go b/x/stake/types/commission.go index b76971faa001..730bb6741394 100644 --- a/x/stake/types/commission.go +++ b/x/stake/types/commission.go @@ -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 } From 37abad4cc3197c817e1f19f76d89c9de5d51a645 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Mon, 5 Nov 2018 11:47:19 +0100 Subject: [PATCH 2/2] 'make format' --- cmd/gaia/app/genesis_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/gaia/app/genesis_test.go b/cmd/gaia/app/genesis_test.go index 6c331856c345..9841fa3f889e 100644 --- a/cmd/gaia/app/genesis_test.go +++ b/cmd/gaia/app/genesis_test.go @@ -92,7 +92,7 @@ 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) + 50), desc, comm) return auth.NewStdTx([]sdk.Msg{msg}, auth.StdFee{}, nil, "") }