2020-09-12 03:07:52 +00:00
|
|
|
package miner
|
|
|
|
|
|
|
|
import (
|
2020-09-18 04:39:34 +00:00
|
|
|
"bytes"
|
2020-09-15 17:44:44 +00:00
|
|
|
"errors"
|
|
|
|
|
2022-11-08 04:55:56 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
|
|
"golang.org/x/xerrors"
|
2022-09-07 23:30:55 +00:00
|
|
|
|
2022-11-08 05:53:13 +00:00
|
|
|
"github.com/filecoin-project/go-bitfield"
|
|
|
|
rle "github.com/filecoin-project/go-bitfield/rle"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
2022-11-08 04:55:56 +00:00
|
|
|
minertypes "github.com/filecoin-project/go-state-types/builtin/v10/miner"
|
2022-11-08 05:53:13 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/dline"
|
2022-11-08 04:55:56 +00:00
|
|
|
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
|
|
|
adt0 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
2022-11-08 05:53:13 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
2020-09-12 03:07:52 +00:00
|
|
|
)
|
|
|
|
|
2020-09-21 06:19:32 +00:00
|
|
|
var _ State = (*state0)(nil)
|
|
|
|
|
2020-09-24 00:40:29 +00:00
|
|
|
func load0(store adt.Store, root cid.Cid) (State, error) {
|
|
|
|
out := state0{store: store}
|
|
|
|
err := store.Get(store.Context(), root, &out)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &out, nil
|
|
|
|
}
|
|
|
|
|
2021-05-15 01:11:23 +00:00
|
|
|
func make0(store adt.Store) (State, error) {
|
|
|
|
out := state0{store: store}
|
|
|
|
out.State = miner0.State{}
|
|
|
|
return &out, nil
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
type state0 struct {
|
|
|
|
miner0.State
|
2020-09-12 03:07:52 +00:00
|
|
|
store adt.Store
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
type deadline0 struct {
|
|
|
|
miner0.Deadline
|
2020-09-12 03:07:52 +00:00
|
|
|
store adt.Store
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
type partition0 struct {
|
|
|
|
miner0.Partition
|
2020-09-12 03:07:52 +00:00
|
|
|
store adt.Store
|
|
|
|
}
|
|
|
|
|
2020-10-11 22:17:28 +00:00
|
|
|
func (s *state0) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) {
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
err = xerrors.Errorf("failed to get available balance: %w", r)
|
|
|
|
available = abi.NewTokenAmount(0)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
// this panics if the miner doesnt have enough funds to cover their locked pledge
|
|
|
|
available = s.GetAvailableBalance(bal)
|
|
|
|
return available, err
|
2020-09-17 08:17:14 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) {
|
2020-09-17 08:17:14 +00:00
|
|
|
return s.CheckVestedFunds(s.store, epoch)
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) LockedFunds() (LockedFunds, error) {
|
2020-09-18 21:46:42 +00:00
|
|
|
return LockedFunds{
|
|
|
|
VestingFunds: s.State.LockedFunds,
|
|
|
|
InitialPledgeRequirement: s.State.InitialPledgeRequirement,
|
|
|
|
PreCommitDeposits: s.State.PreCommitDeposits,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-10-06 08:33:55 +00:00
|
|
|
func (s *state0) FeeDebt() (abi.TokenAmount, error) {
|
|
|
|
return big.Zero(), nil
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) InitialPledge() (abi.TokenAmount, error) {
|
2020-09-18 21:46:42 +00:00
|
|
|
return s.State.InitialPledgeRequirement, nil
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) PreCommitDeposits() (abi.TokenAmount, error) {
|
2020-09-18 21:46:42 +00:00
|
|
|
return s.State.PreCommitDeposits, nil
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
|
2020-09-15 04:55:49 +00:00
|
|
|
info, ok, err := s.State.GetSector(s.store, num)
|
|
|
|
if !ok || err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-09-20 21:53:46 +00:00
|
|
|
ret := fromV0SectorOnChainInfo(*info)
|
|
|
|
return &ret, nil
|
2020-09-15 04:55:49 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) FindSector(num abi.SectorNumber) (*SectorLocation, error) {
|
2020-09-15 17:44:44 +00:00
|
|
|
dlIdx, partIdx, err := s.State.FindSector(s.store, num)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &SectorLocation{
|
|
|
|
Deadline: dlIdx,
|
|
|
|
Partition: partIdx,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-09-21 20:43:47 +00:00
|
|
|
func (s *state0) NumLiveSectors() (uint64, error) {
|
|
|
|
dls, err := s.State.LoadDeadlines(s.store)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
var total uint64
|
|
|
|
if err := dls.ForEach(s.store, func(dlIdx uint64, dl *miner0.Deadline) error {
|
|
|
|
total += dl.LiveSectors
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return total, nil
|
|
|
|
}
|
|
|
|
|
2020-09-15 17:44:44 +00:00
|
|
|
// GetSectorExpiration returns the effective expiration of the given sector.
|
|
|
|
//
|
2020-09-25 18:27:30 +00:00
|
|
|
// If the sector does not expire early, the Early expiration field is 0.
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, error) {
|
2020-09-15 17:44:44 +00:00
|
|
|
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.
|
2021-11-18 23:35:06 +00:00
|
|
|
|
2020-09-15 17:44:44 +00:00
|
|
|
stopErr := errors.New("stop")
|
2020-09-18 05:12:45 +00:00
|
|
|
out := SectorExpiration{}
|
2020-09-18 21:59:27 +00:00
|
|
|
err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner0.Deadline) error {
|
2020-09-15 17:44:44 +00:00
|
|
|
partitions, err := dl.PartitionsArray(s.store)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
quant := s.State.QuantSpecForDeadline(dlIdx)
|
2020-09-18 21:59:27 +00:00
|
|
|
var part miner0.Partition
|
2020-09-15 17:44:44 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
q, err := miner0.LoadExpirationQueue(s.store, part.ExpirationsEpochs, quant)
|
2020-09-15 17:44:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-18 21:59:27 +00:00
|
|
|
var exp miner0.ExpirationSet
|
2020-09-15 17:44:44 +00:00
|
|
|
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
|
|
|
|
}
|
2020-09-15 19:13:13 +00:00
|
|
|
if onTime, err := exp.OnTimeSectors.IsSet(uint64(num)); err != nil {
|
2020-09-15 17:44:44 +00:00
|
|
|
return err
|
|
|
|
} else if onTime {
|
2020-09-15 19:13:13 +00:00
|
|
|
out.OnTime = abi.ChainEpoch(epoch)
|
2020-09-15 17:44:44 +00:00
|
|
|
return stopErr
|
|
|
|
}
|
2020-09-15 19:13:13 +00:00
|
|
|
return nil
|
2020-09-15 17:44:44 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
if err == stopErr {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if out.Early == 0 && out.OnTime == 0 {
|
2020-09-25 18:27:30 +00:00
|
|
|
return nil, xerrors.Errorf("failed to find sector %d", num)
|
2020-09-15 17:44:44 +00:00
|
|
|
}
|
2020-09-18 05:12:45 +00:00
|
|
|
return &out, nil
|
2020-09-15 17:44:44 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (s *state0) GetPrecommittedSector(num abi.SectorNumber) (*minertypes.SectorPreCommitOnChainInfo, error) {
|
2020-09-15 04:55:49 +00:00
|
|
|
info, ok, err := s.State.GetPrecommittedSector(s.store, num)
|
|
|
|
if !ok || err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-09-20 21:53:46 +00:00
|
|
|
ret := fromV0SectorPreCommitOnChainInfo(*info)
|
2021-04-27 18:48:32 +00:00
|
|
|
|
2020-09-20 21:53:46 +00:00
|
|
|
return &ret, nil
|
2020-09-15 04:55:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (s *state0) ForEachPrecommittedSector(cb func(minertypes.SectorPreCommitOnChainInfo) error) error {
|
2021-05-19 00:01:30 +00:00
|
|
|
precommitted, err := adt0.AsMap(s.store, s.State.PreCommittedSectors)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var info miner0.SectorPreCommitOnChainInfo
|
|
|
|
if err := precommitted.ForEach(&info, func(_ string) error {
|
|
|
|
return cb(fromV0SectorPreCommitOnChainInfo(info))
|
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-21 19:05:01 +00:00
|
|
|
func (s *state0) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) {
|
|
|
|
sectors, err := miner0.LoadSectors(s.store, s.State.Sectors)
|
2020-09-15 11:04:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-09-21 19:05:01 +00:00
|
|
|
// If no sector numbers are specified, load all.
|
|
|
|
if snos == nil {
|
|
|
|
infos := make([]*SectorOnChainInfo, 0, sectors.Length())
|
|
|
|
var info0 miner0.SectorOnChainInfo
|
2020-09-23 19:36:15 +00:00
|
|
|
if err := sectors.ForEach(&info0, func(_ int64) error {
|
2020-09-21 19:05:01 +00:00
|
|
|
info := fromV0SectorOnChainInfo(info0)
|
2020-09-23 19:36:15 +00:00
|
|
|
infos = append(infos, &info)
|
2020-09-21 19:05:01 +00:00
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
2020-09-15 11:04:45 +00:00
|
|
|
}
|
2020-09-21 19:05:01 +00:00
|
|
|
return infos, nil
|
2020-09-21 16:28:32 +00:00
|
|
|
}
|
2020-09-21 05:58:20 +00:00
|
|
|
|
2020-09-21 19:05:01 +00:00
|
|
|
// Otherwise, load selected.
|
|
|
|
infos0, err := sectors.Load(*snos)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
infos := make([]*SectorOnChainInfo, len(infos0))
|
|
|
|
for i, info0 := range infos0 {
|
|
|
|
info := fromV0SectorOnChainInfo(*info0)
|
|
|
|
infos[i] = &info
|
|
|
|
}
|
|
|
|
return infos, nil
|
2020-09-17 02:34:13 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 00:01:30 +00:00
|
|
|
func (s *state0) loadAllocatedSectorNumbers() (bitfield.BitField, error) {
|
2020-09-17 02:34:13 +00:00
|
|
|
var allocatedSectors bitfield.BitField
|
2021-05-19 00:01:30 +00:00
|
|
|
err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors)
|
|
|
|
return allocatedSectors, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *state0) IsAllocated(num abi.SectorNumber) (bool, error) {
|
|
|
|
allocatedSectors, err := s.loadAllocatedSectorNumbers()
|
|
|
|
if err != nil {
|
2020-09-17 02:34:13 +00:00
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return allocatedSectors.IsSet(uint64(num))
|
2020-09-15 11:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-05-15 01:11:23 +00:00
|
|
|
func (s *state0) GetProvingPeriodStart() (abi.ChainEpoch, error) {
|
|
|
|
return s.State.ProvingPeriodStart, nil
|
|
|
|
}
|
|
|
|
|
2021-05-19 00:01:30 +00:00
|
|
|
func (s *state0) UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error) {
|
|
|
|
allocatedSectors, err := s.loadAllocatedSectorNumbers()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
allocatedRuns, err := allocatedSectors.RunIterator()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
unallocatedRuns, err := rle.Subtract(
|
|
|
|
&rle.RunSliceIterator{Runs: []rle.Run{{Val: true, Len: abi.MaxSectorNumber}}},
|
|
|
|
allocatedRuns,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
iter, err := rle.BitsFromRuns(unallocatedRuns)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
sectors := make([]abi.SectorNumber, 0, count)
|
|
|
|
for iter.HasNext() && len(sectors) < count {
|
|
|
|
nextNo, err := iter.Next()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
sectors = append(sectors, abi.SectorNumber(nextNo))
|
|
|
|
}
|
|
|
|
|
|
|
|
return sectors, nil
|
|
|
|
}
|
|
|
|
|
2020-10-29 07:18:10 +00:00
|
|
|
func (s *state0) GetAllocatedSectors() (*bitfield.BitField, error) {
|
|
|
|
var allocatedSectors bitfield.BitField
|
|
|
|
if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &allocatedSectors, nil
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) LoadDeadline(idx uint64) (Deadline, error) {
|
2020-09-12 03:07:52 +00:00
|
|
|
dls, err := s.State.LoadDeadlines(s.store)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
dl, err := dls.LoadDeadline(s.store, idx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-18 21:59:27 +00:00
|
|
|
return &deadline0{*dl, s.store}, nil
|
2020-09-12 03:07:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) ForEachDeadline(cb func(uint64, Deadline) error) error {
|
2020-09-12 03:07:52 +00:00
|
|
|
dls, err := s.State.LoadDeadlines(s.store)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-18 21:59:27 +00:00
|
|
|
return dls.ForEach(s.store, func(i uint64, dl *miner0.Deadline) error {
|
|
|
|
return cb(i, &deadline0{*dl, s.store})
|
2020-09-12 03:07:52 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) NumDeadlines() (uint64, error) {
|
|
|
|
return miner0.WPoStPeriodDeadlines, nil
|
2020-09-12 03:07:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 05:19:43 +00:00
|
|
|
func (s *state0) DeadlinesChanged(other State) (bool, error) {
|
2020-09-18 21:59:27 +00:00
|
|
|
other0, ok := other.(*state0)
|
2020-09-18 04:39:34 +00:00
|
|
|
if !ok {
|
|
|
|
// treat an upgrade as a change, always
|
2020-09-23 05:19:43 +00:00
|
|
|
return true, nil
|
2020-09-18 04:39:34 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 21:27:35 +00:00
|
|
|
return !s.State.Deadlines.Equals(other0.Deadlines), nil
|
2020-09-18 04:39:34 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 21:20:25 +00:00
|
|
|
func (s *state0) MinerInfoChanged(other State) (bool, error) {
|
|
|
|
other0, ok := other.(*state0)
|
|
|
|
if !ok {
|
|
|
|
// treat an upgrade as a change, always
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
return !s.State.Info.Equals(other0.State.Info), nil
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) Info() (MinerInfo, error) {
|
2020-09-12 03:07:52 +00:00
|
|
|
info, err := s.State.GetInfo(s.store)
|
2020-09-14 11:14:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return MinerInfo{}, err
|
|
|
|
}
|
2020-09-12 03:07:52 +00:00
|
|
|
|
2021-01-16 06:42:56 +00:00
|
|
|
wpp, err := info.SealProofType.RegisteredWindowPoStProof()
|
|
|
|
if err != nil {
|
|
|
|
return MinerInfo{}, err
|
|
|
|
}
|
|
|
|
|
2020-09-12 03:07:52 +00:00
|
|
|
mi := MinerInfo{
|
|
|
|
Owner: info.Owner,
|
|
|
|
Worker: info.Worker,
|
|
|
|
ControlAddresses: info.ControlAddresses,
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
PendingWorkerKey: (*WorkerKeyChange)(info.PendingWorkerKey),
|
2020-09-12 03:07:52 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
PeerId: info.PeerId,
|
2020-09-12 03:07:52 +00:00
|
|
|
Multiaddrs: info.Multiaddrs,
|
2021-01-16 06:42:56 +00:00
|
|
|
WindowPoStProofType: wpp,
|
2020-09-12 03:07:52 +00:00
|
|
|
SectorSize: info.SectorSize,
|
|
|
|
WindowPoStPartitionSectors: info.WindowPoStPartitionSectors,
|
2020-10-06 08:33:55 +00:00
|
|
|
ConsensusFaultElapsed: -1,
|
2020-09-12 03:07:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 11:14:06 +00:00
|
|
|
return mi, nil
|
2020-09-12 03:07:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 05:19:43 +00:00
|
|
|
func (s *state0) DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) {
|
|
|
|
return s.State.DeadlineInfo(epoch), nil
|
2020-09-15 13:29:25 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 12:29:46 +00:00
|
|
|
func (s *state0) DeadlineCronActive() (bool, error) {
|
|
|
|
return true, nil // always active in this version
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) sectors() (adt.Array, error) {
|
|
|
|
return adt0.AsArray(s.store, s.Sectors)
|
2020-09-18 04:39:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) decodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) {
|
|
|
|
var si miner0.SectorOnChainInfo
|
2020-09-18 04:39:34 +00:00
|
|
|
err := si.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
2020-09-20 21:53:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return SectorOnChainInfo{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return fromV0SectorOnChainInfo(si), nil
|
2020-09-18 04:39:34 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) precommits() (adt.Map, error) {
|
|
|
|
return adt0.AsMap(s.store, s.PreCommittedSectors)
|
2020-09-18 04:39:34 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (s *state0) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (minertypes.SectorPreCommitOnChainInfo, error) {
|
2020-09-18 21:59:27 +00:00
|
|
|
var sp miner0.SectorPreCommitOnChainInfo
|
2020-09-18 04:39:34 +00:00
|
|
|
err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
2020-09-20 21:53:46 +00:00
|
|
|
if err != nil {
|
2022-04-20 21:34:28 +00:00
|
|
|
return minertypes.SectorPreCommitOnChainInfo{}, err
|
2020-09-20 21:53:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fromV0SectorPreCommitOnChainInfo(sp), nil
|
2020-09-18 04:39:34 +00:00
|
|
|
}
|
|
|
|
|
2021-05-15 01:11:23 +00:00
|
|
|
func (s *state0) EraseAllUnproven() error {
|
|
|
|
|
|
|
|
// field doesn't exist until v2
|
|
|
|
return nil
|
2021-08-06 21:56:29 +00:00
|
|
|
|
2021-05-15 01:11:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (d *deadline0) LoadPartition(idx uint64) (Partition, error) {
|
2020-09-12 03:07:52 +00:00
|
|
|
p, err := d.Deadline.LoadPartition(d.store, idx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-18 21:59:27 +00:00
|
|
|
return &partition0{*p, d.store}, nil
|
2020-09-12 03:07:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (d *deadline0) ForEachPartition(cb func(uint64, Partition) error) error {
|
2020-09-12 03:07:52 +00:00
|
|
|
ps, err := d.Deadline.PartitionsArray(d.store)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-18 21:59:27 +00:00
|
|
|
var part miner0.Partition
|
2020-09-12 03:07:52 +00:00
|
|
|
return ps.ForEach(&part, func(i int64) error {
|
2020-09-18 21:59:27 +00:00
|
|
|
return cb(uint64(i), &partition0{part, d.store})
|
2020-09-12 03:07:52 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-09-23 05:19:43 +00:00
|
|
|
func (d *deadline0) PartitionsChanged(other Deadline) (bool, error) {
|
2020-09-18 21:59:27 +00:00
|
|
|
other0, ok := other.(*deadline0)
|
2020-09-18 04:39:34 +00:00
|
|
|
if !ok {
|
|
|
|
// treat an upgrade as a change, always
|
2020-09-23 05:19:43 +00:00
|
|
|
return true, nil
|
2020-09-18 04:39:34 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 21:37:33 +00:00
|
|
|
return !d.Deadline.Partitions.Equals(other0.Deadline.Partitions), nil
|
2020-09-18 04:39:34 +00:00
|
|
|
}
|
|
|
|
|
2021-01-16 05:53:27 +00:00
|
|
|
func (d *deadline0) PartitionsPoSted() (bitfield.BitField, error) {
|
2020-09-17 15:30:15 +00:00
|
|
|
return d.Deadline.PostSubmissions, nil
|
|
|
|
}
|
|
|
|
|
2021-01-18 08:46:22 +00:00
|
|
|
func (d *deadline0) DisputableProofCount() (uint64, error) {
|
2021-04-30 15:51:24 +00:00
|
|
|
|
2021-01-18 08:46:22 +00:00
|
|
|
// field doesn't exist until v3
|
|
|
|
return 0, nil
|
2021-04-30 15:51:24 +00:00
|
|
|
|
2021-01-18 08:46:22 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (p *partition0) AllSectors() (bitfield.BitField, error) {
|
2020-09-12 03:07:52 +00:00
|
|
|
return p.Partition.Sectors, nil
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (p *partition0) FaultySectors() (bitfield.BitField, error) {
|
2020-09-12 03:07:52 +00:00
|
|
|
return p.Partition.Faults, nil
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (p *partition0) RecoveringSectors() (bitfield.BitField, error) {
|
2020-09-12 03:07:52 +00:00
|
|
|
return p.Partition.Recoveries, nil
|
|
|
|
}
|
2020-09-20 21:53:46 +00:00
|
|
|
|
2021-08-31 14:24:29 +00:00
|
|
|
func (p *partition0) UnprovenSectors() (bitfield.BitField, error) {
|
|
|
|
return bitfield.New(), nil
|
|
|
|
}
|
|
|
|
|
2020-09-20 21:53:46 +00:00
|
|
|
func fromV0SectorOnChainInfo(v0 miner0.SectorOnChainInfo) SectorOnChainInfo {
|
2021-11-18 23:35:06 +00:00
|
|
|
info := SectorOnChainInfo{
|
|
|
|
SectorNumber: v0.SectorNumber,
|
|
|
|
SealProof: v0.SealProof,
|
|
|
|
SealedCID: v0.SealedCID,
|
|
|
|
DealIDs: v0.DealIDs,
|
|
|
|
Activation: v0.Activation,
|
|
|
|
Expiration: v0.Expiration,
|
|
|
|
DealWeight: v0.DealWeight,
|
|
|
|
VerifiedDealWeight: v0.VerifiedDealWeight,
|
|
|
|
InitialPledge: v0.InitialPledge,
|
|
|
|
ExpectedDayReward: v0.ExpectedDayReward,
|
|
|
|
ExpectedStoragePledge: v0.ExpectedStoragePledge,
|
|
|
|
}
|
|
|
|
return info
|
2020-09-20 21:53:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func fromV0SectorPreCommitOnChainInfo(v0 miner0.SectorPreCommitOnChainInfo) minertypes.SectorPreCommitOnChainInfo {
|
|
|
|
return minertypes.SectorPreCommitOnChainInfo{
|
2022-09-06 15:49:29 +00:00
|
|
|
Info: minertypes.SectorPreCommitInfo{
|
|
|
|
SealProof: v0.Info.SealProof,
|
|
|
|
SectorNumber: v0.Info.SectorNumber,
|
|
|
|
SealedCID: v0.Info.SealedCID,
|
|
|
|
SealRandEpoch: v0.Info.SealRandEpoch,
|
|
|
|
DealIDs: v0.Info.DealIDs,
|
|
|
|
Expiration: v0.Info.Expiration,
|
|
|
|
UnsealedCid: nil,
|
|
|
|
},
|
|
|
|
PreCommitDeposit: v0.PreCommitDeposit,
|
|
|
|
PreCommitEpoch: v0.PreCommitEpoch,
|
2022-04-20 21:34:28 +00:00
|
|
|
}
|
2020-09-20 21:53:46 +00:00
|
|
|
}
|
2021-05-15 01:11:23 +00:00
|
|
|
|
|
|
|
func (s *state0) GetState() interface{} {
|
|
|
|
return &s.State
|
2020-09-20 21:53:46 +00:00
|
|
|
}
|