2021-06-07 22:05:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-06-08 18:23:51 +00:00
|
|
|
"context"
|
2021-06-07 22:05:52 +00:00
|
|
|
"fmt"
|
2021-06-10 04:27:48 +00:00
|
|
|
"io"
|
2021-06-07 22:05:52 +00:00
|
|
|
"text/tabwriter"
|
2021-06-08 18:23:51 +00:00
|
|
|
"time"
|
2021-06-07 22:05:52 +00:00
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
2021-06-08 18:23:51 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
2021-06-10 02:40:00 +00:00
|
|
|
|
2021-06-14 20:05:28 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
2021-06-08 18:23:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/power"
|
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2021-06-10 04:27:48 +00:00
|
|
|
"github.com/filecoin-project/lotus/cmd/lotus-sim/simulation"
|
2021-06-07 22:05:52 +00:00
|
|
|
)
|
|
|
|
|
2021-06-08 18:23:51 +00:00
|
|
|
func getTotalPower(ctx context.Context, sm *stmgr.StateManager, ts *types.TipSet) (power.Claim, error) {
|
|
|
|
actor, err := sm.LoadActor(ctx, power.Address, ts)
|
|
|
|
if err != nil {
|
|
|
|
return power.Claim{}, err
|
|
|
|
}
|
|
|
|
state, err := power.Load(sm.ChainStore().ActorStore(ctx), actor)
|
|
|
|
if err != nil {
|
|
|
|
return power.Claim{}, err
|
|
|
|
}
|
|
|
|
return state.TotalPower()
|
|
|
|
}
|
|
|
|
|
2021-06-10 04:27:48 +00:00
|
|
|
func printInfo(ctx context.Context, sim *simulation.Simulation, out io.Writer) error {
|
2021-06-12 16:57:27 +00:00
|
|
|
head := sim.GetHead()
|
|
|
|
start := sim.GetStart()
|
|
|
|
|
|
|
|
powerNow, err := getTotalPower(ctx, sim.StateManager, head)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-06-12 18:51:35 +00:00
|
|
|
powerLookbackEpoch := head.Height() - builtin.EpochsInDay*2
|
2021-06-12 16:57:27 +00:00
|
|
|
if powerLookbackEpoch < start.Height() {
|
|
|
|
powerLookbackEpoch = start.Height()
|
|
|
|
}
|
2021-06-21 18:41:06 +00:00
|
|
|
lookbackTs, err := sim.Node.Chainstore.GetTipsetByHeight(ctx, powerLookbackEpoch, head, false)
|
2021-06-10 04:27:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-06-12 16:57:27 +00:00
|
|
|
powerLookback, err := getTotalPower(ctx, sim.StateManager, lookbackTs)
|
2021-06-10 04:27:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-06-12 16:57:27 +00:00
|
|
|
// growth rate in size/day
|
|
|
|
growthRate := big.Div(
|
|
|
|
big.Mul(big.Sub(powerNow.RawBytePower, powerLookback.RawBytePower),
|
|
|
|
big.NewInt(builtin.EpochsInDay)),
|
|
|
|
big.NewInt(int64(head.Height()-lookbackTs.Height())),
|
|
|
|
)
|
2021-06-10 04:27:48 +00:00
|
|
|
|
|
|
|
tw := tabwriter.NewWriter(out, 8, 8, 1, ' ', 0)
|
|
|
|
|
|
|
|
headEpoch := head.Height()
|
|
|
|
firstEpoch := start.Height() + 1
|
|
|
|
|
|
|
|
headTime := time.Unix(int64(head.MinTimestamp()), 0)
|
|
|
|
startTime := time.Unix(int64(start.MinTimestamp()), 0)
|
|
|
|
duration := headTime.Sub(startTime)
|
|
|
|
|
|
|
|
fmt.Fprintf(tw, "Name:\t%s\n", sim.Name())
|
|
|
|
fmt.Fprintf(tw, "Head:\t%s\n", head)
|
2021-06-10 19:32:41 +00:00
|
|
|
fmt.Fprintf(tw, "Start Epoch:\t%d\n", firstEpoch)
|
|
|
|
fmt.Fprintf(tw, "End Epoch:\t%d\n", headEpoch)
|
2021-06-10 04:27:48 +00:00
|
|
|
fmt.Fprintf(tw, "Length:\t%d\n", headEpoch-firstEpoch)
|
2021-06-10 19:32:41 +00:00
|
|
|
fmt.Fprintf(tw, "Start Date:\t%s\n", startTime)
|
|
|
|
fmt.Fprintf(tw, "End Date:\t%s\n", headTime)
|
|
|
|
fmt.Fprintf(tw, "Duration:\t%.2f day(s)\n", duration.Hours()/24)
|
2021-06-12 17:18:17 +00:00
|
|
|
fmt.Fprintf(tw, "Capacity:\t%s\n", types.SizeStr(powerNow.RawBytePower))
|
|
|
|
fmt.Fprintf(tw, "Daily Capacity Growth:\t%s/day\n", types.SizeStr(growthRate))
|
2021-06-10 04:27:48 +00:00
|
|
|
fmt.Fprintf(tw, "Network Version:\t%d\n", sim.GetNetworkVersion())
|
|
|
|
return tw.Flush()
|
|
|
|
}
|
|
|
|
|
2021-06-07 22:05:52 +00:00
|
|
|
var infoSimCommand = &cli.Command{
|
|
|
|
Name: "info",
|
|
|
|
Description: "Output information about the simulation.",
|
2021-06-10 16:39:57 +00:00
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
infoCommitGasSimCommand,
|
2021-06-17 18:32:15 +00:00
|
|
|
infoMessageSizeSimCommand,
|
2021-06-10 21:37:20 +00:00
|
|
|
infoWindowPostBandwidthSimCommand,
|
2021-06-12 18:44:38 +00:00
|
|
|
infoCapacityGrowthSimCommand,
|
2021-06-15 00:38:55 +00:00
|
|
|
infoStateGrowthSimCommand,
|
2021-06-10 16:39:57 +00:00
|
|
|
},
|
2021-06-18 18:17:35 +00:00
|
|
|
Action: func(cctx *cli.Context) (err error) {
|
2021-06-07 22:05:52 +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 22:05:52 +00:00
|
|
|
|
|
|
|
sim, err := node.LoadSim(cctx.Context, cctx.String("simulation"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-06-10 04:27:48 +00:00
|
|
|
return printInfo(cctx.Context, sim, cctx.App.Writer)
|
2021-06-07 22:05:52 +00:00
|
|
|
},
|
|
|
|
}
|