Skip to content

Commit f0f5c76

Browse files
feat(cli): move chainindex cmd from lotus-shed to lotus (#12668)
1 parent a4a7cbe commit f0f5c76

File tree

4 files changed

+75
-8
lines changed

4 files changed

+75
-8
lines changed

cli/clicommands/cmd.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var Commands = []*cli.Command{
2121
lcli.WithCategory("developer", lcli.WaitApiCmd),
2222
lcli.WithCategory("developer", lcli.FetchParamCmd),
2323
lcli.WithCategory("developer", lcli.EvmCmd),
24+
lcli.WithCategory("developer", lcli.IndexCmd),
2425
lcli.WithCategory("network", lcli.NetCmd),
2526
lcli.WithCategory("network", lcli.SyncCmd),
2627
lcli.WithCategory("network", lcli.F3Cmd),

cmd/lotus-shed/chain_index.go cli/index.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cli
22

33
import (
44
"encoding/json"
@@ -10,12 +10,10 @@ import (
1010
"golang.org/x/xerrors"
1111

1212
"github.com/filecoin-project/go-state-types/abi"
13-
14-
lcli "github.com/filecoin-project/lotus/cli"
1513
)
1614

17-
var chainIndexCmds = &cli.Command{
18-
Name: "chainindex",
15+
var IndexCmd = &cli.Command{
16+
Name: "index",
1917
Usage: "Commands related to managing the chainindex",
2018
Subcommands: []*cli.Command{
2119
validateBackfillChainIndexCmd,
@@ -85,7 +83,7 @@ number of failed RPC calls. Otherwise, it will exit with a zero status.
8583
},
8684
},
8785
Action: func(cctx *cli.Context) error {
88-
srv, err := lcli.GetFullNodeServices(cctx)
86+
srv, err := GetFullNodeServices(cctx)
8987
if err != nil {
9088
return xerrors.Errorf("failed to get full node services: %w", err)
9189
}
@@ -96,7 +94,7 @@ number of failed RPC calls. Otherwise, it will exit with a zero status.
9694
}()
9795

9896
api := srv.FullNodeAPI()
99-
ctx := lcli.ReqContext(cctx)
97+
ctx := ReqContext(cctx)
10098

10199
fromEpoch := cctx.Int("from")
102100
if fromEpoch <= 0 {

cmd/lotus-shed/main.go

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ func main() {
8686
invariantsCmd,
8787
gasTraceCmd,
8888
replayOfflineCmd,
89-
chainIndexCmds,
9089
FevmAnalyticsCmd,
9190
mismatchesCmd,
9291
blockCmd,

documentation/en/cli-lotus.md

+69
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ COMMANDS:
3131
wait-api Wait for lotus api to come online
3232
fetch-params Fetch proving parameters
3333
evm Commands related to the Filecoin EVM runtime
34+
index Commands related to managing the chainindex
3435
NETWORK:
3536
net Manage P2P Network
3637
sync Inspect or interact with the chain syncer
@@ -2241,6 +2242,74 @@ OPTIONS:
22412242
--help, -h show help
22422243
```
22432244

2245+
## lotus index
2246+
```
2247+
NAME:
2248+
lotus index - Commands related to managing the chainindex
2249+
2250+
USAGE:
2251+
lotus index command [command options] [arguments...]
2252+
2253+
COMMANDS:
2254+
validate-backfill Validates and optionally backfills the chainindex for a range of epochs
2255+
help, h Shows a list of commands or help for one command
2256+
2257+
OPTIONS:
2258+
--help, -h show help
2259+
```
2260+
2261+
### lotus index validate-backfill
2262+
```
2263+
NAME:
2264+
lotus index validate-backfill - Validates and optionally backfills the chainindex for a range of epochs
2265+
2266+
USAGE:
2267+
lotus index validate-backfill [command options] [arguments...]
2268+
2269+
DESCRIPTION:
2270+
2271+
lotus-shed chainindex validate-backfill --from <start_epoch> --to <end_epoch> [--backfill] [--log-good] [--quiet]
2272+
2273+
The command validates the chain index entries for each epoch in the specified range, checking for missing or
2274+
inconsistent entries (i.e. the indexed data does not match the actual chain state). If '--backfill' is enabled
2275+
(which it is by default), it will attempt to backfill any missing entries using the 'ChainValidateIndex' API.
2276+
2277+
Error conditions:
2278+
- If 'from' or 'to' are invalid (<=0 or 'to' > 'from'), an error is returned.
2279+
- If the 'ChainValidateIndex' API returns an error for an epoch, indicating an inconsistency between the index
2280+
and chain state, an error message is logged for that epoch.
2281+
2282+
Logging:
2283+
- Progress is logged every 2880 epochs (1 day worth of epochs) processed during the validation process.
2284+
- If '--log-good' is enabled, details are also logged for each epoch that has no detected problems. This includes:
2285+
- Null rounds with no messages/events.
2286+
- Epochs with a valid indexed entry.
2287+
- If --quiet is enabled, only errors are logged, unless --log-good is also enabled, in which case good tipsets
2288+
are also logged.
2289+
2290+
Example usage:
2291+
2292+
To validate and backfill the chain index for the last 5760 epochs (2 days) and log details for all epochs:
2293+
2294+
lotus-shed chainindex validate-backfill --from 1000000 --to 994240 --log-good
2295+
2296+
This command is useful for backfilling the chain index over a range of historical epochs during the migration to
2297+
the new ChainIndexer. It can also be run periodically to validate the index's integrity using system schedulers
2298+
like cron.
2299+
2300+
If there are any errors during the validation process, the command will exit with a non-zero status and log the
2301+
number of failed RPC calls. Otherwise, it will exit with a zero status.
2302+
2303+
2304+
OPTIONS:
2305+
--from value from specifies the starting tipset epoch for validation (inclusive) (default: 0)
2306+
--to value to specifies the ending tipset epoch for validation (inclusive) (default: 0)
2307+
--backfill backfill determines whether to backfill missing index entries during validation (default: true) (default: true)
2308+
--log-good log tipsets that have no detected problems (default: false)
2309+
--quiet suppress output except for errors (or good tipsets if log-good is enabled) (default: false)
2310+
--help, -h show help
2311+
```
2312+
22442313
## lotus net
22452314
```
22462315
NAME:

0 commit comments

Comments
 (0)