-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lotus shed util to validate a tipset
- Loading branch information
Showing
6 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ func main() { | |
exportChainCmd, | ||
consensusCmd, | ||
serveDealStatsCmd, | ||
syncCmd, | ||
} | ||
|
||
app := &cli.App{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ipfs/go-cid" | ||
|
||
"github.com/filecoin-project/lotus/chain/types" | ||
lcli "github.com/filecoin-project/lotus/cli" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var syncCmd = &cli.Command{ | ||
Name: "sync", | ||
Usage: "tools for diagnosing sync issues", | ||
Flags: []cli.Flag{}, | ||
Subcommands: []*cli.Command{ | ||
syncValidateCmd, | ||
}, | ||
} | ||
|
||
var syncValidateCmd = &cli.Command{ | ||
Name: "validate", | ||
Usage: "checks whether a provided tipset is valid", | ||
Action: func(cctx *cli.Context) error { | ||
api, closer, err := lcli.GetFullNodeAPI(cctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer closer() | ||
ctx := lcli.ReqContext(cctx) | ||
|
||
if cctx.Args().Len() < 1 { | ||
fmt.Println("usage: <blockCid1> <blockCid2>...") | ||
fmt.Println("At least one block cid must be provided") | ||
return nil | ||
} | ||
|
||
args := cctx.Args().Slice() | ||
|
||
var tscids []cid.Cid | ||
for _, s := range args { | ||
c, err := cid.Decode(s) | ||
if err != nil { | ||
return fmt.Errorf("block cid was invalid: %s", err) | ||
} | ||
tscids = append(tscids, c) | ||
} | ||
|
||
tsk := types.NewTipSetKey(tscids...) | ||
|
||
valid, err := api.SyncValidateTipset(ctx, tsk) | ||
if err != nil { | ||
fmt.Println("Tipset is invalid: ", err) | ||
} | ||
|
||
if valid { | ||
fmt.Println("Tipset is valid") | ||
} | ||
|
||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters