From 3623f9248a54e7c8bc6041372514002d28171637 Mon Sep 17 00:00:00 2001 From: KonradStaniec Date: Mon, 9 Dec 2024 07:13:09 +0100 Subject: [PATCH 1/2] fix linter config and basic lints --- .golangci.yml | 160 ++++++++---------- app/ante/ante_btc_validation_decorator.go | 1 - btcstaking/btcstaking_test.go | 2 - btcstaking/staking.go | 5 - btcstaking/staking_test.go | 1 - btcstaking/types.go | 4 +- btctxformatter/formatter.go | 4 - btctxformatter/formatter_test.go | 1 - cmd/babylond/cmd/genesis.go | 2 - cmd/babylond/cmd/root.go | 1 - cmd/babylond/cmd/testnet.go | 4 - crypto/bip322/bip322.go | 1 - test/e2e/initialization/config.go | 1 - testutil/bitcoin/utils.go | 1 - testutil/datagen/btc_header_info.go | 1 - testutil/datagen/btc_transaction.go | 3 - testutil/datagen/btcstaking.go | 2 - types/btc_schnorr_sig.go | 1 - wasmbinding/test/custom_query_test.go | 2 - x/btccheckpoint/keeper/keeper.go | 3 - x/btccheckpoint/keeper/msg_server.go | 1 - x/btccheckpoint/keeper/msg_server_test.go | 1 - x/btccheckpoint/keeper/submissions.go | 5 +- x/btccheckpoint/types/btcutils.go | 2 - x/btccheckpoint/types/btcutils_test.go | 2 - x/btccheckpoint/types/genesis.go | 1 - x/btclightclient/keeper/grpc_query.go | 1 - x/btclightclient/keeper/utils_test.go | 1 - x/btclightclient/types/btc_light_client.go | 6 - x/btclightclient/types/codec.go | 1 - x/btcstaking/keeper/btc_delegations.go | 1 - x/btcstaking/keeper/grpc_query_test.go | 1 - x/btcstaking/keeper/msg_server.go | 2 +- x/btcstaking/types/btc_slashing_tx.go | 2 - x/btcstaking/types/genesis.go | 1 - x/btcstaking/types/pop.go | 2 - .../types/validate_parsed_message_test.go | 1 - x/checkpointing/module.go | 1 - x/checkpointing/types/codec.go | 1 - x/checkpointing/types/types.go | 1 - x/epoching/keeper/keeper.go | 2 +- x/epoching/types/genesis.go | 1 - x/finality/genesis_test.go | 1 - x/finality/keeper/tallying_test.go | 2 - 44 files changed, 72 insertions(+), 168 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 891b3fd6d..b90ce20e5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,103 +1,77 @@ run: timeout: 5m +# TODO: enable linter +linters: disable-all: true enable: - - asasalint - - asciicheck - - bidichk - - 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 + # - 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 - - ifshort - - importas - - ineffassign - - interfacebloat - - interfacer - - ireturn - - lll - - loggercheck - - maintidx - - makezero - - maligned + # - grouper + # - importas + # - ineffassign + # - loggercheck + # - maintidx + # - makezero - misspell - - nakedret - - nestif - - nilerr - - nilnil - - nlreturn - - noctx - - nolintlint - - nonamedreturns - - nosnakecase - - 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 - - wastedassign + # - nakedret + # - nilerr + # - nlreturn + # - noctx + # - nosprintfhostport + # - paralleltest + # - reassign + # - revive + # - rowserrcheck + # - sqlclosecheck + # - staticcheck + # - stylecheck + # - tenv + # - testableexamples + # - tparallel + # - typecheck + # - unconvert + # - unparam + # - usestdlibvars + # - unused + # - wastedassign - whitespace - - wrapcheck - - wsl + # - wrapcheck # 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 diff --git a/app/ante/ante_btc_validation_decorator.go b/app/ante/ante_btc_validation_decorator.go index ffe7d21cc..3440b9e47 100644 --- a/app/ante/ante_btc_validation_decorator.go +++ b/app/ante/ante_btc_validation_decorator.go @@ -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() { diff --git a/btcstaking/btcstaking_test.go b/btcstaking/btcstaking_test.go index 940a4aace..8bb16bedf 100644 --- a/btcstaking/btcstaking_test.go +++ b/btcstaking/btcstaking_test.go @@ -194,7 +194,6 @@ func GenerateSignatures( stakingOutput *wire.TxOut, leaf txscript.TapLeaf, ) []*schnorr.Signature { - var si []*SignatureInfo for _, key := range keys { @@ -293,7 +292,6 @@ func TestSpendingUnbondingPathCovenant35MultiSig(t *testing.T) { ) } btctest.AssertEngineExecution(t, 0, true, newEngine) - } func TestSpendingUnbondingPathSingleKeyCovenant(t *testing.T) { diff --git a/btcstaking/staking.go b/btcstaking/staking.go index 2a1a5d7b6..ed66f356a 100644 --- a/btcstaking/staking.go +++ b/btcstaking/staking.go @@ -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) } @@ -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, @@ -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) } @@ -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) } @@ -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") } diff --git a/btcstaking/staking_test.go b/btcstaking/staking_test.go index 0f596915a..da28aaf64 100644 --- a/btcstaking/staking_test.go +++ b/btcstaking/staking_test.go @@ -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") } diff --git a/btcstaking/types.go b/btcstaking/types.go index 482238035..89c96c9a5 100644 --- a/btcstaking/types.go +++ b/btcstaking/types.go @@ -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( @@ -181,7 +180,7 @@ func (t *taprootScriptHolder) taprootPkScript(net *chaincfg.Params) ([]byte, err // Package responsible for different kinds of btc scripts used by babylon // Staking script has 3 spending paths: // 1. Staker can spend after relative time lock - staking -// 2. Staker can spend with covenat cooperation any time +// 2. Staker can spend with covenant cooperation any time // 3. Staker can spend with finality provider and covenant cooperation any time. type StakingInfo struct { StakingOutput *wire.TxOut @@ -222,7 +221,6 @@ func SpendInfoFromRevealedScript( revealedScript []byte, internalKey *btcec.PublicKey, tree *txscript.IndexedTapScriptTree) (*SpendInfo, error) { - revealedLeaf := txscript.NewBaseTapLeaf(revealedScript) leafHash := revealedLeaf.TapHash() diff --git a/btctxformatter/formatter.go b/btctxformatter/formatter.go index 14dde7b8b..b3aeaac6c 100644 --- a/btctxformatter/formatter.go +++ b/btctxformatter/formatter.go @@ -103,7 +103,6 @@ func encodeFirstOpRetrun( bitMap []byte, submitterAddress []byte, ) []byte { - var serializedBytes = []byte{} serializedBytes = append(serializedBytes, encodeHeader(tag, version, firstPartIndex)...) @@ -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") } @@ -247,7 +245,6 @@ func GetCheckpointData( partIndex uint8, data []byte, ) ([]byte, error) { - if partIndex > 1 { return nil, errors.New("invalid part index") } @@ -290,7 +287,6 @@ func IsBabylonCheckpointData( version FormatVersion, data []byte, ) (*BabylonData, error) { - var idx uint8 = 0 for idx < NumberOfParts { diff --git a/btctxformatter/formatter_test.go b/btctxformatter/formatter_test.go index 1215a81cf..1cd004722 100644 --- a/btctxformatter/formatter_test.go +++ b/btctxformatter/formatter_test.go @@ -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") } diff --git a/cmd/babylond/cmd/genesis.go b/cmd/babylond/cmd/genesis.go index 02ca02f5a..e95b1edcf 100644 --- a/cmd/babylond/cmd/genesis.go +++ b/cmd/babylond/cmd/genesis.go @@ -154,7 +154,6 @@ func PrepareGenesis( if genesis.Consensus == nil { genesis.Consensus = genutiltypes.NewConsensusGenesis(comettypes.DefaultConsensusParams().ToProto(), nil) - } // Set gas limit @@ -305,7 +304,6 @@ func TestnetGenesisParams( jailDuration time.Duration, finalityActivationBlockHeight uint64, ) GenesisParams { - genParams := GenesisParams{} genParams.GenesisTime = genesisTime diff --git a/cmd/babylond/cmd/root.go b/cmd/babylond/cmd/root.go index e5979db3a..2228d2223 100644 --- a/cmd/babylond/cmd/root.go +++ b/cmd/babylond/cmd/root.go @@ -293,7 +293,6 @@ func appExport( appOpts servertypes.AppOptions, modulesToExport []string, ) (servertypes.ExportedApp, error) { - var babylonApp *app.BabylonApp homePath, ok := appOpts.Get(flags.FlagHome).(string) if !ok || homePath == "" { diff --git a/cmd/babylond/cmd/testnet.go b/cmd/babylond/cmd/testnet.go index 5db92f59e..07dff9fb1 100644 --- a/cmd/babylond/cmd/testnet.go +++ b/cmd/babylond/cmd/testnet.go @@ -178,7 +178,6 @@ func InitTestnet( valAddrCodec runtime.ValidatorAddressCodec, genesisParams GenesisParams, ) error { - nodeIDs := make([]string, numValidators) valKeys := make([]*privval.ValidatorKeys, numValidators) @@ -398,7 +397,6 @@ func InitTestnet( genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()}) genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0)) - } } @@ -424,7 +422,6 @@ func initGenFiles( genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance, genFiles []string, genKeys []*checkpointingtypes.GenesisKey, numValidators int, genesisParams GenesisParams, ) error { - appGenState := mbm.DefaultGenesis(clientCtx.Codec) // set the accounts in the genesis state @@ -465,7 +462,6 @@ func collectGenFiles( nodeIDs []string, genKeys []*checkpointingtypes.GenesisKey, numValidators int, outputDir, nodeDirPrefix, nodeDaemonHome string, genBalIterator banktypes.GenesisBalancesIterator, ) error { - var appState json.RawMessage genTime := cmttime.Now() diff --git a/crypto/bip322/bip322.go b/crypto/bip322/bip322.go index 48b73a9fa..63cbd357c 100644 --- a/crypto/bip322/bip322.go +++ b/crypto/bip322/bip322.go @@ -144,7 +144,6 @@ func Verify( witness wire.TxWitness, address btcutil.Address, net *chaincfg.Params) error { - toSpend, err := GetToSpendTx(msg, address) if err != nil { return err diff --git a/test/e2e/initialization/config.go b/test/e2e/initialization/config.go index 2bcba9c63..f5b286d00 100644 --- a/test/e2e/initialization/config.go +++ b/test/e2e/initialization/config.go @@ -286,7 +286,6 @@ func initGenesis( if err = genutil.ExportGenesisFile(genDoc, path); err != nil { return fmt.Errorf("failed to export app genesis state: %w", err) } - } return nil } diff --git a/testutil/bitcoin/utils.go b/testutil/bitcoin/utils.go index 505a1c1d1..485051c1a 100644 --- a/testutil/bitcoin/utils.go +++ b/testutil/bitcoin/utils.go @@ -14,7 +14,6 @@ import ( // https://github.com/lightningnetwork/lnd/blob/master/input/script_utils_test.go#L24 func AssertEngineExecution(t *testing.T, testNum int, valid bool, newEngine func() (*txscript.Engine, error)) { - t.Helper() // Get a new VM to execute. diff --git a/testutil/datagen/btc_header_info.go b/testutil/datagen/btc_header_info.go index 796e0182e..0cc7d8881 100644 --- a/testutil/datagen/btc_header_info.go +++ b/testutil/datagen/btc_header_info.go @@ -33,7 +33,6 @@ func calculateAdjustedDifficulty( lastRetargetHeader *wire.BlockHeader, currentHeaderTimestamp time.Time, params *chaincfg.Params) uint32 { - targetTimespan := int64(params.TargetTimespan / time.Second) adjustmentFactor := params.RetargetAdjustmentFactor minRetargetTimespan := targetTimespan / adjustmentFactor diff --git a/testutil/datagen/btc_transaction.go b/testutil/datagen/btc_transaction.go index ea5277e5a..51fc81295 100644 --- a/testutil/datagen/btc_transaction.go +++ b/testutil/datagen/btc_transaction.go @@ -95,7 +95,6 @@ func SolveBlock(header *wire.BlockHeader) bool { hash := hdr.BlockHash() if blockchain.HashToBig(&hash).Cmp( targetDifficulty) <= 0 { - results <- sbResult{true, i} return } @@ -245,7 +244,6 @@ func CreateBlock( babylonOpReturnIdx uint32, babylonData []byte, ) *BlockCreationResult { - if babylonOpReturnIdx > numTx { panic("babylon tx index should be less than number of transasactions and greater than 0") } @@ -305,7 +303,6 @@ func CreateBlockWithTransaction( ph *wire.BlockHeader, tx *wire.MsgTx, ) *BtcHeaderWithProof { - var transactions []*wire.MsgTx // height does not matter here, as it is used only for calculation of reward transactions = append(transactions, createCoinbaseTx(int32(889), &chaincfg.SimNetParams)) diff --git a/testutil/datagen/btcstaking.go b/testutil/datagen/btcstaking.go index 21efdc766..f76448a18 100644 --- a/testutil/datagen/btcstaking.go +++ b/testutil/datagen/btcstaking.go @@ -248,7 +248,6 @@ func GenBTCStakingSlashingInfoWithOutPoint( slashingRate sdkmath.LegacyDec, slashingChangeLockTime uint16, ) *TestStakingSlashingInfo { - stakingInfo, err := btcstaking.BuildStakingInfo( stakerSK.PubKey(), fpPKs, @@ -342,7 +341,6 @@ func GenBTCUnbondingSlashingInfo( slashingRate sdkmath.LegacyDec, slashingChangeLockTime uint16, ) *TestUnbondingSlashingInfo { - unbondingInfo, err := btcstaking.BuildUnbondingInfo( stakerSK.PubKey(), fpPKs, diff --git a/types/btc_schnorr_sig.go b/types/btc_schnorr_sig.go index 336cf037b..bf2cfea73 100644 --- a/types/btc_schnorr_sig.go +++ b/types/btc_schnorr_sig.go @@ -12,7 +12,6 @@ type BIP340Signature []byte const BIP340SignatureLen = schnorr.SignatureSize func NewBIP340Signature(data []byte) (*BIP340Signature, error) { - var sig BIP340Signature err := sig.Unmarshal(data) diff --git a/wasmbinding/test/custom_query_test.go b/wasmbinding/test/custom_query_test.go index a5a68527c..afa10352a 100644 --- a/wasmbinding/test/custom_query_test.go +++ b/wasmbinding/test/custom_query_test.go @@ -238,7 +238,6 @@ func fundAccount( ctx sdk.Context, bbn *app.BabylonApp, acc sdk.AccAddress) { - err := mintCoinsTo(bbn.BankKeeper, ctx, acc, sdk.NewCoins( sdk.NewCoin("ubbn", math.NewInt(10000000000)), )) @@ -282,7 +281,6 @@ func deployTestContract( deployer sdk.AccAddress, codePath string, ) sdk.AccAddress { - codeId, _ := storeTestCodeCode(t, ctx, bbn, deployer, codePath) contractAddr := instantiateExampleContract(t, ctx, bbn, deployer, codeId) diff --git a/x/btccheckpoint/keeper/keeper.go b/x/btccheckpoint/keeper/keeper.go index 265abf17d..b9219f4b5 100644 --- a/x/btccheckpoint/keeper/keeper.go +++ b/x/btccheckpoint/keeper/keeper.go @@ -66,7 +66,6 @@ func NewKeeper( powLimit *big.Int, authority string, ) Keeper { - return Keeper{ cdc: cdc, storeService: storeService, @@ -126,7 +125,6 @@ func (k Keeper) checkAncestors( submisionEpoch uint64, newSubmissionInfo *types.SubmissionBtcInfo, ) error { - if submisionEpoch <= 1 { // do not need to check ancestors for epoch 0 and 1 return nil @@ -215,7 +213,6 @@ func (k Keeper) getEpochChanges( ctx context.Context, parentEpochBestSubmission *types.SubmissionBtcInfo, ed *types.EpochData) *epochChangesSummary { - var submissionsToKeep []*types.SubmissionKey var submissionsToDelete []*types.SubmissionKey var currentEpochBestSubmission *types.SubmissionBtcInfo diff --git a/x/btccheckpoint/keeper/msg_server.go b/x/btccheckpoint/keeper/msg_server.go index c46fd6fdf..8af0084b4 100644 --- a/x/btccheckpoint/keeper/msg_server.go +++ b/x/btccheckpoint/keeper/msg_server.go @@ -26,7 +26,6 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer { // TODO emit some events for external consumers. Those should be probably emitted // at EndBlockerCallback func (ms msgServer) InsertBTCSpvProof(ctx context.Context, req *types.MsgInsertBTCSpvProof) (*types.MsgInsertBTCSpvProofResponse, error) { - // Get the SDK wrapped context sdkCtx := sdk.UnwrapSDKContext(ctx) diff --git a/x/btccheckpoint/keeper/msg_server_test.go b/x/btccheckpoint/keeper/msg_server_test.go index 3d4c7266c..ed5e5fb04 100644 --- a/x/btccheckpoint/keeper/msg_server_test.go +++ b/x/btccheckpoint/keeper/msg_server_test.go @@ -324,7 +324,6 @@ func TestRejectSubmissionWithoutAncestorsOnMainchainInPreviousEpoch(t *testing.T _, err = tk.insertProofMsg(msg2) require.NoErrorf(t, err, "Unexpected message processing error: %v", err) - } func TestClearChildEpochsWhenNoParenNotOnMainChain(t *testing.T) { diff --git a/x/btccheckpoint/keeper/submissions.go b/x/btccheckpoint/keeper/submissions.go index 3ea2cc2b1..24de5d3b4 100644 --- a/x/btccheckpoint/keeper/submissions.go +++ b/x/btccheckpoint/keeper/submissions.go @@ -3,9 +3,10 @@ package keeper import ( "context" "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "math" + sdk "github.com/cosmos/cosmos-sdk/types" + "cosmossdk.io/store/prefix" bbn "github.com/babylonlabs-io/babylon/types" "github.com/babylonlabs-io/babylon/x/btccheckpoint/types" @@ -49,7 +50,6 @@ func (k Keeper) addEpochSubmission( sk types.SubmissionKey, sd types.SubmissionData, ) error { - ed := k.GetEpochData(ctx, epochNum) // TODO: SaveEpochData and SaveSubmission should be done in one transaction. @@ -131,7 +131,6 @@ func (k Keeper) checkSubmissionStatus(ctx context.Context, info *types.Submissio } func (k Keeper) GetSubmissionBtcInfo(ctx context.Context, sk types.SubmissionKey) (*types.SubmissionBtcInfo, error) { - var youngestBlockDepth uint32 = math.MaxUint32 var youngestBlockHash *bbn.BTCHeaderHashBytes diff --git a/x/btccheckpoint/types/btcutils.go b/x/btccheckpoint/types/btcutils.go index 02dedcd74..0edeb5d47 100644 --- a/x/btccheckpoint/types/btcutils.go +++ b/x/btccheckpoint/types/btcutils.go @@ -57,7 +57,6 @@ func min(a, b uint) uint { // of the leaf which supposed to be proven // it returns list of hashes required to prove given index func createBranch(nodes []*chainhash.Hash, numfLeafs uint, idx uint) []*chainhash.Hash { - var branch []*chainhash.Hash // size represents number of merkle nodes at given level. At 0 level, number of @@ -71,7 +70,6 @@ func createBranch(nodes []*chainhash.Hash, numfLeafs uint, idx uint) []*chainhas var i uint = 0 for size > 1 { - // index^1 means we want to get sibling of the node we are proving // ie. for index=2, index^1 = 3 and for index=3 index^1=2 // so xoring last bit by 1, select node opposite to the node we want the proof diff --git a/x/btccheckpoint/types/btcutils_test.go b/x/btccheckpoint/types/btcutils_test.go index c632ee3ff..0c4ba3d4c 100644 --- a/x/btccheckpoint/types/btcutils_test.go +++ b/x/btccheckpoint/types/btcutils_test.go @@ -48,7 +48,6 @@ func TestBtcTransactionParsing(t *testing.T) { if !tx.Hash().IsEqual(hashBytes) { t.Errorf("Hash of decoded transaction does not match provided hash %d", i) } - } } @@ -132,7 +131,6 @@ func TestParsingCorrectBtcProofs(t *testing.T) { } for i, test := range tests { - headerBytes, _ := bbn.NewBTCHeaderBytesFromHex(test.header) var transactionBytes [][]byte diff --git a/x/btccheckpoint/types/genesis.go b/x/btccheckpoint/types/genesis.go index 2fb67af14..ffd96d1aa 100644 --- a/x/btccheckpoint/types/genesis.go +++ b/x/btccheckpoint/types/genesis.go @@ -10,6 +10,5 @@ func DefaultGenesis() *GenesisState { // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { - return gs.Params.Validate() } diff --git a/x/btclightclient/keeper/grpc_query.go b/x/btclightclient/keeper/grpc_query.go index 9024cc605..53081ea36 100644 --- a/x/btclightclient/keeper/grpc_query.go +++ b/x/btclightclient/keeper/grpc_query.go @@ -195,7 +195,6 @@ func (k Keeper) BaseHeader(ctx context.Context, req *types.QueryBaseHeaderReques } func (k Keeper) HeaderDepth(ctx context.Context, req *types.QueryHeaderDepthRequest) (*types.QueryHeaderDepthResponse, error) { - if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } diff --git a/x/btclightclient/keeper/utils_test.go b/x/btclightclient/keeper/utils_test.go index 9efbf1e18..b0c266b30 100644 --- a/x/btclightclient/keeper/utils_test.go +++ b/x/btclightclient/keeper/utils_test.go @@ -58,7 +58,6 @@ func checkTip( expectedWork sdkmath.Uint, expectedHeight uint32, expectedTipHeader *wire.BlockHeader) { - currentTip := blcKeeper.GetTipInfo(ctx) blockByHeight := blcKeeper.GetHeaderByHeight(ctx, currentTip.Height) blockByHash, err := blcKeeper.GetHeaderByHash(ctx, currentTip.Hash) diff --git a/x/btclightclient/types/btc_light_client.go b/x/btclightclient/types/btc_light_client.go index 25ad59f70..f2ad3bf05 100644 --- a/x/btclightclient/types/btc_light_client.go +++ b/x/btclightclient/types/btc_light_client.go @@ -31,7 +31,6 @@ var _ blockchain.ChainCtx = (*lightChainCtx)(nil) func newLightChainCtx(params *chaincfg.Params, blocksPerRetarget int32, minRetargetTimespan, maxRetargetTimespan int64) *lightChainCtx { - return &lightChainCtx{ params: params, blocksPerRetarget: blocksPerRetarget, @@ -90,7 +89,6 @@ func newLocalHeaderInfo( header *wire.BlockHeader, height uint32, totalWork sdkmath.Uint) *localHeaderInfo { - return &localHeaderInfo{ header: header, height: height, @@ -142,7 +140,6 @@ var _ blockchain.HeaderCtx = (*lightHeaderCtx)(nil) func newLightHeaderCtx(height uint32, header *wire.BlockHeader, store *storeWithExtensionChain) *lightHeaderCtx { - return &lightHeaderCtx{ height: height, bits: header.Bits, @@ -176,9 +173,7 @@ func (l *lightHeaderCtx) Parent() blockchain.HeaderCtx { func (l *lightHeaderCtx) RelativeAncestorCtx( distance int32) blockchain.HeaderCtx { - ancestorHeight := l.Height() - distance - if ancestorHeight < 0 { // We don't have this header. return nil @@ -273,7 +268,6 @@ func newStoreWithExtensionChain( store BtcChainReadStore, maxExentsionHeaders int, ) *storeWithExtensionChain { - return &storeWithExtensionChain{ // large capacity to avoid reallocation headers: make([]*localHeaderInfo, 0, maxExentsionHeaders), diff --git a/x/btclightclient/types/codec.go b/x/btclightclient/types/codec.go index c1e243974..4ac4ea8d9 100644 --- a/x/btclightclient/types/codec.go +++ b/x/btclightclient/types/codec.go @@ -11,7 +11,6 @@ func RegisterCodec(_ *codec.LegacyAmino) { } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - // Register messages registry.RegisterImplementations((*sdk.Msg)(nil), &MsgInsertHeaders{}, diff --git a/x/btcstaking/keeper/btc_delegations.go b/x/btcstaking/keeper/btc_delegations.go index 3d3d9b22a..0c2357ff3 100644 --- a/x/btcstaking/keeper/btc_delegations.go +++ b/x/btcstaking/keeper/btc_delegations.go @@ -149,7 +149,6 @@ func (k Keeper) addCovenantSigsToBTCDelegation( panic(fmt.Errorf("failed to emit emit for the new verified BTC delegation: %w", err)) } } - } } diff --git a/x/btcstaking/keeper/grpc_query_test.go b/x/btcstaking/keeper/grpc_query_test.go index f640f75de..2a8043746 100644 --- a/x/btcstaking/keeper/grpc_query_test.go +++ b/x/btcstaking/keeper/grpc_query_test.go @@ -258,7 +258,6 @@ func FuzzFinalityProviderDelegations(f *testing.F) { } } require.Equal(t, len(btcDelsFound), len(expectedBtcDelsMap)) - }) } diff --git a/x/btcstaking/keeper/msg_server.go b/x/btcstaking/keeper/msg_server.go index a4e82de38..3e74e11ee 100644 --- a/x/btcstaking/keeper/msg_server.go +++ b/x/btcstaking/keeper/msg_server.go @@ -656,7 +656,7 @@ func (ms msgServer) BTCUndelegate(goCtx context.Context, req *types.MsgBTCUndele types.EmitEarlyUnbondedEvent(ctx, btcDel.MustGetStakingTxHash().String(), stakerSpendigTxHeader.Height) } else { // stakeSpendingTx is not unbonding tx, first we need to verify whether it - // acutally spends staking output + // actually spends staking output stakingTxHash, err := chainhash.NewHashFromStr(req.StakingTxHash) if err != nil { diff --git a/x/btcstaking/types/btc_slashing_tx.go b/x/btcstaking/types/btc_slashing_tx.go index 7258fdea6..d420a3bf0 100644 --- a/x/btcstaking/types/btc_slashing_tx.go +++ b/x/btcstaking/types/btc_slashing_tx.go @@ -237,14 +237,12 @@ func (tx *BTCSlashingTx) EncVerifyAdaptorSignatures( valPKs []bbn.BIP340PubKey, sigs [][]byte, ) error { - _, err := tx.ParseEncVerifyAdaptorSignatures(fundingOut, slashingSpendInfo, pk, valPKs, sigs) if err != nil { return err } return nil - } // findFPIdxInWitness returns the index of the finality provider's signature diff --git a/x/btcstaking/types/genesis.go b/x/btcstaking/types/genesis.go index fe6f15104..670b87c1a 100644 --- a/x/btcstaking/types/genesis.go +++ b/x/btcstaking/types/genesis.go @@ -37,7 +37,6 @@ func (gs GenesisState) Validate() error { if err != nil { return err } - } return nil } diff --git a/x/btcstaking/types/pop.go b/x/btcstaking/types/pop.go index bbfbaafc1..97b014cf9 100644 --- a/x/btcstaking/types/pop.go +++ b/x/btcstaking/types/pop.go @@ -92,7 +92,6 @@ func newBIP322Sig[A btcutil.Address]( net *chaincfg.Params, bip322SignFn bip322Sign[A], ) ([]byte, error) { - address, witnessSignture, err := bip322SignFn( msgToSign, btcSK, @@ -259,7 +258,6 @@ func isSupportedAddressAndWitness( } return nil - }, nil } diff --git a/x/btcstaking/types/validate_parsed_message_test.go b/x/btcstaking/types/validate_parsed_message_test.go index bfdec0734..7e6284621 100644 --- a/x/btcstaking/types/validate_parsed_message_test.go +++ b/x/btcstaking/types/validate_parsed_message_test.go @@ -88,7 +88,6 @@ func generateUnbondingInfo( unbondingValue int64, p *types.Params, ) *unbondingInfo { - covPKs, err := bbn.NewBTCPKsFromBIP340PKs(p.CovenantPks) require.NoError(t, err) diff --git a/x/checkpointing/module.go b/x/checkpointing/module.go index 4602c5744..8ea57b60b 100644 --- a/x/checkpointing/module.go +++ b/x/checkpointing/module.go @@ -143,7 +143,6 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.Ra cdc.MustUnmarshalJSON(gs, &genState) InitGenesis(ctx, am.keeper, genState) - } // ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. diff --git a/x/checkpointing/types/codec.go b/x/checkpointing/types/codec.go index 6f5610d04..210cb05da 100644 --- a/x/checkpointing/types/codec.go +++ b/x/checkpointing/types/codec.go @@ -11,7 +11,6 @@ func RegisterCodec(cdc *codec.LegacyAmino) { } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { - // Register messages registry.RegisterImplementations((*sdk.Msg)(nil), &MsgWrappedCreateValidator{}, diff --git a/x/checkpointing/types/types.go b/x/checkpointing/types/types.go index aaeba6b2c..73893b2b3 100644 --- a/x/checkpointing/types/types.go +++ b/x/checkpointing/types/types.go @@ -57,7 +57,6 @@ func (cm *RawCheckpointWithMeta) Accumulate( signerBlsKey bls12381.PublicKey, sig bls12381.Signature, totalPower int64) error { - // the checkpoint should be accumulating if cm.Status != Accumulating { return ErrCkptNotAccumulating diff --git a/x/epoching/keeper/keeper.go b/x/epoching/keeper/keeper.go index f0eacc6c0..bb75139ae 100644 --- a/x/epoching/keeper/keeper.go +++ b/x/epoching/keeper/keeper.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" corestoretypes "cosmossdk.io/core/store" @@ -32,7 +33,6 @@ func NewKeeper( stk types.StakingKeeper, authority string, ) Keeper { - return Keeper{ cdc: cdc, storeService: storeService, diff --git a/x/epoching/types/genesis.go b/x/epoching/types/genesis.go index 9fec52433..2b7ca883f 100644 --- a/x/epoching/types/genesis.go +++ b/x/epoching/types/genesis.go @@ -20,6 +20,5 @@ func NewGenesis(params Params) *GenesisState { // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { - return gs.Params.Validate() } diff --git a/x/finality/genesis_test.go b/x/finality/genesis_test.go index 3e7b821f7..c083dcff5 100644 --- a/x/finality/genesis_test.go +++ b/x/finality/genesis_test.go @@ -23,5 +23,4 @@ func TestGenesis(t *testing.T) { nullify.Fill(&genesisState) nullify.Fill(got) - } diff --git a/x/finality/keeper/tallying_test.go b/x/finality/keeper/tallying_test.go index 24b4c13e3..f4dde934b 100644 --- a/x/finality/keeper/tallying_test.go +++ b/x/finality/keeper/tallying_test.go @@ -55,7 +55,6 @@ func FuzzTallying_FinalizingNoBlock(f *testing.F) { require.False(t, ib.Finalized) } }) - } func FuzzTallying_FinalizingSomeBlocks(f *testing.F) { @@ -109,7 +108,6 @@ func FuzzTallying_FinalizingSomeBlocks(f *testing.F) { } } }) - } func giveQCToHeight(r *rand.Rand, ctx sdk.Context, fKeeper *keeper.Keeper, height uint64) error { From 2972ba21152835eabca8d12b55763c4917f4a4a1 Mon Sep 17 00:00:00 2001 From: KonradStaniec Date: Mon, 9 Dec 2024 07:20:27 +0100 Subject: [PATCH 2/2] re-enable more linters --- .golangci.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b90ce20e5..b6dd494ab 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,12 +1,12 @@ run: timeout: 5m -# TODO: enable linter +# TODO: enable all linters linters: disable-all: true enable: - # - asasalint - # - asciicheck - # - bidichk + - asasalint + - asciicheck + - bidichk # - bodyclose # - containedctx # - contextcheck @@ -20,13 +20,13 @@ linters: # - exhaustive # - forbidigo # - forcetypeassert - # - goconst + - goconst # - gocritic # - gocyclo # - goheader # - gomodguard - # - goprintffuncname - # - gosimple + - goprintffuncname + - gosimple - govet # - grouper # - importas @@ -45,19 +45,19 @@ linters: # - revive # - rowserrcheck # - sqlclosecheck - # - staticcheck + - staticcheck # - stylecheck # - tenv # - testableexamples # - tparallel - # - typecheck + - typecheck # - unconvert # - unparam # - usestdlibvars - # - unused + - unused # - wastedassign - whitespace - # - wrapcheck # + # - wrapcheck issues: max-same-issues: 0