Skip to content

Commit

Permalink
refactor: simplify job cli (#944)
Browse files Browse the repository at this point in the history
* refactor: simplify job cli
  • Loading branch information
frrist authored May 4, 2022
1 parent a35ae36 commit 2675a4d
Show file tree
Hide file tree
Showing 39 changed files with 1,246 additions and 1,706 deletions.
4 changes: 2 additions & 2 deletions chain/gap/fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type Filler struct {
DB *storage.Database
node lens.API
name string
minHeight, maxHeight uint64
minHeight, maxHeight int64
tasks []string
done chan struct{}
}

func NewFiller(node lens.API, db *storage.Database, name string, minHeight, maxHeight uint64, tasks []string) *Filler {
func NewFiller(node lens.API, db *storage.Database, name string, minHeight, maxHeight int64, tasks []string) *Filler {
return &Filler{
DB: db,
node: node,
Expand Down
6 changes: 3 additions & 3 deletions chain/gap/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ type Finder struct {
DB *storage.Database
node lens.API
name string
minHeight, maxHeight uint64
minHeight, maxHeight int64
tasks []string
done chan struct{}
}

func NewFinder(node lens.API, db *storage.Database, name string, minHeight, maxHeight uint64, tasks []string) *Finder {
func NewFinder(node lens.API, db *storage.Database, name string, minHeight, maxHeight int64, tasks []string) *Finder {
return &Finder{
DB: db,
node: node,
Expand Down Expand Up @@ -89,7 +89,7 @@ func (g *Finder) Run(ctx context.Context) error {
if err != nil {
return err
}
if uint64(head.Height()) < g.maxHeight {
if int64(head.Height()) < g.maxHeight {
return xerrors.Errorf("cannot look for gaps beyond chain head height %d", head.Height())
}

Expand Down
6 changes: 3 additions & 3 deletions chain/gap/find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
)

var (
minHeight = uint64(0)
maxHeight = uint64(10)
minHeight = int64(0)
maxHeight = int64(10)
)

func TestFind(t *testing.T) {
Expand Down Expand Up @@ -459,7 +459,7 @@ func (e *PREditor) truncate() {
require.NoError(e.t, err, "visor_processing_report")
}

func (e *PREditor) initialize(count uint64, tasks ...string) {
func (e *PREditor) initialize(count int64, tasks ...string) {
// build the task array
// uncomment to see all query
// db.AddQueryHook(&LoggingQueryHook{})
Expand Down
4 changes: 2 additions & 2 deletions chain/gap/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ type Notifier struct {
queue *queue.AsynQ
node lens.API
name string
minHeight, maxHeight uint64
minHeight, maxHeight int64
tasks []string
done chan struct{}
}

func NewNotifier(node lens.API, db *storage.Database, queue *queue.AsynQ, name string, minHeight, maxHeight uint64, tasks []string) *Notifier {
func NewNotifier(node lens.API, db *storage.Database, queue *queue.AsynQ, name string, minHeight, maxHeight int64, tasks []string) *Notifier {
return &Notifier{
DB: db,
queue: queue,
Expand Down
2 changes: 1 addition & 1 deletion chain/watch/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func init() {
verifreg.MinVerifiedDealSize = big.NewInt(256)

logging.SetLogLevel("*", "ERROR")
logging.SetLogLevelRegex("visor/.+", "DEBUG")
logging.SetLogLevelRegex("lily/.+", "DEBUG")
}

func TestWatcher(t *testing.T) {
Expand Down
101 changes: 44 additions & 57 deletions commands/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (

"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lily/lens/lily"
"github.com/filecoin-project/lotus/api"
lotusbuild "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
lotuscli "github.com/filecoin-project/lotus/cli"
"github.com/ipfs/go-cid"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"

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

var ChainCmd = &cli.Command{
Expand All @@ -36,12 +37,9 @@ var ChainCmd = &cli.Command{
var ChainHeadCmd = &cli.Command{
Name: "head",
Usage: "Print chain head",
Flags: flagSet(
clientAPIFlagSet,
),
Action: func(cctx *cli.Context) error {
ctx := lotuscli.ReqContext(cctx)
lapi, closer, err := GetAPI(ctx, clientAPIFlags.apiAddr, clientAPIFlags.apiToken)
lapi, closer, err := GetAPI(ctx)
if err != nil {
return err
}
Expand All @@ -63,17 +61,15 @@ var ChainGetBlock = &cli.Command{
Name: "getblock",
Usage: "Get a block and print its details",
ArgsUsage: "[blockCid]",
Flags: flagSet(
clientAPIFlagSet,
[]cli.Flag{
&cli.BoolFlag{
Name: "raw",
Usage: "print just the raw block header",
},
}),
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "raw",
Usage: "print just the raw block header",
},
},
Action: func(cctx *cli.Context) error {
ctx := lotuscli.ReqContext(cctx)
lapi, closer, err := GetAPI(ctx, clientAPIFlags.apiAddr, clientAPIFlags.apiToken)
lapi, closer, err := GetAPI(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -155,12 +151,9 @@ var ChainReadObjCmd = &cli.Command{
Name: "read-obj",
Usage: "Read the raw bytes of an object",
ArgsUsage: "[objectCid]",
Flags: flagSet(
clientAPIFlagSet,
),
Action: func(cctx *cli.Context) error {
ctx := lotuscli.ReqContext(cctx)
lapi, closer, err := GetAPI(ctx, clientAPIFlags.apiAddr, clientAPIFlags.apiToken)
lapi, closer, err := GetAPI(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -190,17 +183,15 @@ var ChainStatObjCmd = &cli.Command{
When a base is provided it will be walked first, and all links visisted
will be ignored when the passed in object is walked.
`,
Flags: flagSet(
clientAPIFlagSet,
[]cli.Flag{
&cli.StringFlag{
Name: "base",
Usage: "ignore links found in this obj",
},
}),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "base",
Usage: "ignore links found in this obj",
},
},
Action: func(cctx *cli.Context) error {
ctx := lotuscli.ReqContext(cctx)
lapi, closer, err := GetAPI(ctx, clientAPIFlags.apiAddr, clientAPIFlags.apiToken)
lapi, closer, err := GetAPI(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -240,7 +231,7 @@ var ChainGetMsgCmd = &cli.Command{
}

ctx := lotuscli.ReqContext(cctx)
lapi, closer, err := GetAPI(ctx, clientAPIFlags.apiAddr, clientAPIFlags.apiToken)
lapi, closer, err := GetAPI(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -282,24 +273,22 @@ var ChainListCmd = &cli.Command{
Name: "list",
Aliases: []string{"love"},
Usage: "View a segment of the chain",
Flags: flagSet(
clientAPIFlagSet,
[]cli.Flag{
&cli.Uint64Flag{Name: "height", DefaultText: "current head"},
&cli.IntFlag{Name: "count", Value: 30},
&cli.StringFlag{
Name: "format",
Usage: "specify the format to print out tipsets",
Value: "<height>: (<time>) <blocks>",
},
&cli.BoolFlag{
Name: "gas-stats",
Usage: "view gas statistics for the chain",
},
}),
Flags: []cli.Flag{
&cli.Uint64Flag{Name: "height", DefaultText: "current head"},
&cli.IntFlag{Name: "count", Value: 30},
&cli.StringFlag{
Name: "format",
Usage: "specify the format to print out tipsets",
Value: "<height>: (<time>) <blocks>",
},
&cli.BoolFlag{
Name: "gas-stats",
Usage: "view gas statistics for the chain",
},
},
Action: func(cctx *cli.Context) error {
ctx := lotuscli.ReqContext(cctx)
lapi, closer, err := GetAPI(ctx, clientAPIFlags.apiAddr, clientAPIFlags.apiToken)
lapi, closer, err := GetAPI(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -413,21 +402,19 @@ var ChainSetHeadCmd = &cli.Command{
Name: "sethead",
Usage: "manually set the local nodes head tipset (Caution: normally only used for recovery)",
ArgsUsage: "[tipsetkey]",
Flags: flagSet(
clientAPIFlagSet,
[]cli.Flag{
&cli.BoolFlag{
Name: "genesis",
Usage: "reset head to genesis",
},
&cli.Uint64Flag{
Name: "epoch",
Usage: "reset head to given epoch",
},
}),
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "genesis",
Usage: "reset head to genesis",
},
&cli.Uint64Flag{
Name: "epoch",
Usage: "reset head to given epoch",
},
},
Action: func(cctx *cli.Context) error {
ctx := lotuscli.ReqContext(cctx)
lapi, closer, err := GetAPI(ctx, clientAPIFlags.apiAddr, clientAPIFlags.apiToken)
lapi, closer, err := GetAPI(ctx)
if err != nil {
return err
}
Expand Down
36 changes: 18 additions & 18 deletions commands/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,31 @@ import (
"github.com/filecoin-project/lily/storage"
)

var clientAPIFlags struct {
apiAddr string
apiToken string
var ClientAPIFlags struct {
ApiAddr string
ApiToken string
}

var clientAPIFlag = &cli.StringFlag{
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{
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
var clientAPIFlagSet = []cli.Flag{
clientAPIFlag,
clientTokenFlag,
// ClientAPIFlagSet are used by commands that act as clients of a daemon's API
var ClientAPIFlagSet = []cli.Flag{
ClientAPIFlag,
ClientTokenFlag,
}

type daemonOpts struct {
Expand All @@ -82,7 +82,7 @@ than operating against an external blockstore but requires more disk space and
memory.
Before starting the daemon for the first time the blockstore must be initialized
and synchronized. Visor can use a copy of an already synchronized Lotus node
and synchronized. Lily can use a copy of an already synchronized Lotus node
repository or can initialize its own empty one and import a snapshot to catch
up to the chain.
Expand All @@ -109,7 +109,7 @@ Once the repository is initialized, start the daemon:
lily daemon --repo=<path> --config=<path>/config.toml
Visor will connect to the filecoin network and begin synchronizing with the
Lily will connect to the filecoin network and begin synchronizing with the
chain. To check the synchronization status use 'lily sync status' or
'lily sync wait'.
Expand All @@ -125,7 +125,7 @@ Note that jobs are not persisted between restarts of the daemon. See
`,

Flags: []cli.Flag{
clientAPIFlag,
ClientAPIFlag,
&cli.StringFlag{
Name: "repo",
Usage: "Specify path where lily should store chain state.",
Expand Down Expand Up @@ -168,15 +168,15 @@ Note that jobs are not persisted between restarts of the daemon. See
Action: func(c *cli.Context) error {
lotuslog.SetupLogLevels()

if err := setupLogging(VisorLogFlags); err != nil {
if err := setupLogging(LilyLogFlags); err != nil {
return xerrors.Errorf("setup logging: %w", err)
}

if err := setupMetrics(VisorMetricFlags); err != nil {
if err := setupMetrics(LilyMetricFlags); err != nil {
return xerrors.Errorf("setup metrics: %w", err)
}

if err := setupTracing(VisorTracingFlags); err != nil {
if err := setupTracing(LilyTracingFlags); err != nil {
return xerrors.Errorf("setup tracing: %w", err)
}

Expand Down Expand Up @@ -266,7 +266,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
Loading

0 comments on commit 2675a4d

Please sign in to comment.