Get State API almost working
This commit is contained in:
parent
053cfc1cc7
commit
31ff5230bb
@ -325,6 +325,8 @@ type FullNode interface {
|
||||
StateMinerPower(context.Context, address.Address, types.TipSetKey) (*MinerPower, error)
|
||||
// StateMinerInfo returns info about the indicated miner
|
||||
StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error)
|
||||
// StateMinerDeadlines returns all the proving deadlines for the given miner
|
||||
StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]*miner.Deadline, error)
|
||||
// StateMinerFaults returns a bitfield indicating the faulty sectors of the given miner
|
||||
StateMinerFaults(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error)
|
||||
// StateAllMinerFaults returns all non-expired Faults that occur within lookback epochs of the given tipset
|
||||
|
@ -167,6 +167,7 @@ type FullNodeStruct struct {
|
||||
StateMinerProvingDeadline func(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) `perm:"read"`
|
||||
StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"`
|
||||
StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) `perm:"read"`
|
||||
StateMinerDeadlines func(context.Context, address.Address, types.TipSetKey) ([]*miner.Deadline, error) `perm:"read"`
|
||||
StateMinerFaults func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"`
|
||||
StateAllMinerFaults func(context.Context, abi.ChainEpoch, types.TipSetKey) ([]*api.Fault, error) `perm:"read"`
|
||||
StateMinerRecoveries func(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) `perm:"read"`
|
||||
@ -751,6 +752,10 @@ func (c *FullNodeStruct) StateMinerInfo(ctx context.Context, actor address.Addre
|
||||
return c.Internal.StateMinerInfo(ctx, actor, tsk)
|
||||
}
|
||||
|
||||
func (c *FullNodeStruct) StateMinerDeadlines(ctx context.Context, actor address.Address, tsk types.TipSetKey) ([]*miner.Deadline, error) {
|
||||
return c.Internal.StateMinerDeadlines(ctx, actor, tsk)
|
||||
}
|
||||
|
||||
func (c *FullNodeStruct) StateMinerFaults(ctx context.Context, actor address.Address, tsk types.TipSetKey) (bitfield.BitField, error) {
|
||||
return c.Internal.StateMinerFaults(ctx, actor, tsk)
|
||||
}
|
||||
|
@ -34,6 +34,9 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) {
|
||||
type State interface {
|
||||
cbor.Marshaler
|
||||
|
||||
AvailableBalance(abi.TokenAmount) (abi.TokenAmount, error)
|
||||
VestedFunds(abi.ChainEpoch) (abi.TokenAmount, error)
|
||||
|
||||
GetSector(abi.SectorNumber) (*SectorOnChainInfo, error)
|
||||
FindSector(abi.SectorNumber) (*SectorLocation, error)
|
||||
GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error)
|
||||
|
@ -31,6 +31,14 @@ type v0Partition struct {
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *v0State) AvailableBalance(bal abi.TokenAmount) (abi.TokenAmount, error) {
|
||||
return s.GetAvailableBalance(bal), nil
|
||||
}
|
||||
|
||||
func (s *v0State) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) {
|
||||
return s.CheckVestedFunds(s.store, epoch)
|
||||
}
|
||||
|
||||
func (s *v0State) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
|
||||
info, ok, err := s.State.GetSector(s.store, num)
|
||||
if !ok || err != nil {
|
||||
|
@ -31,5 +31,7 @@ type State interface {
|
||||
cbor.Marshaler
|
||||
|
||||
RewardSmoothed() (builtin.FilterEstimate, error)
|
||||
TotalStoragePowerReward() abi.TokenAmount
|
||||
EffectiveBaselinePower() (abi.StoragePower, error)
|
||||
ThisEpochBaselinePower() (abi.StoragePower, error)
|
||||
TotalStoragePowerReward() (abi.TokenAmount, error)
|
||||
}
|
||||
|
@ -16,6 +16,14 @@ func (s *v0State) RewardSmoothed() (builtin.FilterEstimate, error) {
|
||||
return *s.State.ThisEpochRewardSmoothed, nil
|
||||
}
|
||||
|
||||
func (s *v0State) TotalStoragePowerReward() abi.TokenAmount {
|
||||
return s.State.TotalMined
|
||||
func (s *v0State) TotalStoragePowerReward() (abi.TokenAmount, error) {
|
||||
return s.State.TotalMined, nil
|
||||
}
|
||||
|
||||
func (s *v0State) EffectiveBaselinePower() (abi.StoragePower, error) {
|
||||
return s.State.EffectiveBaselinePower, nil
|
||||
}
|
||||
|
||||
func (s *v0State) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
||||
return s.State.ThisEpochBaselinePower, nil
|
||||
}
|
||||
|
37
chain/actors/builtin/verifreg/v0.go
Normal file
37
chain/actors/builtin/verifreg/v0.go
Normal file
@ -0,0 +1,37 @@
|
||||
package verifreg
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
v0verifreg "github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
|
||||
v0adt "github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
)
|
||||
|
||||
type v0State struct {
|
||||
v0verifreg.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *v0State) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) {
|
||||
if addr.Protocol() != address.ID {
|
||||
return false, big.Zero(), xerrors.Errorf("can only look up ID addresses")
|
||||
}
|
||||
|
||||
vh, err := v0adt.AsMap(s.store, s.VerifiedClients)
|
||||
if err != nil {
|
||||
return false, big.Zero(), xerrors.Errorf("loading verified clients: %w", err)
|
||||
}
|
||||
|
||||
var dcap abi.StoragePower
|
||||
if found, err := vh.Get(abi.AddrKey(addr), &dcap); err != nil {
|
||||
return false, big.Zero(), xerrors.Errorf("looking up verified clients: %w", err)
|
||||
} else if !found {
|
||||
return false, big.Zero(), nil
|
||||
}
|
||||
|
||||
return true, dcap, nil
|
||||
}
|
34
chain/actors/builtin/verifreg/verifreg.go
Normal file
34
chain/actors/builtin/verifreg/verifreg.go
Normal file
@ -0,0 +1,34 @@
|
||||
package verifreg
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/cbor"
|
||||
v0builtin "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
var Address = v0builtin.VerifiedRegistryActorAddr
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
switch act.Code {
|
||||
case v0builtin.VerifiedRegistryActorCodeID:
|
||||
out := v0State{store: store}
|
||||
err := store.Get(store.Context(), act.Head, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
|
||||
type State interface {
|
||||
cbor.Marshaler
|
||||
|
||||
VerifiedClientDataCap(address.Address) (bool, abi.StoragePower, error)
|
||||
}
|
@ -2,6 +2,7 @@ package stmgr
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
|
@ -1029,7 +1029,7 @@ func GetFilMined(ctx context.Context, st *state.StateTree) (abi.TokenAmount, err
|
||||
return big.Zero(), xerrors.Errorf("failed to load reward state: %w", err)
|
||||
}
|
||||
|
||||
return rst.TotalStoragePowerReward(), nil
|
||||
return rst.TotalStoragePowerReward()
|
||||
}
|
||||
|
||||
func getFilMarketLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) {
|
||||
|
@ -9,6 +9,10 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
v0init "github.com/filecoin-project/specs-actors/actors/builtin/init"
|
||||
v0market "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||
v0power "github.com/filecoin-project/specs-actors/actors/builtin/power"
|
||||
|
||||
v0miner "github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||
|
||||
saruntime "github.com/filecoin-project/specs-actors/actors/runtime"
|
||||
@ -541,12 +545,12 @@ var MethodsMap = map[cid.Cid]map[abi.MethodNum]MethodMeta{}
|
||||
func init() {
|
||||
cidToMethods := map[cid.Cid][2]interface{}{
|
||||
// builtin.SystemActorCodeID: {builtin.MethodsSystem, system.Actor{} }- apparently it doesn't have methods
|
||||
builtin.InitActorCodeID: {builtin.MethodsInit, init_.Actor{}},
|
||||
builtin.InitActorCodeID: {builtin.MethodsInit, v0init.Actor{}},
|
||||
builtin.CronActorCodeID: {builtin.MethodsCron, cron.Actor{}},
|
||||
builtin.AccountActorCodeID: {builtin.MethodsAccount, account.Actor{}},
|
||||
builtin.StoragePowerActorCodeID: {builtin.MethodsPower, power.Actor{}},
|
||||
builtin.StorageMinerActorCodeID: {builtin.MethodsMiner, miner.Actor{}},
|
||||
builtin.StorageMarketActorCodeID: {builtin.MethodsMarket, market.Actor{}},
|
||||
builtin.StoragePowerActorCodeID: {builtin.MethodsPower, v0power.Actor{}},
|
||||
builtin.StorageMinerActorCodeID: {builtin.MethodsMiner, v0miner.Actor{}},
|
||||
builtin.StorageMarketActorCodeID: {builtin.MethodsMarket, v0market.Actor{}},
|
||||
builtin.PaymentChannelActorCodeID: {builtin.MethodsPaych, paych.Actor{}},
|
||||
builtin.MultisigActorCodeID: {builtin.MethodsMultisig, v0msig.Actor{}},
|
||||
builtin.RewardActorCodeID: {builtin.MethodsReward, v0reward.Actor{}},
|
||||
|
@ -1,7 +1,6 @@
|
||||
package sub
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -33,9 +33,9 @@ import (
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
lapi "github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/lib/tablewriter"
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
||||
)
|
||||
|
||||
var CidBaseFlag = cli.StringFlag{
|
||||
@ -417,7 +417,7 @@ var clientDealCmd = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
isVerified := dcap != nil
|
||||
isVerified := dcap != types.EmptyInt
|
||||
|
||||
// If the user has explicitly set the --verified-deal flag
|
||||
if cctx.IsSet("verified-deal") {
|
||||
@ -1044,8 +1044,8 @@ var clientListDeals = &cli.Command{
|
||||
func dealFromDealInfo(ctx context.Context, full api.FullNode, head *types.TipSet, v api.DealInfo) deal {
|
||||
if v.DealID == 0 {
|
||||
return deal{
|
||||
LocalDeal: v,
|
||||
OnChainDealState: *market.EmptyDealState()
|
||||
LocalDeal: v,
|
||||
OnChainDealState: *market.EmptyDealState(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ var provingFaultsCmd = &cli.Command{
|
||||
_, _ = fmt.Fprintln(tw, "deadline\tpartition\tsectors")
|
||||
err = mas.ForEachDeadline(func(dlIdx uint64, dl miner.Deadline) error {
|
||||
dl.ForEachPartition(func(partIdx uint64, part miner.Partition) error {
|
||||
faults, err := part.Faults()
|
||||
faults, err := part.FaultySectors()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -158,7 +158,7 @@ var provingInfoCmd = &cli.Command{
|
||||
}
|
||||
}
|
||||
|
||||
if bf, err := part.Faults(); err != nil {
|
||||
if bf, err := part.FaultySectors(); err != nil {
|
||||
return err
|
||||
} else if count, err := bf.Count(); err != nil {
|
||||
return err
|
||||
@ -166,7 +166,7 @@ var provingInfoCmd = &cli.Command{
|
||||
faults += count
|
||||
}
|
||||
|
||||
if bf, err := part.Recovering(); err != nil {
|
||||
if bf, err := part.RecoveringSectors(); err != nil {
|
||||
return err
|
||||
} else if count, err := bf.Count(); err != nil {
|
||||
return err
|
||||
@ -286,14 +286,14 @@ var provingDeadlinesCmd = &cli.Command{
|
||||
faults := uint64(0)
|
||||
|
||||
for _, partition := range partitions {
|
||||
sc, err := partition.Sectors.Count()
|
||||
sc, err := partition.AllSectors.Count()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sectors += sc
|
||||
|
||||
fc, err := partition.Faults.Count()
|
||||
fc, err := partition.FaultySectors.Count()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -8,8 +8,6 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
@ -362,12 +360,14 @@ func (n *ProviderNodeAdapter) WaitForMessage(ctx context.Context, mcid cid.Cid,
|
||||
return cb(receipt.Receipt.ExitCode, receipt.Receipt.Return, receipt.Message, nil)
|
||||
}
|
||||
|
||||
func (n *ProviderNodeAdapter) GetDataCap(ctx context.Context, addr address.Address, encodedTs shared.TipSetToken) (abi.StoragePower, error) {
|
||||
func (n *ProviderNodeAdapter) GetDataCap(ctx context.Context, addr address.Address, encodedTs shared.TipSetToken) (*abi.StoragePower, error) {
|
||||
tsk, err := types.TipSetKeyFromBytes(encodedTs)
|
||||
if err != nil {
|
||||
return big.Zero(), err
|
||||
return nil, err
|
||||
}
|
||||
return n.StateVerifiedClientStatus(ctx, addr, tsk)
|
||||
|
||||
sp, err := n.StateVerifiedClientStatus(ctx, addr, tsk)
|
||||
return &sp, err
|
||||
}
|
||||
|
||||
func (n *ProviderNodeAdapter) OnDealExpiredOrSlashed(ctx context.Context, dealID abi.DealID, onDealExpired storagemarket.DealExpiredCallback, onDealSlashed storagemarket.DealSlashedCallback) error {
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
v0market "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/verifreg"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/dline"
|
||||
@ -73,6 +75,11 @@ 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
|
||||
ts, err := a.Chain.GetTipSetFromKey(tsk)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
|
||||
}
|
||||
|
||||
act, err := a.StateManager.LoadActorTsk(ctx, maddr, tsk)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to load miner actor: %w", err)
|
||||
@ -88,7 +95,7 @@ func (a *StateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Ad
|
||||
return nil, xerrors.Errorf("merge partition active sets: %w", err)
|
||||
}
|
||||
|
||||
return mas.LoadSectorsFromSet(&activeSectors, false)
|
||||
return stmgr.GetMinerSectorSet(ctx, a.StateManager, ts, maddr, &activeSectors, false)
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) {
|
||||
@ -105,7 +112,7 @@ func (a *StateAPI) StateMinerInfo(ctx context.Context, actor address.Address, ts
|
||||
return mas.Info()
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]miner.Deadline, error) {
|
||||
func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]*miner.Deadline, error) {
|
||||
act, err := a.StateManager.LoadActorTsk(ctx, m, tsk)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to load miner actor: %w", err)
|
||||
@ -121,9 +128,9 @@ func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, t
|
||||
return nil, xerrors.Errorf("getting deadline count: %w", err)
|
||||
}
|
||||
|
||||
out := make([]miner.Deadline, deadlines)
|
||||
out := make([]*miner.Deadline, deadlines)
|
||||
if err := mas.ForEachDeadline(func(i uint64, dl miner.Deadline) error {
|
||||
out[i] = dl
|
||||
out[i] = &dl
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
@ -671,12 +678,18 @@ func (a *StateAPI) StateMinerSectorCount(ctx context.Context, addr address.Addre
|
||||
return api.MinerSectors{Live: liveCount, Active: activeCount, Faulty: faultyCount}, nil
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorPreCommitOnChainInfo, error) {
|
||||
func (a *StateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) {
|
||||
ts, err := a.Chain.GetTipSetFromKey(tsk)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
|
||||
return miner.SectorPreCommitOnChainInfo{}, xerrors.Errorf("loading tipset %s: %w", tsk, err)
|
||||
}
|
||||
return stmgr.PreCommitInfo(ctx, a.StateManager, maddr, n, ts)
|
||||
|
||||
pci, err := stmgr.PreCommitInfo(ctx, a.StateManager, maddr, n, ts)
|
||||
if err != nil {
|
||||
return miner.SectorPreCommitOnChainInfo{}, err
|
||||
}
|
||||
|
||||
return *pci, err
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateSectorGetInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorOnChainInfo, error) {
|
||||
@ -873,7 +886,7 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr
|
||||
// NB: not exactly accurate, but should always lead us to *over* estimate, not under
|
||||
duration := pci.Expiration - ts.Height()
|
||||
|
||||
// TODO: handle changes to this function across actor upgrades.
|
||||
// TODO: ActorUpgrade
|
||||
sectorWeight = v0miner.QAPowerForWeight(ssize, duration, w, vw)
|
||||
}
|
||||
|
||||
@ -899,8 +912,8 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr
|
||||
rewardSmoothed = r
|
||||
}
|
||||
|
||||
// TODO: abstract over network upgrades.
|
||||
deposit := v0miner.PreCommitDepositForPower(rewardSmoothed, powerSmoothed, sectorWeight)
|
||||
// TODO: ActorUpgrade
|
||||
deposit := v0miner.PreCommitDepositForPower(&rewardSmoothed, &powerSmoothed, sectorWeight)
|
||||
|
||||
return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil
|
||||
}
|
||||
@ -940,8 +953,8 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr
|
||||
}
|
||||
|
||||
var (
|
||||
powerSmoothed smoothing.FilterEstimate
|
||||
pledgeCollerateral abi.TokenAmount
|
||||
powerSmoothed smoothing.FilterEstimate
|
||||
pledgeCollateral abi.TokenAmount
|
||||
)
|
||||
if act, err := state.GetActor(power.Address); err != nil {
|
||||
return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err)
|
||||
@ -966,26 +979,26 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr
|
||||
return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err)
|
||||
} else if r, err := s.RewardSmoothed(); err != nil {
|
||||
return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err)
|
||||
} else if p, err := s.BaselinePower(); err != nil {
|
||||
} else if p, err := s.ThisEpochBaselinePower(); err != nil {
|
||||
return types.EmptyInt, xerrors.Errorf("failed to determine baseline power: %w", err)
|
||||
} else {
|
||||
rewardSmoothed = r
|
||||
baselinePower = p
|
||||
}
|
||||
|
||||
// TODO: abstract over network upgrades.
|
||||
|
||||
circSupply, err := a.StateCirculatingSupply(ctx, ts.Key())
|
||||
if err != nil {
|
||||
return big.Zero(), xerrors.Errorf("getting circulating supply: %w", err)
|
||||
}
|
||||
|
||||
initialPledge := miner.InitialPledgeForPower(
|
||||
// TODO: ActorUpgrade
|
||||
|
||||
initialPledge := v0miner.InitialPledgeForPower(
|
||||
sectorWeight,
|
||||
baselinePower,
|
||||
pledgeCollateral,
|
||||
rewardSmoothed,
|
||||
powerSmoothed,
|
||||
&rewardSmoothed,
|
||||
&powerSmoothed,
|
||||
circSupply.FilCirculating,
|
||||
)
|
||||
|
||||
@ -998,23 +1011,27 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address
|
||||
return types.EmptyInt, xerrors.Errorf("loading tipset %s: %w", tsk, err)
|
||||
}
|
||||
|
||||
var act *types.Actor
|
||||
var mas miner.State
|
||||
|
||||
if err := a.StateManager.WithParentState(ts, a.StateManager.WithActor(maddr, func(actor *types.Actor) error {
|
||||
act = actor
|
||||
return a.StateManager.WithActorState(ctx, &mas)(actor)
|
||||
})); err != nil {
|
||||
return types.BigInt{}, xerrors.Errorf("getting miner state: %w", err)
|
||||
act, err := a.StateManager.LoadActor(ctx, maddr, ts)
|
||||
if err != nil {
|
||||
return types.EmptyInt, xerrors.Errorf("failed to load miner actor: %w", err)
|
||||
}
|
||||
as := store.ActorStore(ctx, a.Chain.Blockstore())
|
||||
|
||||
vested, err := mas.CheckVestedFunds(as, ts.Height())
|
||||
mas, err := miner.Load(a.StateManager.ChainStore().Store(ctx), act)
|
||||
if err != nil {
|
||||
return types.EmptyInt, xerrors.Errorf("failed to load miner actor state: %w", err)
|
||||
}
|
||||
|
||||
vested, err := mas.VestedFunds(ts.Height())
|
||||
if err != nil {
|
||||
return types.EmptyInt, err
|
||||
}
|
||||
|
||||
return types.BigAdd(mas.GetAvailableBalance(act.Balance), vested), nil
|
||||
abal, err := mas.AvailableBalance(act.Balance)
|
||||
if err != nil {
|
||||
return types.EmptyInt, err
|
||||
}
|
||||
|
||||
return types.BigAdd(abal, vested), nil
|
||||
}
|
||||
|
||||
// StateVerifiedClientStatus returns the data cap for the given address.
|
||||
@ -1023,23 +1040,23 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address
|
||||
func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (abi.StoragePower, error) {
|
||||
act, err := a.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, tsk)
|
||||
if err != nil {
|
||||
return big.Zero(), err
|
||||
return types.EmptyInt, err
|
||||
}
|
||||
|
||||
aid, err := a.StateLookupID(ctx, addr, tsk)
|
||||
if err != nil {
|
||||
log.Warnf("lookup failure %v", err)
|
||||
return big.Zero(), err
|
||||
return types.EmptyInt, err
|
||||
}
|
||||
|
||||
vrs, err := verifreg.Load(a.StateManager.ChainStore().Store(ctx), act)
|
||||
if err != nil {
|
||||
return big.Zero(), xerrors.Errorf("failed to load verified registry state: %w", err)
|
||||
return types.EmptyInt, xerrors.Errorf("failed to load verified registry state: %w", err)
|
||||
}
|
||||
|
||||
_, dcap, err := vrs.VerifiedClientDataCap(aid)
|
||||
if err != nil {
|
||||
return big.Zero(), xerrors.Errorf("looking up verified client: %w", err)
|
||||
return types.EmptyInt, xerrors.Errorf("looking up verified client: %w", err)
|
||||
}
|
||||
|
||||
return dcap, nil
|
||||
@ -1056,23 +1073,24 @@ func (a *StateAPI) StateDealProviderCollateralBounds(ctx context.Context, size a
|
||||
return api.DealCollateralBounds{}, xerrors.Errorf("loading tipset %s: %w", tsk, err)
|
||||
}
|
||||
|
||||
var powerState power.State
|
||||
var rewardState reward.State
|
||||
|
||||
err = a.StateManager.WithParentStateTsk(ts.Key(), func(state *state.StateTree) error {
|
||||
if err := a.StateManager.WithActor(builtin.StoragePowerActorAddr, a.StateManager.WithActorState(ctx, &powerState))(state); err != nil {
|
||||
return xerrors.Errorf("getting power state: %w", err)
|
||||
}
|
||||
|
||||
if err := a.StateManager.WithActor(builtin.RewardActorAddr, a.StateManager.WithActorState(ctx, &rewardState))(state); err != nil {
|
||||
return xerrors.Errorf("getting reward state: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
pact, err := a.StateGetActor(ctx, builtin.StoragePowerActorAddr, tsk)
|
||||
if err != nil {
|
||||
return api.DealCollateralBounds{}, xerrors.Errorf("getting power and reward actor states: %w", err)
|
||||
return api.DealCollateralBounds{}, xerrors.Errorf("failed to load power actor: %w", err)
|
||||
}
|
||||
|
||||
ract, err := a.StateGetActor(ctx, builtin.RewardActorAddr, tsk)
|
||||
if err != nil {
|
||||
return api.DealCollateralBounds{}, xerrors.Errorf("failed to load reward actor: %w", err)
|
||||
}
|
||||
|
||||
pst, err := power.Load(a.StateManager.ChainStore().Store(ctx), pact)
|
||||
if err != nil {
|
||||
return api.DealCollateralBounds{}, xerrors.Errorf("failed to load power actor state: %w", err)
|
||||
}
|
||||
|
||||
rst, err := reward.Load(a.StateManager.ChainStore().Store(ctx), ract)
|
||||
if err != nil {
|
||||
return api.DealCollateralBounds{}, xerrors.Errorf("failed to load reward actor state: %w", err)
|
||||
}
|
||||
|
||||
circ, err := a.StateCirculatingSupply(ctx, ts.Key())
|
||||
@ -1080,11 +1098,21 @@ func (a *StateAPI) StateDealProviderCollateralBounds(ctx context.Context, size a
|
||||
return api.DealCollateralBounds{}, xerrors.Errorf("getting total circulating supply: %w", err)
|
||||
}
|
||||
|
||||
min, max := market.DealProviderCollateralBounds(size,
|
||||
powClaim, err := pst.TotalPower()
|
||||
if err != nil {
|
||||
return api.DealCollateralBounds{}, xerrors.Errorf("getting total power: %w", err)
|
||||
}
|
||||
|
||||
rewPow, err := rst.ThisEpochBaselinePower()
|
||||
if err != nil {
|
||||
return api.DealCollateralBounds{}, xerrors.Errorf("getting reward baseline power: %w", err)
|
||||
}
|
||||
|
||||
min, max := v0market.DealProviderCollateralBounds(size,
|
||||
verified,
|
||||
powerState.TotalRawBytePower,
|
||||
powerState.ThisEpochQualityAdjPower,
|
||||
rewardState.ThisEpochBaselinePower,
|
||||
powClaim.RawBytePower,
|
||||
powClaim.QualityAdjPower,
|
||||
rewPow,
|
||||
circ.FilCirculating,
|
||||
a.StateManager.GetNtwkVersion(ctx, ts.Height()))
|
||||
return api.DealCollateralBounds{
|
||||
@ -1109,7 +1137,7 @@ func (a *StateAPI) StateCirculatingSupply(ctx context.Context, tsk types.TipSetK
|
||||
func (a *StateAPI) StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (network.Version, error) {
|
||||
ts, err := a.Chain.GetTipSetFromKey(tsk)
|
||||
if err != nil {
|
||||
return -1, xerrors.Errorf("loading tipset %s: %w", tsk, err)
|
||||
return network.VersionMax, xerrors.Errorf("loading tipset %s: %w", tsk, err)
|
||||
}
|
||||
|
||||
return a.StateManager.GetNtwkVersion(ctx, ts.Height()), nil
|
||||
|
@ -328,7 +328,7 @@ func (sm *StorageMinerAPI) listDeals(ctx context.Context) ([]api.MarketDeal, err
|
||||
}
|
||||
|
||||
func (sm *StorageMinerAPI) MarketListDeals(ctx context.Context) ([]api.MarketDeal, error) {
|
||||
return sm.StorageProvider.listDeals(ctx)
|
||||
return sm.listDeals(ctx)
|
||||
}
|
||||
|
||||
func (sm *StorageMinerAPI) MarketListRetrievalDeals(ctx context.Context) ([]retrievalmarket.ProviderDealState, error) {
|
||||
|
@ -84,7 +84,7 @@ func (s SealingAPIAdapter) StateMinerWorkerAddress(ctx context.Context, maddr ad
|
||||
return mi.Worker, nil
|
||||
}
|
||||
|
||||
func (s SealingAPIAdapter) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) ([]miner.Deadline, error) {
|
||||
func (s SealingAPIAdapter) StateMinerDeadlines(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) ([]*miner.Deadline, error) {
|
||||
tsk, err := types.TipSetKeyFromBytes(tok)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err)
|
||||
@ -251,7 +251,7 @@ func (s SealingAPIAdapter) StateMarketStorageDeal(ctx context.Context, dealID ab
|
||||
func (s SealingAPIAdapter) StateNetworkVersion(ctx context.Context, tok sealing.TipSetToken) (network.Version, error) {
|
||||
tsk, err := types.TipSetKeyFromBytes(tok)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
return network.VersionMax, err
|
||||
}
|
||||
|
||||
return s.delegate.StateNetworkVersion(ctx, tsk)
|
||||
|
@ -3,12 +3,13 @@ package storage
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
@ -27,7 +28,7 @@ type addrSelectApi interface {
|
||||
StateAccountKey(context.Context, address.Address, types.TipSetKey) (address.Address, error)
|
||||
}
|
||||
|
||||
func AddressFor(ctx context.Context, a addrSelectApi, mi api.MinerInfo, use AddrUse, minFunds abi.TokenAmount) (address.Address, error) {
|
||||
func AddressFor(ctx context.Context, a addrSelectApi, mi miner.MinerInfo, use AddrUse, minFunds abi.TokenAmount) (address.Address, error) {
|
||||
switch use {
|
||||
case PreCommitAddr, CommitAddr:
|
||||
// always use worker, at least for now
|
||||
|
@ -76,7 +76,7 @@ type storageMinerApi interface {
|
||||
StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error)
|
||||
StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error)
|
||||
StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error)
|
||||
StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]miner.Deadline, error)
|
||||
StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]*miner.Deadline, error)
|
||||
StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error)
|
||||
StateMinerPreCommitDepositForPower(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error)
|
||||
StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (types.BigInt, error)
|
||||
|
@ -4,8 +4,6 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/dline"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
|
Loading…
Reference in New Issue
Block a user