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:
parent
7925b69573
commit
0ccf716989
@ -94,15 +94,7 @@ func (ss *simulationState) packPreCommitsMiner(ctx context.Context, cb packFunc,
|
|||||||
// Load everything.
|
// Load everything.
|
||||||
epoch := ss.nextEpoch()
|
epoch := ss.nextEpoch()
|
||||||
nv := ss.sm.GetNtwkVersion(ctx, epoch)
|
nv := ss.sm.GetNtwkVersion(ctx, epoch)
|
||||||
st, err := ss.stateTree(ctx)
|
actor, minerState, err := ss.getMinerState(ctx, minerAddr)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, false, err
|
return 0, false, err
|
||||||
}
|
}
|
||||||
|
@ -63,13 +63,6 @@ func loadSimulationState(ctx context.Context, sim *Simulation) (*simulationState
|
|||||||
return nil, err
|
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 {
|
type onboardingInfo struct {
|
||||||
addr address.Address
|
addr address.Address
|
||||||
onboardingRate uint64
|
onboardingRate uint64
|
||||||
@ -86,12 +79,7 @@ func loadSimulationState(ctx context.Context, sim *Simulation) (*simulationState
|
|||||||
state.commitQueue.advanceEpoch(state.nextEpoch())
|
state.commitQueue.advanceEpoch(state.nextEpoch())
|
||||||
for addr, claim := range currentPowerTable {
|
for addr, claim := range currentPowerTable {
|
||||||
// Load the miner state.
|
// Load the miner state.
|
||||||
minerActor, err := st.GetActor(addr)
|
_, minerState, err := state.getMinerState(ctx, addr)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
minerState, err := miner.Load(store, minerActor)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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) {
|
func (ss *simulationState) getMinerInfo(ctx context.Context, addr address.Address) (*miner.MinerInfo, error) {
|
||||||
minerInfo, ok := ss.minerInfos[addr]
|
minerInfo, ok := ss.minerInfos[addr]
|
||||||
if !ok {
|
if !ok {
|
||||||
st, err := ss.stateTree(ctx)
|
_, minerState, err := ss.getMinerState(ctx, addr)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -197,3 +177,20 @@ func (ss *simulationState) getMinerInfo(ctx context.Context, addr address.Addres
|
|||||||
}
|
}
|
||||||
return minerInfo, nil
|
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
|
||||||
|
}
|
||||||
|
@ -191,11 +191,6 @@ func (ss *simulationState) stepWindowPoStsMiner(
|
|||||||
func (ss *simulationState) queueWindowPoSts(ctx context.Context) error {
|
func (ss *simulationState) queueWindowPoSts(ctx context.Context) error {
|
||||||
targetHeight := ss.nextEpoch()
|
targetHeight := ss.nextEpoch()
|
||||||
|
|
||||||
st, err := ss.stateTree(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
was := len(ss.pendingWposts)
|
was := len(ss.pendingWposts)
|
||||||
count := 0
|
count := 0
|
||||||
@ -220,14 +215,8 @@ func (ss *simulationState) queueWindowPoSts(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
store := ss.Chainstore.ActorStore(ctx)
|
|
||||||
|
|
||||||
for _, addr := range ss.wpostPeriods[int(ss.nextWpostEpoch%miner.WPoStChallengeWindow)] {
|
for _, addr := range ss.wpostPeriods[int(ss.nextWpostEpoch%miner.WPoStChallengeWindow)] {
|
||||||
minerActor, err := st.GetActor(addr)
|
_, minerState, err := ss.getMinerState(ctx, addr)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
minerState, err := miner.Load(store, minerActor)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user