Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
lint: fix many broken lint issues (#49)
Browse files Browse the repository at this point in the history
* lint: fix many broken lint issues

* more lint issues resolved

* more lint issues resolved

* all actions issues fixed

* pin variables for websocket

* Update .github/workflows/lint.yml

* more fixes

* fix lint issues in pubsub, rpc, types

* fix lint issues in statedb, journal, pubsub, cli

* fix comment

Co-authored-by: Federico Kunze <[email protected]>
  • Loading branch information
Akash Khosla and fedekunze authored Jun 8, 2021
1 parent fcb7c11 commit e3270ae
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 197 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: Lint
# Lint runs golangci-lint over the entire cosmos-sdk repository
# This workflow is run on every pull request and push to development
# The `golangci` will pass without running if no *.{go, mod, sum} files have been changed.
name: Run Lint
# Lint runs golangci-lint over the entire ethermint repository This workflow is
# run on every pull request and push to main The `golangci` will pass without
# running if no *.{go, mod, sum} files have been changed.
on:
pull_request:
push:
branches:
- development
- main
jobs:
golangci:
name: golangci-lint
name: Run golangci-lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
Expand All @@ -20,10 +20,11 @@ jobs:
.go
.mod
.sum
- uses: golangci/golangci-lint-action@master
- uses: golangci/golangci-lint-action@v2.5.2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.28
version: v1.29
args: --timeout 10m
github-token: ${{ secrets.github_token }}
if: "env.GIT_DIFF != ''"
# Check only if there are differences in the source code
if: "env.GIT_DIFF"
5 changes: 0 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ issues:
- text: "ST1003:"
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: "ST1016:"
linters:
- stylecheck
max-issues-per-linter: 10000
max-same-issues: 10000

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ clean:
.PHONY: install clean

docker-build:
# TODO replace with kaniko
docker build -t ${DOCKER_IMAGE}:${DOCKER_TAG} .
docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:latest
# docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:${COMMIT_HASH}
Expand Down
40 changes: 0 additions & 40 deletions client/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -478,42 +477,3 @@ func writeFile(name string, dir string, contents []byte) error {

return nil
}

func appendToFile(name string, dir string, contents []byte) error {
writePath := filepath.Join(dir)
file := filepath.Join(writePath, name)

err := tmos.EnsureDir(writePath, 0755)
if err != nil {
return err
}

if _, err = os.Stat(file); err == nil {
err = os.Chmod(file, 0777)
if err != nil {
fmt.Println(err)
return err
}
}

f, err := os.OpenFile(file, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Println(err)
return err
}
defer f.Close()

_, err = f.Write(contents)
if err != nil {
log.Println(err)
return err
}

f.Write([]byte("\n"))
if err != nil {
log.Println(err)
return err
}

return nil
}
6 changes: 5 additions & 1 deletion cmd/ethermintd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ func addTxFlags(cmd *cobra.Command) *cobra.Command {
//))

//viper.BindPFlag(flags.FlagTrustNode, cmd.Flags().Lookup(flags.FlagTrustNode))

// TODO: we need to handle the errors for these, decide if we should return error upward and handle
// nolint: errcheck
viper.BindPFlag(flags.FlagNode, cmd.Flags().Lookup(flags.FlagNode))
// nolint: errcheck
viper.BindPFlag(flags.FlagKeyringBackend, cmd.Flags().Lookup(flags.FlagKeyringBackend))

// nolint: errcheck
cmd.MarkFlagRequired(flags.FlagChainID)
return cmd
}
1 change: 0 additions & 1 deletion cmd/ethermintd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const (
flagVestingStart = "vesting-start-time"
flagVestingEnd = "vesting-end-time"
flagVestingAmt = "vesting-amount"
flagKeyring = "pass"
)

// AddGenesisAccountCmd returns add-genesis-account cobra Command.
Expand Down
29 changes: 1 addition & 28 deletions cmd/ethermintd/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"context"
"io"
"math/big"
"os"
Expand All @@ -11,7 +10,6 @@ import (
"github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/snapshots"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/crisis"

"github.com/spf13/cast"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -67,28 +65,6 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
},
}

initRootCmd(rootCmd, encodingConfig)

return rootCmd, encodingConfig
}

// Execute executes the root command.
func Execute(rootCmd *cobra.Command) error {
// Create and set a client.Context on the command's Context. During the pre-run
// of the root command, a default initialized client.Context is provided to
// seed child command execution with values such as AccountRetriver, Keyring,
// and a Tendermint RPC. This requires the use of a pointer reference when
// getting and setting the client.Context. Ideally, we utilize
// https://github.com/spf13/cobra/pull/1118.
ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{})
ctx = context.WithValue(ctx, sdkserver.ServerContextKey, sdkserver.NewDefaultContext())

executor := tmcli.PrepareBaseCmd(rootCmd, "", app.DefaultNodeHome)
return executor.ExecuteContext(ctx)
}

func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
authclient.Codec = encodingConfig.Marshaler
sdk.PowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))

Expand Down Expand Up @@ -137,10 +113,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
)
rootCmd = addTxFlags(rootCmd)

}

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
return rootCmd, encodingConfig
}

func queryCommand() *cobra.Command {
Expand Down
9 changes: 5 additions & 4 deletions cmd/ethermintd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (

// Tendermint full-node start flags
const (
flagWithTendermint = "with-tendermint"
flagAddress = "address"
flagTransport = "transport"
flagTraceStore = "trace-store"
Expand All @@ -62,7 +61,6 @@ const (
FlagPruningKeepRecent = "pruning-keep-recent"
FlagPruningKeepEvery = "pruning-keep-every"
FlagPruningInterval = "pruning-interval"
FlagIndexEvents = "index-events"
FlagMinRetainBlocks = "min-retain-blocks"
)

Expand Down Expand Up @@ -114,9 +112,12 @@ which accepts a path for the resulting pprof file.

// Bind flags to the Context's Viper so the app construction can set
// options accordingly.
serverCtx.Viper.BindPFlags(cmd.Flags())
err := serverCtx.Viper.BindPFlags(cmd.Flags())
if err != nil {
return err
}

_, err := server.GetPruningOptionsFromFlags(serverCtx.Viper)
_, err = server.GetPruningOptionsFromFlags(serverCtx.Viper)
return err
},
RunE: func(cmd *cobra.Command, _ []string) error {
Expand Down
10 changes: 8 additions & 2 deletions cmd/ethermintd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ import (
// to get the Tendermint configuration or to get access to Viper.
func InterceptConfigsPreRunHandler(cmd *cobra.Command) error {
rootViper := viper.New()
rootViper.BindPFlags(cmd.Flags())
rootViper.BindPFlags(cmd.PersistentFlags())
err := rootViper.BindPFlags(cmd.Flags())
if err != nil {
return err
}
err = rootViper.BindPFlags(cmd.PersistentFlags())
if err != nil {
return err
}

serverCtx := server.NewDefaultContext()
config, err := interceptConfigs(serverCtx, rootViper)
Expand Down
4 changes: 1 addition & 3 deletions ethereum/rpc/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"math/big"
"strings"
"sync"

"github.com/gogo/protobuf/jsonpb"
"github.com/pkg/errors"
Expand Down Expand Up @@ -45,7 +44,6 @@ type PublicEthAPI struct {
logger log.Logger
backend Backend
nonceLock *rpctypes.AddrLocker
keyringLock sync.Mutex
}

// NewPublicEthAPI creates an instance of the public ETH Web3 API.
Expand Down Expand Up @@ -736,7 +734,7 @@ func (e *PublicEthAPI) GetTransactionReceipt(hash common.Hash) (map[string]inter
return nil, err
}

cumulativeGasUsed := uint64(tx.Receipt.Result.GasUsed)
cumulativeGasUsed := tx.Receipt.Result.GasUsed
if tx.Receipt.Index != 0 {
cumulativeGasUsed += rpctypes.GetBlockCumulativeGas(e.clientCtx, block.Block, int(tx.Receipt.Index))
}
Expand Down
20 changes: 8 additions & 12 deletions ethereum/rpc/pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,15 @@ func (m *memEventBus) Subscribe(name string) (<-chan coretypes.ResultEvent, erro

func (m *memEventBus) publishTopic(name string, src <-chan coretypes.ResultEvent) {
for {
select {
case msg, ok := <-src:
if !ok {
m.closeAllSubscribers(name)
m.topicsMux.Lock()
delete(m.topics, name)
m.topicsMux.Unlock()

return
}

m.publishAllSubscribers(name, msg)
msg, ok := <-src
if !ok {
m.closeAllSubscribers(name)
m.topicsMux.Lock()
delete(m.topics, name)
m.topicsMux.Unlock()
return
}
m.publishAllSubscribers(name, msg)
}
}

Expand Down
24 changes: 8 additions & 16 deletions ethereum/rpc/websockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type websocketsServer struct {
logger log.Logger
}

func NewWebsocketsServer(tmWSClient *rpcclient.WSClient, rpcAddr, wsAddr string) *websocketsServer {
func NewWebsocketsServer(tmWSClient *rpcclient.WSClient, rpcAddr, wsAddr string) WebsocketsServer {
return &websocketsServer{
rpcAddr: rpcAddr,
wsAddr: wsAddr,
Expand Down Expand Up @@ -174,7 +174,7 @@ func (s *websocketsServer) readLoop(wsConn *wsConn) {
continue
}

connId := msg["id"].(float64)
connID := msg["id"].(float64)
if method == "eth_subscribe" {
params := msg["params"].([]interface{})
if len(params) == 0 {
Expand All @@ -190,7 +190,7 @@ func (s *websocketsServer) readLoop(wsConn *wsConn) {

res := &SubscriptionResponseJSON{
Jsonrpc: "2.0",
ID: connId,
ID: connID,
Result: id,
}

Expand All @@ -210,7 +210,7 @@ func (s *websocketsServer) readLoop(wsConn *wsConn) {
ok = s.api.unsubscribe(rpc.ID(ids[0].(string)))
res := &SubscriptionResponseJSON{
Jsonrpc: "2.0",
ID: connId,
ID: connID,
Result: ok,
}

Expand Down Expand Up @@ -325,18 +325,6 @@ func (api *pubSubAPI) unsubscribe(id rpc.ID) bool {
return true
}

func (api *pubSubAPI) getSubscriptionByQuery(query string) *Subscription {
api.filtersMu.Lock()
defer api.filtersMu.Unlock()

for _, wsSub := range api.filters {
if wsSub.query == query {
return wsSub.sub
}
}
return nil
}

func (api *pubSubAPI) subscribeNewHeads(wsConn *wsConn) (rpc.ID, error) {
var query = "subscribeNewHeads"
var subID = rpc.NewID()
Expand Down Expand Up @@ -378,6 +366,8 @@ func (api *pubSubAPI) subscribeNewHeads(wsConn *wsConn) (rpc.ID, error) {

api.filtersMu.RLock()
for subID, wsSub := range api.filters {
subID := subID
wsSub := wsSub
if wsSub.query != query {
continue
}
Expand Down Expand Up @@ -696,6 +686,8 @@ func (api *pubSubAPI) subscribePendingTransactions(wsConn *wsConn) (rpc.ID, erro

api.filtersMu.RLock()
for subID, wsSub := range api.filters {
subID := subID
wsSub := wsSub
if wsSub.query != query {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions tests/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ type Request struct {
ID int `json:"id"`
}

type RPCError struct {
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}

type Response struct {
Error *RPCError `json:"error"`
Error *Error `json:"error"`
ID int `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
}
Expand Down
17 changes: 0 additions & 17 deletions x/evm/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,3 @@ func formatKeyToHash(key string) string {

return ethkey.Hex()
}

// nolint: deadcode
func cosmosAddressFromArg(addr string) (sdk.AccAddress, error) {
if strings.HasPrefix(addr, sdk.GetConfig().GetBech32AccountAddrPrefix()) {
// Check to see if address is Cosmos bech32 formatted
toAddr, err := sdk.AccAddressFromBech32(addr)
if err != nil {
return nil, errors.Wrap(err, "invalid bech32 formatted address")
}
return toAddr, nil
}

// Strip 0x prefix if exists
addr = strings.TrimPrefix(addr, "0x")

return sdk.AccAddressFromHex(addr)
}
Loading

0 comments on commit e3270ae

Please sign in to comment.