fix(lotus-sim): refactor miner state loading

Add a helper function so we don't need to constantly repeat ourselves.
This commit is contained in:
Steven Allen 2021-06-07 18:18:20 -07:00
parent 7925b69573
commit 0ccf716989
3 changed files with 21 additions and 43 deletions

View File

@ -94,15 +94,7 @@ func (ss *simulationState) packPreCommitsMiner(ctx context.Context, cb packFunc,
// Load everything.
epoch := ss.nextEpoch()
nv := ss.sm.GetNtwkVersion(ctx, epoch)
st, err := ss.stateTree(ctx)
if err != nil {
return 0, false, err
}
actor, err := st.GetActor(minerAddr)
if err != nil {
return 0, false, err
}
minerState, err := miner.Load(ss.Chainstore.ActorStore(ctx), actor)
actor, minerState, err := ss.getMinerState(ctx, minerAddr)
if err != nil {
return 0, false, err
}

View File

@ -63,13 +63,6 @@ func loadSimulationState(ctx context.Context, sim *Simulation) (*simulationState
return nil, err
}
// Now load miner state info.
store := sim.Chainstore.ActorStore(ctx)
st, err := sim.stateTree(ctx)
if err != nil {
return nil, err
}
type onboardingInfo struct {
addr address.Address
onboardingRate uint64
@ -86,12 +79,7 @@ func loadSimulationState(ctx context.Context, sim *Simulation) (*simulationState
state.commitQueue.advanceEpoch(state.nextEpoch())
for addr, claim := range currentPowerTable {
// Load the miner state.
minerActor, err := st.GetActor(addr)
if err != nil {
return nil, err
}
minerState, err := miner.Load(store, minerActor)
_, minerState, err := state.getMinerState(ctx, addr)
if err != nil {
return nil, err
}
@ -176,15 +164,7 @@ func (ss *simulationState) nextEpoch() abi.ChainEpoch {
func (ss *simulationState) getMinerInfo(ctx context.Context, addr address.Address) (*miner.MinerInfo, error) {
minerInfo, ok := ss.minerInfos[addr]
if !ok {
st, err := ss.stateTree(ctx)
if err != nil {
return nil, err
}
act, err := st.GetActor(addr)
if err != nil {
return nil, err
}
minerState, err := miner.Load(ss.Chainstore.ActorStore(ctx), act)
_, minerState, err := ss.getMinerState(ctx, addr)
if err != nil {
return nil, err
}
@ -197,3 +177,20 @@ func (ss *simulationState) getMinerInfo(ctx context.Context, addr address.Addres
}
return minerInfo, nil
}
// getMinerState loads the miner actor & state.
func (ss *simulationState) getMinerState(ctx context.Context, addr address.Address) (*types.Actor, miner.State, error) {
st, err := ss.stateTree(ctx)
if err != nil {
return nil, nil, err
}
act, err := st.GetActor(addr)
if err != nil {
return nil, nil, err
}
state, err := miner.Load(ss.Chainstore.ActorStore(ctx), act)
if err != nil {
return nil, nil, err
}
return act, state, err
}

View File

@ -191,11 +191,6 @@ func (ss *simulationState) stepWindowPoStsMiner(
func (ss *simulationState) queueWindowPoSts(ctx context.Context) error {
targetHeight := ss.nextEpoch()
st, err := ss.stateTree(ctx)
if err != nil {
return err
}
now := time.Now()
was := len(ss.pendingWposts)
count := 0
@ -220,14 +215,8 @@ func (ss *simulationState) queueWindowPoSts(ctx context.Context) error {
return err
}
store := ss.Chainstore.ActorStore(ctx)
for _, addr := range ss.wpostPeriods[int(ss.nextWpostEpoch%miner.WPoStChallengeWindow)] {
minerActor, err := st.GetActor(addr)
if err != nil {
return err
}
minerState, err := miner.Load(store, minerActor)
_, minerState, err := ss.getMinerState(ctx, addr)
if err != nil {
return err
}