convert lotus-shed balances

This commit is contained in:
Steven Allen 2020-09-21 13:43:47 -07:00
parent a41bf74bad
commit 916421b247
3 changed files with 46 additions and 16 deletions

View File

@ -18,6 +18,15 @@ import (
"github.com/filecoin-project/lotus/chain/types"
)
// Returns true if the specified actor code ID is a miner actor.
func Is(code cid.Cid) bool {
switch code {
case builtin0.StorageMinerActorCodeID:
return true
}
return false
}
func Load(store adt.Store, act *types.Actor) (st State, err error) {
switch act.Code {
case builtin0.StorageMinerActorCodeID:
@ -46,6 +55,7 @@ type State interface {
GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error)
GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error)
LoadSectors(sectorNos *bitfield.BitField) ([]*SectorOnChainInfo, error)
NumLiveSectors() (uint64, error)
IsAllocated(abi.SectorNumber) (bool, error)
LoadDeadline(idx uint64) (Deadline, error)

View File

@ -79,6 +79,21 @@ func (s *state0) FindSector(num abi.SectorNumber) (*SectorLocation, error) {
}, nil
}
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
}
// GetSectorExpiration returns the effective expiration of the given sector.
//
// If the sector isn't found or has already been terminated, this method returns

View File

@ -12,6 +12,8 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/store"
@ -21,9 +23,6 @@ import (
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
"github.com/filecoin-project/lotus/lib/blockstore"
"github.com/filecoin-project/lotus/node/repo"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/util/adt"
)
type accountInfo struct {
@ -90,7 +89,7 @@ var chainBalanceCmd = &cli.Command{
Type: string(act.Code.Hash()[2:]),
}
if act.Code == builtin.StorageMinerActorCodeID {
if miner.Is(act.Code) {
pow, err := api.StateMinerPower(ctx, addr, tsk)
if err != nil {
return xerrors.Errorf("failed to get power: %w", err)
@ -167,6 +166,7 @@ var chainBalanceStateCmd = &cli.Command{
cs := store.NewChainStore(bs, mds, vm.Syscalls(ffiwrapper.ProofVerifier))
cst := cbor.NewCborStore(bs)
store := adt.WrapStore(ctx, cst)
sm := stmgr.NewStateManager(cs)
@ -191,7 +191,7 @@ var chainBalanceStateCmd = &cli.Command{
PreCommits: types.FIL(big.NewInt(0)),
}
if act.Code == builtin.StorageMinerActorCodeID && minerInfo {
if minerInfo && miner.Is(act.Code) {
pow, _, _, err := stmgr.GetPowerRaw(ctx, sm, sroot, addr)
if err != nil {
return xerrors.Errorf("failed to get power: %w", err)
@ -199,24 +199,29 @@ var chainBalanceStateCmd = &cli.Command{
ai.Power = pow.RawBytePower
var st miner.State
if err := cst.Get(ctx, act.Head, &st); err != nil {
st, err := miner.Load(store, act)
if err != nil {
return xerrors.Errorf("failed to read miner state: %w", err)
}
sectors, err := adt.AsArray(cs.Store(ctx), st.Sectors)
liveSectorCount, err := st.NumLiveSectors()
if err != nil {
return xerrors.Errorf("failed to load sector set: %w", err)
return xerrors.Errorf("failed to compute live sector count: %w", err)
}
ai.InitialPledge = types.FIL(st.InitialPledgeRequirement)
ai.LockedFunds = types.FIL(st.LockedFunds)
ai.PreCommits = types.FIL(st.PreCommitDeposits)
ai.Sectors = sectors.Length()
lockedFunds, err := st.LockedFunds()
if err != nil {
return xerrors.Errorf("failed to compute locked funds: %w", err)
}
var minfo miner.MinerInfo
if err := cst.Get(ctx, st.Info, &minfo); err != nil {
return xerrors.Errorf("failed to read miner info: %w", err)
ai.InitialPledge = types.FIL(lockedFunds.InitialPledgeRequirement)
ai.LockedFunds = types.FIL(lockedFunds.VestingFunds)
ai.PreCommits = types.FIL(lockedFunds.PreCommitDeposits)
ai.Sectors = liveSectorCount
minfo, err := st.Info()
if err != nil {
return xerrors.Errorf("failed to get miner info: %w", err)
}
ai.Worker = minfo.Worker