diff --git a/.golangci.yml b/.golangci.yml index 74c0c7f..219c768 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,15 +20,12 @@ linters: - exhaustive - forbidigo - forcetypeassert - # - gci -# - gochecknoinits - goconst -# - gocritic + - gocritic - gocyclo - goheader - gomodguard - goprintffuncname - # - gosec - gosimple - govet - grouper @@ -39,9 +36,8 @@ linters: - makezero - misspell - nakedret -# - nestif - nilerr - # - nlreturn # Style wise I personally like this one, todo(lazar): unlax at somepoint, good practice +# - nlreturn # Style wise I personally like this one, todo(lazar): unlax at somepoint, good practice - noctx - nonamedreturns - nosprintfhostport @@ -58,7 +54,6 @@ linters: - typecheck - unconvert - unparam - - unused - usestdlibvars - unused - wastedassign @@ -78,11 +73,6 @@ issues: - errcheck - dupl - gosec - # Run some linter only for test files by excluding its issues for everything else. - path-except: _test\.go linters: - - forbidigo - # Exclude `lll` issues for long lines with `go:generate`. - - linters: - - lll - source: "^//go:generate " \ No newline at end of file + - forbidigo \ No newline at end of file diff --git a/btcstaking-tracker/btcslasher/slasher.go b/btcstaking-tracker/btcslasher/slasher.go index 7618a11..5141858 100644 --- a/btcstaking-tracker/btcslasher/slasher.go +++ b/btcstaking-tracker/btcslasher/slasher.go @@ -259,7 +259,8 @@ func (bs *BTCSlasher) SlashFinalityProvider(extractedFpBTCSK *btcec.PrivateKey) // Initialize a semaphore to control the number of concurrent operations sem := semaphore.NewWeighted(bs.maxSlashingConcurrency) - delegations := append(activeBTCDels, unbondedBTCDels...) + activeBTCDels = append(activeBTCDels, unbondedBTCDels...) + delegations := activeBTCDels // try to slash both staking and unbonding txs for each BTC delegation // sign and submit slashing tx for each active and unbonded delegation diff --git a/btcstaking-tracker/btcslasher/slasher_utils.go b/btcstaking-tracker/btcslasher/slasher_utils.go index 010e86b..2538a40 100644 --- a/btcstaking-tracker/btcslasher/slasher_utils.go +++ b/btcstaking-tracker/btcslasher/slasher_utils.go @@ -50,14 +50,15 @@ func (bs *BTCSlasher) slashBTCDelegation( txHash1, err1 := bs.sendSlashingTx(fpBTCPK, extractedfpBTCSK, del, false) txHash2, err2 := bs.sendSlashingTx(fpBTCPK, extractedfpBTCSK, del, true) - if err1 != nil && err2 != nil { + switch { + case err1 != nil && err2 != nil: // both attempts fail accumulatedErrs = multierror.Append(accumulatedErrs, err1, err2) txHash = nil - } else if err1 == nil { + case err1 == nil: // slashing tx is submitted successfully txHash = txHash1 - } else if err2 == nil { + case err2 == nil: // unbonding slashing tx is submitted successfully txHash = txHash2 } diff --git a/monitor/monitor.go b/monitor/monitor.go index f95186c..b961873 100644 --- a/monitor/monitor.go +++ b/monitor/monitor.go @@ -139,14 +139,14 @@ func (m *Monitor) Start(baseHeight uint32) { // get the height from db if it exists otherwise use the baseHeight provided from genesis var startHeight uint32 dbHeight, exists, err := m.store.LatestHeight() - if err != nil { + switch { + case err != nil: panic(fmt.Errorf("error getting latest height from db %w", err)) - } else if !exists { + case !exists: startHeight = baseHeight - } else { - if dbHeight > math.MaxUint32 { - panic(fmt.Errorf("dbHeight %d exceeds uint32 range", dbHeight)) - } + case dbHeight > math.MaxUint32: + panic(fmt.Errorf("dbHeight %d exceeds uint32 range", dbHeight)) + default: startHeight = uint32(dbHeight) + 1 } diff --git a/submitter/relayer/change_address_test.go b/submitter/relayer/change_address_test.go index 591a8c6..4e5a768 100644 --- a/submitter/relayer/change_address_test.go +++ b/submitter/relayer/change_address_test.go @@ -53,7 +53,8 @@ func TestGetChangeAddress(t *testing.T) { submitterMetrics.RelayerMetrics, nil, &cfg, logger, testutil.MakeTestBackend(t)) // 1. only SegWit Bech32 addresses - segWitBech32Addrs := append(SegWitBech32p2wshAddrsStr, SegWitBech32p2wpkhAddrsStr...) + SegWitBech32p2wshAddrsStr = append(SegWitBech32p2wshAddrsStr, SegWitBech32p2wpkhAddrsStr...) + segWitBech32Addrs := SegWitBech32p2wshAddrsStr wallet.EXPECT().ListUnspent().Return(getAddrsResult(segWitBech32Addrs), nil) changeAddr, err := testRelayer.GetChangeAddress() require.NoError(t, err) @@ -70,7 +71,8 @@ func TestGetChangeAddress(t *testing.T) { require.NoError(t, err) // 3. SegWit-Bech32 + legacy addresses, should only return SegWit-Bech32 addresses - addrs := append(segWitBech32Addrs, legacyAddrsStr...) + segWitBech32Addrs = append(segWitBech32Addrs, legacyAddrsStr...) + addrs := segWitBech32Addrs wallet.EXPECT().ListUnspent().Return(getAddrsResult(addrs), nil) changeAddr, err = testRelayer.GetChangeAddress() require.NoError(t, err) diff --git a/testutil/datagen/reporter.go b/testutil/datagen/reporter.go index 30ddb91..f627c05 100644 --- a/testutil/datagen/reporter.go +++ b/testutil/datagen/reporter.go @@ -143,16 +143,18 @@ func GenRandomBlock(r *rand.Rand, numBabylonTxs int, prevHash *chainhash.Hash) ( rawCkpt *btctxformatter.RawBtcCheckpoint ) - if numBabylonTxs == 2 { - randomTxs, rawCkpt = GenRandomBabylonTxPair(r) - } else if numBabylonTxs == 1 { + switch numBabylonTxs { + case 1: randomTxs, _ = GenRandomBabylonTxPair(r) randomTxs[1] = GenRandomTx(r) rawCkpt = nil - } else { + case 2: + randomTxs, rawCkpt = GenRandomBabylonTxPair(r) + default: randomTxs = []*wire.MsgTx{GenRandomTx(r), GenRandomTx(r)} rawCkpt = nil } + coinbaseTx := GenRandomTx(r) msgTxs := []*wire.MsgTx{coinbaseTx} msgTxs = append(msgTxs, randomTxs...) @@ -251,13 +253,14 @@ func GenRandomBlockchainWithBabylonTx(r *rand.Rand, n uint64, partialPercentage for i := uint64(1); i < n; i++ { var msgBlock *wire.MsgBlock prevHash := blocks[len(blocks)-1].BlockHash() - if r.Float32() < partialPercentage { + switch { + case r.Float32() < partialPercentage: msgBlock, rawCkpt = GenRandomBlock(r, 1, &prevHash) numCkptSegs++ - } else if r.Float32() < partialPercentage+fullPercentage { + case r.Float32() < partialPercentage+fullPercentage: msgBlock, rawCkpt = GenRandomBlock(r, 2, &prevHash) numCkptSegs += 2 - } else { + default: msgBlock, rawCkpt = GenRandomBlock(r, 0, &prevHash) }