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{
|
var infoCommitGasSimCommand = &cli.Command{
|
||||||
Name: "commit-gas",
|
Name: "commit-gas",
|
||||||
Description: "Output information about the gas for committs",
|
Description: "Output information about the gas for committs",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.Int64Flag{
|
||||||
|
Name: "lookback",
|
||||||
|
Value: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
log := func(f string, i ...interface{}) {
|
log := func(f string, i ...interface{}) {
|
||||||
fmt.Fprintf(os.Stderr, f, i...)
|
fmt.Fprintf(os.Stderr, f, i...)
|
||||||
@ -119,38 +125,39 @@ var infoCommitGasSimCommand = &cli.Command{
|
|||||||
var gasAgg, proofsAgg uint64
|
var gasAgg, proofsAgg uint64
|
||||||
var gasAggMax, proofsAggMax 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"),
|
||||||
messages []*simulation.AppliedMessage) error {
|
func(sm *stmgr.StateManager, ts *types.TipSet, stCid cid.Cid,
|
||||||
for _, m := range messages {
|
messages []*simulation.AppliedMessage) error {
|
||||||
if m.ExitCode != exitcode.Ok {
|
for _, m := range messages {
|
||||||
continue
|
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
|
|
||||||
}
|
}
|
||||||
c, err := param.SectorNumbers.Count()
|
if m.Method == builtin.MethodsMiner.ProveCommitAggregate {
|
||||||
if err != nil {
|
param := miner.ProveCommitAggregateParams{}
|
||||||
log("failed to count sectors")
|
err := param.UnmarshalCBOR(bytes.NewReader(m.Params))
|
||||||
return nil
|
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 m.Method == builtin.MethodsMiner.ProveCommitSector {
|
||||||
if c == 819 {
|
|
||||||
gasAggMax += uint64(m.GasUsed)
|
|
||||||
proofsAggMax += c
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Method == builtin.MethodsMiner.ProveCommitSector {
|
return nil
|
||||||
}
|
})
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
idealGassUsed := float64(gasAggMax) / float64(proofsAggMax) * float64(proofsAgg)
|
idealGassUsed := float64(gasAggMax) / float64(proofsAggMax) * float64(proofsAgg)
|
||||||
|
|
||||||
fmt.Printf("Gas usage efficiency in comparison to all 819: %f%%\n", 100*idealGassUsed/float64(gasAgg))
|
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.
|
// Walk walks the simulation's chain from the current head back to the first tipset.
|
||||||
func (sim *Simulation) Walk(
|
func (sim *Simulation) Walk(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
|
maxLookback int64,
|
||||||
cb func(sm *stmgr.StateManager,
|
cb func(sm *stmgr.StateManager,
|
||||||
ts *types.TipSet,
|
ts *types.TipSet,
|
||||||
stCid cid.Cid,
|
stCid cid.Cid,
|
||||||
@ -297,7 +298,12 @@ func (sim *Simulation) Walk(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
msgs, err := sim.Chainstore.MessagesForTipset(ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user