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 golangci lint config #93

Merged
merged 6 commits into from
Nov 14, 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
80 changes: 80 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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
- gocritic
- path-except: _test\.go
linters:
- forbidigo
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

* [#93](https://github.com/babylonlabs-io/btc-staker/pull/93) Fix linting config


## v0.10.0

* [#87](https://github.com/babylonlabs-io/btc-staker/pull/87) Bump babylon v15
Expand Down
24 changes: 9 additions & 15 deletions babylonclient/babyloncontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/avast/retry-go/v4"
bbnclient "github.com/babylonlabs-io/babylon/client/client"
bbntypes "github.com/babylonlabs-io/babylon/types"
bcctypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types"
btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
btcstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
"github.com/babylonlabs-io/btc-staker/stakercfg"
Expand Down Expand Up @@ -135,7 +134,7 @@ func (bc *BabylonController) Stop() error {

func (bc *BabylonController) Params() (*StakingParams, error) {
// TODO: it would probably be good to have separate methods for those
var bccParams *bcctypes.Params
var bccParams *btcctypes.Params
if err := retry.Do(func() error {
response, err := bc.bbnClient.BTCCheckpointParams()
if err != nil {
Expand Down Expand Up @@ -181,8 +180,8 @@ func (bc *BabylonController) Params() (*StakingParams, error) {
}

return &StakingParams{
ConfirmationTimeBlocks: uint32(bccParams.BtcConfirmationDepth),
FinalizationTimeoutBlocks: uint32(bccParams.CheckpointFinalizationTimeout),
ConfirmationTimeBlocks: bccParams.BtcConfirmationDepth,
FinalizationTimeoutBlocks: bccParams.CheckpointFinalizationTimeout,
SlashingPkScript: stakingTrackerParams.SlashingPkScript,
CovenantPks: stakingTrackerParams.CovenantPks,
MinSlashingTxFeeSat: stakingTrackerParams.MinSlashingFee,
Expand Down Expand Up @@ -375,13 +374,13 @@ func delegationDataToMsg(dg *DelegationData) (*btcstypes.MsgCreateBTCDelegation,

slashUnbondingTxSig := bbntypes.NewBIP340SignatureFromBTCSig(dg.Ud.SlashUnbondingTransactionSig)

var stakingTransactionInclusionProof *btcstypes.InclusionProof = nil
var stakingTransactionInclusionProof *btcstypes.InclusionProof

if dg.StakingTransactionInclusionInfo != nil {
inclusionBlockHash := bbntypes.NewBTCHeaderHashBytesFromChainhash(
dg.StakingTransactionInclusionInfo.StakingTransactionInclusionBlockHash,
)
txKey := &bcctypes.TransactionKey{
txKey := &btcctypes.TransactionKey{
Index: dg.StakingTransactionInclusionInfo.StakingTransactionIdx,
Hash: &inclusionBlockHash,
}
Expand Down Expand Up @@ -670,7 +669,6 @@ func (bc *BabylonController) QueryHeaderDepth(headerHash *chainhash.Hash) (uint3
"error": err,
}).Error("Failed to query babylon for the depth of the header")
})); err != nil {

// translate errors to locally handable ones
if strings.Contains(err.Error(), btclctypes.ErrHeaderDoesNotExist.Error()) {
return 0, fmt.Errorf("%s: %w", err.Error(), ErrHeaderNotKnownToBabylon)
Expand All @@ -681,10 +679,9 @@ func (bc *BabylonController) QueryHeaderDepth(headerHash *chainhash.Hash) (uint3
}

return response.Depth, nil

}

// Insert BTC block header using rpc client
// InsertBtcBlockHeaders Insert BTC block header using rpc client
func (bc *BabylonController) InsertBtcBlockHeaders(headers []*wire.BlockHeader) (*pv.RelayerTxResponse, error) {
msg := &btclctypes.MsgInsertHeaders{
Signer: bc.getTxSigner(),
Expand Down Expand Up @@ -748,7 +745,7 @@ func (bc *BabylonController) QueryDelegationInfo(stakingTxHash *chainhash.Hash)
return err
}

var udi *UndelegationInfo = nil
var udi *UndelegationInfo

if resp.BtcDelegation.UndelegationResponse != nil {
var coventSigInfos []CovenantSignatureInfo
Expand Down Expand Up @@ -873,7 +870,7 @@ func (bc *BabylonController) QueryPendingBTCDelegations() ([]*btcstypes.BTCDeleg

res, err := queryClient.BTCDelegations(ctx, &queryRequest)
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 @@ -900,17 +897,15 @@ func (bc *BabylonController) InsertSpvProofs(submitter string, proofs []*btcctyp
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
}

func (bc *BabylonController) ActivateDelegation(
ctx context.Context,
stakingTxHash chainhash.Hash,
proof *btcctypes.BTCSpvProof) (*pv.RelayerTxResponse, error) {

msg := &btcstypes.MsgAddBTCDelegationInclusionProof{
Signer: bc.getTxSigner(),
StakingTxHash: stakingTxHash.String(),
Expand All @@ -923,5 +918,4 @@ func (bc *BabylonController) ActivateDelegation(
}

return res, nil

}
26 changes: 13 additions & 13 deletions babylonclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ type StakingParams struct {
// The rate at which the staked funds will be slashed, expressed as a decimal.
SlashingRate sdkmath.LegacyDec

// Convenant quorum threshold
// Covenant quorum threshold
CovenantQuruomThreshold uint32

// Minimum unbonding time required by bayblon
// Minimum unbonding time required by babylon
MinUnbondingTime uint16

// Fee required by unbonding transaction
UnbondingFee btcutil.Amount

// Minimum staking time required by bayblon
// Minimum staking time required by babylon
MinStakingTime uint16

// Maximum staking time required by bayblon
// Maximum staking time required by babylon
MaxStakingTime uint16

// Minimum staking value required by bayblon
// Minimum staking value required by babylon
MinStakingValue btcutil.Amount

// Maximum staking value required by bayblon
// Maximum staking value required by babylon
MaxStakingValue btcutil.Amount
}

Expand Down Expand Up @@ -124,7 +124,7 @@ func (m *MockBabylonClient) Delegate(dg *DelegationData) (*pv.RelayerTxResponse,
return &pv.RelayerTxResponse{Code: 0}, nil
}

func (m *MockBabylonClient) QueryFinalityProviders(limit uint64, offset uint64) (*FinalityProvidersClientResponse, error) {
func (m *MockBabylonClient) QueryFinalityProviders(_ uint64, _ uint64) (*FinalityProvidersClientResponse, error) {
return &FinalityProvidersClientResponse{
FinalityProviders: []FinalityProviderInfo{*m.ActiveFinalityProvider},
Total: 1,
Expand All @@ -136,26 +136,26 @@ func (m *MockBabylonClient) QueryFinalityProvider(btcPubKey *btcec.PublicKey) (*
return &FinalityProviderClientResponse{
FinalityProvider: *m.ActiveFinalityProvider,
}, nil
} else {
return nil, ErrFinalityProviderDoesNotExist
}

return nil, ErrFinalityProviderDoesNotExist
}

func (m *MockBabylonClient) QueryHeaderDepth(headerHash *chainhash.Hash) (uint32, error) {
func (m *MockBabylonClient) QueryHeaderDepth(_ *chainhash.Hash) (uint32, error) {
// return always confirmed depth
return m.ClientParams.ConfirmationTimeBlocks + 1, nil
}

func (m *MockBabylonClient) IsTxAlreadyPartOfDelegation(stakingTxHash *chainhash.Hash) (bool, error) {
func (m *MockBabylonClient) IsTxAlreadyPartOfDelegation(_ *chainhash.Hash) (bool, error) {
return false, nil
}

func (m *MockBabylonClient) QueryDelegationInfo(stakingTxHash *chainhash.Hash) (*DelegationInfo, error) {
func (m *MockBabylonClient) QueryDelegationInfo(_ *chainhash.Hash) (*DelegationInfo, error) {
return nil, fmt.Errorf("delegation do not exist")
}

func (m *MockBabylonClient) Undelegate(
req *UndelegationRequest) (*pv.RelayerTxResponse, error) {
_ *UndelegationRequest) (*pv.RelayerTxResponse, error) {
return &pv.RelayerTxResponse{Code: 0}, nil
}

Expand Down
23 changes: 11 additions & 12 deletions babylonclient/msgsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ func NewBabylonMsgSender(
}
}

func (b *BabylonMsgSender) Start() {
b.startOnce.Do(func() {
b.wg.Add(1)
go b.handleSentToBabylon()
func (m *BabylonMsgSender) Start() {
m.startOnce.Do(func() {
m.wg.Add(1)
go m.handleSentToBabylon()
})
}

func (b *BabylonMsgSender) Stop() {
b.stopOnce.Do(func() {
close(b.quit)
b.wg.Wait()
func (m *BabylonMsgSender) Stop() {
m.stopOnce.Do(func() {
close(m.quit)
m.wg.Wait()
})
}

// isBabylonBtcLcReady checks if Babylon BTC light client is ready to receive delegation
func (b *BabylonMsgSender) isBabylonBtcLcReady(
func (m *BabylonMsgSender) isBabylonBtcLcReady(
requiredInclusionBlockDepth uint32,
req *DelegationData,
) error {
Expand All @@ -90,7 +90,7 @@ func (b *BabylonMsgSender) isBabylonBtcLcReady(
return nil
}

depth, err := b.cl.QueryHeaderDepth(req.StakingTransactionInclusionInfo.StakingTransactionInclusionBlockHash)
depth, err := m.cl.QueryHeaderDepth(req.StakingTransactionInclusionInfo.StakingTransactionInclusionBlockHash)

if err != nil {
// If header is not known to babylon, or it is on LCFork, then most probably
Expand All @@ -103,7 +103,7 @@ func (b *BabylonMsgSender) isBabylonBtcLcReady(
return fmt.Errorf("error while getting delegation data: %w", err)
}

if uint32(depth) < requiredInclusionBlockDepth {
if depth < requiredInclusionBlockDepth {
return fmt.Errorf("btc lc not ready, required depth: %d, current depth: %d: %w", requiredInclusionBlockDepth, depth, ErrBabylonBtcLightClientNotReady)
}

Expand Down Expand Up @@ -183,5 +183,4 @@ func (m *BabylonMsgSender) SendDelegation(
m.sendDelegationRequestChan,
m.quit,
)

}
1 change: 0 additions & 1 deletion babylonclient/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

func GenerateProof(block *wire.MsgBlock, txIdx uint32) ([]byte, error) {

headerBytes := babylontypes.NewBTCHeaderBytesFromBlockHeader(&block.Header)

var txsBytes [][]byte
Expand Down
8 changes: 4 additions & 4 deletions cmd/stakercli/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const (
mnemonicEntropySize = 256
secp256k1Type = "secp256k1"

chainIdFlag = "chain-id"
chainIDFlag = "chain-id"
keyringBackendFlag = "keyring-backend"
keyNameFlag = "key-name"
keyringDir = "keyring-dir"
Expand Down Expand Up @@ -135,13 +135,13 @@ func createKeyRing(c *cli.Context) error {

app := babylonApp.NewTmpBabylonApp()

chainId := c.String(chainIdFlag)
chainID := c.String(chainIDFlag)
backend := c.String(keyringBackendFlag)
keyName := c.String(keyNameFlag)
keyDir := c.String(keyringDir)

kb, err := keyring.New(
chainId,
chainID,
backend,
keyDir,
nil,
Expand Down Expand Up @@ -189,7 +189,7 @@ var createCosmosKeyringCommand = cli.Command{
Value: defaultBackend,
},
cli.StringFlag{
Name: chainIdFlag,
Name: chainIDFlag,
Usage: "Chain ID for which account is created",
Value: defaultChainID,
},
Expand Down
Loading
Loading