Add lookback limit
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
68593ce995
commit
3d3c26fa0c
@ -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,7 +125,8 @@ 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,
|
||||
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 {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user