From 0c8b451a00c485a84371932ea4fd6695fad54fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sat, 18 Jul 2020 14:54:21 +0200 Subject: [PATCH] fix miner info --- api/api_full.go | 4 +-- api/apistruct/struct.go | 4 +-- cmd/lotus-storage-miner/info.go | 10 +++---- node/impl/full/state.go | 46 ++++++++++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index fc1d70d0f..9821b4557 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -374,8 +374,8 @@ type FileRef struct { } type MinerSectors struct { - Sset uint64 - Pset uint64 + Sectors uint64 + Active uint64 } type SectorExpiration struct { diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 89edc1762..326e98453 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -127,7 +127,7 @@ type FullNodeStruct struct { StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"` StateMinerSectors func(context.Context, address.Address, *abi.BitField, bool, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` - StateMinerProvingSet func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` + StateMinerActiveSectors func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*miner.DeadlineInfo, error) `perm:"read"` StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"` StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error) `perm:"read"` @@ -585,7 +585,7 @@ func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Add } func (c *FullNodeStruct) StateMinerActiveSectors(ctx context.Context, addr address.Address, tsk types.TipSetKey) ([]*api.ChainSectorInfo, error) { - return c.Internal.StateMinerProvingSet(ctx, addr, tsk) + return c.Internal.StateMinerActiveSectors(ctx, addr, tsk) } func (c *FullNodeStruct) StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*miner.DeadlineInfo, error) { diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index 7dff5b36c..6a8574c65 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -106,16 +106,16 @@ var infoCmd = &cli.Command{ return xerrors.Errorf("counting faults: %w", err) } - fmt.Printf("\tCommitted: %s\n", types.SizeStr(types.BigMul(types.NewInt(secCounts.Sset), types.NewInt(uint64(mi.SectorSize))))) + fmt.Printf("\tCommitted: %s\n", types.SizeStr(types.BigMul(types.NewInt(secCounts.Sectors), types.NewInt(uint64(mi.SectorSize))))) if nfaults == 0 { - fmt.Printf("\tProving: %s\n", types.SizeStr(types.BigMul(types.NewInt(secCounts.Pset), types.NewInt(uint64(mi.SectorSize))))) + fmt.Printf("\tProving: %s\n", types.SizeStr(types.BigMul(types.NewInt(secCounts.Active), types.NewInt(uint64(mi.SectorSize))))) } else { var faultyPercentage float64 - if secCounts.Sset != 0 { - faultyPercentage = float64(10000*nfaults/secCounts.Sset) / 100. + if secCounts.Sectors != 0 { + faultyPercentage = float64(10000*nfaults/secCounts.Sectors) / 100. } fmt.Printf("\tProving: %s (%s Faulty, %.2f%%)\n", - types.SizeStr(types.BigMul(types.NewInt(secCounts.Pset), types.NewInt(uint64(mi.SectorSize)))), + types.SizeStr(types.BigMul(types.NewInt(secCounts.Sectors), types.NewInt(uint64(mi.SectorSize)))), types.SizeStr(types.BigMul(types.NewInt(nfaults), types.NewInt(uint64(mi.SectorSize)))), faultyPercentage) } diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 4163ab2ef..e8932c78b 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -668,7 +668,51 @@ func (a *StateAPI) StateChangedActors(ctx context.Context, old cid.Cid, new cid. } func (a *StateAPI) StateMinerSectorCount(ctx context.Context, addr address.Address, tsk types.TipSetKey) (api.MinerSectors, error) { - return api.MinerSectors{}, xerrors.Errorf("TODO: FIXME") // TODO + var out api.MinerSectors + + err := a.StateManager.WithParentStateTsk(tsk, + a.StateManager.WithActor(addr, + a.StateManager.WithActorState(ctx, func(store adt.Store, mas *miner.State) error { + var allActive []*abi.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() + if err != nil { + return xerrors.Errorf("partition.ActiveSectors: %w", err) + } + + allActive = append(allActive, active) + return nil + })))(store, mas) + if err != nil { + return xerrors.Errorf("with deadlines: %w", err) + } + + active, err := bitfield.MultiMerge(allActive...) + if err != nil { + return xerrors.Errorf("merging active sector bitfields: %w", err) + } + + out.Active, err = active.Count() + if err != nil { + return xerrors.Errorf("counting active sectors: %w", err) + } + + sarr, err := adt.AsArray(store, mas.Sectors) + if err != nil { + return err + } + + out.Sectors = sarr.Length() + return nil + }))) + if err != nil { + return api.MinerSectors{}, err + } + + return out, nil } func (a *StateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) {