Skip to content

Commit

Permalink
style: make lint-strict
Browse files Browse the repository at this point in the history
  • Loading branch information
fragwuerdig committed Oct 21, 2023
1 parent 51d5557 commit 57dca07
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 93 deletions.
6 changes: 2 additions & 4 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions custom/auth/post/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ type HandlerOptions struct {
// numbers, checks signatures & account numbers, and deducts fees from the first
// signer.
func NewPostHandler(options HandlerOptions) (sdk.AnteHandler, error) {

return sdk.ChainAnteDecorators(
dyncommpost.NewDyncommPostDecorator(options.DyncommKeeper),
), nil

}
6 changes: 0 additions & 6 deletions x/dyncomm/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ func (dd DyncommDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,

msgs := tx.GetMsgs()
err := dd.FilterMsgsAndProcessMsgs(ctx, msgs...)

if err != nil {
return ctx, err
}

return next(ctx, tx, simulate)

}

func (dd DyncommDecorator) FilterMsgsAndProcessMsgs(ctx sdk.Context, msgs ...sdk.Msg) (err error) {

for _, msg := range msgs {

switch msg.(type) {
Expand All @@ -61,11 +58,9 @@ func (dd DyncommDecorator) FilterMsgsAndProcessMsgs(ctx sdk.Context, msgs ...sdk

}
return nil

}

func (dd DyncommDecorator) ProcessEditValidator(ctx sdk.Context, msg sdk.Msg) (err error) {

msgEditValidator := msg.(*stakingtypes.MsgEditValidator)

// no update of CommissionRate provided
Expand All @@ -82,5 +77,4 @@ func (dd DyncommDecorator) ProcessEditValidator(ctx sdk.Context, msg sdk.Msg) (e
}

return nil

}
4 changes: 0 additions & 4 deletions x/dyncomm/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func (suite *AnteTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []
}

func (suite *AnteTestSuite) CreateValidator(tokens int64) (cryptotypes.PrivKey, cryptotypes.PubKey, stakingtypes.Validator) {

priv, pub, addr := testdata.KeyTestPubAddr()
valAddr := sdk.ValAddress(addr)

Expand Down Expand Up @@ -184,15 +183,13 @@ func (suite *AnteTestSuite) CreateValidator(tokens int64) (cryptotypes.PrivKey,
retval, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr)
suite.Require().Equal(true, found)
return priv, pub, retval

}

func TestAnteTestSuite(t *testing.T) {
suite.Run(t, new(AnteTestSuite))
}

func (suite *AnteTestSuite) TestAnte_EnsureDynCommissionIsMinComm() {

suite.SetupTest(true) // setup
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()
suite.ctx = suite.ctx.WithIsCheckTx(false)
Expand Down Expand Up @@ -234,5 +231,4 @@ func (suite *AnteTestSuite) TestAnte_EnsureDynCommissionIsMinComm() {
suite.Require().NoError(err)
_, err = antehandler(suite.ctx, tx, false)
suite.Require().NoError(err)

}
5 changes: 2 additions & 3 deletions x/dyncomm/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState) {
keeper.SetParams(ctx, data.Params)

//iterate validators and set target rates
// iterate validators and set target rates
keeper.StakingKeeper.IterateValidators(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) {
val := validator.(stakingtypes.Validator)
keeper.SetTargetCommissionRate(ctx, val.OperatorAddress, val.Commission.Rate)
Expand All @@ -24,7 +24,6 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState
if err != nil {
panic("could not initialize genesis")
}

}

// ExportGenesis writes the current store values
Expand All @@ -34,7 +33,7 @@ func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data *types.GenesisSt
params := keeper.GetParams(ctx)
var rates []types.ValidatorCommissionRate

//rates = append(rates)
// rates = append(rates)
keeper.IterateDynCommissionRates(ctx, func(rate types.ValidatorCommissionRate) (stop bool) {
rates = append(rates, rate)
return false
Expand Down
12 changes: 0 additions & 12 deletions x/dyncomm/keeper/dyncomm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@ import (

// GetVotingPower calculates the voting power of a validator in percent
func (k Keeper) CalculateVotingPower(ctx sdk.Context, validator stakingtypes.Validator) (ret sdk.Dec) {

totalPower := k.StakingKeeper.GetLastTotalPower(ctx).Int64()
validatorPower := sdk.TokensToConsensusPower(
validator.Tokens,
k.StakingKeeper.PowerReduction(ctx),
)
return sdk.NewDec(validatorPower).QuoInt64(totalPower).MulInt64(100)

}

// CalculateDynCommission calculates the min commission according
// to StrathColes formula
func (k Keeper) CalculateDynCommission(ctx sdk.Context, validator stakingtypes.Validator) (ret sdk.Dec) {

// The original parameters as defined
// by Strath
A := k.GetMaxZero(ctx)
Expand All @@ -42,11 +39,9 @@ func (k Keeper) CalculateDynCommission(ctx sdk.Context, validator stakingtypes.V
y = minComm
}
return y.QuoInt64(100)

}

func (k Keeper) SetDynCommissionRate(ctx sdk.Context, validator string, rate sdk.Dec) {

var preSetRate types.ValidatorCommissionRate
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.GetMinCommissionRatesKey(validator))
Expand All @@ -67,7 +62,6 @@ func (k Keeper) SetDynCommissionRate(ctx sdk.Context, validator string, rate sdk
}

func (k Keeper) SetTargetCommissionRate(ctx sdk.Context, validator string, rate sdk.Dec) {

var preSetRate types.ValidatorCommissionRate
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.GetMinCommissionRatesKey(validator))
Expand Down Expand Up @@ -130,7 +124,6 @@ func (k Keeper) IterateDynCommissionRates(ctx sdk.Context, cb func(types.Validat
}

func (k Keeper) UpdateValidatorMinRates(ctx sdk.Context, validator stakingtypes.Validator) {

var newRate sdk.Dec
minRate := k.CalculateDynCommission(ctx, validator)
newMaxRate := validator.Commission.MaxRate
Expand Down Expand Up @@ -163,14 +156,11 @@ func (k Keeper) UpdateValidatorMinRates(ctx sdk.Context, validator stakingtypes.
// Debug
targetRate = k.GetTargetCommissionRate(ctx, validator.OperatorAddress)
ctx.Logger().Info("dyncomm:", "val", validator.OperatorAddress, "min_rate", minRate, "target_rate", targetRate)

}

func (k Keeper) UpdateAllBondedValidatorRates(ctx sdk.Context) (err error) {

var lastErr error = nil

Check warning on line 162 in x/dyncomm/keeper/dyncomm.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-declaration: should drop = nil from declaration of var lastErr; it is the zero value (revive)
k.StakingKeeper.IterateValidators(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) {

val := validator.(stakingtypes.Validator)

if !val.IsBonded() {
Expand All @@ -180,9 +170,7 @@ func (k Keeper) UpdateAllBondedValidatorRates(ctx sdk.Context) (err error) {
k.UpdateValidatorMinRates(ctx, val)

return false

})

return lastErr

}
4 changes: 0 additions & 4 deletions x/dyncomm/keeper/dyncomm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func TestCalculateVotingPower(t *testing.T) {

input := CreateTestInput(t)
helper := teststaking.NewHelper(
t, input.Ctx, input.StakingKeeper,
Expand All @@ -27,11 +26,9 @@ func TestCalculateVotingPower(t *testing.T) {
sdk.NewDecWithPrec(90, 0),
input.DyncommKeeper.CalculateVotingPower(input.Ctx, vals[0]),
)

}

func TestCalculateDynCommission(t *testing.T) {

input := CreateTestInput(t)
helper := teststaking.NewHelper(
t, input.Ctx, input.StakingKeeper,
Expand Down Expand Up @@ -63,5 +60,4 @@ func TestCalculateDynCommission(t *testing.T) {
sdk.ZeroDec(),
input.DyncommKeeper.CalculateDynCommission(input.Ctx, vals[2]),
)

}
1 change: 0 additions & 1 deletion x/dyncomm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func NewKeeper(
paramstore paramstypes.Subspace,
stakingKeeper types.StakingKeeper,
) Keeper {

// set KeyTable if it has not already been set
if !paramstore.HasKeyTable() {
paramstore = paramstore.WithKeyTable(types.ParamKeyTable())
Expand Down
2 changes: 1 addition & 1 deletion x/dyncomm/keeper/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func CreateTestInput(t *testing.T) TestInput {
accountKeeper.SetModuleAccount(ctx, notBondedPool)
accountKeeper.SetModuleAccount(ctx, distrAcc)

for idx, _ := range PubKeys {
for idx := range PubKeys {
accountKeeper.SetAccount(ctx, authtypes.NewBaseAccountWithAddress(AddrFrom(idx)))
err := bankKeeper.SendCoinsFromModuleToAccount(ctx, faucetAccountName, AddrFrom(idx), InitCoins)
require.NoError(t, err)
Expand Down
10 changes: 0 additions & 10 deletions x/dyncomm/post/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func NewDyncommPostDecorator(dk dyncommkeeper.Keeper) DyncommDecorator {
}

func (dd DyncommDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {

if simulate {
return next(ctx, tx, simulate)
}
Expand All @@ -32,13 +31,10 @@ func (dd DyncommDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,
dd.FilterMsgsAndProcessMsgs(ctx, msgs...)

return next(ctx, tx, simulate)

}

func (dd DyncommDecorator) FilterMsgsAndProcessMsgs(ctx sdk.Context, msgs ...sdk.Msg) {

for _, msg := range msgs {

switch msg.(type) {
case *stakingtypes.MsgEditValidator:
dd.ProcessEditValidator(ctx, msg)
Expand All @@ -47,13 +43,10 @@ func (dd DyncommDecorator) FilterMsgsAndProcessMsgs(ctx sdk.Context, msgs ...sdk
default:
continue
}

}

}

func (dd DyncommDecorator) ProcessEditValidator(ctx sdk.Context, msg sdk.Msg) {

msgEditValidator := msg.(*stakingtypes.MsgEditValidator)

// no update of CommissionRate provided
Expand All @@ -65,15 +58,12 @@ func (dd DyncommDecorator) ProcessEditValidator(ctx sdk.Context, msg sdk.Msg) {
// calling runMsgs -> we can set state changes here!
newIntendedRate := msgEditValidator.CommissionRate
dd.dyncommKeeper.SetTargetCommissionRate(ctx, msgEditValidator.ValidatorAddress, *newIntendedRate)

}

func (dd DyncommDecorator) ProcessCreateValidator(ctx sdk.Context, msg sdk.Msg) {

// post handler runs after successfully
// calling runMsgs -> we can set state changes here!
msgEditValidator := msg.(*stakingtypes.MsgCreateValidator)
newIntendedRate := msgEditValidator.Commission.Rate
dd.dyncommKeeper.SetTargetCommissionRate(ctx, msgEditValidator.ValidatorAddress, newIntendedRate)

}
25 changes: 19 additions & 6 deletions x/dyncomm/types/dyncomm.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 57dca07

Please sign in to comment.