Skip to content

Commit dad14c3

Browse files
committed
Implement Lotus F3 CLI commands for general diagnostics
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
1 parent 7c0c493 commit dad14c3

File tree

4 files changed

+226
-0
lines changed

4 files changed

+226
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- `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))
1111
- `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))
1212
- 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))
13+
- 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))
1314

1415
## Bug Fixes
1516
- 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))

cli/clicommands/cmd.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var Commands = []*cli.Command{
2323
lcli.WithCategory("developer", lcli.EvmCmd),
2424
lcli.WithCategory("network", lcli.NetCmd),
2525
lcli.WithCategory("network", lcli.SyncCmd),
26+
lcli.WithCategory("network", lcli.F3Cmd),
2627
lcli.WithCategory("status", lcli.StatusCmd),
2728
lcli.PprofCmd,
2829
lcli.VersionCmd,

cli/f3.go

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
package cli
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io"
7+
"strings"
8+
9+
"github.com/urfave/cli/v2"
10+
11+
"github.com/filecoin-project/go-f3/manifest"
12+
)
13+
14+
var (
15+
F3Cmd = &cli.Command{
16+
Name: "f3",
17+
Usage: "Manages Filecoin Fast Finality (F3) interactions",
18+
Subcommands: []*cli.Command{
19+
{
20+
Name: "list-participants",
21+
Aliases: []string{"lp"},
22+
Usage: "Lists the miners that currently participate in F3 via this node.",
23+
Action: func(cctx *cli.Context) error {
24+
api, closer, err := GetFullNodeAPIV1(cctx)
25+
if err != nil {
26+
return err
27+
}
28+
defer closer()
29+
30+
participants, err := api.F3ListParticipants(cctx.Context)
31+
if err != nil {
32+
return cli.Exit(fmt.Errorf("listing participants: %w", err), 1)
33+
}
34+
if len(participants) == 0 {
35+
_, _ = fmt.Fprintln(cctx.App.Writer, "No participants.")
36+
return nil
37+
}
38+
for i, participant := range participants {
39+
_, _ = fmt.Fprintf(cctx.App.Writer, "Participant %d:\n", i+1)
40+
_, _ = fmt.Fprintf(cctx.App.Writer, " Miner ID: %d\n", participant.MinerID)
41+
_, _ = fmt.Fprintf(cctx.App.Writer, " From Instance: %d\n", participant.FromInstance)
42+
_, _ = fmt.Fprintf(cctx.App.Writer, " Validity Term: %d\n", participant.ValidityTerm)
43+
_, _ = fmt.Fprintf(cctx.App.Writer, "\n")
44+
}
45+
_, _ = fmt.Fprintf(cctx.App.Writer, "Total of %d participant(s).\n", len(participants))
46+
return nil
47+
},
48+
},
49+
{
50+
Name: "manifest",
51+
Usage: "Gets the current manifest used by F3.",
52+
Flags: []cli.Flag{f3FlagOutput},
53+
Action: func(cctx *cli.Context) error {
54+
api, closer, err := GetFullNodeAPIV1(cctx)
55+
if err != nil {
56+
return err
57+
}
58+
defer closer()
59+
60+
manifest, err := api.F3GetManifest(cctx.Context)
61+
if err != nil {
62+
return cli.Exit(fmt.Errorf("getting manifest: %w", err), 1)
63+
}
64+
switch output := cctx.String("output"); strings.ToLower(output) {
65+
case "text":
66+
prettyPrintManifest(cctx.App.Writer, manifest)
67+
return nil
68+
case "json":
69+
encoder := json.NewEncoder(cctx.App.Writer)
70+
encoder.SetIndent("", " ")
71+
return encoder.Encode(manifest)
72+
default:
73+
return fmt.Errorf("unknown output format: %s", output)
74+
}
75+
},
76+
},
77+
{
78+
Name: "status",
79+
Usage: "Checks the F3 status.",
80+
Action: func(cctx *cli.Context) error {
81+
api, closer, err := GetFullNodeAPIV1(cctx)
82+
if err != nil {
83+
return err
84+
}
85+
defer closer()
86+
87+
running, err := api.F3IsRunning(cctx.Context)
88+
if err != nil {
89+
return cli.Exit(fmt.Errorf("getting running state: %w", err), 1)
90+
}
91+
_, _ = fmt.Fprintf(cctx.App.Writer, "Running: %t\n", running)
92+
if !running {
93+
return nil
94+
}
95+
96+
progress, err := api.F3GetProgress(cctx.Context)
97+
if err != nil {
98+
return cli.Exit(fmt.Errorf("getting progress: %w", err), 1)
99+
}
100+
101+
_, _ = fmt.Fprintln(cctx.App.Writer, "Progress:")
102+
_, _ = fmt.Fprintf(cctx.App.Writer, " Instance: %d\n", progress.ID)
103+
_, _ = fmt.Fprintf(cctx.App.Writer, " Round: %d\n", progress.Round)
104+
_, _ = fmt.Fprintf(cctx.App.Writer, " Phase: %s\n", progress.Phase)
105+
106+
manifest, err := api.F3GetManifest(cctx.Context)
107+
if err != nil {
108+
return cli.Exit(fmt.Errorf("getting manifest: %w", err), 1)
109+
}
110+
prettyPrintManifest(cctx.App.Writer, manifest)
111+
return nil
112+
},
113+
},
114+
},
115+
}
116+
117+
// TODO: we should standardise format as a top level flag. For now, here is an f3
118+
// specific one.
119+
// See: https://github.com/filecoin-project/lotus/issues/12616
120+
f3FlagOutput = &cli.StringFlag{
121+
Name: "output",
122+
Usage: "The output format. Supported formats: text, json",
123+
Value: "text",
124+
Action: func(cctx *cli.Context, output string) error {
125+
switch output {
126+
case "text", "json":
127+
return nil
128+
default:
129+
return fmt.Errorf("unknown output format: %s", output)
130+
}
131+
},
132+
}
133+
)
134+
135+
func prettyPrintManifest(out io.Writer, manifest *manifest.Manifest) {
136+
_, _ = fmt.Fprintf(out, "Manifest: ")
137+
if manifest == nil {
138+
_, _ = fmt.Fprintln(out, "None")
139+
return
140+
}
141+
_, _ = fmt.Fprintln(out)
142+
_, _ = fmt.Fprintf(out, " Protocol Version: %d\n", manifest.ProtocolVersion)
143+
_, _ = fmt.Fprintf(out, " Paused: %t\n", manifest.Pause)
144+
_, _ = fmt.Fprintf(out, " Initial Instance: %d\n", manifest.InitialInstance)
145+
_, _ = fmt.Fprintf(out, " Bootstrap Epoch: %d\n", manifest.BootstrapEpoch)
146+
_, _ = fmt.Fprintf(out, " Network Name: %s\n", manifest.NetworkName)
147+
_, _ = fmt.Fprintf(out, " Ignore EC Power: %t\n", manifest.IgnoreECPower)
148+
_, _ = fmt.Fprintf(out, " Committee Lookback: %d\n", manifest.CommitteeLookback)
149+
_, _ = fmt.Fprintf(out, " Catch Up Alignment: %s\n", manifest.CatchUpAlignment)
150+
151+
_, _ = fmt.Fprintf(out, " GPBFT Delta: %s\n", manifest.Gpbft.Delta)
152+
_, _ = fmt.Fprintf(out, " GPBFT Delta BackOff Exponent: %.2f\n", manifest.Gpbft.DeltaBackOffExponent)
153+
_, _ = fmt.Fprintf(out, " GPBFT Max Lookahead Rounds: %d\n", manifest.Gpbft.MaxLookaheadRounds)
154+
_, _ = fmt.Fprintf(out, " GPBFT Rebroadcast Backoff Base: %s\n", manifest.Gpbft.RebroadcastBackoffBase)
155+
_, _ = fmt.Fprintf(out, " GPBFT Rebroadcast Backoff Spread:%.2f\n", manifest.Gpbft.RebroadcastBackoffSpread)
156+
_, _ = fmt.Fprintf(out, " GPBFT Rebroadcast Backoff Max: %s\n", manifest.Gpbft.RebroadcastBackoffMax)
157+
158+
_, _ = fmt.Fprintf(out, " EC Period: %s\n", manifest.EC.Period)
159+
_, _ = fmt.Fprintf(out, " EC Finality: %d\n", manifest.EC.Finality)
160+
_, _ = fmt.Fprintf(out, " EC Delay Multiplier: %.2f\n", manifest.EC.DelayMultiplier)
161+
_, _ = fmt.Fprintf(out, " EC Head Lookback: %d\n", manifest.EC.HeadLookback)
162+
_, _ = fmt.Fprintf(out, " EC Finalize: %t\n", manifest.EC.Finalize)
163+
164+
_, _ = fmt.Fprintf(out, " Certificate Exchange Client Timeout: %s\n", manifest.CertificateExchange.ClientRequestTimeout)
165+
_, _ = fmt.Fprintf(out, " Certificate Exchange Server Timeout: %s\n", manifest.CertificateExchange.ServerRequestTimeout)
166+
_, _ = fmt.Fprintf(out, " Certificate Exchange Min Poll Interval: %s\n", manifest.CertificateExchange.MinimumPollInterval)
167+
_, _ = fmt.Fprintf(out, " Certificate Exchange Max Poll Interval: %s\n", manifest.CertificateExchange.MaximumPollInterval)
168+
}

documentation/en/cli-lotus.md

+56
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ COMMANDS:
3434
NETWORK:
3535
net Manage P2P Network
3636
sync Inspect or interact with the chain syncer
37+
f3 Manages Filecoin Fast Finality (F3) interactions
3738
STATUS:
3839
status Check node status
3940
@@ -2719,6 +2720,61 @@ OPTIONS:
27192720
--help, -h show help
27202721
```
27212722

2723+
## lotus f3
2724+
```
2725+
NAME:
2726+
lotus f3 - Manages Filecoin Fast Finality (F3) interactions
2727+
2728+
USAGE:
2729+
lotus f3 command [command options] [arguments...]
2730+
2731+
COMMANDS:
2732+
list-participants, lp Lists the miners that currently participate in F3 via this node.
2733+
manifest Gets the current manifest used by F3.
2734+
status Checks the F3 status.
2735+
help, h Shows a list of commands or help for one command
2736+
2737+
OPTIONS:
2738+
--help, -h show help
2739+
```
2740+
2741+
### lotus f3 list-participants
2742+
```
2743+
NAME:
2744+
lotus f3 list-participants - Lists the miners that currently participate in F3 via this node.
2745+
2746+
USAGE:
2747+
lotus f3 list-participants [command options] [arguments...]
2748+
2749+
OPTIONS:
2750+
--help, -h show help
2751+
```
2752+
2753+
### lotus f3 manifest
2754+
```
2755+
NAME:
2756+
lotus f3 manifest - Gets the current manifest used by F3.
2757+
2758+
USAGE:
2759+
lotus f3 manifest [command options] [arguments...]
2760+
2761+
OPTIONS:
2762+
--output value The output format. Supported formats: text, json (default: "text")
2763+
--help, -h show help
2764+
```
2765+
2766+
### lotus f3 status
2767+
```
2768+
NAME:
2769+
lotus f3 status - Checks the F3 status.
2770+
2771+
USAGE:
2772+
lotus f3 status [command options] [arguments...]
2773+
2774+
OPTIONS:
2775+
--help, -h show help
2776+
```
2777+
27222778
## lotus status
27232779
```
27242780
NAME:

0 commit comments

Comments
 (0)