feat(lotus-sim): add command to list pending upgrades

This commit is contained in:
Steven Allen 2021-06-07 14:54:20 -07:00
parent e2f5c494b0
commit 8000decac6
3 changed files with 65 additions and 4 deletions

View File

@ -16,7 +16,7 @@ var root []*cli.Command = []*cli.Command{
deleteSimCommand, deleteSimCommand,
listSimCommand, listSimCommand,
stepSimCommand, stepSimCommand,
setUpgradeCommand, upgradeCommand,
} }
func main() { func main() {

View File

@ -265,6 +265,21 @@ func (sim *Simulation) SetUpgradeHeight(nv network.Version, epoch abi.ChainEpoch
return nil return nil
} }
func (sim *Simulation) ListUpgrades() (stmgr.UpgradeSchedule, error) {
upgrades, err := sim.config.upgradeSchedule()
if err != nil {
return nil, err
}
var pending stmgr.UpgradeSchedule
for _, upgrade := range upgrades {
if upgrade.Height < sim.head.Height() {
continue
}
pending = append(pending, upgrade)
}
return pending, nil
}
func (sim *Simulation) saveConfig() error { func (sim *Simulation) saveConfig() error {
buf, err := json.Marshal(sim.config) buf, err := json.Marshal(sim.config)
if err != nil { if err != nil {

View File

@ -4,16 +4,62 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
"text/tabwriter"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/go-state-types/network"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
var setUpgradeCommand = &cli.Command{ var upgradeCommand = &cli.Command{
Name: "set-upgrade", Name: "upgrade",
Description: "Modifies network upgrade heights.",
Subcommands: []*cli.Command{
upgradeSetCommand,
},
}
var upgradeList = &cli.Command{
Name: "list",
Description: "Lists all pending upgrades.",
Subcommands: []*cli.Command{
upgradeSetCommand,
},
Action: func(cctx *cli.Context) error {
node, err := open(cctx)
if err != nil {
return err
}
defer node.Close()
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",
ArgsUsage: "<network-version> [+]<epochs>", ArgsUsage: "<network-version> [+]<epochs>",
Description: "Set a network upgrade height. prefix with '+' to set it relative to the last epoch.", Description: "Set a network upgrade height. Prefix with '+' to set it relative to the last epoch.",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
args := cctx.Args() args := cctx.Args()
if args.Len() != 2 { if args.Len() != 2 {