Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
chore(style): update golangci lint (#500)
Browse files Browse the repository at this point in the history
Co-authored-by: David <[email protected]>
  • Loading branch information
mask-pp and davidtaikocha committed Jan 14, 2024
1 parent c474956 commit d824d03
Show file tree
Hide file tree
Showing 59 changed files with 334 additions and 267 deletions.
56 changes: 46 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ run:
- bindings/gen_taiko_l2.go

issues:
exclude-rules:
- path: bindings/encoding/custom_error.go
linters:
- errorlint
- path: pkg/tx_list_validator/tx_list_validator_test.go
linters:
- typecheck
- path: prover/proof_submitter/merkle_proof_test.go
linters:
- typecheck
# List of regexps of issue texts to exclude.
#
# But independently of this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`.
# To list all excluded by default patterns execute `golangci-lint run --help`
#
# Default: https://golangci-lint.run/usage/false-positives/#default-exclusions
exclude:
- abcdef

linters:
disable-all: true
enable:
- bidichk
- bodyclose
- durationcheck
- exportloopref
- errcheck
Expand All @@ -35,11 +35,20 @@ linters:
- goimports
- gosimple
- govet
- gosec
- gofmt
- ineffassign
- importas
- lll
- makezero
- misspell
- misspell
- megacheck
- revive
- staticcheck
- sqlclosecheck
- staticcheck
- stylecheck
- typecheck
- unconvert
- unused
Expand All @@ -51,3 +60,30 @@ linters-settings:
goconst:
min-len: 3
min-occurrences: 6

severity:
# Set the default severity for issues.
#
# If severity rules are defined and the issues do not match or no severity is provided to the rule
# this will be the default severity applied.
# Severities should match the supported severity names of the selected out format.
# - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity
# - Checkstyle: https://checkstyle.sourceforge.io/property_types.html#SeverityLevel
# - GitHub: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
# - TeamCity: https://www.jetbrains.com/help/teamcity/service-messages.html#Inspection+Instance
#
# Default: ""
default-severity: error
# If set to true `severity-rules` regular expressions become case-sensitive.
# Default: false
case-sensitive: true
# When a list of severity rules are provided, severity information will be added to lint issues.
# Severity rules have the same filtering capability as exclude rules
# except you are allowed to specify one matcher per severity rule.
# Only affects out formats that support setting severity information.
#
# Default: []
rules:
- linters:
- dupl
severity: info
4 changes: 2 additions & 2 deletions bindings/encoding/custom_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func TryParsingCustomError(originalError error) error {
// getErrorData tries to parse the actual custom error data from the given error.
func getErrorData(err error) string {
// Geth node custom errors, the actual struct of this error is go-ethereum's <rpc.jsonError Value>.
gethJsonError, ok := err.(interface{ ErrorData() interface{} })
gethJSONError, ok := err.(interface{ ErrorData() interface{} }) // nolint: errorlint
if ok {
if errData, ok := gethJsonError.ErrorData().(string); ok {
if errData, ok := gethJSONError.ErrorData().(string); ok {
return errData
}
}
Expand Down
16 changes: 8 additions & 8 deletions bindings/encoding/custom_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
"github.com/stretchr/testify/require"
)

type testJsonError struct{}
type testJSONError struct{}

func (e *testJsonError) Error() string { return common.Bytes2Hex(randomBytes(10)) }
func (e *testJSONError) Error() string { return common.Bytes2Hex(randomBytes(10)) }

func (e *testJsonError) ErrorData() interface{} { return "0x8a1c400f" }
func (e *testJSONError) ErrorData() interface{} { return "0x8a1c400f" }

type emptyTestJsonError struct{}
type emptyTestJSONError struct{}

func (e *emptyTestJsonError) Error() string { return "execution reverted" }
func (e *emptyTestJSONError) Error() string { return "execution reverted" }

func (e *emptyTestJsonError) ErrorData() interface{} { return "0x" }
func (e *emptyTestJSONError) ErrorData() interface{} { return "0x" }

func TestTryParsingCustomError(t *testing.T) {
randomErr := common.Bytes2Hex(randomBytes(10))
Expand All @@ -32,11 +32,11 @@ func TestTryParsingCustomError(t *testing.T) {

require.True(t, strings.HasPrefix(err.Error(), "L1_INVALID_BLOCK_ID"))

err = TryParsingCustomError(&testJsonError{})
err = TryParsingCustomError(&testJSONError{})

require.True(t, strings.HasPrefix(err.Error(), "L1_INVALID_BLOCK_ID"))

err = TryParsingCustomError(&emptyTestJsonError{})
err = TryParsingCustomError(&emptyTestJSONError{})

require.Equal(t, err.Error(), "execution reverted")
}
18 changes: 9 additions & 9 deletions bindings/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (

// Tier IDs defined in protocol.
var (
TierOptimisticID uint16 = 100
TierSgxID uint16 = 200
TierPseZkevmID uint16 = 300
TierSgxAndPseZkevmID uint16 = 400
TierGuardianID uint16 = 1000
ProtocolTiers []uint16 = []uint16{TierOptimisticID, TierSgxID, TierSgxAndPseZkevmID, TierGuardianID}
AnchorTxGasLimit uint64 = 250_000
TierOptimisticID uint16 = 100
TierSgxID uint16 = 200
TierPseZkevmID uint16 = 300
TierSgxAndPseZkevmID uint16 = 400
TierGuardianID uint16 = 1000
ProtocolTiers = []uint16{TierOptimisticID, TierSgxID, TierSgxAndPseZkevmID, TierGuardianID}
AnchorTxGasLimit uint64 = 250_000
)

// BlockHeader represents an Ethereum block header.
Expand Down Expand Up @@ -67,7 +67,7 @@ type TierFee struct {
type ProverAssignment struct {
FeeToken common.Address
Expiry uint64
MaxBlockId uint64
MaxBlockId uint64 // nolint: revive,stylecheck
MaxProposedIn uint64
MetaHash [32]byte
TierFees []TierFee
Expand All @@ -82,7 +82,7 @@ type AssignmentHookInput struct {

// ZKEvmProof should be same as PseZkVerifier.ZkEvmProof
type ZKEvmProof struct {
VerifierId uint16
VerifierId uint16 // nolint: revive, stylecheck
Zkp []byte
PointProof []byte
}
Expand Down
21 changes: 11 additions & 10 deletions bindings/encoding/struct_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package encoding

import (
cryptoRand "crypto/rand"
"crypto/rand"
"math/big"
"math/rand"
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"

"github.com/taikoxyz/taiko-client/common/utils"
)

var (
Expand All @@ -22,15 +23,15 @@ var (
TxHash: randomHash(),
ReceiptHash: randomHash(),
Bloom: types.BytesToBloom(randomHash().Bytes()),
Difficulty: new(big.Int).SetUint64(rand.Uint64()),
Number: new(big.Int).SetUint64(rand.Uint64()),
GasLimit: rand.Uint64(),
GasUsed: rand.Uint64(),
Difficulty: new(big.Int).SetUint64(utils.RandUint64(nil)),
Number: new(big.Int).SetUint64(utils.RandUint64(nil)),
GasLimit: utils.RandUint64(nil),
GasUsed: utils.RandUint64(nil),
Time: uint64(time.Now().Unix()),
Extra: randomHash().Bytes(),
MixDigest: randomHash(),
Nonce: types.EncodeNonce(rand.Uint64()),
BaseFee: new(big.Int).SetUint64(rand.Uint64()),
Nonce: types.EncodeNonce(utils.RandUint64(nil)),
BaseFee: new(big.Int).SetUint64(utils.RandUint64(nil)),
}
)

Expand Down Expand Up @@ -102,7 +103,7 @@ func TestToExecutableData(t *testing.T) {
// randomHash generates a random blob of data and returns it as a hash.
func randomHash() common.Hash {
var hash common.Hash
if n, err := cryptoRand.Read(hash[:]); n != common.HashLength || err != nil {
if n, err := rand.Read(hash[:]); n != common.HashLength || err != nil {
panic(err)
}
return hash
Expand All @@ -111,7 +112,7 @@ func randomHash() common.Hash {
// randomBytes generates a random bytes.
func randomBytes(size int) (b []byte) {
b = make([]byte, size)
if _, err := cryptoRand.Read(b); err != nil {
if _, err := rand.Read(b); err != nil {
log.Crit("Generate random bytes error", "error", err)
}
return
Expand Down
6 changes: 3 additions & 3 deletions cmd/flags/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var (
Value: 3,
Category: loggingCategory,
}
LogJson = &cli.BoolFlag{
LogJSON = &cli.BoolFlag{
Name: "log.json",
Usage: "Format logs with JSON",
Category: loggingCategory,
Expand Down Expand Up @@ -116,15 +116,15 @@ var (
}
)

// All common flags.
// CommonFlags All common flags.
var CommonFlags = []cli.Flag{
// Required
L1WSEndpoint,
TaikoL1Address,
TaikoL2Address,
// Optional
Verbosity,
LogJson,
LogJSON,
MetricsEnabled,
MetricsAddr,
MetricsPort,
Expand Down
6 changes: 3 additions & 3 deletions cmd/flags/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ var (
Value: 1 * time.Hour,
Category: driverCategory,
}
CheckPointSyncUrl = &cli.StringFlag{
CheckPointSyncURL = &cli.StringFlag{
Name: "p2p.checkPointSyncUrl",
Usage: "HTTP RPC endpoint of another synced L2 execution engine node",
Category: driverCategory,
}
)

// All driver flags.
// DriverFlags All driver flags.
var DriverFlags = MergeFlags(CommonFlags, []cli.Flag{
L2WSEndpoint,
L2AuthEndpoint,
JWTSecret,
P2PSyncVerifiedBlocks,
P2PSyncTimeout,
CheckPointSyncUrl,
CheckPointSyncURL,
})
4 changes: 2 additions & 2 deletions cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var (
ExtraData = &cli.StringFlag{
Name: "extraData",
Usage: "Block extra data set by the proposer (default = client version)",
Value: version.VersionWithCommit(),
Value: version.CommitVersion(),
Category: proposerCategory,
}
// Transactions pool related.
Expand Down Expand Up @@ -123,7 +123,7 @@ var (
}
)

// All proposer flags.
// ProposerFlags All proposer flags.
var ProposerFlags = MergeFlags(CommonFlags, []cli.Flag{
L2HTTPEndpoint,
TaikoTokenAddress,
Expand Down
2 changes: 1 addition & 1 deletion cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ var (
}
)

// All prover flags.
// ProverFlags All prover flags.
var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
L1HTTPEndpoint,
L2WSEndpoint,
Expand Down
2 changes: 1 addition & 1 deletion cmd/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func InitLogger(c *cli.Context) {
slogVerbosity = log.FromLegacyLevel(c.Int(flags.Verbosity.Name))
)

if c.Bool(flags.LogJson.Name) {
if c.Bool(flags.LogJSON.Name) {
glogger := log.NewGlogHandler(log.NewGlogHandler(log.JSONHandler(os.Stdout)))
glogger.Verbosity(slogVerbosity)
log.SetDefault(log.NewLogger(glogger))
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
app.Name = "Taiko Clients"
app.Usage = "The taiko client software command line interface"
app.Copyright = "Copyright 2021-2022 Taiko Labs"
app.Version = version.VersionWithCommit()
app.Version = version.CommitVersion()
app.Description = "Client software implementation in Golang for Taiko protocol"
app.Authors = []*cli.Author{{Name: "Taiko Labs", Email: "[email protected]"}}
app.EnableBashCompletion = true
Expand Down
27 changes: 26 additions & 1 deletion common/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
package utils

import "github.com/modern-go/reflect2"
import (
"crypto/rand"
"math/big"

"github.com/ethereum/go-ethereum/common/math"
"github.com/modern-go/reflect2"
)

func RandUint64(max *big.Int) uint64 {
if max == nil {
max = new(big.Int)
max.SetUint64(math.MaxUint64)
}
num, _ := rand.Int(rand.Reader, max)

return num.Uint64()
}

func RandUint32(max *big.Int) uint32 {
if max == nil {
max = new(big.Int)
max.SetUint64(math.MaxUint32)
}
num, _ := rand.Int(rand.Reader, max)
return uint32(num.Uint64())
}

// IsNil checks if the interface is empty.
func IsNil(i interface{}) bool {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const docTemplate = `{
"name": "MIT",
"url": "https://github.com/taikoxyz/taiko-client/blob/main/LICENSE.md"
},
"version": "{{.Version}}"
"version": "{{.JsonRPC}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
Expand Down
2 changes: 1 addition & 1 deletion driver/anchor_tx_constructor/anchor_tx_constructor.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package anchorTxConstructor
package anchortxconstructor

import (
"context"
Expand Down
Loading

0 comments on commit d824d03

Please sign in to comment.