Skip to content

Commit

Permalink
more lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Nov 11, 2024
1 parent 23cb24b commit 1c8604f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 32 deletions.
16 changes: 3 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ linters:
- exhaustive
- forbidigo
- forcetypeassert
# - gci
# - gochecknoinits
- goconst
# - gocritic
- gocritic
- gocyclo
- goheader
- gomodguard
- goprintffuncname
# - gosec
- gosimple
- govet
- grouper
Expand All @@ -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
Expand All @@ -58,7 +54,6 @@ linters:
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- unused
- wastedassign
Expand All @@ -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 "
- forbidigo
3 changes: 2 additions & 1 deletion btcstaking-tracker/btcslasher/slasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions btcstaking-tracker/btcslasher/slasher_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 4 additions & 2 deletions submitter/relayer/change_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
17 changes: 10 additions & 7 deletions testutil/datagen/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 1c8604f

Please sign in to comment.