Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): shift chainindex validate-backfill command #12668

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/clicommands/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var Commands = []*cli.Command{
lcli.WithCategory("developer", lcli.WaitApiCmd),
lcli.WithCategory("developer", lcli.FetchParamCmd),
lcli.WithCategory("developer", lcli.EvmCmd),
lcli.WithCategory("developer", lcli.IndexCmd),
lcli.WithCategory("network", lcli.NetCmd),
lcli.WithCategory("network", lcli.SyncCmd),
lcli.WithCategory("network", lcli.F3Cmd),
Expand Down
12 changes: 5 additions & 7 deletions cmd/lotus-shed/chain_index.go → cli/index.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cli

import (
"encoding/json"
Expand All @@ -10,12 +10,10 @@ import (
"golang.org/x/xerrors"

"github.com/filecoin-project/go-state-types/abi"

lcli "github.com/filecoin-project/lotus/cli"
)

var chainIndexCmds = &cli.Command{
Name: "chainindex",
var IndexCmd = &cli.Command{
Name: "index",
Usage: "Commands related to managing the chainindex",
Subcommands: []*cli.Command{
validateBackfillChainIndexCmd,
Expand Down Expand Up @@ -85,7 +83,7 @@ number of failed RPC calls. Otherwise, it will exit with a zero status.
},
},
Action: func(cctx *cli.Context) error {
srv, err := lcli.GetFullNodeServices(cctx)
srv, err := GetFullNodeServices(cctx)
if err != nil {
return xerrors.Errorf("failed to get full node services: %w", err)
}
Expand All @@ -96,7 +94,7 @@ number of failed RPC calls. Otherwise, it will exit with a zero status.
}()

api := srv.FullNodeAPI()
ctx := lcli.ReqContext(cctx)
ctx := ReqContext(cctx)

fromEpoch := cctx.Int("from")
if fromEpoch <= 0 {
Expand Down
1 change: 0 additions & 1 deletion cmd/lotus-shed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func main() {
invariantsCmd,
gasTraceCmd,
replayOfflineCmd,
chainIndexCmds,
FevmAnalyticsCmd,
mismatchesCmd,
blockCmd,
Expand Down
69 changes: 69 additions & 0 deletions documentation/en/cli-lotus.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ COMMANDS:
wait-api Wait for lotus api to come online
fetch-params Fetch proving parameters
evm Commands related to the Filecoin EVM runtime
index Commands related to managing the chainindex
NETWORK:
net Manage P2P Network
sync Inspect or interact with the chain syncer
Expand Down Expand Up @@ -2241,6 +2242,74 @@ OPTIONS:
--help, -h show help
```

## lotus index
```
NAME:
lotus index - Commands related to managing the chainindex

USAGE:
lotus index command [command options] [arguments...]

COMMANDS:
validate-backfill Validates and optionally backfills the chainindex for a range of epochs
help, h Shows a list of commands or help for one command

OPTIONS:
--help, -h show help
```

### lotus index validate-backfill
```
NAME:
lotus index validate-backfill - Validates and optionally backfills the chainindex for a range of epochs

USAGE:
lotus index validate-backfill [command options] [arguments...]

DESCRIPTION:

lotus-shed chainindex validate-backfill --from <start_epoch> --to <end_epoch> [--backfill] [--log-good] [--quiet]

The command validates the chain index entries for each epoch in the specified range, checking for missing or
inconsistent entries (i.e. the indexed data does not match the actual chain state). If '--backfill' is enabled
(which it is by default), it will attempt to backfill any missing entries using the 'ChainValidateIndex' API.

Error conditions:
- If 'from' or 'to' are invalid (<=0 or 'to' > 'from'), an error is returned.
- If the 'ChainValidateIndex' API returns an error for an epoch, indicating an inconsistency between the index
and chain state, an error message is logged for that epoch.

Logging:
- Progress is logged every 2880 epochs (1 day worth of epochs) processed during the validation process.
- If '--log-good' is enabled, details are also logged for each epoch that has no detected problems. This includes:
- Null rounds with no messages/events.
- Epochs with a valid indexed entry.
- If --quiet is enabled, only errors are logged, unless --log-good is also enabled, in which case good tipsets
are also logged.

Example usage:

To validate and backfill the chain index for the last 5760 epochs (2 days) and log details for all epochs:

lotus-shed chainindex validate-backfill --from 1000000 --to 994240 --log-good

This command is useful for backfilling the chain index over a range of historical epochs during the migration to
the new ChainIndexer. It can also be run periodically to validate the index's integrity using system schedulers
like cron.

If there are any errors during the validation process, the command will exit with a non-zero status and log the
number of failed RPC calls. Otherwise, it will exit with a zero status.


OPTIONS:
--from value from specifies the starting tipset epoch for validation (inclusive) (default: 0)
--to value to specifies the ending tipset epoch for validation (inclusive) (default: 0)
--backfill backfill determines whether to backfill missing index entries during validation (default: true) (default: true)
--log-good log tipsets that have no detected problems (default: false)
--quiet suppress output except for errors (or good tipsets if log-good is enabled) (default: false)
--help, -h show help
```

## lotus net
```
NAME:
Expand Down
Loading