Merge pull request #8911 from filecoin-project/asr/manifest-cid-check

feat: shed: print out actor code CIDs in manifest cid checker
This commit is contained in:
Aayush Rajasekaran 2022-06-23 16:57:48 -04:00 committed by GitHub
commit 2f2760290a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,8 +5,10 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"os" "os"
"text/tabwriter"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/ipld/go-car" "github.com/ipld/go-car"
mh "github.com/multiformats/go-multihash" mh "github.com/multiformats/go-multihash"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -15,6 +17,8 @@ import (
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/blockstore"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"
) )
var cidCmd = &cli.Command{ var cidCmd = &cli.Command{
@ -22,7 +26,7 @@ var cidCmd = &cli.Command{
Usage: "Cid command", Usage: "Cid command",
Subcommands: cli.Commands{ Subcommands: cli.Commands{
cidIdCmd, cidIdCmd,
cidFromCarCmd, inspectBundleCmd,
}, },
} }
@ -90,9 +94,9 @@ var cidIdCmd = &cli.Command{
}, },
} }
var cidFromCarCmd = &cli.Command{ var inspectBundleCmd = &cli.Command{
Name: "manifest-cid-from-car", Name: "inspect-bundle",
Usage: "Get the manifest CID from a car file", Usage: "Get the manifest CID from a car file, as well as the actor code CIDs",
ArgsUsage: "[path]", ArgsUsage: "[path]",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
ctx := cctx.Context ctx := cctx.Context
@ -104,6 +108,7 @@ var cidFromCarCmd = &cli.Command{
} }
bs := blockstore.NewMemory() bs := blockstore.NewMemory()
wrapBs := adt.WrapStore(ctx, cbor.NewCborStore(bs))
hdr, err := car.LoadCar(ctx, bs, f) hdr, err := car.LoadCar(ctx, bs, f)
if err != nil { if err != nil {
@ -114,6 +119,19 @@ var cidFromCarCmd = &cli.Command{
fmt.Printf("Manifest CID: %s\n", manifestCid.String()) fmt.Printf("Manifest CID: %s\n", manifestCid.String())
return nil entries, err := actors.ReadManifest(ctx, wrapBs, manifestCid)
if err != nil {
return xerrors.Errorf("error loading manifest: %w", err)
}
tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
_, _ = fmt.Fprintln(tw, "\nActor\tCID\t")
for name, cid := range entries {
_, _ = fmt.Fprintf(tw, "%v\t%v\n", name, cid)
}
return tw.Flush()
}, },
} }