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

Konradstaniec/enable more lin #350

Merged
merged 2 commits into from
Dec 16, 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
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ linters:
- errname
# - errorlint
# - exhaustive
# - forbidigo
- forbidigo
# - forcetypeassert
- goconst
# - gocritic
- gocritic
# - gocyclo
- goheader
- gomodguard
Expand All @@ -33,7 +33,7 @@ linters:
- ineffassign
- loggercheck
# - maintidx
# - makezero
- makezero
- misspell
- nakedret
- nilerr
Expand All @@ -52,7 +52,7 @@ linters:
# - tparallel
- typecheck
- unconvert
# - unparam
- unparam
- usestdlibvars
- unused
- wastedassign
Expand Down
6 changes: 2 additions & 4 deletions app/upgrades/v1/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func CreateUpgradeHandler(upgradeDataStr UpgradeDataString) upgrades.UpgradeHand
// mint module with our own one.
err = upgradeMint(
ctx,
keepers.EncCfg.Codec,
&keepers.MintKeeper,
&keepers.AccountKeeper,
keepers.StakingKeeper,
Expand Down Expand Up @@ -118,7 +117,6 @@ func CreateUpgradeHandler(upgradeDataStr UpgradeDataString) upgrades.UpgradeHand

func upgradeMint(
ctx sdk.Context,
cdc codec.Codec,
k *mintkeeper.Keeper,
ak *accountkeeper.AccountKeeper,
stk *stakingkeeper.Keeper,
Expand Down Expand Up @@ -237,7 +235,7 @@ func upgradeLaunch(
return fmt.Errorf("failed to upgrade tokens distribution: %w", err)
}

if err := upgradeAllowedStakingTransactions(ctx, encCfg.Codec, btcK, allowedStakingTxHashes); err != nil {
if err := upgradeAllowedStakingTransactions(ctx, btcK, allowedStakingTxHashes); err != nil {
return fmt.Errorf("failed to upgrade allowed staking transactions: %w", err)
}

Expand Down Expand Up @@ -274,7 +272,7 @@ func upgradeTokensDistribution(ctx sdk.Context, bankK bankkeeper.SendKeeper, tok
return nil
}

func upgradeAllowedStakingTransactions(ctx sdk.Context, cdc codec.Codec, btcStakingK *btcstkkeeper.Keeper, allowedStakingTxHashes string) error {
func upgradeAllowedStakingTransactions(ctx sdk.Context, btcStakingK *btcstkkeeper.Keeper, allowedStakingTxHashes string) error {
data, err := LoadAllowedStakingTransactionHashesFromData(allowedStakingTxHashes)
if err != nil {
return fmt.Errorf("failed to load allowed staking transaction hashes from string %s: %w", allowedStakingTxHashes, err)
Expand Down
7 changes: 4 additions & 3 deletions btcstaking/identifiable_staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ func generateTxFromOutputs(r *rand.Rand, info *btcstaking.IdentifiableStakingInf

tx := wire.NewMsgTx(2)
for i := 0; i < int(numOutputs); i++ {
if i == stakingOutputIdx {
switch {
case i == stakingOutputIdx:
tx.AddTxOut(info.StakingOutput)
} else if i == opReturnOutputIdx {
case i == opReturnOutputIdx:
tx.AddTxOut(info.OpReturnOutput)
} else {
default:
tx.AddTxOut(wire.NewTxOut((r.Int63n(1000000000) + 10000), datagen.GenRandomByteArray(r, 32)))
}
}
Expand Down
7 changes: 4 additions & 3 deletions btcstaking/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,14 @@ func testSlashingTx(
slashingOutput := outputFromAddressAndValue(t, slashingAddress, slashingAmount)
changeOutput := taprootOutputWithValue(t, r, changeAmount)

if changeAmount <= 0 {
switch {
case changeAmount <= 0:
require.Error(t, err)
require.ErrorIs(t, err, btcstaking.ErrInsufficientChangeAmount)
} else if mempool.IsDust(slashingOutput, mempool.DefaultMinRelayTxFee) || mempool.IsDust(changeOutput, mempool.DefaultMinRelayTxFee) {
case mempool.IsDust(slashingOutput, mempool.DefaultMinRelayTxFee) || mempool.IsDust(changeOutput, mempool.DefaultMinRelayTxFee):
require.Error(t, err)
require.ErrorIs(t, err, btcstaking.ErrDustOutputFound)
} else {
default:
require.NoError(t, err)
err = btcstaking.CheckSlashingTxMatchFundingTx(
slashingTx,
Expand Down
2 changes: 1 addition & 1 deletion client/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (c *Client) SendMessageWithSigner(
return nil, err
}

//txf ready
// txf ready
_, adjusted, err := c.CalculateGas(ctx, txf, signerPvKey.PubKey(), cMsgs...)
if err != nil {
return nil, err
Expand Down
7 changes: 4 additions & 3 deletions cmd/babylond/cmd/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ Example:
chainID := args[1]

var genesisParams GenesisParams
if network == "testnet" {
switch network {
case "testnet":
genesisParams = TestnetGenesisParams(
genesisCliArgs.MaxActiveValidators,
genesisCliArgs.BtcConfirmationDepth,
Expand Down Expand Up @@ -109,9 +110,9 @@ Example:
genesisCliArgs.JailDuration,
genesisCliArgs.FinalityActivationBlockHeight,
)
} else if network == "mainnet" {
case "mainnet":
panic("Mainnet params not implemented.")
} else {
default:
return fmt.Errorf("please choose testnet or mainnet")
}

Expand Down
7 changes: 5 additions & 2 deletions cmd/babylond/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ func NewRootCmd() *cobra.Command {
}

if !initClientCtx.Offline {
enabledSignModes := append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL)
var modes []signing.SignMode
modes = append(modes, tx.DefaultSignModes...)
modes = append(modes, signing.SignMode_SIGN_MODE_TEXTUAL)

txConfigOpts := tx.ConfigOptions{
EnabledSignModes: enabledSignModes,
EnabledSignModes: modes,
TextualCoinMetadataQueryFn: authtxconfig.NewGRPCCoinMetadataQueryFn(initClientCtx),
}
txConfig, err := tx.NewTxConfigWithOptions(
Expand Down
2 changes: 1 addition & 1 deletion cmd/babylond/cmd/sizes_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
// r is a regular expression that matched the store key prefix
// we cannot use modules names directly as sometimes module key != store key
// for example account module has store key "acc" and module key "auth"
var r, _ = regexp.Compile("s/k:[A-Za-z]+/")
var r = regexp.MustCompile("s/k:[A-Za-z]+/")

func OpenDB(dir string) (dbm.DB, error) {
fmt.Printf("Opening database at: %s\n", dir)
Expand Down
5 changes: 2 additions & 3 deletions cmd/babylond/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,9 @@ func calculateIP(ip string, i int) (string, error) {
}

func writeFile(name string, dir string, contents []byte) error {
writePath := filepath.Join(dir)
file := filepath.Join(writePath, name)
file := filepath.Join(dir, name)

err := cmtos.EnsureDir(writePath, 0755)
err := cmtos.EnsureDir(dir, 0755)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/bls12381/bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestVerifyBlsSig(t *testing.T) {
func TestVerifyBlsMultiSig(t *testing.T) {
msga := []byte("aaaaaaaa")
msgb := []byte("bbbbbbbb")
n := 100
n := 105
sks, pks := generateBatchTestKeyPairs(n)
sigs := make([]Signature, n)
for i := 0; i < n; i++ {
Expand Down
22 changes: 16 additions & 6 deletions crypto/schnorr-adaptor-signature/sign_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ const (
AdaptorSignatureSize = JacobianPointSize + ModNScalarSize + 1
)

func encSign(privKey, nonce *btcec.ModNScalar, pubKey *btcec.PublicKey, m []byte, T *btcec.JacobianPoint) (*AdaptorSignature, error) {
func encSign(
privKey, nonce *btcec.ModNScalar,
pubKey *btcec.PublicKey,
m []byte,
t *btcec.JacobianPoint,
) (*AdaptorSignature, error) {
// R' = kG
var RHat btcec.JacobianPoint
k := *nonce
btcec.ScalarBaseMultNonConst(&k, &RHat)

// get R = R'+T
var R btcec.JacobianPoint
btcec.AddNonConst(&RHat, T, &R)
btcec.AddNonConst(&RHat, t, &R)
// negate k and R if R.y is odd
affineRWithEvenY, needNegation := intoPointWithEvenY(&R)
R = *affineRWithEvenY
Expand Down Expand Up @@ -52,15 +57,20 @@ func encSign(privKey, nonce *btcec.ModNScalar, pubKey *btcec.PublicKey, m []byte
// can only be because of bad nonces. The caller function `EncSign` will
// keep trying `encSign` until finding a nonce that generates correct
// signature
if err := encVerify(sig, m, pBytes, T); err != nil {
if err := encVerify(sig, m, pBytes, t); err != nil {
return nil, fmt.Errorf("the provided nonce does not work: %w", err)
}

// Return signature
return sig, nil
}

func encVerify(sig *AdaptorSignature, m []byte, pubKeyBytes []byte, T *btcec.JacobianPoint) error {
func encVerify(
sig *AdaptorSignature,
m []byte,
pubKeyBytes []byte,
t *btcec.JacobianPoint,
) error {
// Fail if m is not 32 bytes
if len(m) != chainhash.HashSize {
return fmt.Errorf("wrong size for message (got %v, want %v)",
Expand All @@ -71,9 +81,9 @@ func encVerify(sig *AdaptorSignature, m []byte, pubKeyBytes []byte, T *btcec.Jac
R := &sig.r // NOTE: R is an affine point
var RHat btcec.JacobianPoint
if sig.needNegation {
btcec.AddNonConst(R, T, &RHat)
btcec.AddNonConst(R, t, &RHat)
} else {
btcec.AddNonConst(R, negatePoint(T), &RHat)
btcec.AddNonConst(R, negatePoint(t), &RHat)
}

RHat.ToAffine()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/configurer/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (uc *UpgradeConfigurer) ConfigureChain(chainConfig *chain.Config) error {

forkHeight := uc.forkHeight
if forkHeight > 0 {
forkHeight = forkHeight - config.ForkHeightPreUpgradeOffset
forkHeight -= config.ForkHeightPreUpgradeOffset
}

chainInitResource, err := uc.containerManager.RunChainInitResource(
Expand Down
9 changes: 6 additions & 3 deletions test/e2e/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ func (m *Manager) ExecTxCmd(t *testing.T, chainId string, nodeName string, comma
// namely adding flags `--chain-id={chain-id} -b=block --yes --keyring-backend=test "--log_format=json"`,
// and searching for `successStr`
func (m *Manager) ExecTxCmdWithSuccessString(t *testing.T, chainId string, containerName string, command []string, successStr string) (bytes.Buffer, bytes.Buffer, error) {
allTxArgs := []string{fmt.Sprintf("--chain-id=%s", chainId), "--gas-prices=0.002ubbn", "-b=sync", "--yes", "--keyring-backend=test", "--log_format=json", "--home=/home/babylon/babylondata"}
txCommand := append(command, allTxArgs...)
return m.ExecCmd(t, containerName, txCommand, successStr)
additionalArgs := []string{fmt.Sprintf("--chain-id=%s", chainId), "--gas-prices=0.002ubbn", "-b=sync", "--yes", "--keyring-backend=test", "--log_format=json", "--home=/home/babylon/babylondata"}

cmd := command
cmd = append(cmd, additionalArgs...)

return m.ExecCmd(t, containerName, cmd, successStr)
}

// ExecHermesCmd executes command on the hermes relaer container.
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/initialization/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ type internalChain struct {
nodes []*internalNode
}

func new(id, dataDir string) (*internalChain, error) {
func new(id, dataDir string) *internalChain {
chainMeta := ChainMeta{
Id: id,
DataDir: dataDir,
}
return &internalChain{
chainMeta: chainMeta,
}, nil
}
}

func (c *internalChain) export() *Chain {
Expand Down
5 changes: 1 addition & 4 deletions test/e2e/initialization/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ func InitChain(
forkHeight int,
btcHeaders []*btclighttypes.BTCHeaderInfo,
) (*Chain, error) {
chain, err := new(id, dataDir)
if err != nil {
return nil, err
}
chain := new(id, dataDir)

for _, nodeConfig := range nodeConfigs {
newNode, err := newNode(chain, nodeConfig)
Expand Down
8 changes: 5 additions & 3 deletions testutil/datagen/btc_blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,15 @@ func GenRandomBtcdBlockchainWithBabylonTx(r *rand.Rand, n uint64, oneTxThreshold
for i := uint64(1); i < n; i++ {
var msgBlock *wire.MsgBlock
prevHash := blocks[len(blocks)-1].BlockHash()
if r.Float32() < oneTxThreshold {

switch {
case r.Float32() < oneTxThreshold:
msgBlock, rawCkpt = GenRandomBtcdBlock(r, 1, &prevHash)
numCkptSegs += 1
} else if r.Float32() < twoTxThreshold {
case r.Float32() < twoTxThreshold:
msgBlock, rawCkpt = GenRandomBtcdBlock(r, 2, &prevHash)
numCkptSegs += 2
} else {
default:
msgBlock, rawCkpt = GenRandomBtcdBlock(r, 0, &prevHash)
}

Expand Down
7 changes: 4 additions & 3 deletions testutil/datagen/btc_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,15 @@ func CreateBlock(
var transactions []*wire.MsgTx

for i := uint32(0); i <= numTx; i++ {
if i == 0 {
switch {
case i == 0:
tx := createCoinbaseTx(int32(height), &chaincfg.SimNetParams)
transactions = append(transactions, tx)
} else if i == babylonOpReturnIdx {
case i == babylonOpReturnIdx:
out := makeSpendableOutWithRandOutPoint(r, 1000)
tx := createSpendOpReturnTx(&out, lowFee, babylonData)
transactions = append(transactions, tx)
} else {
default:
out := makeSpendableOutWithRandOutPoint(r, 1000)
tx := createSpendTx(r, &out, lowFee)
transactions = append(transactions, tx)
Expand Down
7 changes: 4 additions & 3 deletions testutil/datagen/raw_checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ func GenRandomSequenceRawCheckpointsWithMeta(r *rand.Rand) []*types.RawCheckpoin
var topEpoch, finalEpoch uint64
epoch1 := GenRandomEpochNum(r)
epoch2 := GenRandomEpochNum(r)
if epoch1 > epoch2 {
switch {
case epoch1 > epoch2:
topEpoch = epoch1
finalEpoch = epoch2
} else if epoch1 < epoch2 {
case epoch1 < epoch2:
topEpoch = epoch2
finalEpoch = epoch1
} else { // In the case they are equal, make the topEpoch one more
default:
topEpoch = epoch1 + 1
finalEpoch = epoch2
}
Expand Down
13 changes: 7 additions & 6 deletions types/btc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ func getParams(opts servertypes.AppOptions) *chaincfg.Params {
panic("Bitcoin network config should be valid string")
}

if network == string(BtcMainnet) {
switch network {
case string(BtcMainnet):
return &chaincfg.MainNetParams
} else if network == string(BtcTestnet) {
case string(BtcTestnet):
return &chaincfg.TestNet3Params
} else if network == string(BtcSimnet) {
case string(BtcSimnet):
return &chaincfg.SimNetParams
} else if network == string(BtcRegtest) {
case string(BtcRegtest):
return &chaincfg.RegressionNetParams
} else if network == string(BtcSignet) {
case string(BtcSignet):
return &chaincfg.SigNetParams
} else {
default:
panic("Bitcoin network should be one of [mainet, testnet, simnet, regtest, signet]")
}
}
Expand Down
7 changes: 4 additions & 3 deletions wasmbinding/test/custom_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import (
// TODO consider doing it by environmental variables as currently it may fail on some
// weird architectures
func getArtifactPath() string {
if runtime.GOARCH == "amd64" {
switch runtime.GOARCH {
case "amd64":
return "../testdata/artifacts/testdata.wasm"
} else if runtime.GOARCH == "arm64" {
case "arm64":
return "../testdata/artifacts/testdata-aarch64.wasm"
} else {
default:
panic("Unsupported architecture")
}
}
Expand Down
Loading
Loading