diff --git a/api/api_full.go b/api/api_full.go index 2a95c33a6..a1b9a8215 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -118,6 +118,7 @@ type FullNode interface { StateNetworkName(context.Context) (dtypes.NetworkName, error) StateMinerSectors(context.Context, address.Address, *abi.BitField, types.TipSetKey) ([]*ChainSectorInfo, error) + StateMinerProvingSet(context.Context, address.Address, types.TipSetKey) ([]*ChainSectorInfo, error) StateMinerPower(context.Context, address.Address, types.TipSetKey) (*MinerPower, error) StateMinerWorker(context.Context, address.Address, types.TipSetKey) (address.Address, error) StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) (*miner.Deadlines, error) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 92451abc7..672e5a638 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -114,11 +114,12 @@ type FullNodeStruct struct { StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"` StateMinerSectors func(context.Context, address.Address, *abi.BitField, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` + StateMinerProvingSet func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"` StateMinerWorker func(context.Context, address.Address, types.TipSetKey) (address.Address, error) `perm:"read"` StateMinerPeerID func(ctx context.Context, m address.Address, tsk types.TipSetKey) (peer.ID, error) `perm:"read"` StateMinerSectorSize func(context.Context, address.Address, types.TipSetKey) (abi.SectorSize, error) `perm:"read"` - StateMinerDeadlines func(context.Context, address.Address, types.TipSetKey) (*miner.Deadlines, error) + StateMinerDeadlines func(context.Context, address.Address, types.TipSetKey) (*miner.Deadlines, error) `perm:"read"` StateMinerFaults func(context.Context, address.Address, types.TipSetKey) ([]abi.SectorNumber, error) `perm:"read"` StateSectorPreCommitInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) `perm:"read"` StateCall func(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) `perm:"read"` @@ -483,6 +484,10 @@ func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Add return c.Internal.StateMinerSectors(ctx, addr, filter, tsk) } +func (c *FullNodeStruct) StateMinerProvingSet(ctx context.Context, addr address.Address, tsk types.TipSetKey) ([]*api.ChainSectorInfo, error) { + return c.Internal.StateMinerProvingSet(ctx, addr, tsk) +} + func (c *FullNodeStruct) StateMinerPower(ctx context.Context, a address.Address, tsk types.TipSetKey) (*api.MinerPower, error) { return c.Internal.StateMinerPower(ctx, a, tsk) } diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 4fcf5aa7d..96f877d9b 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -371,6 +371,20 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch, return root, trace, nil } +func GetProvingSetRaw(ctx context.Context, sm *StateManager, mas miner.State) ([]*api.ChainSectorInfo, error) { + notProving, err := abi.BitFieldUnion(mas.Faults, mas.Recoveries, mas.NewSectors) + if err != nil { + return nil, err + } + + provset, err := LoadSectorsFromSet(ctx, sm.cs.Blockstore(), mas.Sectors, ¬Proving) + if err != nil { + return nil, xerrors.Errorf("failed to get proving set: %w", err) + } + + return provset, nil +} + func MinerGetBaseInfo(ctx context.Context, sm *StateManager, tsk types.TipSetKey, maddr address.Address) (*api.MiningBaseInfo, error) { ts, err := sm.ChainStore().LoadTipSet(tsk) if err != nil { @@ -388,16 +402,11 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, tsk types.TipSetKey return nil, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) } - notProving, err := abi.BitFieldUnion(mas.Faults, mas.Recoveries, mas.NewSectors) + provset, err := GetProvingSetRaw(ctx, sm, mas) if err != nil { return nil, err } - provset, err := LoadSectorsFromSet(ctx, sm.cs.Blockstore(), mas.Sectors, ¬Proving) - if err != nil { - return nil, xerrors.Errorf("failed to get proving set: %w", err) - } - mpow, tpow, err := getPowerRaw(ctx, sm, st, maddr) if err != nil { return nil, xerrors.Errorf("failed to get power: %w", err) diff --git a/cli/state.go b/cli/state.go index da5cb8c09..3abb8f23b 100644 --- a/cli/state.go +++ b/cli/state.go @@ -225,7 +225,7 @@ var stateSectorsCmd = &cli.Command{ return err } - sectors, err := api.StateMinerSectors(ctx, maddr, ts.Key()) + sectors, err := api.StateMinerSectors(ctx, maddr, nil, ts.Key()) if err != nil { return err } diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 2dad67f91..9cf850f49 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -57,6 +57,21 @@ func (a *StateAPI) StateMinerSectors(ctx context.Context, addr address.Address, return stmgr.GetMinerSectorSet(ctx, a.StateManager, ts, addr, filter) } +func (a *StateAPI) StateMinerProvingSet(ctx context.Context, addr address.Address, tsk types.TipSetKey) ([]*api.ChainSectorInfo, error) { + ts, err := a.Chain.GetTipSetFromKey(tsk) + if err != nil { + return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) + } + + var mas miner.State + _, err = a.StateManager.LoadActorState(ctx, addr, &mas, ts) + if err != nil { + return nil, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err) + } + + return stmgr.GetProvingSetRaw(ctx, a.StateManager, mas) +} + func (a *StateAPI) StateMinerWorker(ctx context.Context, m address.Address, tsk types.TipSetKey) (address.Address, error) { ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { @@ -97,6 +112,23 @@ func (a *StateAPI) StateMinerFaults(ctx context.Context, addr address.Address, t return stmgr.GetMinerFaults(ctx, a.StateManager, ts, addr) } +func (a *StateAPI) StateMinerPower(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*api.MinerPower, error) { + ts, err := a.Chain.GetTipSetFromKey(tsk) + if err != nil { + return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err) + } + + m, net, err := stmgr.GetPower(ctx, a.StateManager, ts, addr) + if err != nil { + return nil, err + } + + return &api.MinerPower{ + MinerPower: m, + TotalPower: net, + }, nil +} + func (a *StateAPI) StatePledgeCollateral(ctx context.Context, tsk types.TipSetKey) (types.BigInt, error) { /*ts, err := a.Chain.GetTipSetFromKey(tsk) if err != nil { diff --git a/storage/miner.go b/storage/miner.go index a88c76ff5..7b4fdc88d 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -51,8 +51,7 @@ type storageMinerApi interface { StateCall(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) StateMinerWorker(context.Context, address.Address, types.TipSetKey) (address.Address, error) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok types.TipSetKey) (*miner.Deadlines, error) - StateMinerSectors(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) - StateMinerProvingSet(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) + StateMinerSectors(context.Context, address.Address, *abi.BitField, types.TipSetKey) ([]*api.ChainSectorInfo, error) StateMinerSectorSize(context.Context, address.Address, types.TipSetKey) (abi.SectorSize, error) StateSectorPreCommitInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) StateWaitMsg(context.Context, cid.Cid) (*api.MsgLookup, error) // TODO: removeme eventually