expose bad block cache reasons through api/cli

This commit is contained in:
whyrusleeping
2020-02-11 23:44:55 -08:00
parent 0661a1bbfc
commit 243b295559
5 changed files with 55 additions and 0 deletions
+36
View File
@@ -20,6 +20,7 @@ var syncCmd = &cli.Command{
syncStatusCmd,
syncWaitCmd,
syncMarkBadCmd,
syncCheckBadCmd,
},
}
@@ -115,6 +116,41 @@ var syncMarkBadCmd = &cli.Command{
},
}
var syncCheckBadCmd = &cli.Command{
Name: "check-bad",
Usage: "check if the given block was marked bad, and for what reason",
Action: func(cctx *cli.Context) error {
napi, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must specify block cid to check")
}
bcid, err := cid.Decode(cctx.Args().First())
if err != nil {
return fmt.Errorf("failed to decode input as a cid: %s", err)
}
reason, err := napi.SyncCheckBad(ctx, bcid)
if err != nil {
return err
}
if reason == "" {
fmt.Println("block was not marked as bad")
return nil
}
fmt.Println(reason)
return nil
},
}
func SyncWait(ctx context.Context, napi api.FullNode) error {
for {
state, err := napi.SyncState(ctx)