abstract over deal collateral

This commit is contained in:
Steven Allen 2020-09-30 13:30:24 -07:00
parent 35e606d397
commit 8dcbd525da
2 changed files with 28 additions and 12 deletions

View File

@ -2,12 +2,15 @@ package policy
import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/chain/actors"
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
power0 "github.com/filecoin-project/specs-actors/actors/builtin/power"
verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
verifreg2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg"
)
@ -79,3 +82,18 @@ func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) ab
panic("unsupported actors version")
}
}
func DealProviderCollateralBounds(
size abi.PaddedPieceSize, verified bool,
rawBytePower, qaPower, baselinePower abi.StoragePower,
circulatingFil abi.TokenAmount, nwVer network.Version,
) (min, max abi.TokenAmount) {
switch actors.VersionForNetwork(nwVer) {
case actors.Version0:
return market0.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer)
case actors.Version2:
return market2.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil)
default:
panic("unsupported network version")
}
}

View File

@ -5,10 +5,8 @@ import (
"context"
"strconv"
lotusbuiltin "github.com/filecoin-project/lotus/chain/actors/builtin"
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/policy"
"github.com/filecoin-project/lotus/chain/actors/builtin/verifreg"
@ -883,10 +881,10 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr
} else {
// NB: not exactly accurate, but should always lead us to *over* estimate, not under
duration := pci.Expiration - ts.Height()
sectorWeight = lotusbuiltin.QAPowerForWeight(ssize, duration, w, vw)
sectorWeight = builtin.QAPowerForWeight(ssize, duration, w, vw)
}
var powerSmoothed lotusbuiltin.FilterEstimate
var powerSmoothed builtin.FilterEstimate
if act, err := state.GetActor(power.Address); err != nil {
return types.EmptyInt, xerrors.Errorf("loading power actor: %w", err)
} else if s, err := power.Load(store, act); err != nil {
@ -944,11 +942,11 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr
} else {
// NB: not exactly accurate, but should always lead us to *over* estimate, not under
duration := pci.Expiration - ts.Height()
sectorWeight = lotusbuiltin.QAPowerForWeight(ssize, duration, w, vw)
sectorWeight = builtin.QAPowerForWeight(ssize, duration, w, vw)
}
var (
powerSmoothed lotusbuiltin.FilterEstimate
powerSmoothed builtin.FilterEstimate
pledgeCollateral abi.TokenAmount
)
if act, err := state.GetActor(power.Address); err != nil {
@ -1025,7 +1023,7 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address
// Returns zero if there is no entry in the data cap table for the
// address.
func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) {
act, err := a.StateGetActor(ctx, builtin0.VerifiedRegistryActorAddr, tsk)
act, err := a.StateGetActor(ctx, verifreg.Address, tsk)
if err != nil {
return nil, err
}
@ -1063,12 +1061,12 @@ func (a *StateAPI) StateDealProviderCollateralBounds(ctx context.Context, size a
return api.DealCollateralBounds{}, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}
pact, err := a.StateGetActor(ctx, builtin0.StoragePowerActorAddr, tsk)
pact, err := a.StateGetActor(ctx, power.Address, tsk)
if err != nil {
return api.DealCollateralBounds{}, xerrors.Errorf("failed to load power actor: %w", err)
}
ract, err := a.StateGetActor(ctx, builtin0.RewardActorAddr, tsk)
ract, err := a.StateGetActor(ctx, reward.Address, tsk)
if err != nil {
return api.DealCollateralBounds{}, xerrors.Errorf("failed to load reward actor: %w", err)
}
@ -1098,7 +1096,7 @@ func (a *StateAPI) StateDealProviderCollateralBounds(ctx context.Context, size a
return api.DealCollateralBounds{}, xerrors.Errorf("getting reward baseline power: %w", err)
}
min, max := market0.DealProviderCollateralBounds(size,
min, max := policy.DealProviderCollateralBounds(size,
verified,
powClaim.RawBytePower,
powClaim.QualityAdjPower,