Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
55 changes: 55 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: golangci-lint
on:
push:
branches:
- master
- main
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# github.com/mvdan/github-actions-golang
on: [push, pull_request]
name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.19.x, 1.20.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- run: go test ./...
178 changes: 122 additions & 56 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,70 +1,136 @@
run:
tests: true
timeout: 10m
sort-results: true
allow-parallel-runners: true
exclude-dir: testutil/testdata
skip-files:
- server/grpc/gogoreflection/fix_registration.go

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
# - funlen
# - gochecknoglobals
# - gochecknoinits
# - gocognit
- goconst
# - gocritic
# - gocyclo
# - godox
- gofmt
- goimports
- revive
- gosec
- gosimple
- govet
- ineffassign
# - interfacer
- lll
# - maligned
# - misspell
# - dogsled
# - exportloopref
# - goconst
# - gocritic
- gci
- gofumpt
# - gosec
# - gosimple
# - govet
# - ineffassign
# - misspell
- nakedret
- nolintlint
- prealloc
- staticcheck
- structcheck
- stylecheck
# - typecheck
- unconvert
# - unparam
- unused
- varcheck
# - whitespace
# - wsl
# - nolintlint
# - staticcheck
# - revive
# - stylecheck
# - typecheck
# - unconvert
# - unused

issues:
exclude-rules:
- path: _test\.go
- text: 'Use of weak random number generator'
linters:
- gosec
- linters:
- lll
source: "https://"
max-same-issues: 50
- 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
- text: 'SA1019: codec.NewAminoCodec is deprecated' # TODO remove once migration path is set out
linters:
- staticcheck
- text: 'SA1019: legacybech32.MustMarshalPubKey' # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: 'SA1019: legacybech32.MarshalPubKey' # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: 'SA1019: legacybech32.UnmarshalPubKey' # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: 'leading space'
linters:
- nolintlint

max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
dogsled:
max-blank-identifiers: 3
maligned:
suggest-new: true
# govet:
# check-shadowing: true
gci:
custom-order: true
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(cosmossdk.io)
- prefix(github.com/cosmos/cosmos-sdk)
- prefix(github.com/ConsiderItDone/LandslideCore)
revive:
min-confidence: 0
maligned:
suggest-new: true
rules:
- name: redefines-builtin-id
disabled: true

gosec:
# To select a subset of rules to run.
# Available rules: https://github.com/securego/gosec#available-rules
# Default: [] - means include all rules
includes:
# - G101 # Look for hard coded credentials
- G102 # Bind to all interfaces
- G103 # Audit the use of unsafe block
- G104 # Audit errors not checked
- G106 # Audit the use of ssh.InsecureIgnoreHostKey
- G107 # Url provided to HTTP request as taint input
- G108 # Profiling endpoint automatically exposed on /debug/pprof
- G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32
- G110 # Potential DoS vulnerability via decompression bomb
- G111 # Potential directory traversal
- G112 # Potential slowloris attack
- G113 # Usage of Rat.SetString in math/big with an overflow (CVE-2022-23772)
- G114 # Use of net/http serve function that has no support for setting timeouts
- G201 # SQL query construction using format string
- G202 # SQL query construction using string concatenation
- G203 # Use of unescaped data in HTML templates
- G204 # Audit use of command execution
- G301 # Poor file permissions used when creating a directory
- G302 # Poor file permissions used with chmod
- G303 # Creating tempfile using a predictable path
- G304 # File path provided as taint input
- G305 # File traversal when extracting zip/tar archive
- G306 # Poor file permissions used when writing to a new file
- G307 # Deferring a method which returns an error
- G401 # Detect the usage of DES, RC4, MD5 or SHA1
- G402 # Look for bad TLS connection settings
- G403 # Ensure minimum RSA key length of 2048 bits
- G404 # Insecure random number source (rand)
- G501 # Import blocklist: crypto/md5
- G502 # Import blocklist: crypto/des
- G503 # Import blocklist: crypto/rc4
- G504 # Import blocklist: net/http/cgi
- G505 # Import blocklist: crypto/sha1
- G601 # Implicit memory aliasing of items from a range statement
misspell:
locale: US
ignore-words:
- behaviour

gofumpt:
extra-rules: true
dogsled:
max-blank-identifiers: 5
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: true
require-specific: false
gosimple:
checks: ['all']

gocritic:
disabled-checks:
- regexpMust
- appendAssign
- ifElseChain
11 changes: 6 additions & 5 deletions abci/client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"sync"
"time"

"golang.org/x/net/context"
"google.golang.org/grpc"

"github.com/consideritdone/landslidecore/abci/types"
tmnet "github.com/consideritdone/landslidecore/libs/net"
"github.com/consideritdone/landslidecore/libs/service"
tmsync "github.com/consideritdone/landslidecore/libs/sync"
"golang.org/x/net/context"
"google.golang.org/grpc"
)

var _ Client = (*grpcClient)(nil)
Expand Down Expand Up @@ -408,13 +407,15 @@ func (cli *grpcClient) OfferSnapshotSync(params types.RequestOfferSnapshot) (*ty
}

func (cli *grpcClient) LoadSnapshotChunkSync(
params types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
params types.RequestLoadSnapshotChunk,
) (*types.ResponseLoadSnapshotChunk, error) {
reqres := cli.LoadSnapshotChunkAsync(params)
return cli.finishSyncCall(reqres).GetLoadSnapshotChunk(), cli.Error()
}

func (cli *grpcClient) ApplySnapshotChunkSync(
params types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
params types.RequestApplySnapshotChunk,
) (*types.ResponseApplySnapshotChunk, error) {
reqres := cli.ApplySnapshotChunkAsync(params)
return cli.finishSyncCall(reqres).GetApplySnapshotChunk(), cli.Error()
}
6 changes: 4 additions & 2 deletions abci/client/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ func (app *localClient) OfferSnapshotSync(req types.RequestOfferSnapshot) (*type
}

func (app *localClient) LoadSnapshotChunkSync(
req types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
req types.RequestLoadSnapshotChunk,
) (*types.ResponseLoadSnapshotChunk, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

Expand All @@ -315,7 +316,8 @@ func (app *localClient) LoadSnapshotChunkSync(
}

func (app *localClient) ApplySnapshotChunkSync(
req types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
req types.RequestApplySnapshotChunk,
) (*types.ResponseApplySnapshotChunk, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

Expand Down
8 changes: 5 additions & 3 deletions abci/client/socket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (cli *socketClient) sendRequestsRoutine(conn io.Writer) {
func (cli *socketClient) recvResponseRoutine(conn io.Reader) {
r := bufio.NewReader(conn)
for {
var res = &types.Response{}
res := &types.Response{}
err := types.ReadMessage(r, res)
if err != nil {
cli.stopForError(fmt.Errorf("read message: %w", err))
Expand Down Expand Up @@ -399,7 +399,8 @@ func (cli *socketClient) OfferSnapshotSync(req types.RequestOfferSnapshot) (*typ
}

func (cli *socketClient) LoadSnapshotChunkSync(
req types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
req types.RequestLoadSnapshotChunk,
) (*types.ResponseLoadSnapshotChunk, error) {
reqres := cli.queueRequest(types.ToRequestLoadSnapshotChunk(req))
if err := cli.FlushSync(); err != nil {
return nil, err
Expand All @@ -409,7 +410,8 @@ func (cli *socketClient) LoadSnapshotChunkSync(
}

func (cli *socketClient) ApplySnapshotChunkSync(
req types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
req types.RequestApplySnapshotChunk,
) (*types.ResponseApplySnapshotChunk, error) {
reqres := cli.queueRequest(types.ToRequestApplySnapshotChunk(req))
if err := cli.FlushSync(); err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions abci/client/socket_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

abcicli "github.com/consideritdone/landslidecore/abci/client"
"github.com/consideritdone/landslidecore/abci/server"
"github.com/consideritdone/landslidecore/abci/types"
tmrand "github.com/consideritdone/landslidecore/libs/rand"
"github.com/consideritdone/landslidecore/libs/service"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestProperSyncCalls(t *testing.T) {
Expand Down Expand Up @@ -93,7 +92,8 @@ func TestHangingSyncCalls(t *testing.T) {
}

func setupClientServer(t *testing.T, app types.Application) (
service.Service, abcicli.Client) {
service.Service, abcicli.Client,
) {
// some port between 20k and 30k
port := 20000 + tmrand.Int32()%10000
addr := fmt.Sprintf("localhost:%d", port)
Expand Down
Loading