Api getting correct sector expiration info
This commit is contained in:
parent
5a3ab5c5f0
commit
bdc8f7a2cb
@ -269,7 +269,11 @@ type FullNode interface {
|
||||
// StateSectorPreCommitInfo returns the PreCommit info for the specified miner's sector
|
||||
StateSectorPreCommitInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error)
|
||||
// StateSectorGetInfo returns the on-chain info for the specified miner's sector
|
||||
// NOTE: returned info.Expiration may not be accurate in some cases, use StateSectorExpiration to get accurate
|
||||
// expiration epoch
|
||||
StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error)
|
||||
// StateSectorExpiration returns epoch at which given sector will expire
|
||||
StateSectorExpiration(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*SectorExpiration, error)
|
||||
// StateSectorPartition finds deadline/partition with the specified sector
|
||||
StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*SectorLocation, error)
|
||||
StatePledgeCollateral(context.Context, types.TipSetKey) (types.BigInt, error)
|
||||
@ -362,6 +366,14 @@ type MinerSectors struct {
|
||||
Pset uint64
|
||||
}
|
||||
|
||||
type SectorExpiration struct {
|
||||
OnTime abi.ChainEpoch
|
||||
|
||||
// non-zero if sector is faulty, epoch at which it will it will be
|
||||
// permanently removed if it doesn't recover
|
||||
Early abi.ChainEpoch
|
||||
}
|
||||
|
||||
type SectorLocation struct {
|
||||
Deadline uint64
|
||||
Partition uint64
|
||||
|
@ -140,6 +140,7 @@ type FullNodeStruct struct {
|
||||
StateMinerAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"`
|
||||
StateSectorPreCommitInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) `perm:"read"`
|
||||
StateSectorGetInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) `perm:"read"`
|
||||
StateSectorExpiration func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*api.SectorExpiration, error) `perm:"read"`
|
||||
StateSectorPartition func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*api.SectorLocation, error) `perm:"read"`
|
||||
StateCall func(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) `perm:"read"`
|
||||
StateReplay func(context.Context, types.TipSetKey, cid.Cid) (*api.InvocResult, error) `perm:"read"`
|
||||
@ -630,6 +631,10 @@ func (c *FullNodeStruct) StateSectorGetInfo(ctx context.Context, maddr address.A
|
||||
return c.Internal.StateSectorGetInfo(ctx, maddr, n, tsk)
|
||||
}
|
||||
|
||||
func (c *FullNodeStruct) StateSectorExpiration(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*api.SectorExpiration, error) {
|
||||
return c.Internal.StateSectorExpiration(ctx, maddr, n, tsk)
|
||||
}
|
||||
|
||||
func (c *FullNodeStruct) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*api.SectorLocation, error) {
|
||||
return c.Internal.StateSectorPartition(ctx, maddr, sectorNumber, tok)
|
||||
}
|
||||
|
@ -83,14 +83,14 @@ func TestCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
||||
// Validate upgrade
|
||||
|
||||
{
|
||||
si, err := client.StateSectorGetInfo(ctx, maddr, CC, types.EmptyTSK)
|
||||
exp, err := client.StateSectorExpiration(ctx, maddr, CC, types.EmptyTSK)
|
||||
require.NoError(t, err)
|
||||
require.Greater(t, 50000, int(si.Expiration))
|
||||
require.Greater(t, 50000, int(exp.OnTime))
|
||||
}
|
||||
{
|
||||
si, err := client.StateSectorGetInfo(ctx, maddr, Upgraded, types.EmptyTSK)
|
||||
exp, err := client.StateSectorExpiration(ctx, maddr, Upgraded, types.EmptyTSK)
|
||||
require.NoError(t, err)
|
||||
require.Less(t, 50000, int(si.Expiration))
|
||||
require.Less(t, 50000, int(exp.OnTime))
|
||||
}
|
||||
|
||||
fmt.Println("shutting down mining")
|
||||
|
@ -654,13 +654,13 @@ func (a *StateAPI) StateSectorGetInfo(ctx context.Context, maddr address.Address
|
||||
return stmgr.MinerSectorInfo(ctx, a.StateManager, maddr, n, ts)
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*api.SectorLocation, error) {
|
||||
var found *api.SectorLocation
|
||||
type sectorPartitionCb func(store adt.Store, mas *miner.State, di uint64, pi uint64, part *miner.Partition) error
|
||||
|
||||
err := a.StateManager.WithParentStateTsk(tsk,
|
||||
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,
|
||||
a.StateManager.WithDeadlines(func(store adt.Store, deadlines *miner.Deadlines) error {
|
||||
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))
|
||||
@ -668,10 +668,10 @@ func (a *StateAPI) StateSectorPartition(ctx context.Context, maddr address.Addre
|
||||
return xerrors.Errorf("is set: %w", err)
|
||||
}
|
||||
if set {
|
||||
found = &api.SectorLocation{
|
||||
Deadline: di,
|
||||
Partition: pi,
|
||||
if err := cb(store, mas, di, pi, partition); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return errBreakForeach
|
||||
}
|
||||
return nil
|
||||
@ -681,7 +681,65 @@ func (a *StateAPI) StateSectorPartition(ctx context.Context, maddr address.Addre
|
||||
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) {
|
||||
var onTimeEpoch, earlyEpoch abi.ChainEpoch
|
||||
|
||||
err := a.sectorPartition(ctx, maddr, sectorNumber, tsk, func(store adt.Store, mas *miner.State, di uint64, pi uint64, part *miner.Partition) error {
|
||||
quant := mas.QuantEndOfDeadline()
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if onTimeEpoch == 0 {
|
||||
return nil, xerrors.Errorf("expiration for sector %d not found", 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) {
|
||||
var found *api.SectorLocation
|
||||
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user