From 3d3c26fa0c797b6ebae73e8b2f335df50da4ef72 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 10 Jun 2021 19:04:15 +0200 Subject: [PATCH] Add lookback limit Signed-off-by: Jakub Sztandera --- cmd/lotus-sim/info.go | 61 ++++++++++++++------------ cmd/lotus-sim/simulation/simulation.go | 8 +++- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/cmd/lotus-sim/info.go b/cmd/lotus-sim/info.go index d87b3da63..252642eea 100644 --- a/cmd/lotus-sim/info.go +++ b/cmd/lotus-sim/info.go @@ -101,6 +101,12 @@ var infoSimCommand = &cli.Command{ var infoCommitGasSimCommand = &cli.Command{ Name: "commit-gas", Description: "Output information about the gas for committs", + Flags: []cli.Flag{ + &cli.Int64Flag{ + Name: "lookback", + Value: 0, + }, + }, Action: func(cctx *cli.Context) error { log := func(f string, i ...interface{}) { fmt.Fprintf(os.Stderr, f, i...) @@ -119,38 +125,39 @@ var infoCommitGasSimCommand = &cli.Command{ var gasAgg, proofsAgg uint64 var gasAggMax, proofsAggMax uint64 - sim.Walk(cctx.Context, func(sm *stmgr.StateManager, ts *types.TipSet, stCid cid.Cid, - messages []*simulation.AppliedMessage) error { - for _, m := range messages { - if m.ExitCode != exitcode.Ok { - continue - } - if m.Method == builtin.MethodsMiner.ProveCommitAggregate { - param := miner.ProveCommitAggregateParams{} - err := param.UnmarshalCBOR(bytes.NewReader(m.Params)) - if err != nil { - log("failed to decode params: %+v", err) - return nil + sim.Walk(cctx.Context, cctx.Int64("lookback"), + func(sm *stmgr.StateManager, ts *types.TipSet, stCid cid.Cid, + messages []*simulation.AppliedMessage) error { + for _, m := range messages { + if m.ExitCode != exitcode.Ok { + continue } - c, err := param.SectorNumbers.Count() - if err != nil { - log("failed to count sectors") - return nil + if m.Method == builtin.MethodsMiner.ProveCommitAggregate { + param := miner.ProveCommitAggregateParams{} + err := param.UnmarshalCBOR(bytes.NewReader(m.Params)) + if err != nil { + log("failed to decode params: %+v", err) + return nil + } + c, err := param.SectorNumbers.Count() + if err != nil { + log("failed to count sectors") + return nil + } + gasAgg += uint64(m.GasUsed) + proofsAgg += c + if c == 819 { + gasAggMax += uint64(m.GasUsed) + proofsAggMax += c + } } - gasAgg += uint64(m.GasUsed) - proofsAgg += c - if c == 819 { - gasAggMax += uint64(m.GasUsed) - proofsAggMax += c + + if m.Method == builtin.MethodsMiner.ProveCommitSector { } } - if m.Method == builtin.MethodsMiner.ProveCommitSector { - } - } - - return nil - }) + return nil + }) idealGassUsed := float64(gasAggMax) / float64(proofsAggMax) * float64(proofsAgg) fmt.Printf("Gas usage efficiency in comparison to all 819: %f%%\n", 100*idealGassUsed/float64(gasAgg)) diff --git a/cmd/lotus-sim/simulation/simulation.go b/cmd/lotus-sim/simulation/simulation.go index 2d8b4f388..ab021ddd5 100644 --- a/cmd/lotus-sim/simulation/simulation.go +++ b/cmd/lotus-sim/simulation/simulation.go @@ -286,6 +286,7 @@ type AppliedMessage struct { // Walk walks the simulation's chain from the current head back to the first tipset. func (sim *Simulation) Walk( ctx context.Context, + maxLookback int64, cb func(sm *stmgr.StateManager, ts *types.TipSet, stCid cid.Cid, @@ -297,7 +298,12 @@ func (sim *Simulation) Walk( if err != nil { return err } - for !ts.Equals(sim.start) && ctx.Err() == nil { + minEpoch := abi.ChainEpoch(0) + if maxLookback != 0 { + minEpoch = ts.Height() - abi.ChainEpoch(maxLookback) + } + + for !ts.Equals(sim.start) && ctx.Err() == nil && ts.Height() > minEpoch { msgs, err := sim.Chainstore.MessagesForTipset(ts) if err != nil { return err