more progress
This commit is contained in:
parent
9dad38c9a5
commit
00c6397ec9
@ -473,19 +473,6 @@ type MinerSectors struct {
|
|||||||
Active uint64
|
Active uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type SectorExpiration struct {
|
|
||||||
OnTime abi.ChainEpoch
|
|
||||||
|
|
||||||
// non-zero if sector is faulty, epoch at which it will be permanently
|
|
||||||
// removed if it doesn't recover
|
|
||||||
Early abi.ChainEpoch
|
|
||||||
}
|
|
||||||
|
|
||||||
type SectorLocation struct {
|
|
||||||
Deadline uint64
|
|
||||||
Partition uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
type ImportRes struct {
|
type ImportRes struct {
|
||||||
Root cid.Cid
|
Root cid.Cid
|
||||||
ImportID multistore.StoreID
|
ImportID multistore.StoreID
|
||||||
|
@ -35,6 +35,8 @@ type State interface {
|
|||||||
cbor.Marshaler
|
cbor.Marshaler
|
||||||
|
|
||||||
GetSector(abi.SectorNumber) (*SectorOnChainInfo, error)
|
GetSector(abi.SectorNumber) (*SectorOnChainInfo, error)
|
||||||
|
FindSector(abi.SectorNumber) (*SectorLocation, error)
|
||||||
|
GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error)
|
||||||
GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error)
|
GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error)
|
||||||
LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) ([]*ChainSectorInfo, error)
|
LoadSectorsFromSet(filter *bitfield.BitField, filterOut bool) ([]*ChainSectorInfo, error)
|
||||||
|
|
||||||
@ -80,3 +82,16 @@ type ChainSectorInfo struct {
|
|||||||
Info SectorOnChainInfo
|
Info SectorOnChainInfo
|
||||||
ID abi.SectorNumber
|
ID abi.SectorNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SectorExpiration struct {
|
||||||
|
OnTime abi.ChainEpoch
|
||||||
|
|
||||||
|
// non-zero if sector is faulty, epoch at which it will be permanently
|
||||||
|
// removed if it doesn't recover
|
||||||
|
Early abi.ChainEpoch
|
||||||
|
}
|
||||||
|
|
||||||
|
type SectorLocation struct {
|
||||||
|
Deadline uint64
|
||||||
|
Partition uint64
|
||||||
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package miner
|
package miner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-bitfield"
|
"github.com/filecoin-project/go-bitfield"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
@ -39,6 +41,87 @@ func (s *v0State) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
|
|||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *v0State) FindSector(num abi.SectorNumber) (*SectorLocation, error) {
|
||||||
|
dlIdx, partIdx, err := s.State.FindSector(s.store, num)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &SectorLocation{
|
||||||
|
Deadline: dlIdx,
|
||||||
|
Partition: partIdx,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSectorExpiration returns the effective expiration of the given sector.
|
||||||
|
//
|
||||||
|
// If the sector isn't found or has already been terminated, this method returns
|
||||||
|
// nil and no error. If the sector does not expire early, the Early expiration
|
||||||
|
// field is 0.
|
||||||
|
func (s *v0State) GetSectorExpiration(num abi.SectorNumber) (out *SectorExpiration, err error) {
|
||||||
|
dls, err := s.State.LoadDeadlines(s.store)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// NOTE: this can be optimized significantly.
|
||||||
|
// 1. If the sector is non-faulty, it will either expire on-time (can be
|
||||||
|
// learned from the sector info), or in the next quantized expiration
|
||||||
|
// epoch (i.e., the first element in the partition's expiration queue.
|
||||||
|
// 2. If it's faulty, it will expire early within the first 14 entries
|
||||||
|
// of the expiration queue.
|
||||||
|
stopErr := errors.New("stop")
|
||||||
|
err := dls.ForEach(s.store, func(dlIdx uint64, dl *miner.Deadline) error {
|
||||||
|
partitions, err := dl.PartitionsArray(s.store)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
quant := s.State.QuantSpecForDeadline(dlIdx)
|
||||||
|
var part miner.Partition
|
||||||
|
return partitions.ForEach(&part, func(partIdx int64) error {
|
||||||
|
if found, err := part.Sectors.IsSet(uint64(num)); err != nil {
|
||||||
|
return err
|
||||||
|
} else if !found {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if found, err := part.Terminated.IsSet(uint64(num)); err != nil {
|
||||||
|
return err
|
||||||
|
} else if found {
|
||||||
|
// already terminated
|
||||||
|
return stopErr
|
||||||
|
}
|
||||||
|
|
||||||
|
q, err := miner.LoadExpirationQueue(s.store, part.EarlyTerminated, quant)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var exp miner.ExpirationSet
|
||||||
|
return q.ForEach(&exp, func(epoch int64) error {
|
||||||
|
if early, err := exp.EarlySectors.IsSet(uint64(num)); err != nil {
|
||||||
|
return err
|
||||||
|
} else if early {
|
||||||
|
out.Early = abi.ChainEpoch(epoch)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if onTime, err := exp.OnTime.IsSet(uint64(num)); err != nil {
|
||||||
|
return err
|
||||||
|
} else if onTime {
|
||||||
|
out.OnTime = epoch
|
||||||
|
return stopErr
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
if err == stopErr {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if out.Early == 0 && out.OnTime == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *v0State) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) {
|
func (s *v0State) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) {
|
||||||
info, ok, err := s.State.GetPrecommittedSector(s.store, num)
|
info, ok, err := s.State.GetPrecommittedSector(s.store, num)
|
||||||
if !ok || err != nil {
|
if !ok || err != nil {
|
||||||
|
@ -698,97 +698,28 @@ func (a *StateAPI) StateSectorGetInfo(ctx context.Context, maddr address.Address
|
|||||||
return stmgr.MinerSectorInfo(ctx, a.StateManager, maddr, n, ts)
|
return stmgr.MinerSectorInfo(ctx, a.StateManager, maddr, n, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sectorPartitionCb func(store adt.Store, mas *miner.State, di uint64, pi uint64, part *miner.Partition) error
|
|
||||||
|
|
||||||
func (a *StateAPI) sectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey, cb sectorPartitionCb) error {
|
|
||||||
return a.StateManager.WithParentStateTsk(tsk,
|
|
||||||
a.StateManager.WithActor(maddr,
|
|
||||||
a.StateManager.WithActorState(ctx, func(store adt.Store, mas *miner.State) error {
|
|
||||||
return a.StateManager.WithDeadlines(func(store adt.Store, deadlines *miner.Deadlines) error {
|
|
||||||
err := a.StateManager.WithEachDeadline(func(store adt.Store, di uint64, deadline *miner.Deadline) error {
|
|
||||||
return a.StateManager.WithEachPartition(func(store adt.Store, pi uint64, partition *miner.Partition) error {
|
|
||||||
set, err := partition.Sectors.IsSet(uint64(sectorNumber))
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("is set: %w", err)
|
|
||||||
}
|
|
||||||
if set {
|
|
||||||
if err := cb(store, mas, di, pi, partition); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return errBreakForeach
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})(store, di, deadline)
|
|
||||||
})(store, deadlines)
|
|
||||||
if err == errBreakForeach {
|
|
||||||
err = nil
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
})(store, mas)
|
|
||||||
})))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *StateAPI) StateSectorExpiration(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*api.SectorExpiration, error) {
|
func (a *StateAPI) StateSectorExpiration(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*api.SectorExpiration, error) {
|
||||||
var onTimeEpoch, earlyEpoch abi.ChainEpoch
|
act, err := a.StateManager.LoadActorTsk(ctx, maddr, tsk)
|
||||||
|
|
||||||
err := a.sectorPartition(ctx, maddr, sectorNumber, tsk, func(store adt.Store, mas *miner.State, di uint64, pi uint64, part *miner.Partition) error {
|
|
||||||
quant := mas.QuantSpecForDeadline(di)
|
|
||||||
expirations, err := miner.LoadExpirationQueue(store, part.ExpirationsEpochs, quant)
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("loading expiration queue: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var eset miner.ExpirationSet
|
|
||||||
return expirations.Array.ForEach(&eset, func(epoch int64) error {
|
|
||||||
set, err := eset.OnTimeSectors.IsSet(uint64(sectorNumber))
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("checking if sector is in onTime set: %w", err)
|
|
||||||
}
|
|
||||||
if set {
|
|
||||||
onTimeEpoch = abi.ChainEpoch(epoch)
|
|
||||||
}
|
|
||||||
|
|
||||||
set, err = eset.EarlySectors.IsSet(uint64(sectorNumber))
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("checking if sector is in early set: %w", err)
|
|
||||||
}
|
|
||||||
if set {
|
|
||||||
earlyEpoch = abi.ChainEpoch(epoch)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act)
|
||||||
if onTimeEpoch == 0 {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("expiration for sector %d not found", sectorNumber)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return mas.GetSectorExpiration(sectorNumber)
|
||||||
return &api.SectorExpiration{
|
|
||||||
OnTime: onTimeEpoch,
|
|
||||||
Early: earlyEpoch,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *StateAPI) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*api.SectorLocation, error) {
|
func (a *StateAPI) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*api.SectorLocation, error) {
|
||||||
var found *api.SectorLocation
|
act, err := a.StateManager.LoadActorTsk(ctx, maddr, tsk)
|
||||||
|
|
||||||
err := a.sectorPartition(ctx, maddr, sectorNumber, tsk, func(store adt.Store, mas *miner.State, di, pi uint64, partition *miner.Partition) error {
|
|
||||||
found = &api.SectorLocation{
|
|
||||||
Deadline: di,
|
|
||||||
Partition: pi,
|
|
||||||
}
|
|
||||||
return errBreakForeach
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act)
|
||||||
return found, nil
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return mas.FindSector(sectorNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *StateAPI) StateListMessages(ctx context.Context, match *types.Message, tsk types.TipSetKey, toheight abi.ChainEpoch) ([]cid.Cid, error) {
|
func (a *StateAPI) StateListMessages(ctx context.Context, match *types.Message, tsk types.TipSetKey, toheight abi.ChainEpoch) ([]cid.Cid, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user