Skip to content

Commit

Permalink
chore: lint: update linter settings, fix lint errors
Browse files Browse the repository at this point in the history
Ref: #11967
  • Loading branch information
rvagg committed May 7, 2024
1 parent d6d4fee commit 42720b8
Show file tree
Hide file tree
Showing 88 changed files with 292 additions and 284 deletions.
23 changes: 2 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ linters:
- goimports
- misspell
- goconst
- golint
- revive
- errcheck
- gosec
- unconvert
- staticcheck
- varcheck
- deadcode
- scopelint
- exportloopref
- unused

# We don't want to skip builtin/
Expand Down Expand Up @@ -44,18 +42,6 @@ issues:
exclude-use-default: false
exclude-rules:

- path: node/modules/lp2p
linters:
- golint

- path: build/params_.*\.go
linters:
- golint

- path: api/apistruct/struct.go
linters:
- golint

- path: .*_test.go
linters:
- gosec
Expand All @@ -68,11 +54,6 @@ issues:
linters:
- gosec

- path: api/test/.*
text: "context.Context should be the first parameter"
linters:
- golint

linters-settings:
goconst:
min-occurrences: 6
8 changes: 4 additions & 4 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,17 +552,17 @@ type FullNode interface {
StateMarketStorageDeal(context.Context, abi.DealID, types.TipSetKey) (*MarketDeal, error) //perm:read
// StateGetAllocationForPendingDeal returns the allocation for a given deal ID of a pending deal. Returns nil if
// pending allocation is not found.
StateGetAllocationForPendingDeal(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*verifregtypes.Allocation, error) //perm:read
StateGetAllocationForPendingDeal(ctx context.Context, dealID abi.DealID, tsk types.TipSetKey) (*verifregtypes.Allocation, error) //perm:read
// StateGetAllocationIdForPendingDeal is like StateGetAllocationForPendingDeal except it returns the allocation ID
StateGetAllocationIdForPendingDeal(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (verifreg.AllocationId, error) //perm:read
StateGetAllocationIdForPendingDeal(ctx context.Context, dealID abi.DealID, tsk types.TipSetKey) (verifreg.AllocationId, error) //perm:read
// StateGetAllocation returns the allocation for a given address and allocation ID.
StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error) //perm:read
StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationID verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error) //perm:read
// StateGetAllocations returns the all the allocations for a given client.
StateGetAllocations(ctx context.Context, clientAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) //perm:read
// StateGetAllAllocations returns the all the allocations available in verified registry actor.
StateGetAllAllocations(ctx context.Context, tsk types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) //perm:read
// StateGetClaim returns the claim for a given address and claim ID.
StateGetClaim(ctx context.Context, providerAddr address.Address, claimId verifregtypes.ClaimId, tsk types.TipSetKey) (*verifregtypes.Claim, error) //perm:read
StateGetClaim(ctx context.Context, providerAddr address.Address, claimID verifregtypes.ClaimId, tsk types.TipSetKey) (*verifregtypes.Claim, error) //perm:read
// StateGetClaims returns the all the claims for a given provider.
StateGetClaims(ctx context.Context, providerAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) //perm:read
// StateGetAllClaims returns the all the claims available in verified registry actor.
Expand Down
4 changes: 2 additions & 2 deletions api/api_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ type Gateway interface {
StateDecodeParams(ctx context.Context, toAddr address.Address, method abi.MethodNum, params []byte, tsk types.TipSetKey) (interface{}, error)
StateGetActor(ctx context.Context, actor address.Address, ts types.TipSetKey) (*types.Actor, error)
StateGetAllocationForPendingDeal(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*verifregtypes.Allocation, error)
StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error)
StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationID verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error)
StateGetAllocations(ctx context.Context, clientAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error)
StateGetClaim(ctx context.Context, providerAddr address.Address, claimId verifregtypes.ClaimId, tsk types.TipSetKey) (*verifregtypes.Claim, error)
StateGetClaim(ctx context.Context, providerAddr address.Address, claimID verifregtypes.ClaimId, tsk types.TipSetKey) (*verifregtypes.Claim, error)
StateGetClaims(ctx context.Context, providerAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error)
StateReadState(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*ActorState, error)
StateListMiners(ctx context.Context, tsk types.TipSetKey) ([]address.Address, error)
Expand Down
2 changes: 1 addition & 1 deletion api/api_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ type StorageMiner interface {
SealingSchedDiag(ctx context.Context, doSched bool) (interface{}, error) //perm:admin
SealingAbort(ctx context.Context, call storiface.CallID) error //perm:admin
// SealingSchedRemove removes a request from sealing pipeline
SealingRemoveRequest(ctx context.Context, schedId uuid.UUID) error //perm:admin
SealingRemoveRequest(ctx context.Context, schedID uuid.UUID) error //perm:admin

// paths.SectorIndex
StorageAttach(context.Context, storiface.StorageInfo, fsutil.FsStat) error //perm:admin
Expand Down
2 changes: 1 addition & 1 deletion api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestReturnTypes(t *testing.T) {
t.Run("worker", tst(new(Worker)))
}

func TestPermTags(t *testing.T) {
func TestPermTags(_ *testing.T) {
//stm: @OTHER_IMPLEMENTATION_PERM_TAGS_001
_ = PermissionedFullAPI(&FullNodeStruct{})
_ = PermissionedStorMinerAPI(&StorageMinerStruct{})
Expand Down
20 changes: 10 additions & 10 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ func NewFullNodeRPCV1(ctx context.Context, addr string, requestHeader http.Heade
}

func getPushUrl(addr string) (string, error) {
pushUrl, err := url.Parse(addr)
pushURL, err := url.Parse(addr)
if err != nil {
return "", err
}
switch pushUrl.Scheme {
switch pushURL.Scheme {
case "ws":
pushUrl.Scheme = "http"
pushURL.Scheme = "http"
case "wss":
pushUrl.Scheme = "https"
pushURL.Scheme = "https"
}
///rpc/v0 -> /rpc/streams/v0/push

pushUrl.Path = path.Join(pushUrl.Path, "../streams/v0/push")
return pushUrl.String(), nil
pushURL.Path = path.Join(pushURL.Path, "../streams/v0/push")
return pushURL.String(), nil
}

// NewStorageMinerRPCV0 creates a new http jsonrpc client for miner
func NewStorageMinerRPCV0(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (v0api.StorageMiner, jsonrpc.ClientCloser, error) {
pushUrl, err := getPushUrl(addr)
pushURL, err := getPushUrl(addr)
if err != nil {
return nil, nil, err
}
Expand All @@ -81,15 +81,15 @@ func NewStorageMinerRPCV0(ctx context.Context, addr string, requestHeader http.H
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
api.GetInternalStructs(&res), requestHeader,
append([]jsonrpc.Option{
rpcenc.ReaderParamEncoder(pushUrl),
rpcenc.ReaderParamEncoder(pushURL),
jsonrpc.WithErrors(api.RPCErrors),
}, opts...)...)

return &res, closer, err
}

func NewWorkerRPCV0(ctx context.Context, addr string, requestHeader http.Header) (v0api.Worker, jsonrpc.ClientCloser, error) {
pushUrl, err := getPushUrl(addr)
pushURL, err := getPushUrl(addr)
if err != nil {
return nil, nil, err
}
Expand All @@ -98,7 +98,7 @@ func NewWorkerRPCV0(ctx context.Context, addr string, requestHeader http.Header)
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
api.GetInternalStructs(&res),
requestHeader,
rpcenc.ReaderParamEncoder(pushUrl),
rpcenc.ReaderParamEncoder(pushURL),
jsonrpc.WithNoReconnect(),
jsonrpc.WithTimeout(30*time.Second),
jsonrpc.WithErrors(api.RPCErrors),
Expand Down
2 changes: 2 additions & 0 deletions api/types.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// revive:disable var-naming

package api

import (
Expand Down
6 changes: 2 additions & 4 deletions blockstore/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ func (a *apiBlockstore) PutMany(ctx context.Context, blocks []blocks.Block) erro
return nil
}

func (a *apiBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {
func (a *apiBlockstore) AllKeysChan(_ context.Context) (<-chan cid.Cid, error) {
return nil, xerrors.New("not supported")
}

func (a *apiBlockstore) HashOnRead(enabled bool) {
return
}
func (a *apiBlockstore) HashOnRead(_ bool) {}
6 changes: 2 additions & 4 deletions blockstore/buffered.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,9 @@ func (bs *BufferedBlockstore) DeleteMany(ctx context.Context, cids []cid.Cid) er

func (bs *BufferedBlockstore) View(ctx context.Context, c cid.Cid, callback func([]byte) error) error {
// both stores are viewable.
if err := bs.write.View(ctx, c, callback); ipld.IsNotFound(err) {
// not found in write blockstore; fall through.
} else {
if err := bs.write.View(ctx, c, callback); !ipld.IsNotFound(err) {
return err // propagate errors, or nil, i.e. found.
}
} // else not found in write blockstore; fall through.
return bs.read.View(ctx, c, callback)
}

Expand Down
2 changes: 1 addition & 1 deletion blockstore/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ func (m MemBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error)

// HashOnRead specifies if every read block should be
// rehashed to make sure it matches its CID.
func (m MemBlockstore) HashOnRead(enabled bool) {
func (m MemBlockstore) HashOnRead(_ bool) {
// no-op
}
2 changes: 2 additions & 0 deletions blockstore/net.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// revive:disable var-naming

package blockstore

import (
Expand Down
6 changes: 3 additions & 3 deletions blockstore/net_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type wsWrapper struct {
nextMsg []byte
}

func (w *wsWrapper) Read(b []byte) (int, error) {
func (w *wsWrapper) Read(_ []byte) (int, error) {
return 0, xerrors.New("read unsupported")
}

Expand Down Expand Up @@ -47,7 +47,7 @@ func (w *wsWrapper) ReadMsg() ([]byte, error) {
return mbuf.Bytes(), nil
}

func (w *wsWrapper) ReleaseMsg(bytes []byte) {
func (w *wsWrapper) ReleaseMsg(_ []byte) {
// todo use a pool
}

Expand All @@ -71,7 +71,7 @@ func (w *wsWrapper) NextMsgLen() (int, error) {
return len(w.nextMsg), nil
}

func (w *wsWrapper) Write(bytes []byte) (int, error) {
func (w *wsWrapper) Write(_ []byte) (int, error) {
return 0, xerrors.New("write unsupported")
}

Expand Down
2 changes: 1 addition & 1 deletion blockstore/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ func (m *SyncBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error
return m.bs.AllKeysChan(ctx)
}

func (m *SyncBlockstore) HashOnRead(enabled bool) {
func (m *SyncBlockstore) HashOnRead(_ bool) {
// noop
}
2 changes: 1 addition & 1 deletion build/builtin_actors_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/ipfs/go-cid"
)

var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMetadata{{
var EmbeddedBuiltinActorsMetadata = []*BuiltinActorsMetadata{{
Network: "butterflynet",
Version: 8,

Expand Down
2 changes: 2 additions & 0 deletions build/params_mainnet.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:build !debug && !2k && !testground && !calibnet && !butterflynet && !interopnet
// +build !debug,!2k,!testground,!calibnet,!butterflynet,!interopnet

// revive:disable:var-naming

package build

import (
Expand Down
3 changes: 3 additions & 0 deletions build/params_shared_vals.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//go:build !testground
// +build !testground

// revive:disable:var-naming

package build

import (
Expand Down Expand Up @@ -124,6 +126,7 @@ const MinimumBaseFee = 100
const PackingEfficiencyNum = 4
const PackingEfficiencyDenom = 5

// revive:disable-next-line:exported
// Actor consts
// TODO: pieceSize unused from actors
var MinDealDuration, MaxDealDuration = policy.DealDurationBounds(0)
24 changes: 12 additions & 12 deletions chain/actors/aerrors/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@ import (

"github.com/filecoin-project/go-state-types/exitcode"

. "github.com/filecoin-project/lotus/chain/actors/aerrors"
"github.com/filecoin-project/lotus/chain/actors/aerrors"
)

func TestFatalError(t *testing.T) {
//stm: @OTHER_IMPLEMENTATION_ACTOR_ERRORS_001
e1 := xerrors.New("out of disk space")
e2 := xerrors.Errorf("could not put node: %w", e1)
e3 := xerrors.Errorf("could not save head: %w", e2)
ae := Escalate(e3, "failed to save the head")
aw1 := Wrap(ae, "saving head of new miner actor")
aw2 := Absorb(aw1, 1, "try to absorb fatal error")
aw3 := Wrap(aw2, "initializing actor")
aw4 := Wrap(aw3, "creating miner in storage market")
ae := aerrors.Escalate(e3, "failed to save the head")
aw1 := aerrors.Wrap(ae, "saving head of new miner actor")
aw2 := aerrors.Absorb(aw1, 1, "try to absorb fatal error")
aw3 := aerrors.Wrap(aw2, "initializing actor")
aw4 := aerrors.Wrap(aw3, "creating miner in storage market")
t.Logf("Verbose error: %+v", aw4)
t.Logf("Normal error: %v", aw4)
assert.True(t, IsFatal(aw4), "should be fatal")
assert.True(t, aerrors.IsFatal(aw4), "should be fatal")
}
func TestAbsorbeError(t *testing.T) {
//stm: @OTHER_IMPLEMENTATION_ACTOR_ERRORS_001
e1 := xerrors.New("EOF")
e2 := xerrors.Errorf("could not decode: %w", e1)
ae := Absorb(e2, 35, "failed to decode CBOR")
aw1 := Wrap(ae, "saving head of new miner actor")
aw2 := Wrap(aw1, "initializing actor")
aw3 := Wrap(aw2, "creating miner in storage market")
ae := aerrors.Absorb(e2, 35, "failed to decode CBOR")
aw1 := aerrors.Wrap(ae, "saving head of new miner actor")
aw2 := aerrors.Wrap(aw1, "initializing actor")
aw3 := aerrors.Wrap(aw2, "creating miner in storage market")
t.Logf("Verbose error: %+v", aw3)
t.Logf("Normal error: %v", aw3)
assert.Equal(t, exitcode.ExitCode(35), RetCode(aw3))
assert.Equal(t, exitcode.ExitCode(35), aerrors.RetCode(aw3))
}
2 changes: 1 addition & 1 deletion chain/actors/aerrors/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewfSkip(skip int, retCode exitcode.ExitCode, format string, args ...interf
}
}

func Fatal(message string, args ...interface{}) ActorError {
func Fatal(message string, _ ...interface{}) ActorError {
return &actorError{
fatal: true,
msg: message,
Expand Down
4 changes: 2 additions & 2 deletions chain/actors/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func RegisterManifest(av actorstypes.Version, manifestCid cid.Cid, entries map[s
}
}

func AddActorMeta(name string, codeId cid.Cid, av actorstypes.Version) {
func AddActorMeta(name string, codeID cid.Cid, av actorstypes.Version) {
manifestMx.Lock()
defer manifestMx.Unlock()
actorMeta[codeId] = actorEntry{name: name, version: av}
actorMeta[codeID] = actorEntry{name: name, version: av}
}

// GetManifest gets a loaded manifest.
Expand Down
4 changes: 2 additions & 2 deletions chain/beacon/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (mb *mockBeacon) Entry(ctx context.Context, index uint64) <-chan Response {
return out
}

func (mb *mockBeacon) VerifyEntry(from types.BeaconEntry, _prevEntrySig []byte) error {
func (mb *mockBeacon) VerifyEntry(from types.BeaconEntry, _ []byte) error {
// TODO: cache this, especially for bls
oe := mb.entryForIndex(from.Round)
if !bytes.Equal(from.Data, oe.Data) {
Expand All @@ -60,7 +60,7 @@ func (mb *mockBeacon) VerifyEntry(from types.BeaconEntry, _prevEntrySig []byte)
return nil
}

func (mb *mockBeacon) MaxBeaconRoundForEpoch(nv network.Version, epoch abi.ChainEpoch) uint64 {
func (mb *mockBeacon) MaxBeaconRoundForEpoch(_ network.Version, epoch abi.ChainEpoch) uint64 {
// offset for better testing
return uint64(epoch + 100)
}
Expand Down
Loading

0 comments on commit 42720b8

Please sign in to comment.