Merge pull request #8120 from filecoin-project/travis/set-current-network-version

feat: cli: set current network version from params
This commit is contained in:
Aayush Rajasekaran 2022-02-16 19:28:59 -05:00 committed by GitHub
commit 4767f3d87e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -508,12 +508,19 @@ var genesisSetRemainderCmd = &cli.Command{
} }
var genesisSetActorVersionCmd = &cli.Command{ var genesisSetActorVersionCmd = &cli.Command{
Name: "set-network-version", Name: "set-network-version",
Usage: "Set the version that this network will start from", Usage: "Set the version that this network will start from",
ArgsUsage: "<genesisFile> <actorVersion>", Flags: []cli.Flag{
&cli.IntFlag{
Name: "network-version",
Usage: "network version to start genesis with",
Value: int(build.GenesisNetworkVersion),
},
},
ArgsUsage: "<genesisFile>",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
if cctx.Args().Len() != 2 { if cctx.Args().Len() != 1 {
return fmt.Errorf("must specify genesis file and network version (e.g. '0'") return fmt.Errorf("must specify genesis file")
} }
genf, err := homedir.Expand(cctx.Args().First()) genf, err := homedir.Expand(cctx.Args().First())
@ -531,16 +538,12 @@ var genesisSetActorVersionCmd = &cli.Command{
return xerrors.Errorf("unmarshal genesis template: %w", err) return xerrors.Errorf("unmarshal genesis template: %w", err)
} }
nv, err := strconv.ParseUint(cctx.Args().Get(1), 10, 64) nv := network.Version(cctx.Int("network-version"))
if err != nil { if nv > build.NewestNetworkVersion {
return xerrors.Errorf("parsing network version: %w", err)
}
if nv > uint64(build.NewestNetworkVersion) {
return xerrors.Errorf("invalid network version: %d", nv) return xerrors.Errorf("invalid network version: %d", nv)
} }
template.NetworkVersion = network.Version(nv) template.NetworkVersion = nv
b, err = json.MarshalIndent(&template, "", " ") b, err = json.MarshalIndent(&template, "", " ")
if err != nil { if err != nil {