diff --git a/cmd/lotus-sim/simulation/precommit.go b/cmd/lotus-sim/simulation/precommit.go index 055918c8c..619ba467d 100644 --- a/cmd/lotus-sim/simulation/precommit.go +++ b/cmd/lotus-sim/simulation/precommit.go @@ -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 } diff --git a/cmd/lotus-sim/simulation/state.go b/cmd/lotus-sim/simulation/state.go index 88971c9f0..23de7038c 100644 --- a/cmd/lotus-sim/simulation/state.go +++ b/cmd/lotus-sim/simulation/state.go @@ -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 +} diff --git a/cmd/lotus-sim/simulation/wdpost.go b/cmd/lotus-sim/simulation/wdpost.go index fe93a5f0c..c940c8d51 100644 --- a/cmd/lotus-sim/simulation/wdpost.go +++ b/cmd/lotus-sim/simulation/wdpost.go @@ -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 }