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

chore(*): fix lint config #126

Merged
merged 7 commits into from
Nov 13, 2024
Merged
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
81 changes: 81 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
run:
timeout: 5m

linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- decorder
- dogsled
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- forbidigo
- forcetypeassert
- goconst
- gocritic
- gocyclo
- goheader
- gomodguard
- goprintffuncname
- gosimple
- govet
- grouper
- importas
- ineffassign
- loggercheck
- maintidx
- makezero
- misspell
- nakedret
- nilerr
# - nlreturn # Style wise I personally like this one, todo(lazar): unlax at somepoint, good practice
- noctx
- nonamedreturns
- nosprintfhostport
- paralleltest
- reassign
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tenv
- testableexamples
- tparallel
- typecheck
- unconvert
- unparam
- usestdlibvars
- unused
- wastedassign
- whitespace
# - 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
- itest
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- nonamedreturns
- unparam
- path-except: _test\.go
linters:
- forbidigo
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Improvements

* [#126](https://github.com/babylonlabs-io/finality-provider/pull/126) Adds linting config

### Documentation

* [#117](https://github.com/babylonlabs-io/finality-provider/pull/117) Spec of
Expand Down
24 changes: 12 additions & 12 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func NewBabylonController(
btcParams *chaincfg.Params,
logger *zap.Logger,
) (*BabylonController, error) {

bbnConfig := fpcfg.BBNConfigToBabylonConfig(cfg)

bc, err := bbnclient.New(
Expand Down Expand Up @@ -298,11 +297,12 @@ func (bc *BabylonController) UnjailFinalityProvider(fpPk *btcec.PublicKey) (*typ
return &types.TxResponse{TxHash: res.TxHash, Events: res.Events}, nil
}

func (bc *BabylonController) QueryFinalityProviderSlashedOrJailed(fpPk *btcec.PublicKey) (slashed bool, jailed bool, err error) {
// QueryFinalityProviderSlashedOrJailed - returns if the fp has been slashed, jailed, err
func (bc *BabylonController) QueryFinalityProviderSlashedOrJailed(fpPk *btcec.PublicKey) (bool, bool, error) {
fpPubKey := bbntypes.NewBIP340PubKeyFromBTCPK(fpPk)
res, err := bc.bbnClient.QueryClient.FinalityProvider(fpPubKey.MarshalHex())
if err != nil {
return false, false, fmt.Errorf("failed to query the finality provider %s: %v", fpPubKey.MarshalHex(), err)
return false, false, fmt.Errorf("failed to query the finality provider %s: %w", fpPubKey.MarshalHex(), err)
}

return res.FinalityProvider.SlashedBtcHeight > 0, res.FinalityProvider.Jailed, nil
Expand Down Expand Up @@ -364,7 +364,7 @@ func (bc *BabylonController) queryLatestBlocks(startKey []byte, count uint64, st

res, err := bc.bbnClient.QueryClient.ListBlocks(status, pagination)
if err != nil {
return nil, fmt.Errorf("failed to query finalized blocks: %v", err)
return nil, fmt.Errorf("failed to query finalized blocks: %w", err)
}

for _, b := range res.Blocks {
Expand Down Expand Up @@ -526,7 +526,7 @@ func (bc *BabylonController) QueryFinalityProviders() ([]*btcstakingtypes.Finali
for {
res, err := bc.bbnClient.QueryClient.FinalityProviders(pagination)
if err != nil {
return nil, fmt.Errorf("failed to query finality providers: %v", err)
return nil, fmt.Errorf("failed to query finality providers: %w", err)
}
fps = append(fps, res.FinalityProviders...)
if res.Pagination == nil || res.Pagination.NextKey == nil {
Expand All @@ -543,7 +543,7 @@ func (bc *BabylonController) QueryFinalityProvider(fpPk *btcec.PublicKey) (*btcs
fpPubKey := bbntypes.NewBIP340PubKeyFromBTCPK(fpPk)
res, err := bc.bbnClient.QueryClient.FinalityProvider(fpPubKey.MarshalHex())
if err != nil {
return nil, fmt.Errorf("failed to query the finality provider %s: %v", fpPubKey.MarshalHex(), err)
return nil, fmt.Errorf("failed to query the finality provider %s: %w", fpPubKey.MarshalHex(), err)
}

return res, nil
Expand Down Expand Up @@ -597,7 +597,7 @@ func (bc *BabylonController) EditFinalityProvider(fpPk *btcec.PublicKey,

_, err = bc.reliablySendMsg(msg, emptyErrs, emptyErrs)
if err != nil {
return nil, fmt.Errorf("failed to query the finality provider %s: %v", fpPk.SerializeCompressed(), err)
return nil, fmt.Errorf("failed to query the finality provider %s: %w", fpPk.SerializeCompressed(), err)
}

return msg, nil
Expand All @@ -606,7 +606,7 @@ func (bc *BabylonController) EditFinalityProvider(fpPk *btcec.PublicKey,
func (bc *BabylonController) QueryBtcLightClientTip() (*btclctypes.BTCHeaderInfoResponse, error) {
res, err := bc.bbnClient.QueryClient.BTCHeaderChainTip()
if err != nil {
return nil, fmt.Errorf("failed to query BTC tip: %v", err)
return nil, fmt.Errorf("failed to query BTC tip: %w", err)
}

return res.Header, nil
Expand All @@ -615,7 +615,7 @@ func (bc *BabylonController) QueryBtcLightClientTip() (*btclctypes.BTCHeaderInfo
func (bc *BabylonController) QueryCurrentEpoch() (uint64, error) {
res, err := bc.bbnClient.QueryClient.CurrentEpoch()
if err != nil {
return 0, fmt.Errorf("failed to query BTC tip: %v", err)
return 0, fmt.Errorf("failed to query BTC tip: %w", err)
}

return res.CurrentEpoch, nil
Expand Down Expand Up @@ -648,7 +648,7 @@ func (bc *BabylonController) queryDelegationsWithStatus(status btcstakingtypes.B

res, err := bc.bbnClient.QueryClient.BTCDelegations(status, pagination)
if err != nil {
return nil, fmt.Errorf("failed to query BTC delegations: %v", err)
return nil, fmt.Errorf("failed to query BTC delegations: %w", err)
}

return res.BtcDelegations, nil
Expand All @@ -658,13 +658,13 @@ func (bc *BabylonController) QueryStakingParams() (*types.StakingParams, error)
// query btc checkpoint params
ckptParamRes, err := bc.bbnClient.QueryClient.BTCCheckpointParams()
if err != nil {
return nil, fmt.Errorf("failed to query params of the btccheckpoint module: %v", err)
return nil, fmt.Errorf("failed to query params of the btccheckpoint module: %w", err)
}

// query btc staking params
stakingParamRes, err := bc.bbnClient.QueryClient.BTCStakingParams()
if err != nil {
return nil, fmt.Errorf("failed to query staking params: %v", err)
return nil, fmt.Errorf("failed to query staking params: %w", err)
}

covenantPks := make([]*btcec.PublicKey, 0, len(stakingParamRes.Params.CovenantPks))
Expand Down
1 change: 1 addition & 0 deletions clientcontroller/retry_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestExpectedErr(t *testing.T) {
t.Parallel()
expectedErr := Expected(fmt.Errorf("some error"))
require.True(t, IsExpected(expectedErr))
wrappedErr := fmt.Errorf("expected: %w", expectedErr)
Expand Down
2 changes: 1 addition & 1 deletion eotsmanager/cmd/eotsd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ func initHome(cmd *cobra.Command, _ []string) error {
defaultConfig.DatabaseConfig.DBPath = dataDir
fileParser := flags.NewParser(defaultConfig, flags.Default)

return flags.NewIniParser(fileParser).WriteFile(eotscfg.ConfigFile(homePath), flags.IniIncludeComments|flags.IniIncludeDefaults)
return flags.NewIniParser(fileParser).WriteFile(eotscfg.CfgFile(homePath), flags.IniIncludeComments|flags.IniIncludeDefaults)
}
2 changes: 1 addition & 1 deletion eotsmanager/cmd/eotsd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func saveKeyNameMapping(cmd *cobra.Command, args []string) error {
}

// Get database backend
dbBackend, err := cfg.DatabaseConfig.GetDbBackend()
dbBackend, err := cfg.DatabaseConfig.GetDBBackend()
if err != nil {
return fmt.Errorf("failed to create db backend: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion eotsmanager/cmd/eotsd/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func FuzzNewKeysCmd(f *testing.F) {

// Load the EOTS manager and verify the key existence
eotsCfg := eotscfg.DefaultConfigWithHomePath(tempHome)
dbBackend, err := eotsCfg.DatabaseConfig.GetDbBackend()
dbBackend, err := eotsCfg.DatabaseConfig.GetDBBackend()
require.NoError(t, err)
defer func() {
err := dbBackend.Close()
Expand Down
6 changes: 3 additions & 3 deletions eotsmanager/cmd/eotsd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewStartCmd() *cobra.Command {
return cmd
}

func startFn(cmd *cobra.Command, args []string) error {
func startFn(cmd *cobra.Command, _ []string) error {
homePath, err := getHomePath(cmd)
if err != nil {
return fmt.Errorf("failed to load home flag: %w", err)
Expand All @@ -48,15 +48,15 @@ func startFn(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("invalid RPC listener address %s: %w", rpcListener, err)
}
cfg.RpcListener = rpcListener
cfg.RPCListener = rpcListener
}

logger, err := log.NewRootLoggerWithFile(config.LogFile(homePath), cfg.LogLevel)
if err != nil {
return fmt.Errorf("failed to load the logger: %w", err)
}

dbBackend, err := cfg.DatabaseConfig.GetDbBackend()
dbBackend, err := cfg.DatabaseConfig.GetDBBackend()
if err != nil {
return fmt.Errorf("failed to create db backend: %w", err)
}
Expand Down
14 changes: 7 additions & 7 deletions eotsmanager/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ var (
// ~/Library/Application Support/Eotsd on MacOS
DefaultEOTSDir = btcutil.AppDataDir("eotsd", false)

defaultRpcListener = "127.0.0.1:" + strconv.Itoa(DefaultRPCPort)
defaultRPCListener = "127.0.0.1:" + strconv.Itoa(DefaultRPCPort)
)

type Config struct {
LogLevel string `long:"loglevel" description:"Logging level for all subsystems" choice:"trace" choice:"debug" choice:"info" choice:"warn" choice:"error" choice:"fatal"`
KeyringBackend string `long:"keyring-type" description:"Type of keyring to use"`
RpcListener string `long:"rpclistener" description:"the listener for RPC connections, e.g., 127.0.0.1:1234"`
RPCListener string `long:"rpclistener" description:"the listener for RPC connections, e.g., 127.0.0.1:1234"`
Metrics *metrics.Config `group:"metrics" namespace:"metrics"`

DatabaseConfig *DBConfig `group:"dbconfig" namespace:"dbconfig"`
Expand All @@ -54,7 +54,7 @@ type Config struct {
func LoadConfig(homePath string) (*Config, error) {
// The home directory is required to have a configuration file with a specific name
// under it.
cfgFile := ConfigFile(homePath)
cfgFile := CfgFile(homePath)
if !util.FileExists(cfgFile) {
return nil, fmt.Errorf("specified config file does "+
"not exist in %s", cfgFile)
Expand All @@ -80,9 +80,9 @@ func LoadConfig(homePath string) (*Config, error) {
// illegal values or combination of values are set. All file system paths are
// normalized. The cleaned up config is returned on success.
func (cfg *Config) Validate() error {
_, err := net.ResolveTCPAddr("tcp", cfg.RpcListener)
_, err := net.ResolveTCPAddr("tcp", cfg.RPCListener)
if err != nil {
return fmt.Errorf("invalid RPC listener address %s, %w", cfg.RpcListener, err)
return fmt.Errorf("invalid RPC listener address %s, %w", cfg.RPCListener, err)
}

if cfg.KeyringBackend == "" {
Expand All @@ -100,7 +100,7 @@ func (cfg *Config) Validate() error {
return nil
}

func ConfigFile(homePath string) string {
func CfgFile(homePath string) string {
return filepath.Join(homePath, defaultConfigFileName)
}

Expand All @@ -125,7 +125,7 @@ func DefaultConfigWithHomePath(homePath string) *Config {
LogLevel: defaultLogLevel,
KeyringBackend: defaultKeyringBackend,
DatabaseConfig: DefaultDBConfigWithHomePath(homePath),
RpcListener: defaultRpcListener,
RPCListener: defaultRPCListener,
Metrics: metrics.DefaultEotsConfig(),
}
if err := cfg.Validate(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions eotsmanager/config/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

const (
defaultDbName = "eots.db"
defaultDBName = "eots.db"
)

type DBConfig struct {
Expand Down Expand Up @@ -47,7 +47,7 @@ func DefaultDBConfig() *DBConfig {
func DefaultDBConfigWithHomePath(homePath string) *DBConfig {
return &DBConfig{
DBPath: DataDir(homePath),
DBFileName: defaultDbName,
DBFileName: defaultDBName,
NoFreelistSync: true,
AutoCompact: false,
AutoCompactMinAge: kvdb.DefaultBoltAutoCompactMinAge,
Expand All @@ -66,6 +66,6 @@ func (db *DBConfig) DBConfigToBoltBackendConfig() *kvdb.BoltBackendConfig {
}
}

func (db *DBConfig) GetDbBackend() (kvdb.Backend, error) {
func (db *DBConfig) GetDBBackend() (kvdb.Backend, error) {
return kvdb.GetBoltBackend(db.DBConfigToBoltBackendConfig())
}
4 changes: 2 additions & 2 deletions eotsmanager/localmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func FuzzCreateKey(f *testing.F) {
fpName := testutil.GenRandomHexStr(r, 4)
homeDir := filepath.Join(t.TempDir(), "eots-home")
eotsCfg := eotscfg.DefaultConfigWithHomePath(homeDir)
dbBackend, err := eotsCfg.DatabaseConfig.GetDbBackend()
dbBackend, err := eotsCfg.DatabaseConfig.GetDBBackend()
require.NoError(t, err)
defer func() {
dbBackend.Close()
Expand Down Expand Up @@ -65,7 +65,7 @@ func FuzzCreateRandomnessPairList(f *testing.F) {
fpName := testutil.GenRandomHexStr(r, 4)
homeDir := filepath.Join(t.TempDir(), "eots-home")
eotsCfg := eotscfg.DefaultConfigWithHomePath(homeDir)
dbBackend, err := eotsCfg.DatabaseConfig.GetDbBackend()
dbBackend, err := eotsCfg.DatabaseConfig.GetDBBackend()
defer func() {
dbBackend.Close()
err := os.RemoveAll(homeDir)
Expand Down
Loading
Loading