state api impl fixes
This commit is contained in:
parent
4dabab5ce6
commit
4419850195
@ -20,11 +20,11 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/power"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
|
||||
"github.com/filecoin-project/specs-actors/actors/runtime/proof"
|
||||
|
||||
miner2 "github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/power"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
marketevents "github.com/filecoin-project/lotus/markets/loggers"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
|
@ -1,6 +1,7 @@
|
||||
package miner
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-state-types/dline"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
@ -41,6 +42,8 @@ type State interface {
|
||||
ForEachDeadline(cb func(idx uint64, dl Deadline) error) error
|
||||
NumDeadlines() (uint64, error)
|
||||
Info() (MinerInfo, error)
|
||||
|
||||
DeadlineInfo(epoch abi.ChainEpoch) *dline.Info
|
||||
}
|
||||
|
||||
type Deadline interface {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-bitfield"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/dline"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
v0adt "github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
@ -142,6 +143,10 @@ func (s *v0State) Info() (MinerInfo, error) {
|
||||
return mi, nil
|
||||
}
|
||||
|
||||
func (s *v0State) DeadlineInfo(epoch abi.ChainEpoch) *dline.Info {
|
||||
return s.State.DeadlineInfo(epoch)
|
||||
}
|
||||
|
||||
func (d *v0Deadline) LoadPartition(idx uint64) (Partition, error) {
|
||||
p, err := d.Deadline.LoadPartition(d.store, idx)
|
||||
if err != nil {
|
||||
|
@ -30,7 +30,7 @@ type State interface {
|
||||
|
||||
TotalLocked() (abi.TokenAmount, error)
|
||||
TotalPower() (Claim, error)
|
||||
MinerPower(address.Address) (Claim, error)
|
||||
MinerPower(address.Address) (Claim, bool, error)
|
||||
MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error)
|
||||
}
|
||||
|
||||
|
@ -23,19 +23,20 @@ func (s *v0State) TotalPower() (Claim, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *v0State) MinerPower(addr address.Address) (Claim, error) {
|
||||
func (s *v0State) MinerPower(addr address.Address) (Claim, bool, error) {
|
||||
claims, err := adt.AsMap(s.store, s.Claims)
|
||||
if err != nil {
|
||||
return Claim{}, err
|
||||
return Claim{}, false, err
|
||||
}
|
||||
var claim power.Claim
|
||||
if _, err := claims.Get(abi.AddrKey(addr), &claim); err != nil {
|
||||
return Claim{}, err
|
||||
ok, err := claims.Get(abi.AddrKey(addr), &claim)
|
||||
if err != nil {
|
||||
return Claim{}, false, err
|
||||
}
|
||||
return Claim{
|
||||
RawBytePower: claim.RawBytePower,
|
||||
QualityAdjPower: claim.QualityAdjPower,
|
||||
}, nil
|
||||
}, ok, nil
|
||||
}
|
||||
|
||||
func (s *v0State) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) {
|
||||
|
@ -26,7 +26,6 @@ import (
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/account"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/cron"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/reward"
|
||||
@ -36,6 +35,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||
"github.com/filecoin-project/lotus/chain/beacon"
|
||||
"github.com/filecoin-project/lotus/chain/state"
|
||||
@ -257,17 +257,11 @@ func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, ma
|
||||
return false, xerrors.Errorf("failed to load power actor state: %w", err)
|
||||
}
|
||||
|
||||
store := sm.cs.Store(ctx)
|
||||
|
||||
claims, err := adt.AsMap(store, spas.Claims)
|
||||
_, ok, err := spas.MinerPower(maddr)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return false, xerrors.Errorf("getting miner power: %w", err)
|
||||
}
|
||||
|
||||
ok, err := claims.Get(abi.AddrKey(maddr), nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !ok {
|
||||
return true, nil
|
||||
}
|
||||
|
@ -71,127 +71,121 @@ func (a *StateAPI) StateMinerSectors(ctx context.Context, addr address.Address,
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*miner.ChainSectorInfo, error) { // TODO: only used in cli
|
||||
var out []*miner.ChainSectorInfo
|
||||
|
||||
err := a.StateManager.WithParentStateTsk(tsk,
|
||||
a.StateManager.WithActor(maddr,
|
||||
a.StateManager.WithActorState(ctx, func(store adt.Store, mas *miner.State) error {
|
||||
var allActive []bitfield.BitField
|
||||
|
||||
err := a.StateManager.WithDeadlines(
|
||||
a.StateManager.WithEachDeadline(
|
||||
a.StateManager.WithEachPartition(func(store adt.Store, partIdx uint64, partition *miner.Partition) error {
|
||||
active, err := partition.ActiveSectors()
|
||||
act, err := a.StateManager.LoadActorTsk(ctx, maddr, tsk)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("partition.ActiveSectors: %w", err)
|
||||
return nil, xerrors.Errorf("failed to load miner actor: %w", err)
|
||||
}
|
||||
|
||||
allActive = append(allActive, active)
|
||||
return nil
|
||||
})))(store, mas)
|
||||
mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("with deadlines: %w", err)
|
||||
return nil, xerrors.Errorf("failed to load miner actor state: %w", err)
|
||||
}
|
||||
|
||||
active, err := bitfield.MultiMerge(allActive...)
|
||||
activeSectors, err := miner.AllPartSectors(mas, miner.Partition.ActiveSectors)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("merging active sector bitfields: %w", err)
|
||||
return nil, xerrors.Errorf("merge partition active sets: %w", err)
|
||||
}
|
||||
|
||||
out, err = stmgr.LoadSectorsFromSet(ctx, a.Chain.Blockstore(), mas.Sectors, &active, false)
|
||||
return err
|
||||
})))
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("getting active sectors from partitions: %w", err)
|
||||
}
|
||||
|
||||
return out, nil
|
||||
return mas.LoadSectorsFromSet(&activeSectors, false)
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (api.MinerInfo, error) {
|
||||
ts, err := a.Chain.GetTipSetFromKey(tsk)
|
||||
func (a *StateAPI) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) {
|
||||
act, err := a.StateManager.LoadActorTsk(ctx, actor, tsk)
|
||||
if err != nil {
|
||||
return api.MinerInfo{}, xerrors.Errorf("loading tipset %s: %w", tsk, err)
|
||||
return miner.MinerInfo{}, xerrors.Errorf("failed to load miner actor: %w", err)
|
||||
}
|
||||
|
||||
a.StateManager.LoadActorStateRaw(ctx context.Context, addr address.Address, out interface{}, st cid.Cid)
|
||||
|
||||
mi, err := stmgr.StateMinerInfo(ctx, a.StateManager, ts, actor)
|
||||
mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act)
|
||||
if err != nil {
|
||||
return api.MinerInfo{}, err
|
||||
return miner.MinerInfo{}, xerrors.Errorf("failed to load miner actor state: %w", err)
|
||||
}
|
||||
return api.NewApiMinerInfo(mi), nil
|
||||
|
||||
return mas.Info()
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]miner.Deadline, error) {
|
||||
var out []*miner.Deadline
|
||||
state, err := a.StateManager.LoadParentStateTsk(tsk)
|
||||
act, err := a.StateManager.LoadActorTsk(ctx, m, tsk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("failed to load miner actor: %w", err)
|
||||
}
|
||||
act, err := state.GetActor(addr)
|
||||
|
||||
mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("failed to load miner actor state: %w", err)
|
||||
}
|
||||
mas, err := miner.Load(a.Chain.Store(ctx), act)
|
||||
|
||||
deadlines, err := mas.NumDeadlines()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("getting deadline count: %w", err)
|
||||
}
|
||||
var deadlines []miner.Deadline
|
||||
if err := mas.ForEachDeadline(func(_ uint64, dl miner.Deadline) error {
|
||||
deadlines = append(deadlines, dl)
|
||||
|
||||
out := make([]miner.Deadline, deadlines)
|
||||
if err := mas.ForEachDeadline(func(i uint64, dl miner.Deadline) error {
|
||||
out[i] = dl
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
return deadlines, nil
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerPartitions(ctx context.Context, m address.Address, dlIdx uint64, tsk types.TipSetKey) ([]*miner.Partition, error) {
|
||||
act, err := a.StateManager.LoadActorTsk(ctx, m, tsk)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to load miner actor: %w", err)
|
||||
}
|
||||
|
||||
mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to load miner actor state: %w", err)
|
||||
}
|
||||
|
||||
dl, err := mas.LoadDeadline(dlIdx)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to load the deadline: %w", err)
|
||||
}
|
||||
|
||||
var out []*miner.Partition
|
||||
return out, a.StateManager.WithParentStateTsk(tsk,
|
||||
a.StateManager.WithActor(m,
|
||||
a.StateManager.WithActorState(ctx,
|
||||
a.StateManager.WithDeadlines(
|
||||
a.StateManager.WithDeadline(dlIdx,
|
||||
a.StateManager.WithEachPartition(func(store adt.Store, partIdx uint64, partition *miner.Partition) error {
|
||||
out = append(out, partition)
|
||||
err = dl.ForEachPartition(func(_ uint64, part miner.Partition) error {
|
||||
p := part
|
||||
out = append(out, &p)
|
||||
return nil
|
||||
}))))))
|
||||
})
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*dline.Info, error) {
|
||||
ts, err := a.Chain.GetTipSetFromKey(tsk)
|
||||
ts, err := a.StateManager.ChainStore().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)
|
||||
act, err := a.StateManager.LoadActor(ctx, addr, ts)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err)
|
||||
return nil, xerrors.Errorf("failed to load miner actor: %w", err)
|
||||
}
|
||||
|
||||
mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to load miner actor state: %w", err)
|
||||
}
|
||||
|
||||
return mas.DeadlineInfo(ts.Height()).NextNotElapsed(), nil
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerFaults(ctx context.Context, addr address.Address, tsk types.TipSetKey) (bitfield.BitField, error) {
|
||||
out := bitfield.New()
|
||||
|
||||
err := a.StateManager.WithParentStateTsk(tsk,
|
||||
a.StateManager.WithActor(addr,
|
||||
a.StateManager.WithActorState(ctx,
|
||||
a.StateManager.WithDeadlines(
|
||||
a.StateManager.WithEachDeadline(
|
||||
a.StateManager.WithEachPartition(func(store adt.Store, idx uint64, partition *miner.Partition) (err error) {
|
||||
out, err = bitfield.MergeBitFields(out, partition.Faults)
|
||||
return err
|
||||
}))))))
|
||||
act, err := a.StateManager.LoadActorTsk(ctx, addr, tsk)
|
||||
if err != nil {
|
||||
return bitfield.BitField{}, err
|
||||
return bitfield.BitField{}, xerrors.Errorf("failed to load miner actor: %w", err)
|
||||
}
|
||||
|
||||
return out, err
|
||||
mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act)
|
||||
if err != nil {
|
||||
return bitfield.BitField{}, xerrors.Errorf("failed to load miner actor state: %w", err)
|
||||
}
|
||||
|
||||
return miner.AllPartSectors(mas, miner.Partition.FaultySectors)
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateAllMinerFaults(ctx context.Context, lookback abi.ChainEpoch, endTsk types.TipSetKey) ([]*api.Fault, error) {
|
||||
@ -238,22 +232,17 @@ func (a *StateAPI) StateAllMinerFaults(ctx context.Context, lookback abi.ChainEp
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerRecoveries(ctx context.Context, addr address.Address, tsk types.TipSetKey) (bitfield.BitField, error) {
|
||||
out := bitfield.New()
|
||||
|
||||
err := a.StateManager.WithParentStateTsk(tsk,
|
||||
a.StateManager.WithActor(addr,
|
||||
a.StateManager.WithActorState(ctx,
|
||||
a.StateManager.WithDeadlines(
|
||||
a.StateManager.WithEachDeadline(
|
||||
a.StateManager.WithEachPartition(func(store adt.Store, idx uint64, partition *miner.Partition) (err error) {
|
||||
out, err = bitfield.MergeBitFields(out, partition.Recoveries)
|
||||
return err
|
||||
}))))))
|
||||
act, err := a.StateManager.LoadActorTsk(ctx, addr, tsk)
|
||||
if err != nil {
|
||||
return bitfield.BitField{}, err
|
||||
return bitfield.BitField{}, xerrors.Errorf("failed to load miner actor: %w", err)
|
||||
}
|
||||
|
||||
return out, err
|
||||
mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act)
|
||||
if err != nil {
|
||||
return bitfield.BitField{}, xerrors.Errorf("failed to load miner actor state: %w", err)
|
||||
}
|
||||
|
||||
return miner.AllPartSectors(mas, miner.Partition.RecoveringSectors)
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerPower(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*api.MinerPower, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user