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