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

chore(lint): upgrade golangci-lint & fix new lint errors #12887

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 1 addition & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ jobs:
- uses: ./.github/actions/install-system-dependencies
- uses: ./.github/actions/install-go
- uses: ./.github/actions/make-deps
- run: go install github.com/golangci/golangci-lint/cmd/[email protected]
- run: golangci-lint run -v --timeout 10m --concurrency 4
- run: make lint
check-fmt:
name: Check (gofmt)
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ linters:
- gosec
- unconvert
- staticcheck
- exportloopref
- copyloopvar
- unused

# We don't want to skip builtin/
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ $(warning Your Golang version is go$(shell expr $(GOVERSION) / 1000000).$(shell
$(error Update Golang to version to at least $(shell cat GO_VERSION_MIN))
endif

GOLANGCI_LINT_VERSION=v1.63.4

# git modules that need to be loaded
MODULES:=

Expand Down Expand Up @@ -283,6 +285,20 @@ unittests: ## Run unit tests
@$(GOCC) test $(shell go list ./... | grep -v /lotus/itests)
.PHONY: unittests

install-linter:
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION)" && \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION); \
elif ! golangci-lint --version | grep -q "$(GOLANGCI_LINT_VERSION) "; then \
echo "Updating golangci-lint to $(GOLANGCI_LINT_VERSION)" && \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION); \
fi
.PHONY: install-linter

lint: install-linter
golangci-lint run --timeout 10m --concurrency 4
.PHONY: lint

clean: ## Clean build artifacts
rm -rf $(CLEAN) $(BINS)
-$(MAKE) -C $(FFI_PATH) clean
Expand Down
4 changes: 2 additions & 2 deletions api/api_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ func (e *ErrExecutionReverted) ToJSONRPCError() (jsonrpc.JSONRPCError, error) {
}

// NewErrExecutionReverted creates a new ErrExecutionReverted with the given reason.
func NewErrExecutionReverted(exitCode exitcode.ExitCode, error, reason string, data []byte) *ErrExecutionReverted {
func NewErrExecutionReverted(exitCode exitcode.ExitCode, errMsg, reason string, data []byte) *ErrExecutionReverted {
return &ErrExecutionReverted{
Message: fmt.Sprintf("message execution failed (exit=[%s], revert reason=[%s], vm error=[%s])", exitCode, reason, error),
Message: fmt.Sprintf("message execution failed (exit=[%s], revert reason=[%s], vm error=[%s])", exitCode, reason, errMsg),
Data: fmt.Sprintf("0x%x", data),
}
}
Expand Down
1 change: 0 additions & 1 deletion api/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,6 @@ func Generate(out io.Writer, iface, pkg string, ainfo ApiASTInfo) error {
}

for _, g := range groupslice {
g := g
if _, err := fmt.Fprintf(out, "## %s\n", g.GroupName); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions blockstore/splitstore/markset_badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ func (s *BadgerMarkSet) Close() error {
return closeBadgerDB(db, s.path, s.persist)
}

func openBadgerDB(path string, recover bool) (*badger.DB, error) {
func openBadgerDB(path string, doRecover bool) (*badger.DB, error) {
// if it is not a recovery, clean up first
if !recover {
if !doRecover {
err := os.RemoveAll(path)
if err != nil {
return nil, xerrors.Errorf("error clearing markset directory: %w", err)
Expand Down
23 changes: 20 additions & 3 deletions chain/actors/aerrors/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ func Newf(retCode exitcode.ExitCode, format string, args ...interface{}) ActorEr
}
}

// todo: bit hacky

func NewfSkip(skip int, retCode exitcode.ExitCode, format string, args ...interface{}) ActorError {
func NewSkipf(skip int, retCode exitcode.ExitCode, format string, args ...interface{}) ActorError {
if retCode == 0 {
return &actorError{
fatal: true,
Expand All @@ -71,6 +69,25 @@ func NewfSkip(skip int, retCode exitcode.ExitCode, format string, args ...interf
}
}

func NewSkip(skip int, retCode exitcode.ExitCode, reason string) ActorError {
if retCode == 0 {
return &actorError{
fatal: true,
retCode: 0,

msg: "tried creating an error and setting RetCode to 0",
frame: xerrors.Caller(skip),
err: errors.New(reason),
}
}
return &actorError{
retCode: retCode,

msg: reason,
frame: xerrors.Caller(skip),
}
}

func Fatal(message string, args ...interface{}) ActorError {
return &actorError{
fatal: true,
Expand Down
2 changes: 1 addition & 1 deletion chain/actors/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func DealProviderCollateralBounds(
size abi.PaddedPieceSize, verified bool,
rawBytePower, qaPower, baselinePower abi.StoragePower,
circulatingFil abi.TokenAmount, nwVer network.Version,
) (min, max abi.TokenAmount, err error) {
) (abi.TokenAmount, abi.TokenAmount, error) {
v, err := actorstypes.VersionForNetwork(nwVer)
if err != nil {
return big.Zero(), big.Zero(), err
Expand Down
2 changes: 1 addition & 1 deletion chain/actors/policy/policy.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func DealProviderCollateralBounds(
size abi.PaddedPieceSize, verified bool,
rawBytePower, qaPower, baselinePower abi.StoragePower,
circulatingFil abi.TokenAmount, nwVer network.Version,
) (min, max abi.TokenAmount, err error) {
) (abi.TokenAmount, abi.TokenAmount, error) {
v, err := actorstypes.VersionForNetwork(nwVer)
if err != nil {
return big.Zero(), big.Zero(), err
Expand Down
4 changes: 2 additions & 2 deletions chain/badtscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ type BadBlockReason struct {
OriginalReason *BadBlockReason
}

func NewBadBlockReason(cid []cid.Cid, format string, i ...interface{}) BadBlockReason {
func NewBadBlockReason(cid []cid.Cid, reason string) BadBlockReason {
return BadBlockReason{
TipSet: cid,
Reason: fmt.Sprintf(format, i...),
Reason: reason,
}
}

Expand Down
1 change: 0 additions & 1 deletion chain/events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,6 @@ func TestStateChangedTimeout(t *testing.T) {
}}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
fcs := newFakeCS(t)

Expand Down
1 change: 0 additions & 1 deletion chain/events/filter/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ func TestEventFilterCollectEvents(t *testing.T) {
}

for _, tc := range testCases {
tc := tc // appease lint
t.Run(tc.name, func(t *testing.T) {
if err := tc.filter.CollectEvents(context.Background(), tc.te, false, addrMap.ResolveAddress); err != nil {
require.NoError(t, err, "collect events")
Expand Down
6 changes: 3 additions & 3 deletions chain/events/tscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ type tipSetCache struct {
storage tsCacheAPI
}

func newTSCache(storage tsCacheAPI, cap abi.ChainEpoch) *tipSetCache {
func newTSCache(storage tsCacheAPI, capacity abi.ChainEpoch) *tipSetCache {
return &tipSetCache{
byKey: make(map[types.TipSetKey]*types.TipSet, cap),
byHeight: make([]*types.TipSet, cap),
byKey: make(map[types.TipSetKey]*types.TipSet, capacity),
byHeight: make([]*types.TipSet, capacity),
start: 0,
len: 0,

Expand Down
3 changes: 0 additions & 3 deletions chain/gen/genesis/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
rawPow, qaPow := big.NewInt(0), big.NewInt(0)
for i, m := range miners {
// Create miner through power actor
i := i
m := m

variant := miner.SealProofVariant_Standard
if synthetic {
variant = miner.SealProofVariant_Synthetic
Expand Down
3 changes: 0 additions & 3 deletions chain/index/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,21 +295,18 @@ func (si *SqliteIndexer) indexTipset(ctx context.Context, tx *sql.Tx, ts *types.

for i, msg := range msgs {
insertTipsetMsgStmt := tx.Stmt(si.stmts.insertTipsetMessageStmt)
msg := msg
if _, err := insertTipsetMsgStmt.ExecContext(ctx, tsKeyCidBytes, height, 0, msg.Cid().Bytes(), i); err != nil {
return xerrors.Errorf("failed to insert tipset message: %w", err)
}
}

for _, blk := range ts.Blocks() {
blk := blk
_, smsgs, err := si.cs.MessagesForBlock(ctx, blk)
if err != nil {
return xerrors.Errorf("failed to get messages for block: %w", err)
}

for _, smsg := range smsgs {
smsg := smsg
if smsg.Signature.Type != crypto.SigTypeDelegated {
continue
}
Expand Down
2 changes: 0 additions & 2 deletions chain/index/pub_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ func (si *SqliteIndexer) notifyUpdateSubs() {
si.mu.Lock()
tSubs := make([]*updateSub, 0, len(si.updateSubs))
for _, tSub := range si.updateSubs {
tSub := tSub
tSubs = append(tSubs, tSub)
}
si.mu.Unlock()

for _, tSub := range tSubs {
tSub := tSub
select {
case tSub.ch <- chainIndexUpdated{}:
case <-tSub.ctx.Done():
Expand Down
1 change: 0 additions & 1 deletion chain/messagepool/selection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,6 @@ func TestGasReward(t *testing.T) {

mp := new(MessagePool)
for _, test := range tests {
test := test
t.Run(fmt.Sprintf("%v", test), func(t *testing.T) {
msg := &types.SignedMessage{
Message: types.Message{
Expand Down
1 change: 0 additions & 1 deletion chain/messagesigner/messagesigner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func TestMessageSignerSignMessage(t *testing.T) {
}},
}}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
mpool := newMockMpool()
ds := ds_sync.MutexWrap(datastore.NewMapDatastore())
Expand Down
3 changes: 0 additions & 3 deletions chain/stmgr/forks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,6 @@ func TestForkRefuseCall(t *testing.T) {

for after := 0; after < 3; after++ {
for before := 0; before < 3; before++ {
// Makes the lints happy...
after := after
before := before
t.Run(fmt.Sprintf("after:%d,before:%d", after, before), func(t *testing.T) {
testForkRefuseCall(t, before, after)
})
Expand Down
1 change: 0 additions & 1 deletion chain/store/basefee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestBaseFee(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(fmt.Sprintf("%v", test), func(t *testing.T) {
preSmoke := ComputeNextBaseFee(types.NewInt(test.basefee), test.limitUsed, test.noOfBlocks, buildconstants.UpgradeSmokeHeight-1)
assert.Equal(t, fmt.Sprintf("%d", test.preSmoke), preSmoke.String())
Expand Down
1 change: 0 additions & 1 deletion chain/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,6 @@ func (cs *ChainStore) LoadTipSet(ctx context.Context, tsk types.TipSetKey) (*typ
cids := tsk.Cids()
blks := make([]*types.BlockHeader, len(cids))
for i, c := range cids {
i, c := i, c
eg.Go(func() error {
b, err := cs.GetBlock(ctx, c)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions chain/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,6 @@ func (syncer *Syncer) ValidateTipSet(ctx context.Context, fts *store.FullTipSet,

var futures []async.ErrorFuture
for _, b := range fts.Blocks {
b := b // rebind to a scoped variable

futures = append(futures, async.Err(func() error {
if err := syncer.ValidateBlock(ctx, b, useCache); err != nil {
if isPermanent(err) {
Expand Down
2 changes: 0 additions & 2 deletions chain/types/electionproof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func TestPoissonFunction(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(fmt.Sprintf("lam-%d-%d", test.lambdaBase, test.lambdaShift), func(t *testing.T) {
b := &bytes.Buffer{}
b.WriteString("icdf\n")
Expand Down Expand Up @@ -58,7 +57,6 @@ func TestLambdaFunction(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(fmt.Sprintf("%s-%s", test.power, test.totalPower), func(t *testing.T) {
pow, ok := new(big.Int).SetString(test.power, 10)
assert.True(t, ok)
Expand Down
2 changes: 0 additions & 2 deletions chain/types/ethtypes/eth_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ func TestEthFilterResultMarshalJSON(t *testing.T) {
}

for _, tc := range testcases {
tc := tc
t.Run("", func(t *testing.T) {
data, err := json.Marshal(tc.res)
require.NoError(t, err)
Expand Down Expand Up @@ -442,7 +441,6 @@ func TestEthAddressListUnmarshalJSON(t *testing.T) {
},
}
for _, tc := range testcases {
tc := tc
t.Run("", func(t *testing.T) {
var got EthAddressList
err := json.Unmarshal([]byte(tc.input), &got)
Expand Down
1 change: 0 additions & 1 deletion chain/types/fil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func TestFilShort(t *testing.T) {
{fil: "-0.0002212344", expect: "-221.234 μFIL"},
{fil: "-0.00022123444", expect: "-221.234 μFIL"},
} {
s := s
t.Run(s.fil, func(t *testing.T) {
f, err := ParseFIL(s.fil)
require.NoError(t, err)
Expand Down
1 change: 0 additions & 1 deletion chain/types/percent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func TestPercent(t *testing.T) {
{-1012, "-10.12"},
{0, "0.0"},
} {
tc := tc
t.Run(fmt.Sprintf("%d <> %s", tc.p, tc.s), func(t *testing.T) {
m, err := tc.p.MarshalJSON()
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions chain/types/tipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ func (ts *TipSet) MinTimestamp() uint64 {
func (ts *TipSet) MinTicketBlock() *BlockHeader {
blks := ts.Blocks()

min := blks[0]
minBlk := blks[0]

for _, b := range blks[1:] {
if b.LastTicket().Less(min.LastTicket()) {
min = b
if b.LastTicket().Less(minBlk.LastTicket()) {
minBlk = b
}
}

return min
return minBlk
}

func (ts *TipSet) ParentMessageReceipts() cid.Cid {
Expand Down
2 changes: 0 additions & 2 deletions chain/vm/burn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestGasBurn(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(fmt.Sprintf("%v", test), func(t *testing.T) {
refund, toBurn := ComputeGasOverestimationBurn(test.used, test.limit)
assert.Equal(t, test.refund, refund, "refund")
Expand Down Expand Up @@ -62,7 +61,6 @@ func TestGasOutputs(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(fmt.Sprintf("%v", test), func(t *testing.T) {
output := ComputeGasOutputs(test.used, test.limit, baseFee, types.NewInt(test.feeCap), types.NewInt(test.premium), true)
i2s := func(i uint64) string {
Expand Down
1 change: 0 additions & 1 deletion chain/vm/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ func (*ActorRegistry) transform(instance invokee) (nativeCode, error) {
exports := instance.Exports()
runtimeType := reflect.TypeOf((*vmr.Runtime)(nil)).Elem()
for i, e := range exports {
i := i
m := e.Method
newErr := func(format string, args ...interface{}) error {
str := fmt.Sprintf(format, args...)
Expand Down
Loading
Loading