Skip to content

Commit

Permalink
Implement Lotus F3 CLI commands for general diagnostics
Browse files Browse the repository at this point in the history
Implement `lotus f3` CLI sub commands:

* `manifest` to dump the current F3 manifest in either JSON or text.
* `list-participants` to list the current F3 participants.
* `status` to print summary status of F3.

Part of #12607
  • Loading branch information
masih committed Oct 18, 2024
1 parent 7c0c493 commit dad14c3
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `lotus chain head` now supports a `--height` flag to print just the epoch number of the current chain head ([filecoin-project/lotus#12609](https://github.com/filecoin-project/lotus/pull/12609))
- `lotus-shed indexes inspect-indexes` now performs a comprehensive comparison of the event index data for each message by comparing the AMT root CID from the message receipt with the root of a reconstructed AMT. Previously `inspect-indexes` simply compared event counts, comparing AMT roots confirms all the event data is byte-perfect. ([filecoin-project/lotus#12570](https://github.com/filecoin-project/lotus/pull/12570))
- Expose APIs to list the miner IDs that are currently participating in F3 via node. ([filecoin-project/lotus#12608](https://github.com/filecoin-project/lotus/pull/12608))
- Implement new `lotus f3` CLI commands to list F3 participants, dump manifest and check the F3 status. ([filecoin-project/lotus#12617](https://github.com/filecoin-project/lotus/pull/12617))

## Bug Fixes
- Fix a bug in the `lotus-shed indexes backfill-events` command that may result in either duplicate events being backfilled where there are existing events (such an operation *should* be idempotent) or events erroneously having duplicate `logIndex` values when queried via ETH APIs. ([filecoin-project/lotus#12567](https://github.com/filecoin-project/lotus/pull/12567))
Expand Down
1 change: 1 addition & 0 deletions cli/clicommands/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var Commands = []*cli.Command{
lcli.WithCategory("developer", lcli.EvmCmd),
lcli.WithCategory("network", lcli.NetCmd),
lcli.WithCategory("network", lcli.SyncCmd),
lcli.WithCategory("network", lcli.F3Cmd),
lcli.WithCategory("status", lcli.StatusCmd),
lcli.PprofCmd,
lcli.VersionCmd,
Expand Down
168 changes: 168 additions & 0 deletions cli/f3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package cli

import (
"encoding/json"
"fmt"
"io"
"strings"

"github.com/urfave/cli/v2"

"github.com/filecoin-project/go-f3/manifest"
)

var (
F3Cmd = &cli.Command{
Name: "f3",
Usage: "Manages Filecoin Fast Finality (F3) interactions",
Subcommands: []*cli.Command{
{
Name: "list-participants",
Aliases: []string{"lp"},
Usage: "Lists the miners that currently participate in F3 via this node.",
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPIV1(cctx)
if err != nil {
return err
}
defer closer()

participants, err := api.F3ListParticipants(cctx.Context)
if err != nil {
return cli.Exit(fmt.Errorf("listing participants: %w", err), 1)
}
if len(participants) == 0 {
_, _ = fmt.Fprintln(cctx.App.Writer, "No participants.")
return nil
}
for i, participant := range participants {
_, _ = fmt.Fprintf(cctx.App.Writer, "Participant %d:\n", i+1)
_, _ = fmt.Fprintf(cctx.App.Writer, " Miner ID: %d\n", participant.MinerID)
_, _ = fmt.Fprintf(cctx.App.Writer, " From Instance: %d\n", participant.FromInstance)
_, _ = fmt.Fprintf(cctx.App.Writer, " Validity Term: %d\n", participant.ValidityTerm)
_, _ = fmt.Fprintf(cctx.App.Writer, "\n")
}
_, _ = fmt.Fprintf(cctx.App.Writer, "Total of %d participant(s).\n", len(participants))
return nil
},
},
{
Name: "manifest",
Usage: "Gets the current manifest used by F3.",
Flags: []cli.Flag{f3FlagOutput},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPIV1(cctx)
if err != nil {
return err
}
defer closer()

manifest, err := api.F3GetManifest(cctx.Context)
if err != nil {
return cli.Exit(fmt.Errorf("getting manifest: %w", err), 1)
}
switch output := cctx.String("output"); strings.ToLower(output) {
case "text":
prettyPrintManifest(cctx.App.Writer, manifest)
return nil
case "json":
encoder := json.NewEncoder(cctx.App.Writer)
encoder.SetIndent("", " ")
return encoder.Encode(manifest)
default:
return fmt.Errorf("unknown output format: %s", output)
}
},
},
{
Name: "status",
Usage: "Checks the F3 status.",
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPIV1(cctx)
if err != nil {
return err
}
defer closer()

running, err := api.F3IsRunning(cctx.Context)
if err != nil {
return cli.Exit(fmt.Errorf("getting running state: %w", err), 1)
}
_, _ = fmt.Fprintf(cctx.App.Writer, "Running: %t\n", running)
if !running {
return nil
}

progress, err := api.F3GetProgress(cctx.Context)
if err != nil {
return cli.Exit(fmt.Errorf("getting progress: %w", err), 1)
}

_, _ = fmt.Fprintln(cctx.App.Writer, "Progress:")
_, _ = fmt.Fprintf(cctx.App.Writer, " Instance: %d\n", progress.ID)
_, _ = fmt.Fprintf(cctx.App.Writer, " Round: %d\n", progress.Round)
_, _ = fmt.Fprintf(cctx.App.Writer, " Phase: %s\n", progress.Phase)

manifest, err := api.F3GetManifest(cctx.Context)
if err != nil {
return cli.Exit(fmt.Errorf("getting manifest: %w", err), 1)
}
prettyPrintManifest(cctx.App.Writer, manifest)
return nil
},
},
},
}

// TODO: we should standardise format as a top level flag. For now, here is an f3
// specific one.
// See: https://github.com/filecoin-project/lotus/issues/12616
f3FlagOutput = &cli.StringFlag{
Name: "output",
Usage: "The output format. Supported formats: text, json",
Value: "text",
Action: func(cctx *cli.Context, output string) error {
switch output {
case "text", "json":
return nil
default:
return fmt.Errorf("unknown output format: %s", output)
}
},
}
)

func prettyPrintManifest(out io.Writer, manifest *manifest.Manifest) {
_, _ = fmt.Fprintf(out, "Manifest: ")
if manifest == nil {
_, _ = fmt.Fprintln(out, "None")
return
}
_, _ = fmt.Fprintln(out)
_, _ = fmt.Fprintf(out, " Protocol Version: %d\n", manifest.ProtocolVersion)
_, _ = fmt.Fprintf(out, " Paused: %t\n", manifest.Pause)
_, _ = fmt.Fprintf(out, " Initial Instance: %d\n", manifest.InitialInstance)
_, _ = fmt.Fprintf(out, " Bootstrap Epoch: %d\n", manifest.BootstrapEpoch)
_, _ = fmt.Fprintf(out, " Network Name: %s\n", manifest.NetworkName)
_, _ = fmt.Fprintf(out, " Ignore EC Power: %t\n", manifest.IgnoreECPower)
_, _ = fmt.Fprintf(out, " Committee Lookback: %d\n", manifest.CommitteeLookback)
_, _ = fmt.Fprintf(out, " Catch Up Alignment: %s\n", manifest.CatchUpAlignment)

_, _ = fmt.Fprintf(out, " GPBFT Delta: %s\n", manifest.Gpbft.Delta)
_, _ = fmt.Fprintf(out, " GPBFT Delta BackOff Exponent: %.2f\n", manifest.Gpbft.DeltaBackOffExponent)
_, _ = fmt.Fprintf(out, " GPBFT Max Lookahead Rounds: %d\n", manifest.Gpbft.MaxLookaheadRounds)
_, _ = fmt.Fprintf(out, " GPBFT Rebroadcast Backoff Base: %s\n", manifest.Gpbft.RebroadcastBackoffBase)
_, _ = fmt.Fprintf(out, " GPBFT Rebroadcast Backoff Spread:%.2f\n", manifest.Gpbft.RebroadcastBackoffSpread)
_, _ = fmt.Fprintf(out, " GPBFT Rebroadcast Backoff Max: %s\n", manifest.Gpbft.RebroadcastBackoffMax)

_, _ = fmt.Fprintf(out, " EC Period: %s\n", manifest.EC.Period)
_, _ = fmt.Fprintf(out, " EC Finality: %d\n", manifest.EC.Finality)
_, _ = fmt.Fprintf(out, " EC Delay Multiplier: %.2f\n", manifest.EC.DelayMultiplier)
_, _ = fmt.Fprintf(out, " EC Head Lookback: %d\n", manifest.EC.HeadLookback)
_, _ = fmt.Fprintf(out, " EC Finalize: %t\n", manifest.EC.Finalize)

_, _ = fmt.Fprintf(out, " Certificate Exchange Client Timeout: %s\n", manifest.CertificateExchange.ClientRequestTimeout)
_, _ = fmt.Fprintf(out, " Certificate Exchange Server Timeout: %s\n", manifest.CertificateExchange.ServerRequestTimeout)
_, _ = fmt.Fprintf(out, " Certificate Exchange Min Poll Interval: %s\n", manifest.CertificateExchange.MinimumPollInterval)
_, _ = fmt.Fprintf(out, " Certificate Exchange Max Poll Interval: %s\n", manifest.CertificateExchange.MaximumPollInterval)
}
56 changes: 56 additions & 0 deletions documentation/en/cli-lotus.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ COMMANDS:
NETWORK:
net Manage P2P Network
sync Inspect or interact with the chain syncer
f3 Manages Filecoin Fast Finality (F3) interactions
STATUS:
status Check node status
Expand Down Expand Up @@ -2719,6 +2720,61 @@ OPTIONS:
--help, -h show help
```

## lotus f3
```
NAME:
lotus f3 - Manages Filecoin Fast Finality (F3) interactions
USAGE:
lotus f3 command [command options] [arguments...]
COMMANDS:
list-participants, lp Lists the miners that currently participate in F3 via this node.
manifest Gets the current manifest used by F3.
status Checks the F3 status.
help, h Shows a list of commands or help for one command
OPTIONS:
--help, -h show help
```

### lotus f3 list-participants
```
NAME:
lotus f3 list-participants - Lists the miners that currently participate in F3 via this node.
USAGE:
lotus f3 list-participants [command options] [arguments...]
OPTIONS:
--help, -h show help
```

### lotus f3 manifest
```
NAME:
lotus f3 manifest - Gets the current manifest used by F3.
USAGE:
lotus f3 manifest [command options] [arguments...]
OPTIONS:
--output value The output format. Supported formats: text, json (default: "text")
--help, -h show help
```

### lotus f3 status
```
NAME:
lotus f3 status - Checks the F3 status.
USAGE:
lotus f3 status [command options] [arguments...]
OPTIONS:
--help, -h show help
```

## lotus status
```
NAME:
Expand Down

0 comments on commit dad14c3

Please sign in to comment.