2021-05-19 00:01:30 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2021-06-07 21:54:20 +00:00
|
|
|
"text/tabwriter"
|
2021-05-19 00:01:30 +00:00
|
|
|
|
2021-06-10 02:40:00 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
2021-05-19 00:01:30 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
|
|
|
)
|
|
|
|
|
2021-06-07 21:54:20 +00:00
|
|
|
var upgradeCommand = &cli.Command{
|
|
|
|
Name: "upgrade",
|
|
|
|
Description: "Modifies network upgrade heights.",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
upgradeSetCommand,
|
2021-06-18 18:17:35 +00:00
|
|
|
upgradeList,
|
2021-06-07 21:54:20 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var upgradeList = &cli.Command{
|
|
|
|
Name: "list",
|
|
|
|
Description: "Lists all pending upgrades.",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
upgradeSetCommand,
|
|
|
|
},
|
2021-06-18 18:17:35 +00:00
|
|
|
Action: func(cctx *cli.Context) (err error) {
|
2021-06-07 21:54:20 +00:00
|
|
|
node, err := open(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-06-18 18:17:35 +00:00
|
|
|
defer func() {
|
|
|
|
if cerr := node.Close(); err == nil {
|
|
|
|
err = cerr
|
|
|
|
}
|
|
|
|
}()
|
2021-06-07 21:54:20 +00:00
|
|
|
|
|
|
|
sim, err := node.LoadSim(cctx.Context, cctx.String("simulation"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
upgrades, err := sim.ListUpgrades()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
tw := tabwriter.NewWriter(cctx.App.Writer, 8, 8, 0, ' ', 0)
|
|
|
|
fmt.Fprintf(tw, "version\theight\tepochs\tmigration\texpensive")
|
|
|
|
epoch := sim.GetHead().Height()
|
|
|
|
for _, upgrade := range upgrades {
|
|
|
|
fmt.Fprintf(
|
|
|
|
tw, "%d\t%d\t%+d\t%t\t%t",
|
|
|
|
upgrade.Network, upgrade.Height, upgrade.Height-epoch,
|
|
|
|
upgrade.Migration != nil,
|
|
|
|
upgrade.Expensive,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var upgradeSetCommand = &cli.Command{
|
|
|
|
Name: "set",
|
2021-05-19 00:01:30 +00:00
|
|
|
ArgsUsage: "<network-version> [+]<epochs>",
|
2021-06-07 21:54:20 +00:00
|
|
|
Description: "Set a network upgrade height. Prefix with '+' to set it relative to the last epoch.",
|
2021-06-18 18:17:35 +00:00
|
|
|
Action: func(cctx *cli.Context) (err error) {
|
2021-05-19 00:01:30 +00:00
|
|
|
args := cctx.Args()
|
|
|
|
if args.Len() != 2 {
|
|
|
|
return fmt.Errorf("expected 2 arguments")
|
|
|
|
}
|
|
|
|
nvString := args.Get(0)
|
2021-06-21 16:05:48 +00:00
|
|
|
networkVersion, err := strconv.ParseUint(nvString, 10, 32)
|
2021-05-19 00:01:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to parse network version %q: %w", nvString, err)
|
|
|
|
}
|
|
|
|
heightString := args.Get(1)
|
|
|
|
relative := false
|
|
|
|
if strings.HasPrefix(heightString, "+") {
|
|
|
|
heightString = heightString[1:]
|
|
|
|
relative = true
|
|
|
|
}
|
|
|
|
height, err := strconv.ParseInt(heightString, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to parse height version %q: %w", heightString, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
node, err := open(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-06-18 18:17:35 +00:00
|
|
|
defer func() {
|
|
|
|
if cerr := node.Close(); err == nil {
|
|
|
|
err = cerr
|
|
|
|
}
|
|
|
|
}()
|
2021-05-19 00:01:30 +00:00
|
|
|
|
|
|
|
sim, err := node.LoadSim(cctx.Context, cctx.String("simulation"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if relative {
|
|
|
|
height += int64(sim.GetHead().Height())
|
|
|
|
}
|
|
|
|
return sim.SetUpgradeHeight(network.Version(networkVersion), abi.ChainEpoch(height))
|
|
|
|
},
|
|
|
|
}
|