Merge pull request #613 from filecoin-project/fix/st-mpow-slashed

StateAPI: account for slashing in StateMinerPower
This commit is contained in:
Łukasz Magiera 2019-11-15 02:07:29 +01:00 committed by GitHub
commit abb8f29dfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -193,6 +193,16 @@ func GetMinerSectorSize(ctx context.Context, sm *StateManager, ts *types.TipSet,
return minfo.SectorSize, nil 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) { func GetStorageDeal(ctx context.Context, sm *StateManager, dealId uint64, ts *types.TipSet) (*actors.OnChainDeal, error) {
var state actors.StorageMarketState var state actors.StorageMarketState
if _, err := sm.LoadActorState(ctx, actors.StorageMarketAddress, &state, ts); err != nil { if _, err := sm.LoadActorState(ctx, actors.StorageMarketAddress, &state, ts); err != nil {

View File

@ -34,7 +34,7 @@ func (s *seal) precommit(t *testing.T, sb *sectorbuilder.SectorBuilder, sid uint
dlen := sectorbuilder.UserBytesForSectorSize(sectorSize) dlen := sectorbuilder.UserBytesForSectorSize(sectorSize)
var err error 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{}) s.ppi, err = sb.AddPiece(dlen, sid, r, []uint64{})
if err != nil { if err != nil {
t.Fatalf("%+v", err) t.Fatalf("%+v", err)

View File

@ -52,6 +52,14 @@ func (a *StateAPI) StateMinerPower(ctx context.Context, maddr address.Address, t
return api.MinerPower{}, err 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{ return api.MinerPower{
MinerPower: mpow, MinerPower: mpow,
TotalPower: tpow, TotalPower: tpow,