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

golangci lint fix #8971

Merged
merged 6 commits into from
Feb 24, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
mode: [no-deprecations, no-failure]
mode: [no-failure]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
Expand Down
4 changes: 4 additions & 0 deletions golang/cosmos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,9 @@ grpc-gateway-stamp:
tools-clean:
rm -f proto-tools-stamp buf-stamp grpc-gateway-stamp


lint:
golangci-lint run

test:
go test -coverprofile=coverage.txt -covermode=atomic ./...
11 changes: 6 additions & 5 deletions golang/cosmos/ante/ante.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ante

import (
sdkioerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
Expand All @@ -21,19 +22,19 @@ type HandlerOptions struct {

func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
if opts.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
return nil, sdkioerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
}
if opts.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
return nil, sdkioerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
}
if opts.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
return nil, sdkioerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}
if opts.AdmissionData == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "admission data is required for AnteHandler")
return nil, sdkioerrors.Wrap(sdkerrors.ErrLogic, "admission data is required for AnteHandler")
}
if opts.SwingsetKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "swingset keeper is required for AnteHandler")
return nil, sdkioerrors.Wrap(sdkerrors.ErrLogic, "swingset keeper is required for AnteHandler")
}

var sigGasConsumer = opts.SigGasConsumer
Expand Down
15 changes: 8 additions & 7 deletions golang/cosmos/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ante
import (
"fmt"

sdkioerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -31,11 +32,11 @@ func NewDeductFeeDecorator(ak AccountKeeper, bk types.BankKeeper, fk FeegrantKee
func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
return ctx, sdkioerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}

if addr := dfd.ak.GetModuleAddress(dfd.feeCollectorName); addr == nil {
return ctx, fmt.Errorf("Fee collector module account (%s) has not been set", dfd.feeCollectorName)
return ctx, fmt.Errorf("fee collector module account (%s) has not been set", dfd.feeCollectorName)
}

fee := feeTx.GetFee()
Expand All @@ -48,12 +49,12 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
// this works with only when feegrant enabled.
if feeGranter != nil {
if dfd.feegrantKeeper == nil {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not enabled")
return ctx, sdkioerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not enabled")
} else if !feeGranter.Equals(feePayer) {
err := dfd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, fee, tx.GetMsgs())

if err != nil {
return ctx, sdkerrors.Wrapf(err, "%s not allowed to pay fees from %s", feeGranter, feePayer)
return ctx, sdkioerrors.Wrapf(err, "%s not allowed to pay fees from %s", feeGranter, feePayer)
}
}

Expand All @@ -62,7 +63,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo

deductFeesFromAcc := dfd.ak.GetAccount(ctx, deductFeesFrom)
if deductFeesFromAcc == nil {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "fee payer address: %s does not exist", deductFeesFrom)
return ctx, sdkioerrors.Wrapf(sdkerrors.ErrUnknownAddress, "fee payer address: %s does not exist", deductFeesFrom)
}

// deduct the fees
Expand All @@ -84,12 +85,12 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
// DeductFees deducts fees from the given account.
func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc types.AccountI, fees sdk.Coins, feeCollectorName string) error {
if !fees.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees)
return sdkioerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees)
}

err := bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), feeCollectorName, fees)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
return sdkioerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}

return nil
Expand Down
5 changes: 3 additions & 2 deletions golang/cosmos/ante/inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"reflect"
"testing"

sdkmath "cosmossdk.io/math"
swingtypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -210,11 +211,11 @@ func (msk mockSwingsetKeeper) IsHighPriorityAddress(ctx sdk.Context, addr sdk.Ac
return msk.isHighPriorityOwner, nil
}

func (msk mockSwingsetKeeper) GetBeansPerUnit(ctx sdk.Context) map[string]sdk.Uint {
func (msk mockSwingsetKeeper) GetBeansPerUnit(ctx sdk.Context) map[string]sdkmath.Uint {
return nil
}

func (msk mockSwingsetKeeper) ChargeBeans(ctx sdk.Context, addr sdk.AccAddress, beans sdk.Uint) error {
func (msk mockSwingsetKeeper) ChargeBeans(ctx sdk.Context, addr sdk.AccAddress, beans sdkmath.Uint) error {
return fmt.Errorf("not implemented")
}

Expand Down
3 changes: 2 additions & 1 deletion golang/cosmos/ante/vm_admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ante
import (
"github.com/armon/go-metrics"

sdkioerrors "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -57,7 +58,7 @@ func (ad AdmissionDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate boo
if numErrors > 0 {
// Add to instrumentation.

return ctx, sdkerrors.Wrapf(ErrAdmissionRefused, "controller refused message admission: %s", errors[0].Error())
return ctx, sdkioerrors.Wrapf(ErrAdmissionRefused, "controller refused message admission: %s", errors[0].Error())
}

return next(ctx, tx, simulate)
Expand Down
6 changes: 3 additions & 3 deletions golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"runtime/debug"
"time"

sdkioerrors "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
Expand All @@ -24,7 +25,6 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand Down Expand Up @@ -999,12 +999,12 @@ func (app *GaiaApp) initController(ctx sdk.Context, bootstrap bool) {
// fmt.Fprintf(os.Stderr, "AG_COSMOS_INIT Returned from SwingSet: %s, %v\n", out, err)

if err != nil {
panic(errors.Wrap(err, "cannot initialize Controller"))
panic(sdkioerrors.Wrap(err, "cannot initialize Controller"))
}
var res bool
err = json.Unmarshal([]byte(out), &res)
if err != nil {
panic(errors.Wrapf(err, "cannot unmarshal Controller init response: %s", out))
panic(sdkioerrors.Wrapf(err, "cannot unmarshal Controller init response: %s", out))
}
if !res {
panic(fmt.Errorf("controller negative init response"))
Expand Down
3 changes: 2 additions & 1 deletion golang/cosmos/cmd/libdaemon/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"strings"
"testing"

sdkioerrors "cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

func TestErrorStackTraces(t *testing.T) {
err := sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "my error %d", 123)
err := sdkioerrors.Wrapf(sdkerrors.ErrInsufficientFee, "my error %d", 123)
expected := "my error 123: insufficient fee"

// Check that sdkerrors.Wrapf(...).Error() does not leak stack.
Expand Down
2 changes: 1 addition & 1 deletion golang/cosmos/daemon/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (ac appCreator) newApp(
}

snapshotDir := filepath.Join(homePath, "data", "snapshots")
snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir)
snapshotDB, err := dbm.NewDB("metadata", dbm.GoLevelDBBackend, snapshotDir)
if err != nil {
panic(err)
}
Expand Down
5 changes: 3 additions & 2 deletions golang/cosmos/x/lien/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types"

sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -20,7 +21,7 @@ type Keeper interface {
GetLien(ctx sdk.Context, addr sdk.AccAddress) types.Lien
SetLien(ctx sdk.Context, addr sdk.AccAddress, lien types.Lien)
IterateLiens(ctx sdk.Context, cb func(addr sdk.AccAddress, lien types.Lien) bool)
ChangeLien(ctx sdk.Context, addr sdk.AccAddress, denom string, delta sdk.Int) (sdk.Int, error)
ChangeLien(ctx sdk.Context, addr sdk.AccAddress, denom string, delta sdkmath.Int) (sdkmath.Int, error)
GetAccountState(ctx sdk.Context, addr sdk.AccAddress) types.AccountState
BondDenom(ctx sdk.Context) string
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
Expand Down Expand Up @@ -112,7 +113,7 @@ func (lk keeperImpl) IterateLiens(ctx sdk.Context, cb func(addr sdk.AccAddress,
// independently.
//
// The delta is given as a raw Int instead of a Coin since it may be negative.
func (lk keeperImpl) ChangeLien(ctx sdk.Context, addr sdk.AccAddress, denom string, delta sdk.Int) (sdk.Int, error) {
func (lk keeperImpl) ChangeLien(ctx sdk.Context, addr sdk.AccAddress, denom string, delta sdkmath.Int) (sdkmath.Int, error) {
oldLien := lk.GetLien(ctx, addr)
oldCoins := oldLien.Coins
oldAmt := oldCoins.AmountOf(denom)
Expand Down
37 changes: 19 additions & 18 deletions golang/cosmos/x/lien/lien.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/Agoric/agoric-sdk/golang/cosmos/vm"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -22,37 +23,37 @@ type portHandler struct {

// portMessage is a struct that any lien bridge message can unmarshal into.
type portMessage struct {
Type string `json:"type"`
Address string `json:"address"`
Denom string `json:"denom"`
Delta sdk.Int `json:"delta"`
Validators []string `json:"validators"`
Delegators []string `json:"delegators"`
Type string `json:"type"`
Address string `json:"address"`
Denom string `json:"denom"`
Delta sdkmath.Int `json:"delta"`
Validators []string `json:"validators"`
Delegators []string `json:"delegators"`
}

// msgAccountState marshals into the AccountState message for the lien bridge.
type msgAccountState struct {
CurrentTime int64 `json:"currentTime"`
Total sdk.Int `json:"total"`
Bonded sdk.Int `json:"bonded"`
Unbonding sdk.Int `json:"unbonding"`
Locked sdk.Int `json:"locked"`
Liened sdk.Int `json:"liened"`
CurrentTime int64 `json:"currentTime"`
Total sdkmath.Int `json:"total"`
Bonded sdkmath.Int `json:"bonded"`
Unbonding sdkmath.Int `json:"unbonding"`
Locked sdkmath.Int `json:"locked"`
Liened sdkmath.Int `json:"liened"`
// TODO: send unvested amount
}

type delegatorState struct {
ValidatorIdx []int `json:"val_idx"`
Values []sdk.Int `json:"values"`
Other sdk.Int `json:"other"`
ValidatorIdx []int `json:"val_idx"`
Values []sdkmath.Int `json:"values"`
Other sdkmath.Int `json:"other"`
}

type msgStaking struct {
EpochTag string `json:"epoch_tag"`
Denom string `json:"denom"`
// the following fields are arrays of pointer types so we can use JSON null
// for out-of-band values
ValidatorValues []*sdk.Int `json:"validator_values"`
ValidatorValues []*sdkmath.Int `json:"validator_values"`
DelegatorStates []*delegatorState `json:"delegator_states"`
}

Expand Down Expand Up @@ -95,7 +96,7 @@ func (ch portHandler) handleGetStaking(ctx sdk.Context, msg portMessage) (string
reply := msgStaking{
EpochTag: fmt.Sprint(ctx.BlockHeight()),
Denom: ch.keeper.BondDenom(ctx),
ValidatorValues: make([]*sdk.Int, len(msg.Validators)),
ValidatorValues: make([]*sdkmath.Int, len(msg.Validators)),
DelegatorStates: make([]*delegatorState, len(msg.Delegators)),
}
validatorIndex := map[string]int{} // map of validators addresses to indexes
Expand Down Expand Up @@ -123,7 +124,7 @@ func (ch portHandler) handleGetStaking(ctx sdk.Context, msg portMessage) (string
// Note that the delegations were returned in a specific order - no nodeterminism
state := delegatorState{
ValidatorIdx: make([]int, 0, len(delegations)),
Values: make([]sdk.Int, 0, len(delegations)),
Values: make([]sdkmath.Int, 0, len(delegations)),
Other: sdk.NewInt(0),
}
for _, d := range delegations {
Expand Down
Loading
Loading