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

Fix linter file and issues #282

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
65 changes: 20 additions & 45 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
run:
timeout: 5m

linters:
disable-all: true
enable:
- asasalint
Expand All @@ -8,96 +10,69 @@ run:
- bodyclose
- containedctx
- contextcheck
- cyclop
- decorder
- depguard
- dogsled
- dupl
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exhaustivestruct
- exhaustruct
- exportloopref
- forbidigo
- forcetypeassert
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- godox
- goerr113
- gofumpt
- goheader
- golint
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
- ifshort
- importas
- ineffassign
- interfacebloat
- interfacer
- ireturn
- lll
- loggercheck
- maintidx
- makezero
- maligned
- misspell
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
# - nlreturn # Style wise I personally like this one, todo(lazar): unlax at somepoint, good practice
- noctx
- nolintlint
- nonamedreturns
- nosnakecase
# - nonamedreturns # Named returns in functions help understand what they do
- nosprintfhostport
- paralleltest
- prealloc
- predeclared
- promlinter
- reassign
- revive
- rowserrcheck
- scopelint
- sqlclosecheck
- staticcheck
- structcheck
- stylecheck
- tagliatelle
- tenv
- testableexamples
- testpackage
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- varcheck
- varnamelen
- unused
- wastedassign
- whitespace
- wrapcheck
- wsl
# - wrapcheck # we really should be using this, lax for now todo(lazar): unlax at somepoint, good practice

issues:
max-same-issues: 0
# Default: https://golangci-lint.run/usage/false-positives/#default-exclusions
exclude-dirs:
- e2etest
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- path-except: _test\.go
linters:
- forbidigo
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ making params valid for btc light client ranges
- [#289](https://github.com/babylonlabs-io/babylon/pull/289) hotfix: Invalid minUnbondingTime for verifying inclusion proof

## v0.17.0
- [#282](https://github.com/babylonlabs-io/babylon/pull/282) Fix linter config and issues

### State Breaking

Expand Down
1 change: 0 additions & 1 deletion app/ante/ante_btc_validation_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func NewBtcValidationDecorator(
}

func (bvd BtcValidationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {

// only do this validation when handling mempool addition. During DeliverTx they
// should be performed by btclightclient and btccheckpoint modules
if ctx.IsCheckTx() || ctx.IsReCheckTx() {
Expand Down
8 changes: 4 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,14 +528,14 @@ func NewBabylonApp(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
)
if err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
panic(fmt.Errorf("failed to register snapshot extension: %w", err))
}

err = manager.RegisterExtensions(
ibcwasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.IBCWasmKeeper),
)
if err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
panic(fmt.Errorf("failed to register snapshot extension: %w", err))
}
}

Expand Down Expand Up @@ -722,8 +722,8 @@ func (app *BabylonApp) RegisterNodeService(clientCtx client.Context, cfg config.
}

// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
func (a *BabylonApp) DefaultGenesis() map[string]json.RawMessage {
return a.BasicModuleManager.DefaultGenesis(a.appCodec)
func (app *BabylonApp) DefaultGenesis() map[string]json.RawMessage {
return app.BasicModuleManager.DefaultGenesis(app.appCodec)
}

func (app *BabylonApp) TxConfig() client.TxConfig {
Expand Down
3 changes: 3 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

func TestBabylonBlockedAddrs(t *testing.T) {
t.Parallel()
db := dbm.NewMemDB()
signer, _ := SetupTestPrivSigner()
logger := log.NewTestLogger(t)
Expand Down Expand Up @@ -65,11 +66,13 @@ func TestBabylonBlockedAddrs(t *testing.T) {
}

func TestGetMaccPerms(t *testing.T) {
t.Parallel()
dup := GetMaccPerms()
require.Equal(t, maccPerms, dup, "duplicated module account permissions differed from actual module account permissions")
}

func TestUpgradeStateOnGenesis(t *testing.T) {
t.Parallel()
db := dbm.NewMemDB()
privSigner, err := SetupTestPrivSigner()
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions app/keepers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ func saveClientConfig(homePath string, cliConf *config.ClientConfig) error {
configPath := filepath.Join(homePath, "config")
configFilePath := filepath.Join(configPath, "client.toml")
if err = ensureConfigPath(configPath); err != nil {
return fmt.Errorf("couldn't make client config: %v", err)
return fmt.Errorf("couldn't make client config: %w", err)
}

if err = writeConfigToFile(configFilePath, cliConf); err != nil {
return fmt.Errorf("could not write client config to the file: %v", err)
return fmt.Errorf("could not write client config to the file: %w", err)
}

return nil
Expand Down
4 changes: 1 addition & 3 deletions btcstaking/btcstaking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ func GenerateSignatures(
stakingOutput *wire.TxOut,
leaf txscript.TapLeaf,
) []*schnorr.Signature {

var si []*SignatureInfo

for _, key := range keys {
Expand All @@ -216,7 +215,7 @@ func GenerateSignatures(
// sort signatures by public key
sortedSigInfo := sortSignatureInfo(si)

var sigs []*schnorr.Signature = make([]*schnorr.Signature, len(sortedSigInfo))
sigs := make([]*schnorr.Signature, len(sortedSigInfo))

for i, sigInfo := range sortedSigInfo {
sig := sigInfo
Expand Down Expand Up @@ -293,7 +292,6 @@ func TestSpendingUnbondingPathCovenant35MultiSig(t *testing.T) {
)
}
btctest.AssertEngineExecution(t, 0, true, newEngine)

}

func TestSpendingUnbondingPathSingleKeyCovenant(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions btcstaking/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ func validateSlashingTx(
slashingChangeLockTime uint16,
net *chaincfg.Params,
) error {

if err := CheckPreSignedSlashingTxSanity(slashingTx); err != nil {
return fmt.Errorf("invalid slashing tx: %w", err)
}
Expand Down Expand Up @@ -470,7 +469,6 @@ func signTxWithOneScriptSpendInputFromTapLeafInternal(
fundingOutput *wire.TxOut,
privKey *btcec.PrivateKey,
tapLeaf txscript.TapLeaf) (*schnorr.Signature, error) {

inputFetcher := txscript.NewCannedPrevOutputFetcher(
fundingOutput.PkScript,
fundingOutput.Value,
Expand Down Expand Up @@ -558,7 +556,6 @@ func SignTxWithOneScriptSpendInputStrict(
signedScriptPath []byte,
privKey *btcec.PrivateKey,
) (*schnorr.Signature, error) {

if err := checkTxBeforeSigning(txToSign, fundingTx, fundingOutputIdx); err != nil {
return nil, fmt.Errorf("invalid tx: %w", err)
}
Expand All @@ -579,7 +576,6 @@ func EncSignTxWithOneScriptSpendInputStrict(
privKey *btcec.PrivateKey,
encKey *asig.EncryptionKey,
) (*asig.AdaptorSignature, error) {

if err := checkTxBeforeSigning(txToSign, fundingTx, fundingOutputIdx); err != nil {
return nil, fmt.Errorf("invalid tx: %w", err)
}
Expand Down Expand Up @@ -650,7 +646,6 @@ func VerifyTransactionSigWithOutput(
script []byte,
pubKey *btcec.PublicKey,
signature []byte) error {

if fundingOutput == nil {
return fmt.Errorf("funding output must not be nil")
}
Expand Down
2 changes: 1 addition & 1 deletion btcstaking/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func NewStakingScriptData(
fpKey,
covenantKey *btcec.PublicKey,
stakingTime uint16) (*StakingScriptData, error) {

if stakerKey == nil || fpKey == nil || covenantKey == nil {
return nil, fmt.Errorf("staker, finality provider and covenant keys cannot be nil")
}
Expand Down Expand Up @@ -253,6 +252,7 @@ func FuzzGeneratingSignatureValidation(f *testing.F) {
}

func TestSlashingTxWithOverflowMustNotAccepted(t *testing.T) {
t.Parallel()
r := rand.New(rand.NewSource(time.Now().Unix()))
// we do not care for inputs in staking tx
stakingTx := wire.NewMsgTx(2)
Expand Down
16 changes: 7 additions & 9 deletions btcstaking/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func DeriveTaprootAddress(
tapScriptTree *txscript.IndexedTapScriptTree,
internalPubKey *btcec.PublicKey,
net *chaincfg.Params) (*btcutil.AddressTaproot, error) {

tapScriptRootHash := tapScriptTree.RootNode.TapHash()

outputKey := txscript.ComputeTaprootOutputKey(
Expand All @@ -76,7 +75,7 @@ func DeriveTaprootAddress(
schnorr.SerializePubKey(outputKey), net)

if err != nil {
return nil, fmt.Errorf("error encoding Taproot address: %v", err)
return nil, fmt.Errorf("error encoding Taproot address: %w", err)
}

return address, nil
Expand Down Expand Up @@ -222,7 +221,6 @@ func SpendInfoFromRevealedScript(
revealedScript []byte,
internalKey *btcec.PublicKey,
tree *txscript.IndexedTapScriptTree) (*SpendInfo, error) {

revealedLeaf := txscript.NewBaseTapLeaf(revealedScript)
leafHash := revealedLeaf.TapHash()

Expand Down Expand Up @@ -402,7 +400,7 @@ func BuildStakingInfo(
)

if err != nil {
return nil, fmt.Errorf("%s: %w", errBuildingStakingInfo, err)
return nil, fmt.Errorf("%w: %w", errBuildingStakingInfo, err)
}

var unbondingPaths [][]byte
Expand All @@ -420,13 +418,13 @@ func BuildStakingInfo(
)

if err != nil {
return nil, fmt.Errorf("%s: %w", errBuildingStakingInfo, err)
return nil, fmt.Errorf("%w: %w", errBuildingStakingInfo, err)
}

taprootPkScript, err := sh.taprootPkScript(net)

if err != nil {
return nil, fmt.Errorf("%s: %w", errBuildingStakingInfo, err)
return nil, fmt.Errorf("%w: %w", errBuildingStakingInfo, err)
}

stakingOutput := wire.NewTxOut(int64(stakingAmount), taprootPkScript)
Expand Down Expand Up @@ -488,7 +486,7 @@ func BuildUnbondingInfo(
)

if err != nil {
return nil, fmt.Errorf("%s: %w", errBuildingUnbondingInfo, err)
return nil, fmt.Errorf("%w: %w", errBuildingUnbondingInfo, err)
}

var unbondingPaths [][]byte
Expand All @@ -504,13 +502,13 @@ func BuildUnbondingInfo(
)

if err != nil {
return nil, fmt.Errorf("%s: %w", errBuildingUnbondingInfo, err)
return nil, fmt.Errorf("%w: %w", errBuildingUnbondingInfo, err)
}

taprootPkScript, err := sh.taprootPkScript(net)

if err != nil {
return nil, fmt.Errorf("%s: %w", errBuildingUnbondingInfo, err)
return nil, fmt.Errorf("%w: %w", errBuildingUnbondingInfo, err)
}

unbondingOutput := wire.NewTxOut(int64(unbondingAmount), taprootPkScript)
Expand Down
4 changes: 0 additions & 4 deletions btctxformatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func encodeFirstOpRetrun(
bitMap []byte,
submitterAddress []byte,
) []byte {

var serializedBytes = []byte{}

serializedBytes = append(serializedBytes, encodeHeader(tag, version, firstPartIndex)...)
Expand Down Expand Up @@ -148,7 +147,6 @@ func EncodeCheckpointData(
version FormatVersion,
rawBTCCheckpoint *RawBtcCheckpoint,
) ([]byte, []byte, error) {

if len(tag) != TagLength {
return nil, nil, errors.New("tag should have 4 bytes")
}
Expand Down Expand Up @@ -247,7 +245,6 @@ func GetCheckpointData(
partIndex uint8,
data []byte,
) ([]byte, error) {

if partIndex > 1 {
return nil, errors.New("invalid part index")
}
Expand Down Expand Up @@ -290,7 +287,6 @@ func IsBabylonCheckpointData(
version FormatVersion,
data []byte,
) (*BabylonData, error) {

var idx uint8 = 0

for idx < NumberOfParts {
Expand Down
1 change: 0 additions & 1 deletion btctxformatter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func FuzzEncodingDecoding(f *testing.F) {
f.Add(uint64(2000), randNBytes(TagLength), randNBytes(BlockHashLength), randNBytes(BitMapLength), randNBytes(BlsSigLength), randNBytes(AddressLength))

f.Fuzz(func(t *testing.T, epoch uint64, tag []byte, appHash []byte, bitMap []byte, blsSig []byte, address []byte) {

if len(tag) < TagLength {
t.Skip("Tag should have 4 bytes")
}
Expand Down
Loading
Loading