Skip to content

Commit

Permalink
Backport #1171
Browse files Browse the repository at this point in the history
  • Loading branch information
tkxkd0159 committed Jun 19, 2024
1 parent 2350c1a commit 888642a
Show file tree
Hide file tree
Showing 435 changed files with 1,797 additions and 1,397 deletions.
159 changes: 137 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,59 @@
run:
tests: false
# # timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m
tests: true
timeout: 15m
allow-parallel-runners: true
build-tags:
- ledger
- goleveldb
- test_ledger_mock

output:
sort-results: true

linters:
disable-all: false
disable-all: true
enable:
- gofmt
- goconst
- goimports
- gosec
- errcheck
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- prealloc
- staticcheck
- stylecheck
- typecheck
- unconvert
- unused
- unparam
- misspell
disable:
- dogsled
- gosec
- gci
- gofumpt
- goconst
- gocritic
- errcheck
- interfacer
- wsl
- nakedret
- nolintlint
- revive
- misspell
- stylecheck
- typecheck
- thelper
- unconvert
- asasalint
- asciicheck
- bidichk
- bodyclose
- copyloopvar
- errchkjson
- errorlint
- tenv
- wastedassign
- fatcontext

issues:
exclude-dirs:
- "testdata$"
exclude-files:
- server/grpc/gogoreflection/fix_registration.go
- "fix_registration.go"
- ".*\\.pb\\.go$"
- ".*\\.pb\\.gw\\.go$"
- ".*\\.pulsar\\.go$"
- crypto/keys/secp256k1/internal/*
exclude-rules:
- text: "Use of weak random number generator"
linters:
Expand All @@ -54,13 +77,105 @@ issues:
text: "SA1019: token."
linters:
- staticcheck
- path: "legacy"
text: "SA1019:"
linters:
- staticcheck
- 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: "SA1019: params.SendEnabled is deprecated" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1019: \"github.com/golang/protobuf/proto\" is deprecated" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1019: vote.Option is deprecated" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "SA1019: types.QueryNextAccountNumberRequest is deprecated" # TODO remove once ready to remove from the sdk
linters:
- staticcheck
- text: "leading space"
linters:
- nolintlint
- path: _test\.go
linters:
- goconst
max-issues-per-linter: 10000
max-same-issues: 10000

linters-settings:
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(github.com/Finschia/finschia-sdk)
revive:
rules:
- name: redefines-builtin-id
disabled: true

gosec:
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
gofumpt:
extra-rules: true
dogsled:
max-blank-identifiers: 3
max-blank-identifiers: 6
nolintlint:
allow-unused: false
require-explanation: false
require-specific: false
require-specific: false
gosimple:
checks: ["all"]
gocritic:
disabled-checks:
- regexpMust
- appendAssign
- ifElseChain
6 changes: 2 additions & 4 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ import (
"github.com/Finschia/finschia-sdk/telemetry"
sdk "github.com/Finschia/finschia-sdk/types"
sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
ocabci "github.com/Finschia/ostracon/abci/types"
)

// InitChain implements the ABCI interface. It runs the initialization logic
// directly on the CommitMultiStore.
func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) {
func (app *BaseApp) InitChain(req abci.RequestInitChain) abci.ResponseInitChain {
// On a new chain, we consider the init chain block height as 0, even though
// req.InitialHeight is 1 by default.
initHeader := tmproto.Header{ChainID: req.ChainId, Time: req.Time}
Expand Down Expand Up @@ -62,7 +61,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
// add block gas meter for any genesis transactions (allow infinite gas)
app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(sdk.NewInfiniteGasMeter())

res = app.initChainer(app.deliverState.ctx, req)
res := app.initChainer(app.deliverState.ctx, req)

// sanity check
if len(req.Validators) > 0 {
Expand Down Expand Up @@ -925,7 +924,6 @@ func splitPath(requestPath string) (path []string) {
// createQueryContext creates a new sdk.Context for a query, taking as args
// the block height and whether the query needs a proof or not.
func (app *BaseApp) createQueryContextWithCheckState() sdk.Context {

cacheMS := app.checkState.CacheMultiStore()

// branch the commit-multistore for safety
Expand Down
11 changes: 8 additions & 3 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ func TestBaseAppCreateQueryContext(t *testing.T) {
db := dbm.NewMemDB()
name := t.Name()
app := NewBaseApp(name, logger, db, nil)
app.init()
err := app.init()
require.NoError(t, err)

app.BeginBlock(ocabci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})
app.Commit()
Expand Down Expand Up @@ -190,7 +191,8 @@ func TestBaseAppBeginBlockConsensusParams(t *testing.T) {
},
},
})
app.init()
err := app.init()
require.NoError(t, err)

// set block params
app.BeginBlock(ocabci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})
Expand Down Expand Up @@ -218,7 +220,10 @@ func (ps *paramStore) Set(_ sdk.Context, key []byte, value interface{}) {
panic(err)
}

ps.db.Set(key, bz)
err = ps.db.Set(key, bz)
if err != nil {
panic(err)
}
}

func (ps *paramStore) Has(_ sdk.Context, key []byte) bool {
Expand Down
3 changes: 1 addition & 2 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"sync"

"github.com/gogo/protobuf/proto"

abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

ocabci "github.com/Finschia/ostracon/abci/types"
"github.com/Finschia/ostracon/crypto/tmhash"
Expand Down Expand Up @@ -672,7 +672,6 @@ func (app *BaseApp) anteTx(ctx sdk.Context, txBytes []byte, tx sdk.Tx, simulate
anteCtx, msCache := app.cacheTxContext(ctx, txBytes)
anteCtx = anteCtx.WithEventManager(sdk.NewEventManager())
newCtx, err := app.anteHandler(anteCtx, tx, simulate)

if err != nil {
return newCtx, err
}
Expand Down
11 changes: 3 additions & 8 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func aminoTxEncoder() sdk.TxEncoder {

// simple one store baseapp
func setupBaseApp(t *testing.T, options ...func(*BaseApp)) *BaseApp {
t.Helper()
app := newBaseApp(t.Name(), options...)
require.Equal(t, t.Name(), app.Name())

Expand Down Expand Up @@ -132,6 +133,7 @@ func TestLoadVersionPruning(t *testing.T) {
}

func testLoadVersionHelper(t *testing.T, app *BaseApp, expectedHeight int64, expectedID sdk.CommitID) {
t.Helper()
lastHeight := app.LastBlockHeight()
lastID := app.LastCommitID()
require.Equal(t, expectedHeight, lastHeight)
Expand Down Expand Up @@ -163,13 +165,6 @@ func TestGetMaximumBlockGas(t *testing.T) {
}

func TestListSnapshots(t *testing.T) {
type setupConfig struct {
blocks uint64
blockTxs int
snapshotInterval uint64
snapshotKeepEvery uint32
}

app, _ := setupBaseAppWithSnapshots(t, 2, 5)

expected := abci.ResponseListSnapshots{Snapshots: []*abci.Snapshot{
Expand Down Expand Up @@ -222,7 +217,7 @@ func TestSetChanCheckTxSize(t *testing.T) {
logger := defaultLogger()
db := dbm.NewMemDB()

var size = uint(100)
size := uint(100)

app := NewBaseApp(t.Name(), logger, db, nil, SetChanCheckTxSize(size))
require.Equal(t, int(size), cap(app.chCheckTx))
Expand Down
2 changes: 1 addition & 1 deletion baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
}
}

func createTestTx(txConfig client.TxConfig, txBuilder client.TxBuilder, privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, []byte, error) {
func createTestTx(txConfig client.TxConfig, txBuilder client.TxBuilder, privs []cryptotypes.PrivKey, accNums, accSeqs []uint64, chainID string) (xauthsigning.Tx, []byte, error) {
// First round: we gather all the signer infos. We use the "set empty
// signature" hack to do that.
var sigsV2 []signing.SignatureV2
Expand Down
9 changes: 8 additions & 1 deletion baseapp/deliver_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ func TestCustomRunTxPanicHandler(t *testing.T) {
{
tx := newTxCounter(0, 0)

require.PanicsWithValue(t, customPanicMsg, func() { app.Deliver(aminoTxEncoder(), tx) })
require.PanicsWithValue(t, customPanicMsg, func() { app.Deliver(aminoTxEncoder(), tx) }) //nolint:errcheck
}
}

Expand Down Expand Up @@ -1284,6 +1284,7 @@ func testTxDecoder(cdc *codec.LegacyAmino) sdk.TxDecoder {
}

func anteHandlerTxTest(t *testing.T, capKey sdk.StoreKey, storeKey []byte) sdk.AnteHandler {
t.Helper()
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
store := ctx.KVStore(capKey)
txTest := tx.(txTest)
Expand All @@ -1307,6 +1308,7 @@ func anteHandlerTxTest(t *testing.T, capKey sdk.StoreKey, storeKey []byte) sdk.A

// TODO(dudong2): remove this func after reverting CheckTx logic
func anteHandlerTxTest2(t *testing.T, capKey sdk.StoreKey, storeKey []byte) sdk.AnteHandler {
t.Helper()
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
store := ctx.KVStore(capKey)
txTest := tx.(*txTest)
Expand Down Expand Up @@ -1338,6 +1340,7 @@ func counterEvent(evType string, msgCount int64) sdk.Events {
}

func handlerMsgCounter(t *testing.T, capKey sdk.StoreKey, deliverKey []byte) sdk.Handler {
t.Helper()
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())
store := ctx.KVStore(capKey)
Expand Down Expand Up @@ -1389,6 +1392,7 @@ func setIntOnStore(store sdk.KVStore, key []byte, i int64) {
// check counter matches what's in store.
// increment and store
func incrementingCounter(t *testing.T, store sdk.KVStore, counterKey []byte, counter int64) (*sdk.Result, error) {
t.Helper()
storedCounter := getIntFromStore(store, counterKey)
require.Equal(t, storedCounter, counter)
setIntOnStore(store, counterKey, counter+1)
Expand Down Expand Up @@ -1649,6 +1653,7 @@ func TestLoadVersionInvalid(t *testing.T) {

// simple one store baseapp with data and snapshots. Each tx is 1 MB in size (uncompressed).
func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options ...func(*BaseApp)) (*BaseApp, func()) {
t.Helper()
codec := codec.NewLegacyAmino()
registerTestCodec(codec)
routerOpt := func(bapp *BaseApp) {
Expand Down Expand Up @@ -1785,6 +1790,7 @@ func useDefaultLoader(app *BaseApp) {
}

func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) {
t.Helper()
rs := rootmulti.NewStore(db, log.NewNopLogger())
rs.SetPruning(store.PruneNothing)
key := sdk.NewKVStoreKey(storeKey)
Expand All @@ -1802,6 +1808,7 @@ func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) {
}

func checkStore(t *testing.T, db dbm.DB, ver int64, storeKey string, k, v []byte) {
t.Helper()
rs := rootmulti.NewStore(db, log.NewNopLogger())
rs.SetPruning(store.PruneDefault)
key := sdk.NewKVStoreKey(storeKey)
Expand Down
3 changes: 2 additions & 1 deletion baseapp/grpcrouter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"os"
"testing"

"github.com/Finschia/ostracon/libs/log"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"

"github.com/Finschia/ostracon/libs/log"

"github.com/Finschia/finschia-sdk/baseapp"
"github.com/Finschia/finschia-sdk/codec/types"
"github.com/Finschia/finschia-sdk/simapp"
Expand Down
Loading

0 comments on commit 888642a

Please sign in to comment.