2021-06-14 20:05:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
var infoCapacityGrowthSimCommand = &cli.Command{
|
|
|
|
Name: "capacity-growth",
|
|
|
|
Description: "List daily capacity growth over the course of the simulation starting at the end.",
|
2021-06-18 18:17:35 +00:00
|
|
|
Action: func(cctx *cli.Context) (err error) {
|
2021-06-14 20:05:28 +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-14 20:05:28 +00:00
|
|
|
|
|
|
|
sim, err := node.LoadSim(cctx.Context, cctx.String("simulation"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
firstEpoch := sim.GetStart().Height()
|
|
|
|
ts := sim.GetHead()
|
|
|
|
lastPower, err := getTotalPower(cctx.Context, sim.StateManager, ts)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
lastHeight := ts.Height()
|
|
|
|
|
|
|
|
for ts.Height() > firstEpoch && cctx.Err() == nil {
|
2021-12-13 13:15:38 +00:00
|
|
|
ts, err = sim.Node.Chainstore.LoadTipSet(cctx.Context, ts.Parents())
|
2021-06-14 20:05:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
newEpoch := ts.Height()
|
|
|
|
if newEpoch != firstEpoch && newEpoch+builtin.EpochsInDay > lastHeight {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
newPower, err := getTotalPower(cctx.Context, sim.StateManager, ts)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
growthRate := big.Div(
|
|
|
|
big.Mul(big.Sub(lastPower.RawBytePower, newPower.RawBytePower),
|
|
|
|
big.NewInt(builtin.EpochsInDay)),
|
|
|
|
big.NewInt(int64(lastHeight-newEpoch)),
|
|
|
|
)
|
|
|
|
lastPower = newPower
|
|
|
|
lastHeight = newEpoch
|
2024-06-04 02:53:29 +00:00
|
|
|
_, _ = fmt.Fprintf(cctx.App.Writer, "%s/day\n", types.SizeStr(growthRate))
|
2021-06-14 20:05:28 +00:00
|
|
|
}
|
|
|
|
return cctx.Err()
|
|
|
|
},
|
|
|
|
}
|