From 2c1cf42aa05f1ec501a8bde20b643c648c11489b Mon Sep 17 00:00:00 2001 From: Jennifer Wang Date: Wed, 18 May 2022 01:52:32 -0400 Subject: [PATCH] add cli to get the actor cid forthe current network version --- build/params_2k.go | 2 +- cli/state.go | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/build/params_2k.go b/build/params_2k.go index 26afdbabe..b37bf3f9a 100644 --- a/build/params_2k.go +++ b/build/params_2k.go @@ -20,7 +20,7 @@ const GenesisFile = "" var NetworkBundle = "devnet" -const GenesisNetworkVersion = network.Version15 +const GenesisNetworkVersion = network.Version16 var UpgradeBreezeHeight = abi.ChainEpoch(-1) diff --git a/cli/state.go b/cli/state.go index 18d9a12bd..d9df7bce3 100644 --- a/cli/state.go +++ b/cli/state.go @@ -15,8 +15,13 @@ import ( "sort" "strconv" "strings" + "text/tabwriter" "time" + "github.com/filecoin-project/go-state-types/network" + + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/consensus/filcns" @@ -79,6 +84,7 @@ var StateCmd = &cli.Command{ StateExecTraceCmd, StateNtwkVersionCmd, StateMinerProvingDeadlineCmd, + StateSysActorCIDsCmd, }, } @@ -1872,3 +1878,82 @@ var StateNtwkVersionCmd = &cli.Command{ return nil }, } + +var StateSysActorCIDsCmd = &cli.Command{ + Name: "actor-cids", + Usage: "Returns the built-in actor bundle manifest ID & system actor cids", + Flags: []cli.Flag{ + &cli.UintFlag{ + Name: "network-version", + Usage: "specify network version", + Value: uint(build.NewestNetworkVersion), + }, + }, + Action: func(cctx *cli.Context) error { + if cctx.Args().Present() { + return ShowHelp(cctx, fmt.Errorf("doesn't expect any arguments")) + } + + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + + ctx := ReqContext(cctx) + + ts, err := LoadTipSet(ctx, cctx, api) + if err != nil { + return err + } + + nv, err := api.StateNetworkVersion(ctx, ts.Key()) + if err != nil { + return err + } + + if cctx.IsSet("network-version") { + nv = network.Version(cctx.Uint64("network-version")) + } + + fmt.Printf("Network Version: %d\n", nv) + + actorVersion, err := actors.VersionForNetwork(nv) + if err != nil { + return err + } + fmt.Printf("Actor Version: %d\n", actorVersion) + + manifestCid, ok := actors.GetManifest(actorVersion) + if !ok { + return xerrors.Errorf("cannot get manifest CID") + } + fmt.Printf("Manifest CID: %v\n", manifestCid) + + tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) + _, _ = fmt.Fprintln(tw, "\nActor\tCID\t") + + for _, name := range []string{ + actors.AccountKey, + actors.CronKey, + actors.InitKey, + actors.MarketKey, + actors.MinerKey, + actors.MultisigKey, + actors.PaychKey, + actors.PowerKey, + actors.RewardKey, + actors.SystemKey, + actors.VerifregKey, + } { + sysActorCID, ok := actors.GetActorCodeID(actorVersion, name) + if !ok { + return xerrors.Errorf("error getting actor %v code id for actor version %d", name, + actorVersion) + } + _, _ = fmt.Fprintf(tw, "%v\t%v\n", name, sysActorCID) + + } + return tw.Flush() + }, +}