Skip to content

Commit 1db1b6f

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-miners` to list the current F3 participants. * `status` to print summary status of F3. Part of #12607
1 parent 89b0941 commit 1db1b6f

File tree

4 files changed

+238
-0
lines changed

4 files changed

+238
-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

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

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)