remove hacky bits

This commit is contained in:
Jeromy 2020-04-01 18:25:58 -07:00
parent 5b9ee1dea9
commit c55501024e

View File

@ -74,8 +74,12 @@ func GetMinerOwner(ctx context.Context, sm *StateManager, st cid.Cid, maddr addr
} }
func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (types.BigInt, types.BigInt, error) { func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (types.BigInt, types.BigInt, error) {
return getPowerRaw(ctx, sm, ts.ParentState(), maddr)
}
func getPowerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (types.BigInt, types.BigInt, error) {
var ps power.State var ps power.State
_, err := sm.LoadActorState(ctx, builtin.StoragePowerActorAddr, &ps, ts) _, err := sm.LoadActorStateRaw(ctx, builtin.StoragePowerActorAddr, &ps, st)
if err != nil { if err != nil {
return big.Zero(), big.Zero(), xerrors.Errorf("(get sset) failed to load power actor state: %w", err) return big.Zero(), big.Zero(), xerrors.Errorf("(get sset) failed to load power actor state: %w", err)
} }
@ -142,8 +146,12 @@ func SectorSetSizes(ctx context.Context, sm *StateManager, maddr address.Address
} }
func GetMinerProvingSet(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) ([]*api.ChainSectorInfo, error) { func GetMinerProvingSet(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) ([]*api.ChainSectorInfo, error) {
return getMinerProvingSetRaw(ctx, sm, ts.ParentState(), maddr)
}
func getMinerProvingSetRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) ([]*api.ChainSectorInfo, error) {
var mas miner.State var mas miner.State
_, err := sm.LoadActorState(ctx, maddr, &mas, ts) _, err := sm.LoadActorStateRaw(ctx, maddr, &mas, st)
if err != nil { if err != nil {
return nil, xerrors.Errorf("(get pset) failed to load miner actor state: %w", err) return nil, xerrors.Errorf("(get pset) failed to load miner actor state: %w", err)
} }
@ -180,8 +188,12 @@ func GetSectorsForElectionPost(ctx context.Context, sm *StateManager, ts *types.
} }
func GetMinerSectorSize(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (abi.SectorSize, error) { func GetMinerSectorSize(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (abi.SectorSize, error) {
return getMinerSectorSizeRaw(ctx, sm, ts.ParentState(), maddr)
}
func getMinerSectorSizeRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (abi.SectorSize, error) {
var mas miner.State var mas miner.State
_, err := sm.LoadActorState(ctx, maddr, &mas, ts) _, err := sm.LoadActorStateRaw(ctx, maddr, &mas, st)
if err != nil { if err != nil {
return 0, xerrors.Errorf("(get ssize) failed to load miner actor state: %w", err) return 0, xerrors.Errorf("(get ssize) failed to load miner actor state: %w", err)
} }
@ -364,42 +376,27 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, tsk types.TipSetKey
return nil, xerrors.Errorf("failed to load tipset for mining base: %w", err) return nil, xerrors.Errorf("failed to load tipset for mining base: %w", err)
} }
st, mr, err := sm.TipSetState(ctx, ts) st, _, err := sm.TipSetState(ctx, ts)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// HAXX: we want to use this tipsets evaluated state for all the information provset, err := getMinerProvingSetRaw(ctx, sm, st, maddr)
nb := &types.BlockHeader{
Miner: maddr,
Parents: ts.Cids(),
ParentStateRoot: st,
ParentMessageReceipts: mr,
Messages: ts.Blocks()[0].Messages, // TODO: horribly wrong, can't take a cid without it though
Height: ts.Height() + 1,
}
nts, err := types.NewTipSet([]*types.BlockHeader{nb})
if err != nil {
return nil, xerrors.Errorf("failed to make 'next' tipset for getting base info: %w", err)
}
provset, err := GetMinerProvingSet(ctx, sm, nts, maddr)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to get proving set: %w", err) return nil, xerrors.Errorf("failed to get proving set: %w", err)
} }
mpow, tpow, err := GetPower(ctx, sm, nts, maddr) mpow, tpow, err := getPowerRaw(ctx, sm, st, maddr)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to get power: %w", err) return nil, xerrors.Errorf("failed to get power: %w", err)
} }
worker, err := GetMinerWorker(ctx, sm, nts, maddr) worker, err := GetMinerWorkerRaw(ctx, sm, st, maddr)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to get miner worker: %w", err) return nil, xerrors.Errorf("failed to get miner worker: %w", err)
} }
ssize, err := GetMinerSectorSize(ctx, sm, nts, maddr) ssize, err := getMinerSectorSizeRaw(ctx, sm, st, maddr)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to get miner sector size: %w", err) return nil, xerrors.Errorf("failed to get miner sector size: %w", err)
} }