Abstract FilterEstimate, PreCommitDepositForPower, and InitialPledgeForPower
This commit is contained in:
parent
35bce5a5c6
commit
7c3f638f68
@ -3,9 +3,9 @@ package builtin
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/network"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
|
|
||||||
smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing"
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Version int
|
type Version int
|
||||||
@ -24,5 +24,8 @@ func VersionForNetwork(version network.Version) Version {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: find some way to abstract over this.
|
// TODO: Why does actors have 2 different versions of this?
|
||||||
type FilterEstimate = smoothing0.FilterEstimate
|
type FilterEstimate struct {
|
||||||
|
PositionEstimate big.Int
|
||||||
|
VelocityEstimate big.Int
|
||||||
|
}
|
||||||
|
@ -53,7 +53,10 @@ func (s *state0) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) TotalPowerSmoothed() (builtin.FilterEstimate, error) {
|
func (s *state0) TotalPowerSmoothed() (builtin.FilterEstimate, error) {
|
||||||
return *s.State.ThisEpochQAPowerSmoothed, nil
|
return builtin.FilterEstimate{
|
||||||
|
PositionEstimate: s.State.ThisEpochQAPowerSmoothed.PositionEstimate,
|
||||||
|
VelocityEstimate: s.State.ThisEpochQAPowerSmoothed.VelocityEstimate,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) MinerCounts() (uint64, uint64, error) {
|
func (s *state0) MinerCounts() (uint64, uint64, error) {
|
||||||
|
@ -41,4 +41,7 @@ type State interface {
|
|||||||
|
|
||||||
CumsumBaseline() (abi.StoragePower, error)
|
CumsumBaseline() (abi.StoragePower, error)
|
||||||
CumsumRealized() (abi.StoragePower, error)
|
CumsumRealized() (abi.StoragePower, error)
|
||||||
|
|
||||||
|
InitialPledgeForPower(abi.StoragePower, abi.TokenAmount, *builtin.FilterEstimate, abi.TokenAmount) (abi.TokenAmount, error)
|
||||||
|
PreCommitDepositForPower(builtin.FilterEstimate, abi.StoragePower) (abi.TokenAmount, error)
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,10 @@ package reward
|
|||||||
import (
|
import (
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
|
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin/reward"
|
"github.com/filecoin-project/specs-actors/actors/builtin/reward"
|
||||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/util/smoothing"
|
||||||
)
|
)
|
||||||
|
|
||||||
type state0 struct {
|
type state0 struct {
|
||||||
@ -17,7 +19,10 @@ func (s *state0) ThisEpochReward() (abi.StoragePower, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
func (s *state0) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
||||||
return *s.State.ThisEpochRewardSmoothed, nil
|
return builtin.FilterEstimate{
|
||||||
|
PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate,
|
||||||
|
VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
func (s *state0) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
||||||
@ -43,3 +48,25 @@ func (s *state0) CumsumBaseline() (abi.StoragePower, error) {
|
|||||||
func (s *state0) CumsumRealized() (abi.StoragePower, error) {
|
func (s *state0) CumsumRealized() (abi.StoragePower, error) {
|
||||||
return s.State.CumsumBaseline, nil
|
return s.State.CumsumBaseline, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *state0) InitialPledgeForPower(sectorWeight abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount) (abi.TokenAmount, error) {
|
||||||
|
return miner0.InitialPledgeForPower(
|
||||||
|
sectorWeight,
|
||||||
|
s.State.ThisEpochBaselinePower,
|
||||||
|
networkTotalPledge,
|
||||||
|
s.State.ThisEpochRewardSmoothed,
|
||||||
|
&smoothing.FilterEstimate{
|
||||||
|
PositionEstimate: networkQAPower.PositionEstimate,
|
||||||
|
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||||
|
},
|
||||||
|
circSupply), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state0) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, sectorWeight abi.StoragePower) (abi.TokenAmount, error) {
|
||||||
|
return miner0.PreCommitDepositForPower(s.State.ThisEpochRewardSmoothed,
|
||||||
|
&smoothing.FilterEstimate{
|
||||||
|
PositionEstimate: networkQAPower.PositionEstimate,
|
||||||
|
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||||
|
},
|
||||||
|
sectorWeight), nil
|
||||||
|
}
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
builtin2 "github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
|
|
||||||
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/verifreg"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/verifreg"
|
||||||
@ -26,7 +28,6 @@ import (
|
|||||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||||
"github.com/filecoin-project/specs-actors/actors/util/smoothing"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
||||||
@ -924,7 +925,7 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr
|
|||||||
sectorWeight = miner0.QAPowerForWeight(ssize, duration, w, vw)
|
sectorWeight = miner0.QAPowerForWeight(ssize, duration, w, vw)
|
||||||
}
|
}
|
||||||
|
|
||||||
var powerSmoothed smoothing.FilterEstimate
|
var powerSmoothed builtin2.FilterEstimate
|
||||||
if act, err := state.GetActor(power.Address); err != nil {
|
if act, err := state.GetActor(power.Address); err != nil {
|
||||||
return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err)
|
return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err)
|
||||||
} else if s, err := power.Load(store, act); err != nil {
|
} else if s, err := power.Load(store, act); err != nil {
|
||||||
@ -935,19 +936,20 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr
|
|||||||
powerSmoothed = p
|
powerSmoothed = p
|
||||||
}
|
}
|
||||||
|
|
||||||
var rewardSmoothed smoothing.FilterEstimate
|
rewardActor, err := state.GetActor(reward.Address)
|
||||||
if act, err := state.GetActor(reward.Address); err != nil {
|
if err != nil {
|
||||||
return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err)
|
return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err)
|
||||||
} else if s, err := reward.Load(store, act); err != nil {
|
|
||||||
return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err)
|
|
||||||
} else if r, err := s.ThisEpochRewardSmoothed(); err != nil {
|
|
||||||
return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err)
|
|
||||||
} else {
|
|
||||||
rewardSmoothed = r
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: ActorUpgrade
|
rewardState, err := reward.Load(store, rewardActor)
|
||||||
deposit := miner0.PreCommitDepositForPower(&rewardSmoothed, &powerSmoothed, sectorWeight)
|
if err != nil {
|
||||||
|
return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
deposit, err := rewardState.PreCommitDepositForPower(powerSmoothed, sectorWeight)
|
||||||
|
if err != nil {
|
||||||
|
return big.Zero(), xerrors.Errorf("calculating precommit deposit: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil
|
return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil
|
||||||
}
|
}
|
||||||
@ -982,12 +984,12 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr
|
|||||||
// NB: not exactly accurate, but should always lead us to *over* estimate, not under
|
// NB: not exactly accurate, but should always lead us to *over* estimate, not under
|
||||||
duration := pci.Expiration - ts.Height()
|
duration := pci.Expiration - ts.Height()
|
||||||
|
|
||||||
// TODO: handle changes to this function across actor upgrades.
|
// TODO: ActorUpgrade
|
||||||
sectorWeight = miner0.QAPowerForWeight(ssize, duration, w, vw)
|
sectorWeight = miner0.QAPowerForWeight(ssize, duration, w, vw)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
powerSmoothed smoothing.FilterEstimate
|
powerSmoothed builtin2.FilterEstimate
|
||||||
pledgeCollateral abi.TokenAmount
|
pledgeCollateral abi.TokenAmount
|
||||||
)
|
)
|
||||||
if act, err := state.GetActor(power.Address); err != nil {
|
if act, err := state.GetActor(power.Address); err != nil {
|
||||||
@ -1003,21 +1005,14 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr
|
|||||||
pledgeCollateral = c
|
pledgeCollateral = c
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
rewardActor, err := state.GetActor(reward.Address)
|
||||||
rewardSmoothed smoothing.FilterEstimate
|
if err != nil {
|
||||||
baselinePower abi.StoragePower
|
|
||||||
)
|
|
||||||
if act, err := state.GetActor(reward.Address); err != nil {
|
|
||||||
return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err)
|
return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err)
|
||||||
} else if s, err := reward.Load(store, act); err != nil {
|
}
|
||||||
|
|
||||||
|
rewardState, err := reward.Load(store, rewardActor)
|
||||||
|
if err != nil {
|
||||||
return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err)
|
return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err)
|
||||||
} else if r, err := s.ThisEpochRewardSmoothed(); err != nil {
|
|
||||||
return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err)
|
|
||||||
} 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
circSupply, err := a.StateCirculatingSupply(ctx, ts.Key())
|
circSupply, err := a.StateCirculatingSupply(ctx, ts.Key())
|
||||||
@ -1025,16 +1020,15 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr
|
|||||||
return big.Zero(), xerrors.Errorf("getting circulating supply: %w", err)
|
return big.Zero(), xerrors.Errorf("getting circulating supply: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: ActorUpgrade
|
initialPledge, err := rewardState.InitialPledgeForPower(
|
||||||
|
|
||||||
initialPledge := miner0.InitialPledgeForPower(
|
|
||||||
sectorWeight,
|
sectorWeight,
|
||||||
baselinePower,
|
|
||||||
pledgeCollateral,
|
pledgeCollateral,
|
||||||
&rewardSmoothed,
|
|
||||||
&powerSmoothed,
|
&powerSmoothed,
|
||||||
circSupply.FilCirculating,
|
circSupply.FilCirculating,
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
return big.Zero(), xerrors.Errorf("calculating initial pledge: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return types.BigDiv(types.BigMul(initialPledge, initialPledgeNum), initialPledgeDen), nil
|
return types.BigDiv(types.BigMul(initialPledge, initialPledgeNum), initialPledgeDen), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user