Skip to content

Commit

Permalink
tweak golangci-lint conf
Browse files Browse the repository at this point in the history
  • Loading branch information
libotony committed Jan 30, 2024
1 parent d49ce07 commit 8c337a5
Show file tree
Hide file tree
Showing 35 changed files with 94 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
with:
version: v1.54
# use the default if on main branch, otherwise use the pull request config
args: --timeout=30m --config=${{ github.event_name == 'pull_request' && '.golangci.pull-request.yml' || '.golangci.yml' }}
args: --timeout=30m --config=.golangci.yml
only-new-issues: true
skip-cache: true
skip-pkg-cache: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-docker-build.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker
name: Test Docker Buld

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Unit Tests

on: [push, pull_request]

Expand Down
29 changes: 23 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml

linters:
disable:
disable-all: true
enable:
- goimports
- gosimple
- govet
- ineffassign
- misspell
- unconvert
- typecheck
- unused
- errcheck
- staticcheck
- bidichk
- durationcheck
- exportloopref
- whitespace

# - structcheck # lots of false positives
# - errcheck #lot of false positives
# - contextcheck
# - errchkjson # lots of false positives
# - errorlint # this check crashes
# - exhaustive # silly check
# - makezero # false positives
# - nilerr # several intentional

run:
timeout: 10m
Expand All @@ -16,7 +37,3 @@ issues:
exclude-rules:
- path: vm/contracts.go
text: 'SA1019: "golang.org/x/crypto/ripemd160" is deprecated: RIPEMD-160 is a legacy hash and should not be used for new applications.'
- path: vm/bn256/cloudflare/optate.go
linters:
- deadcode
- staticcheck
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,5 @@ test-coverage:| go_version_check #@ Run the tests with coverage
lint_command_check:
@command -v golangci-lint || (echo "golangci-lint not found, please install it from https://golangci-lint.run/usage/install/" && exit 1)

lint: | go_version_check lint_command_check #@ Run 'golangci-lint' on new code changes
@golangci-lint run --new --config .golangci.pull-request.yml

lint-all: | go_version_check lint_command_check #@ Run 'golangci-lint' on the entire codebase
lint: | go_version_check lint_command_check #@ Run 'golangci-lint'
@golangci-lint run --config .golangci.yml
1 change: 0 additions & 1 deletion api/accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,5 +355,4 @@ func (a *Accounts) Mount(root *mux.Router, pathPrefix string) {
sub.Path("/{address}/storage/{key}").Methods("GET").HandlerFunc(utils.WrapHandlerFunc(a.handleGetStorage))
sub.Path("").Methods("POST").HandlerFunc(utils.WrapHandlerFunc(a.handleCallContract))
sub.Path("/{address}").Methods("POST").HandlerFunc(utils.WrapHandlerFunc(a.handleCallContract))

}
1 change: 0 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func New(
allowCustomTracer bool,
forkConfig thor.ForkConfig,
) (http.HandlerFunc, func()) {

origins := strings.Split(strings.TrimSpace(allowedOrigins), ",")
for i, o := range origins {
origins[i] = strings.ToLower(strings.TrimSpace(o))
Expand Down
1 change: 0 additions & 1 deletion api/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,5 +458,4 @@ func (d *Debug) Mount(root *mux.Router, pathPrefix string) {
sub.Path("/tracers").Methods(http.MethodPost).HandlerFunc(utils.WrapHandlerFunc(d.handleTraceClause))
sub.Path("/tracers/call").Methods(http.MethodPost).HandlerFunc(utils.WrapHandlerFunc(d.handleTraceCall))
sub.Path("/storage-range").Methods(http.MethodPost).HandlerFunc(utils.WrapHandlerFunc(d.handleDebugStorage))

}
20 changes: 9 additions & 11 deletions api/events/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,19 @@ func convertEventFilter(chain *chain.Chain, filter *EventFilter) (*logdb.EventFi
Order: filter.Order,
}
if len(filter.CriteriaSet) > 0 {
criterias := make([]*logdb.EventCriteria, len(filter.CriteriaSet))
for i, criteria := range filter.CriteriaSet {
f.CriteriaSet = make([]*logdb.EventCriteria, len(filter.CriteriaSet))
for i, criterion := range filter.CriteriaSet {
var topics [5]*thor.Bytes32
topics[0] = criteria.Topic0
topics[1] = criteria.Topic1
topics[2] = criteria.Topic2
topics[3] = criteria.Topic3
topics[4] = criteria.Topic4
criteria := &logdb.EventCriteria{
Address: criteria.Address,
topics[0] = criterion.Topic0
topics[1] = criterion.Topic1
topics[2] = criterion.Topic2
topics[3] = criterion.Topic3
topics[4] = criterion.Topic4
f.CriteriaSet[i] = &logdb.EventCriteria{
Address: criterion.Address,
Topics: topics,
}
criterias[i] = criteria
}
f.CriteriaSet = criterias
}
return f, nil
}
Expand Down
1 change: 0 additions & 1 deletion api/transactions/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func (t *Transactions) handleGetTransactionByID(w http.ResponseWriter, req *http
return err
}
return utils.WriteJSON(w, tx)

}

func (t *Transactions) handleGetTransactionReceiptByID(w http.ResponseWriter, req *http.Request) error {
Expand Down
1 change: 0 additions & 1 deletion api/transactions/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ func convertReceipt(txReceipt *tx.Receipt, header *block.Header, tx *tx.Transact
event.Topics = make([]thor.Bytes32, len(txEvent.Topics))
copy(event.Topics, txEvent.Topics)
otp.Events[j] = event

}
for j, txTransfer := range output.Transfers {
transfer := &Transfer{
Expand Down
3 changes: 1 addition & 2 deletions bft/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ func (engine *BFTEngine) ShouldVote(parentID thor.Bytes32) (bool, error) {
if !includes {
return false, nil
}

}
}

Expand All @@ -234,7 +233,7 @@ func (engine *BFTEngine) computeState(header *block.Header) (*bftState, error) {
)

if entry := engine.caches.justifier.Remove(header.ParentID()); !isCheckPoint(header.Number()) && entry != nil {
js = interface{}(entry.Entry.Value).(*justifier)
js = (entry.Entry.Value).(*justifier)
end = header.Number()
} else {
// create a new vote set if cache missed or new block is checkpoint
Expand Down
1 change: 0 additions & 1 deletion cmd/thor/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func New(
skipLogs bool,
forkConfig thor.ForkConfig,
) *Node {

return &Node{
packer: packer.New(repo, stater, master.Address(), master.Beneficiary, forkConfig),
cons: consensus.New(repo, stater, forkConfig),
Expand Down
4 changes: 2 additions & 2 deletions cmd/thor/sync_logdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ func verifyLogDBPerBlock(
block *block.Block,
receipts tx.Receipts,
eventLogs []*logdb.Event,
transferLogs []*logdb.Transfer) error {

transferLogs []*logdb.Transfer,
) error {
convertTopics := func(topics []thor.Bytes32) (r [5]*thor.Bytes32) {
for i, t := range topics {
t := t
Expand Down
1 change: 0 additions & 1 deletion comm/communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ func (c *Communicator) BroadcastBlock(blk *block.Block) {
peer := peer
peer.MarkBlock(blk.Header().ID())
c.goes.Go(func() {

if err := proto.NotifyNewBlockID(c.ctx, peer, blk.Header().ID()); err != nil {
peer.logger.Debug("failed to broadcast new block id", "err", err)
}
Expand Down
1 change: 0 additions & 1 deletion comm/handle_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

// peer will be disconnected if error returned
func (c *Communicator) handleRPC(peer *Peer, msg *p2p.Msg, write func(interface{}), txsToSync *txsToSync) (err error) {

log := peer.logger.New("msg", proto.MsgName(msg.Code))
log.Debug("received RPC call")
defer func() {
Expand Down
1 change: 0 additions & 1 deletion comm/txs_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func (c *Communicator) txsLoop() {

txEvCh := make(chan *txpool.TxEvent, 10)
sub := c.txPool.SubscribeTxEvent(txEvCh)
defer sub.Unsubscribe()
Expand Down
60 changes: 30 additions & 30 deletions consensus/errors.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// Copyright (c) 2018 The VeChainThor developers

// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package consensus

import (
"errors"
)

var errFutureBlock = errors.New("block in the future")

type consensusError string

func (err consensusError) Error() string {
return string(err)
}

// IsFutureBlock returns if the error indicates that the block should be
// processed later.
func IsFutureBlock(err error) bool {
return err == errFutureBlock
}

// IsCritical returns if the error is consensus related.
func IsCritical(err error) bool {
_, ok := err.(consensusError)
return ok
}
// Copyright (c) 2018 The VeChainThor developers

// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package consensus

import (
"errors"
)

var errFutureBlock = errors.New("block in the future")

type consensusError string

func (err consensusError) Error() string {
return string(err)
}

// IsFutureBlock returns if the error indicates that the block should be
// processed later.
func IsFutureBlock(err error) bool {
return err == errFutureBlock
}

// IsCritical returns if the error is consensus related.
func IsCritical(err error) bool {
_, ok := err.(consensusError)
return ok
}
3 changes: 1 addition & 2 deletions consensus/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (c *Consensus) validate(

// if no event emitted from Authority contract, it's believed that the candidates list not changed
if !hasAuthorityEvent {

// if no endorsor related transfer, or no event emitted from Params contract, the proposers list
// can be reused
hasEndorsorEvent := func() bool {
Expand Down Expand Up @@ -120,7 +119,7 @@ func (c *Consensus) validateBlockHeader(header *block.Header, parent *block.Head

if header.Number() < c.forkConfig.VIP214 {
if len(header.Alpha()) > 0 {
return consensusError("invlid block, alpha should be empty before VIP214")
return consensusError("invalid block, alpha should be empty before VIP214")
}
if len(signature) != 65 {
return consensusError(fmt.Sprintf("block signature length invalid: want 65 have %v", len(signature)))
Expand Down
1 change: 0 additions & 1 deletion genesis/devnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func NewDevnet() *Genesis {
GasLimit(thor.InitialGasLimit).
Timestamp(launchTime).
State(func(state *state.State) error {

// setup builtin contracts
if err := state.SetCode(builtin.Authority.Address, builtin.Authority.RuntimeBytecodes()); err != nil {
return err
Expand Down
3 changes: 0 additions & 3 deletions logdb/logdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (db *LogDB) Path() string {
}

func (db *LogDB) FilterEvents(ctx context.Context, filter *EventFilter) ([]*Event, error) {

const query = `SELECT e.seq, r0.data, e.blockTime, r1.data, r2.data, e.clauseIndex, r3.data, r4.data, r5.data, r6.data, r7.data, r8.data, e.data
FROM (%v) e
LEFT JOIN ref r0 ON e.blockID = r0.id
Expand Down Expand Up @@ -166,7 +165,6 @@ FROM (%v) e
}

func (db *LogDB) FilterTransfers(ctx context.Context, filter *TransferFilter) ([]*Transfer, error) {

const query = `SELECT t.seq, r0.data, t.blockTime, r1.data, r2.data, t.clauseIndex, r3.data, r4.data, t.amount
FROM (%v) t
LEFT JOIN ref r0 ON t.blockID = r0.id
Expand Down Expand Up @@ -467,7 +465,6 @@ func (w *Writer) Write(b *block.Block, receipts tx.Receipts) error {
tx := txs[i]
txID = tx.ID()
txOrigin, _ = tx.Origin()

}
if err := w.exec(
"INSERT OR IGNORE INTO ref(data) VALUES(?),(?)",
Expand Down
2 changes: 1 addition & 1 deletion logdb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type EventFilter struct {
type TransferCriteria struct {
TxOrigin *thor.Address //who send transaction
Sender *thor.Address //who transferred tokens
Recipient *thor.Address //who recieved tokens
Recipient *thor.Address //who received tokens
}

func (c *TransferCriteria) toWhereCondition() (cond string, args []interface{}) {
Expand Down
1 change: 0 additions & 1 deletion p2psrv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ func (s *Server) listenDiscV5() (err error) {
}
for _, node := range s.opts.KnownNodes {
s.bootstrapNodes = append(s.bootstrapNodes, discv5.NewNode(discv5.NodeID(node.ID), node.IP, node.UDP, node.TCP))

}

if err := network.SetFallbackNodes(s.bootstrapNodes); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions packer/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func New(
stater *state.Stater,
nodeMaster thor.Address,
beneficiary *thor.Address,
forkConfig thor.ForkConfig) *Packer {

forkConfig thor.ForkConfig,
) *Packer {
return &Packer{
repo,
stater,
Expand Down
5 changes: 2 additions & 3 deletions poa/sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func NewSchedulerV1(
addr thor.Address,
proposers []Proposer,
parentBlockNumber uint32,
parentBlockTime uint64) (*SchedulerV1, error) {

parentBlockTime uint64,
) (*SchedulerV1, error) {
actives := make([]Proposer, 0, len(proposers))
listed := false
var proposer Proposer
Expand Down Expand Up @@ -108,7 +108,6 @@ func (s *SchedulerV1) IsTheTime(newBlockTime uint64) bool {

// Updates returns proposers whose status are changed, and the score when new block time is assumed to be newBlockTime.
func (s *SchedulerV1) Updates(newBlockTime uint64) (updates []Proposer, score uint64) {

toDeactivate := make(map[thor.Address]Proposer)

t := newBlockTime - thor.BlockInterval
Expand Down
1 change: 0 additions & 1 deletion poa/sched_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func NewSchedulerV2(
parentBlockNumber uint32,
parentBlockTime uint64,
seed []byte) (*SchedulerV2, error) {

var (
listed = false
proposer Proposer
Expand Down
2 changes: 2 additions & 0 deletions poa/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var epochInterval uint32 = thor.SeederInterval

// mockEpochInterval mocks the epoch interval。
// TEST ONLY
//
//nolint:unused
func mockEpochInterval(interval uint32) {
epochInterval = interval
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ func (rt *Runtime) newEVM(stateDB *statedb.StateDB, clauseIndex uint32, txCtx *x
panic(err)
}

stateDB.SubBalance(common.Address(sender), amount)
stateDB.AddBalance(common.Address(recipient), amount)
stateDB.SubBalance(sender, amount)
stateDB.AddBalance(recipient, amount)

stateDB.AddTransfer(&tx.Transfer{
Sender: thor.Address(sender),
Expand Down Expand Up @@ -242,7 +242,7 @@ func (rt *Runtime) newEVM(stateDB *statedb.StateDB, clauseIndex uint32, txCtx *x
}

stateDB.AddLog(&types.Log{
Address: common.Address(contractAddr),
Address: contractAddr,
Topics: []common.Hash{common.Hash(prototypeSetMasterEvent.ID())},
Data: data,
})
Expand Down
Loading

0 comments on commit 8c337a5

Please sign in to comment.