Skip to content

Commit

Permalink
chore: unify dev and ci linting
Browse files Browse the repository at this point in the history
- CI now matches linting in dev environments
- Addressed new issues caught by improvmed linting
  • Loading branch information
frrist committed Jun 16, 2022
1 parent 56fcf12 commit a3df9e7
Show file tree
Hide file tree
Showing 64 changed files with 1,821 additions and 205 deletions.
27 changes: 9 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ jobs:
key: lily-test-vectors-{{ checksum "./build/test-vectors/vectors.json" }}
paths:
- /var/tmp/lily-test-vectors/

lint: &lint
description: |
Run golangci-lint.
Expand All @@ -284,28 +285,17 @@ jobs:
steps:
- install-deps
- prepare
- run: make deps
- run:
name: Install staticcheck
command: go install honnef.co/go/tools/cmd/staticcheck@434f5f3816b358fe468fa83dcba62d794e7fe04b # 2021.1 (v0.2.0)
- run:
name: gofmt
command: |
out=$(gofmt -l . | { grep -v extern || true; })
if [[ -n "$out" ]]; then
echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}'
exit 1
fi
- run: make build
- run:
name: go vet
command: go vet $(go list ./... | grep -v /tasks/messages/types)
command: make -j3 support/tools/bin/golangci-lint
- run:
name: staticcheck
name: Lint
command: |
set -o pipefail
staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
support/tools/bin/golangci-lint run -v --timeout 5m \
--concurrency << parameters.concurrency >> << parameters.args >>
lint-all:
<<: *lint

test-docker-mainnet:
executor: dockerizer
steps:
Expand Down Expand Up @@ -374,7 +364,8 @@ workflows:
# `test` and `mod-tidy-check` runs for all branches
jobs:
- mod-tidy-check
- lint-all
- lint-all:
concurrency: "8"
- test
- integration-test
- test-docker-mainnet
Expand Down
16 changes: 9 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ linters:
- goimports
- misspell
- goconst
- golint
- revive
- errcheck
- gosec
- unconvert
- staticcheck
- varcheck
- structcheck
- deadcode
- scopelint
- exportloopref


issues:
Expand All @@ -35,14 +34,17 @@ issues:

exclude-use-default: false
exclude-rules:
- path: lens/util/.*
linters:
- golint

- path: storage/migrations/.*
linters:
- misspell
- path: schemas/.*
linters:
- misspell

linters-settings:
goconst:
min-occurrences: 6
misspell:
ignore-words:
- "surveyer"
- "Surveyer"
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ build/.update-modules:

CLEAN+=build/.update-modules

# tools
toolspath:=support/tools

ldflags=-X=github.com/filecoin-project/lily/version.GitVersion=$(LILY_VERSION)
ifneq ($(strip $(LDFLAGS)),)
Expand Down Expand Up @@ -113,14 +111,15 @@ test-coverage:
LILY_TEST_DB="postgres://postgres:password@localhost:5432/postgres?sslmode=disable" go test -coverprofile=coverage.out ./...

# tools
toolspath:=support/tools

$(toolspath)/bin/golangci-lint: $(toolspath)/go.mod
@mkdir -p $(dir $@)
(cd $(toolspath); go build -tags tools -o $(@:$(toolspath)/%=%) github.com/golangci/golangci-lint/cmd/golangci-lint)

.PHONY: lint
lint: $(toolspath)/bin/golangci-lint
$(toolspath)/bin/golangci-lint run ./...
$(toolspath)/bin/golangci-lint run --concurrency 8 ./...

.PHONY: actors-gen
actors-gen:
Expand Down
2 changes: 1 addition & 1 deletion chain/cache/tipset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ type TestWarmer struct {

func (tw *TestWarmer) GetTipSet(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error) {
defer func() {
tw.idx += 1
tw.idx++
}()
return tw.tss[tw.idx], nil
}
Expand Down
2 changes: 1 addition & 1 deletion chain/gap/find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func TestFind(t *testing.T) {
actual, err := NewFinder(nil, strg, t.Name(), minHeight, maxHeight, tasktype.AllTableTasks).Find(ctx)
require.NoError(t, err)

// expect nothing since tasks have an OK status dispite the error
// expect nothing since tasks have an OK status despite the error
require.Len(t, actual, 0)
})

Expand Down
5 changes: 2 additions & 3 deletions chain/indexer/distributed/queue/tasks/gapfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,13 @@ func (gh *AsynqGapFillTipSetTaskHandler) HandleGapFillTipSetTask(ctx context.Con
log.Errorw("failed to index tipset for gap fill", zap.Inline(p), "error", err)
// return SkipRetry to prevent the task from being retried since nodes do not contain the block
return fmt.Errorf("indexing tipset for gap fill %s.(%d) taskID %s: Error %s : %w", p.TipSet.Key().String(), p.TipSet.Height(), taskID, err, asynq.SkipRetry)
} else {
return err
}
return err
}
if !success {
log.Errorw("failed to gap fill task successfully", "taskID", taskID, zap.Inline(p))
return fmt.Errorf("gap filling tipset.(height) %s.(%d) taskID: %s", p.TipSet.Key(), p.TipSet.Height(), taskID)
} else {
} else { // nolint: revive
if err := gh.db.SetGapsFilled(ctx, int64(p.TipSet.Height()), p.Tasks...); err != nil {
log.Errorw("failed to mark gap as filled", "taskID", taskID, zap.Inline(p), "error", err)
return err
Expand Down
2 changes: 1 addition & 1 deletion chain/indexer/integrated/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (i *Manager) TipSet(ctx context.Context, ts *types.TipSet, options ...index
return false, err
}

// asynchronously begin indexing tipset `ts`, returning results as they become avaiable.
// asynchronously begin indexing tipset `ts`, returning results as they become available.
taskResults, taskErrors, err := idxer.TipSet(procCtx, ts)
// indexer suffered fatal error, abort.
if err != nil {
Expand Down
44 changes: 22 additions & 22 deletions chain/indexer/integrated/tipset/tipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ import (
"github.com/filecoin-project/lily/tasks/chaineconomics"
"github.com/filecoin-project/lily/tasks/consensus"
indexTask "github.com/filecoin-project/lily/tasks/indexer"
"github.com/filecoin-project/lily/tasks/messageexecutions/internal_message"
"github.com/filecoin-project/lily/tasks/messageexecutions/internal_parsed_message"
"github.com/filecoin-project/lily/tasks/messages/block_message"
"github.com/filecoin-project/lily/tasks/messages/gas_economy"
"github.com/filecoin-project/lily/tasks/messages/gas_output"
"github.com/filecoin-project/lily/tasks/messageexecutions/internalmessage"
"github.com/filecoin-project/lily/tasks/messageexecutions/internalparsedmessage"
"github.com/filecoin-project/lily/tasks/messages/blockmessage"
"github.com/filecoin-project/lily/tasks/messages/gaseconomy"
"github.com/filecoin-project/lily/tasks/messages/gasoutput"
"github.com/filecoin-project/lily/tasks/messages/message"
"github.com/filecoin-project/lily/tasks/messages/parsed_message"
"github.com/filecoin-project/lily/tasks/messages/parsedmessage"
"github.com/filecoin-project/lily/tasks/messages/receipt"
"github.com/filecoin-project/lily/tasks/msapprovals"
)
Expand Down Expand Up @@ -236,19 +236,19 @@ func (ti *TipSetIndexer) init() error {
case tasktype.Message:
tipsetsProcessors[t] = message.NewTask(ti.node)
case tasktype.GasOutputs:
tipsetsProcessors[t] = gas_output.NewTask(ti.node)
tipsetsProcessors[t] = gasoutput.NewTask(ti.node)
case tasktype.BlockMessage:
tipsetsProcessors[t] = block_message.NewTask(ti.node)
tipsetsProcessors[t] = blockmessage.NewTask(ti.node)
case tasktype.ParsedMessage:
tipsetsProcessors[t] = parsed_message.NewTask(ti.node)
tipsetsProcessors[t] = parsedmessage.NewTask(ti.node)
case tasktype.Receipt:
tipsetsProcessors[t] = receipt.NewTask(ti.node)
case tasktype.InternalMessage:
tipsetsProcessors[t] = internal_message.NewTask(ti.node)
tipsetsProcessors[t] = internalmessage.NewTask(ti.node)
case tasktype.InternalParsedMessage:
tipsetsProcessors[t] = internal_parsed_message.NewTask(ti.node)
tipsetsProcessors[t] = internalparsedmessage.NewTask(ti.node)
case tasktype.MessageGasEconomy:
tipsetsProcessors[t] = gas_economy.NewTask(ti.node)
tipsetsProcessors[t] = gaseconomy.NewTask(ti.node)
case tasktype.MultisigApproval:
tipsetsProcessors[t] = msapprovals.NewTask(ti.node)

Expand Down Expand Up @@ -293,10 +293,10 @@ type Result struct {
// TipSet keeps no internal state and asynchronously indexes `ts` returning Result's as they extracted.
// If the TipSetIndexer encounters an error (fails to fetch ts's parent) it returns immediately and performs no work.
// If one of the TipSetIndexer's tasks encounters a fatal error, the error is return on the error channel.
func (t *TipSetIndexer) TipSet(ctx context.Context, ts *types.TipSet) (chan *Result, chan error, error) {
func (ti *TipSetIndexer) TipSet(ctx context.Context, ts *types.TipSet) (chan *Result, chan error, error) {
start := time.Now()

ctx, _ = tag.New(ctx, tag.Upsert(metrics.Name, t.name))
ctx, _ = tag.New(ctx, tag.Upsert(metrics.Name, ti.name))
ctx, span := otel.Tracer("").Start(ctx, "TipSetIndexer.TipSet")

if ts.Height() == 0 {
Expand All @@ -305,7 +305,7 @@ func (t *TipSetIndexer) TipSet(ctx context.Context, ts *types.TipSet) (chan *Res
}

var executed, current *types.TipSet
pts, err := t.node.TipSet(ctx, ts.Parents())
pts, err := ti.node.TipSet(ctx, ts.Parents())
if err != nil {
return nil, nil, err
}
Expand All @@ -318,13 +318,13 @@ func (t *TipSetIndexer) TipSet(ctx context.Context, ts *types.TipSet) (chan *Res
attribute.Int64("current_height", int64(current.Height())),
attribute.String("executed_tipset", executed.String()),
attribute.Int64("executed_height", int64(executed.Height())),
attribute.String("name", t.name),
attribute.StringSlice("tasks", t.taskNames),
attribute.String("name", ti.name),
attribute.StringSlice("tasks", ti.taskNames),
)
}

log.Infow("index", "reporter", t.name, "current", current.Height(), "executed", executed.Height())
stateResults, taskNames := t.procBuilder.Build().State(ctx, current, executed)
log.Infow("index", "reporter", ti.name, "current", current.Height(), "executed", executed.Height())
stateResults, taskNames := ti.procBuilder.Build().State(ctx, current, executed)

// build list of executing tasks, used below to label incomplete tasks as skipped.
executingTasks := make(map[string]bool, len(taskNames))
Expand Down Expand Up @@ -359,7 +359,7 @@ func (t *TipSetIndexer) TipSet(ctx context.Context, ts *types.TipSet) (chan *Res
&visormodel.ProcessingReport{
Height: int64(current.Height()),
StateRoot: current.ParentState().String(),
Reporter: t.name,
Reporter: ti.name,
Task: name,
StartedAt: start,
CompletedAt: time.Now(),
Expand All @@ -372,7 +372,7 @@ func (t *TipSetIndexer) TipSet(ctx context.Context, ts *types.TipSet) (chan *Res
default:
// received a result

llt := log.With("height", current.Height(), "task", res.Task, "reporter", t.name)
llt := log.With("height", current.Height(), "task", res.Task, "reporter", ti.name)

// Was there a fatal error?
if res.Error != nil {
Expand All @@ -391,7 +391,7 @@ func (t *TipSetIndexer) TipSet(ctx context.Context, ts *types.TipSet) (chan *Res

for idx := range res.Report {
// Fill in some report metadata
res.Report[idx].Reporter = t.name
res.Report[idx].Reporter = ti.name
res.Report[idx].Task = res.Task
res.Report[idx].StartedAt = res.StartedAt
res.Report[idx].CompletedAt = res.CompletedAt
Expand Down
2 changes: 1 addition & 1 deletion chain/indexer/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ func ConstructOptions(opts ...Option) (IndexerOptions, error) {
// Indexer implemented to index TipSets.
type Indexer interface {
// TipSet indexes a TipSet. The returned error is non-nill if a fatal error is encountered. True is returned if the
// TipSet is indexed successfully, false if returned if the TipSet was only paritally indexer.
// TipSet is indexed successfully, false if returned if the TipSet was only partially indexer.
TipSet(ctx context.Context, ts *types.TipSet, opts ...Option) (bool, error)
}
10 changes: 8 additions & 2 deletions chain/watch/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ func init() {
power.ConsensusMinerMinPower = big.NewInt(2048)
verifreg.MinVerifiedDealSize = big.NewInt(256)

logging.SetLogLevel("*", "ERROR")
logging.SetLogLevelRegex("lily/.+", "DEBUG")
err = logging.SetLogLevel("*", "ERROR")
if err != nil {
panic(err)
}
err = logging.SetLogLevelRegex("lily/.+", "DEBUG")
if err != nil {
panic(err)
}
}

func TestWatcher(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions commands/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ import (
)

var ClientAPIFlags struct {
ApiAddr string
ApiToken string
APIAddr string
APIToken string
}

var ClientAPIFlag = &cli.StringFlag{
Name: "api",
Usage: "Address of lily api in multiaddr format.",
EnvVars: []string{"LILY_API"},
Value: "/ip4/127.0.0.1/tcp/1234",
Destination: &ClientAPIFlags.ApiAddr,
Destination: &ClientAPIFlags.APIAddr,
}

var ClientTokenFlag = &cli.StringFlag{
Name: "api-token",
Usage: "Authentication token for lily api.",
EnvVars: []string{"LILY_API_TOKEN"},
Value: "",
Destination: &ClientAPIFlags.ApiToken,
Destination: &ClientAPIFlags.APIToken,
}

// ClientAPIFlagSet are used by commands that act as clients of a daemon's API
Expand Down Expand Up @@ -275,7 +275,7 @@ Note that jobs are not persisted between restarts of the daemon. See

node.ApplyIf(func(s *node.Settings) bool { return c.IsSet("api") },
node.Override(node.SetApiEndpointKey, func(lr repo.LockedRepo) error {
apima, err := multiaddr.NewMultiaddr(ClientAPIFlags.ApiAddr)
apima, err := multiaddr.NewMultiaddr(ClientAPIFlags.APIAddr)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion commands/job/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var WatchBufferSizeFlag = &cli.IntFlag{

var WatchCmd = &cli.Command{
Name: "watch",
Usage: "watch the head of the filecoin blockchain and index each new head as it becomes avaiable",
Usage: "watch the head of the filecoin blockchain and index each new head as it becomes available",
Description: `
The watch command subscribes to incoming tipsets from the filecoin blockchain and indexes them as the arrive.
Expand Down
4 changes: 2 additions & 2 deletions commands/lily.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
)

func GetAPI(ctx context.Context) (lily.LilyAPI, jsonrpc.ClientCloser, error) {
addrStr := strings.TrimSpace(ClientAPIFlags.ApiAddr)
addrStr := strings.TrimSpace(ClientAPIFlags.APIAddr)

ainfo := cliutil.APIInfo{Addr: addrStr, Token: []byte(ClientAPIFlags.ApiToken)}
ainfo := cliutil.APIInfo{Addr: addrStr, Token: []byte(ClientAPIFlags.APIToken)}

addr, err := ainfo.DialArgs("v0")
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions commands/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ var NetPeers = &cli.Command{
}
fmt.Fprintf(w, "%s\t%s\t%s\n", peer.ID, peer.Addrs, agent)
}
w.Flush()
if err := w.Flush(); err != nil {
return err
}

}

Expand Down Expand Up @@ -204,7 +206,9 @@ var NetScores = &cli.Command{
for _, peer := range scores {
fmt.Fprintf(w, "%s\t%f\n", peer.ID, peer.Score.Score)
}
w.Flush()
if err := w.Flush(); err != nil {
return err
}
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions commands/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/urfave/cli/v2"
)

var WaitApiCmd = &cli.Command{
var WaitAPICmd = &cli.Command{
Name: "wait-api",
Usage: "Wait for lily api to come online",
Flags: []cli.Flag{
Expand All @@ -30,7 +30,7 @@ var WaitApiCmd = &cli.Command{
}

for {
err := checkAPI(ctx, ClientAPIFlags.ApiAddr, ClientAPIFlags.ApiToken)
err := checkAPI(ctx, ClientAPIFlags.APIAddr, ClientAPIFlags.APIToken)
if err == nil {
return nil
}
Expand Down
Loading

0 comments on commit a3df9e7

Please sign in to comment.