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: reject invalid tasks on client #975

Merged
merged 1 commit into from
Jun 3, 2022
Merged
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
10 changes: 10 additions & 0 deletions commands/job/fill.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package job

import (
"fmt"
"os"

lotuscli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"

"github.com/filecoin-project/lily/chain/indexer/tasktype"
"github.com/filecoin-project/lily/commands"
"github.com/filecoin-project/lily/lens/lily"
)
Expand Down Expand Up @@ -35,6 +37,14 @@ Constraints:
GapFillNotifyCmd,
},
Before: func(cctx *cli.Context) error {
tasks := RunFlags.Tasks.Value()
for _, taskName := range tasks {
if _, found := tasktype.TaskLookup[taskName]; found {
} else if _, found := tasktype.TableLookup[taskName]; found {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why twice? No objection but it's unusual.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its different. TaskLookup vs TableLookup where TableLookup contains the granular task names.

} else {
return fmt.Errorf("unknown task: %s", taskName)
}
}
return rangeFlags.validate()
},
Action: func(cctx *cli.Context) error {
Expand Down
10 changes: 10 additions & 0 deletions commands/job/find.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package job

import (
"fmt"
"os"

lotuscli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"

"github.com/filecoin-project/lily/chain/indexer/tasktype"
"github.com/filecoin-project/lily/commands"
"github.com/filecoin-project/lily/lens/lily"
)
Expand Down Expand Up @@ -35,6 +37,14 @@ since visor_processing_report entries will not be present for imported data (mea
RangeToFlag,
},
Before: func(cctx *cli.Context) error {
tasks := RunFlags.Tasks.Value()
for _, taskName := range tasks {
if _, found := tasktype.TaskLookup[taskName]; found {
} else if _, found := tasktype.TableLookup[taskName]; found {
} else {
return fmt.Errorf("unknown task: %s", taskName)
}
}
return rangeFlags.validate()
},
Action: func(cctx *cli.Context) error {
Expand Down
12 changes: 12 additions & 0 deletions commands/job/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ipfs/go-cid"
"github.com/urfave/cli/v2"

"github.com/filecoin-project/lily/chain/indexer/tasktype"
"github.com/filecoin-project/lily/commands"
"github.com/filecoin-project/lily/lens/lily"
)
Expand All @@ -33,6 +34,17 @@ The index command may be used to index a single tipset from the filecoin blockch
IndexTipSetCmd,
IndexHeightCmd,
},
Before: func(cctx *cli.Context) error {
tasks := RunFlags.Tasks.Value()
for _, taskName := range tasks {
if _, found := tasktype.TaskLookup[taskName]; found {
} else if _, found := tasktype.TableLookup[taskName]; found {
} else {
return fmt.Errorf("unknown task: %s", taskName)
}
}
return nil
},
}

var IndexTipSetCmd = &cli.Command{
Expand Down
12 changes: 12 additions & 0 deletions commands/job/survey.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package job

import (
"fmt"
"os"
"time"

Expand All @@ -9,6 +10,7 @@ import (

"github.com/filecoin-project/lily/commands"
"github.com/filecoin-project/lily/lens/lily"
"github.com/filecoin-project/lily/network"
)

var surveyFlags struct {
Expand All @@ -29,6 +31,16 @@ var SurveyCmd = &cli.Command{
Destination: &surveyFlags.interval,
},
},
Before: func(cctx *cli.Context) error {
tasks := RunFlags.Tasks.Value()
if len(tasks) != 1 {
return fmt.Errorf("survey accepts single task type: '%s'", network.PeerAgentsTask)
}
if tasks[0] != network.PeerAgentsTask {
return fmt.Errorf("unknown task: %s", tasks[0])
}
return nil
},
Action: func(cctx *cli.Context) error {
ctx := lotuscli.ReqContext(cctx)

Expand Down
10 changes: 10 additions & 0 deletions commands/job/walk.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package job

import (
"fmt"
"os"

lotuscli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"

"github.com/filecoin-project/lily/chain/indexer/tasktype"
"github.com/filecoin-project/lily/commands"
"github.com/filecoin-project/lily/lens/lily"
)
Expand All @@ -30,6 +32,14 @@ The status of each epoch and its set of tasks can be observed in the visor_proce
WalkNotifyCmd,
},
Before: func(cctx *cli.Context) error {
tasks := RunFlags.Tasks.Value()
for _, taskName := range tasks {
if _, found := tasktype.TaskLookup[taskName]; found {
} else if _, found := tasktype.TableLookup[taskName]; found {
} else {
return fmt.Errorf("unknown task: %s", taskName)
}
}
return rangeFlags.validate()
},
Action: func(cctx *cli.Context) error {
Expand Down
13 changes: 13 additions & 0 deletions commands/job/watch.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package job

import (
"fmt"
"os"

lotuscli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"

"github.com/filecoin-project/lily/chain/indexer/tasktype"
"github.com/filecoin-project/lily/commands"
"github.com/filecoin-project/lily/lens/lily"
"github.com/filecoin-project/lily/schedule"
Expand Down Expand Up @@ -86,6 +88,17 @@ watches the chain head and only indexes a tipset after observing 10 subsequent t
WatchWorkersFlag,
WatchBufferSizeFlag,
},
Before: func(cctx *cli.Context) error {
tasks := RunFlags.Tasks.Value()
for _, taskName := range tasks {
if _, found := tasktype.TaskLookup[taskName]; found {
} else if _, found := tasktype.TableLookup[taskName]; found {
} else {
return fmt.Errorf("unknown task: %s", taskName)
}
}
return nil
},
Subcommands: []*cli.Command{
WatchNotifyCmd,
},
Expand Down