From 37e7d88c51fd417859ea922d20f355c1088862ac Mon Sep 17 00:00:00 2001 From: Geoff Lee Date: Wed, 17 Jul 2024 18:08:04 +0900 Subject: [PATCH] Chore/action lint fix (#41) * fix lint action and lint errors * remove unnecessary goprivate from workflow --- .github/workflows/lint.yml | 38 +++++++++++++++++++++++++++++--------- Makefile | 14 ++++++++++++++ app/ante/verify.go | 2 +- app/app.go | 4 +++- app/test_helpers.go | 4 ++-- jsonrpc/backend/block.go | 10 ++++++++-- jsonrpc/backend/filters.go | 5 ++++- jsonrpc/backend/gas.go | 11 ++++++++--- x/evm/keeper/genesis.go | 15 ++++++++++++--- x/evm/keeper/txutils.go | 8 ++++++-- 10 files changed, 87 insertions(+), 24 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index dfbe439..b7f66a7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,15 +24,18 @@ jobs: golangci: env: # for private repo access - GOPRIVATE: github.com/initia-labs/* + GOPRIVATE: github.com/initia-labs GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }} + GOLANGCI_LINT_VERSION: v1.59.1 name: golangci-lint runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v2.1.4 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version: 1.22 - - uses: technote-space/get-diff-action@v5 + check-latest: true + - uses: technote-space/get-diff-action@v6.1.2 id: git_diff with: PATTERNS: | @@ -41,26 +44,43 @@ jobs: go.sum # for private repo access - run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:x-oauth-basic@github.com/.insteadOf https://github.com/ - - name: run go linters + # install golangci-lint + - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION} + - name: run go linters (long) + if: env.GIT_DIFF + id: lint_long run: | - make tools make lint - if: env.GIT_DIFF + - uses: technote-space/get-diff-action@v6.1.2 + if: steps.lint_long.outcome == 'skipped' + with: + PATTERNS: | + **/**.go + go.mod + go.sum + - name: run go linters (short) + if: steps.lint_long.outcome == 'skipped' && env.GIT_DIFF + run: | + make lint + env: + GIT_DIFF: ${{ env.GIT_DIFF }} + LINT_DIFF: 1 # Use --check or --exit-code when available (Go 1.19?) # https://github.com/golang/go/issues/27005 tidy: env: # for private repo access - GOPRIVATE: github.com/initia-labs/* + GOPRIVATE: github.com/initia-labs,github.com/skip-mev/slinky GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }} runs-on: ubuntu-latest name: tidy steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: 1.22 + check-latest: true # for private repo access - run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:x-oauth-basic@github.com/.insteadOf https://github.com/ - run: | diff --git a/Makefile b/Makefile index f43925c..eceae11 100644 --- a/Makefile +++ b/Makefile @@ -202,3 +202,17 @@ benchmark: @go test -timeout 20m -mod=readonly -bench=. ./... .PHONY: test test-all test-cover test-unit test-race benchmark contracts-gen + +############################################################################### +### Linting ### +############################################################################### + +lint: + golangci-lint run --out-format=tab --timeout=15m + +lint-fix: + golangci-lint run --fix --out-format=tab --timeout=15m + +.PHONY: lint lint-fix + + diff --git a/app/ante/verify.go b/app/ante/verify.go index 0cb00a0..7e85d0b 100644 --- a/app/ante/verify.go +++ b/app/ante/verify.go @@ -32,7 +32,7 @@ func internalSignModeToAPI(mode signing.SignMode) (signingv1beta1.SignMode, erro case signing.SignMode_SIGN_MODE_DIRECT_AUX: return signingv1beta1.SignMode_SIGN_MODE_DIRECT_AUX, nil case signing.SignMode_SIGN_MODE_EIP_191: - return signingv1beta1.SignMode_SIGN_MODE_EIP_191, nil + return signingv1beta1.SignMode_SIGN_MODE_EIP_191, nil //nolint:staticcheck default: return signingv1beta1.SignMode_SIGN_MODE_UNSPECIFIED, fmt.Errorf("unsupported sign mode %s", mode) } diff --git a/app/app.go b/app/app.go index 1007d76..41d675d 100644 --- a/app/app.go +++ b/app/app.go @@ -1081,7 +1081,9 @@ func (app *MinitiaApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil { panic(err) } - app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) + if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()); err != nil { + panic(err) + } return app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState) } diff --git a/app/test_helpers.go b/app/test_helpers.go index 9691375..fedcd09 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -93,7 +93,7 @@ func SetupWithGenesisAccounts( // allow empty validator if valSet == nil || len(valSet.Validators) == 0 { privVal := ed25519.GenPrivKey() - pubKey, err := cryptocodec.ToTmPubKeyInterface(privVal.PubKey()) + pubKey, err := cryptocodec.ToTmPubKeyInterface(privVal.PubKey()) //nolint:staticcheck if err != nil { panic(err) } @@ -104,7 +104,7 @@ func SetupWithGenesisAccounts( validators := make([]opchildtypes.Validator, 0, len(valSet.Validators)) for _, val := range valSet.Validators { - pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey) + pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey) //nolint:staticcheck if err != nil { panic(err) } diff --git a/jsonrpc/backend/block.go b/jsonrpc/backend/block.go index 8dcf480..6cde7f0 100644 --- a/jsonrpc/backend/block.go +++ b/jsonrpc/backend/block.go @@ -106,10 +106,13 @@ func (b *JSONRPCBackend) GetBlockByNumber(ethBlockNum rpc.BlockNumber, fullTx bo txs := []*rpctypes.RPCTransaction{} if fullTx { - b.app.EVMIndexer().IterateBlockTxs(queryCtx, blockNumber, func(tx *rpctypes.RPCTransaction) (bool, error) { + err = b.app.EVMIndexer().IterateBlockTxs(queryCtx, blockNumber, func(tx *rpctypes.RPCTransaction) (bool, error) { txs = append(txs, tx) return false, nil }) + if err != nil { + return nil, err + } } return formatBlock(header, txs), nil @@ -129,10 +132,13 @@ func (b *JSONRPCBackend) GetBlockByHash(hash common.Hash, fullTx bool) (map[stri txs := []*rpctypes.RPCTransaction{} if fullTx { blockNumber := header.Number.Uint64() - b.app.EVMIndexer().IterateBlockTxs(queryCtx, blockNumber, func(tx *rpctypes.RPCTransaction) (bool, error) { + err = b.app.EVMIndexer().IterateBlockTxs(queryCtx, blockNumber, func(tx *rpctypes.RPCTransaction) (bool, error) { txs = append(txs, tx) return false, nil }) + if err != nil { + return nil, err + } } return formatBlock(header, txs), nil diff --git a/jsonrpc/backend/filters.go b/jsonrpc/backend/filters.go index 8cf9113..3fb38ac 100644 --- a/jsonrpc/backend/filters.go +++ b/jsonrpc/backend/filters.go @@ -21,10 +21,13 @@ func (b *JSONRPCBackend) GetLogsByHeight(height uint64) ([]*coretypes.Log, error } txs := []*rpctypes.RPCTransaction{} - b.app.EVMIndexer().IterateBlockTxs(queryCtx, height, func(tx *rpctypes.RPCTransaction) (bool, error) { + err = b.app.EVMIndexer().IterateBlockTxs(queryCtx, height, func(tx *rpctypes.RPCTransaction) (bool, error) { txs = append(txs, tx) return false, nil }) + if err != nil { + return nil, err + } for _, tx := range txs { receipt, err := b.app.EVMIndexer().TxReceiptByHash(queryCtx, tx.Hash) diff --git a/jsonrpc/backend/gas.go b/jsonrpc/backend/gas.go index 4f98230..ce10a9e 100644 --- a/jsonrpc/backend/gas.go +++ b/jsonrpc/backend/gas.go @@ -61,16 +61,21 @@ func (b *JSONRPCBackend) EstimateGas(args rpctypes.TransactionArgs, blockNrOrHas } txBuilder := b.app.TxConfig().NewTxBuilder() - txBuilder.SetMsgs(sdkMsgs...) - txBuilder.SetSignatures(signing.SignatureV2{ + if err = txBuilder.SetMsgs(sdkMsgs...); err != nil { + return hexutil.Uint64(0), err + } + if err = txBuilder.SetSignatures(signing.SignatureV2{ PubKey: nil, Data: &signing.SingleSignatureData{ SignMode: keeper.SignMode_SIGN_MODE_ETHEREUM, Signature: nil, }, Sequence: uint64(*args.Nonce), - }) + }); err != nil { + return hexutil.Uint64(0), err + } tx := txBuilder.GetTx() + txBytes, err := b.app.TxConfig().TxEncoder()(tx) if err != nil { return hexutil.Uint64(0), err diff --git a/x/evm/keeper/genesis.go b/x/evm/keeper/genesis.go index 984f4f7..a0935fa 100644 --- a/x/evm/keeper/genesis.go +++ b/x/evm/keeper/genesis.go @@ -104,14 +104,17 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState { } kvs := []types.GenesisKeyValue{} - k.VMStore.Walk(ctx, nil, func(key, value []byte) (stop bool, err error) { + err = k.VMStore.Walk(ctx, nil, func(key, value []byte) (stop bool, err error) { kvs = append(kvs, types.GenesisKeyValue{Key: key, Value: value}) return false, nil }) + if err != nil { + panic(err) + } var stores *types.GenesisERC20Stores erc20Stores := []types.GenesisERC20Stores{} - k.ERC20Stores.Walk(ctx, nil, func(key collections.Pair[[]byte, []byte]) (stop bool, err error) { + err = k.ERC20Stores.Walk(ctx, nil, func(key collections.Pair[[]byte, []byte]) (stop bool, err error) { if stores == nil || !bytes.Equal(stores.Address, key.K1()) { erc20Stores = append(erc20Stores, types.GenesisERC20Stores{ Address: key.K1(), @@ -125,9 +128,12 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState { stores.Stores = append(stores.Stores, key.K2()) return false, nil }) + if err != nil { + panic(err) + } denomAddresses := []types.GenesisDenomAddress{} - k.ERC20ContractAddrsByDenom.Walk(ctx, nil, func(denom string, contractAddr []byte) (stop bool, err error) { + err = k.ERC20ContractAddrsByDenom.Walk(ctx, nil, func(denom string, contractAddr []byte) (stop bool, err error) { denomAddresses = append(denomAddresses, types.GenesisDenomAddress{ Denom: denom, ContractAddress: contractAddr, @@ -135,6 +141,9 @@ func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState { return false, nil }) + if err != nil { + panic(err) + } factoryAddr, err := k.ERC20FactoryAddr.Get(ctx) if err != nil { diff --git a/x/evm/keeper/txutils.go b/x/evm/keeper/txutils.go index be226c4..a3dc55f 100644 --- a/x/evm/keeper/txutils.go +++ b/x/evm/keeper/txutils.go @@ -154,10 +154,14 @@ func (u *TxUtils) ConvertEthereumTxToCosmosTx(ctx context.Context, ethTx *corety } txBuilder := authtx.NewTxConfig(u.cdc, authtx.DefaultSignModes).NewTxBuilder() - txBuilder.SetMsgs(sdkMsgs...) + if err = txBuilder.SetMsgs(sdkMsgs...); err != nil { + return nil, err + } txBuilder.SetFeeAmount(feeAmount) txBuilder.SetGasLimit(gasLimit) - txBuilder.SetSignatures(sig) + if err = txBuilder.SetSignatures(sig); err != nil { + return nil, err + } // set memo memo, err := json.Marshal(metadata{