StateAPI: account for slashing in StateMinerPower
This commit is contained in:
parent
ff94e7680d
commit
5381d10fe3
@ -193,6 +193,16 @@ func GetMinerSectorSize(ctx context.Context, sm *StateManager, ts *types.TipSet,
|
||||
return minfo.SectorSize, nil
|
||||
}
|
||||
|
||||
func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (uint64, error) {
|
||||
var mas actors.StorageMinerActorState
|
||||
_, err := sm.LoadActorState(ctx, maddr, &mas, ts)
|
||||
if err != nil {
|
||||
return 0, xerrors.Errorf("failed to load miner actor state: %w", err)
|
||||
}
|
||||
|
||||
return mas.SlashedAt, nil
|
||||
}
|
||||
|
||||
func GetStorageDeal(ctx context.Context, sm *StateManager, dealId uint64, ts *types.TipSet) (*actors.OnChainDeal, error) {
|
||||
var state actors.StorageMarketState
|
||||
if _, err := sm.LoadActorState(ctx, actors.StorageMarketAddress, &state, ts); err != nil {
|
||||
|
@ -34,7 +34,7 @@ func (s *seal) precommit(t *testing.T, sb *sectorbuilder.SectorBuilder, sid uint
|
||||
dlen := sectorbuilder.UserBytesForSectorSize(sectorSize)
|
||||
|
||||
var err error
|
||||
r := io.LimitReader(rand.New(rand.NewSource(42 + int64(sid))), int64(dlen))
|
||||
r := io.LimitReader(rand.New(rand.NewSource(42+int64(sid))), int64(dlen))
|
||||
s.ppi, err = sb.AddPiece(dlen, sid, r, []uint64{})
|
||||
if err != nil {
|
||||
t.Fatalf("%+v", err)
|
||||
|
@ -52,6 +52,14 @@ func (a *StateAPI) StateMinerPower(ctx context.Context, maddr address.Address, t
|
||||
return api.MinerPower{}, err
|
||||
}
|
||||
|
||||
slashed, err := stmgr.GetMinerSlashed(ctx, a.StateManager, ts, maddr)
|
||||
if err != nil {
|
||||
return api.MinerPower{}, err
|
||||
}
|
||||
if slashed != 0 {
|
||||
mpow = types.NewInt(0)
|
||||
}
|
||||
|
||||
return api.MinerPower{
|
||||
MinerPower: mpow,
|
||||
TotalPower: tpow,
|
||||
|
Loading…
Reference in New Issue
Block a user