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,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))
|
||||
|
@ -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