Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 101 additions & 16 deletions chain/actors/builtin/miner/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,41 @@ package miner

import (
"github.com/ipfs/go-cid"
actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/chain/actors"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/abi"
actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/go-state-types/big"
gstbuiltin "github.com/filecoin-project/go-state-types/builtin"
minertypes13 "github.com/filecoin-project/go-state-types/builtin/v13/miner"
{{- range .versions}}
{{- if (ge . 16)}}
minertypes{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/miner"
smoothing{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/util/smoothing"
{{- end -}}
{{end}}
minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/go-state-types/dline"
"github.com/filecoin-project/go-state-types/manifest"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/go-state-types/proof"
{{- range .versions}}
{{- if (le . 7)}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
{{- end -}}
{{end}}

"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/types"
minertypes16 "github.com/filecoin-project/go-state-types/builtin/v16/miner"
minertypes13 "github.com/filecoin-project/go-state-types/builtin/v13/miner"
minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner"
"github.com/filecoin-project/go-state-types/manifest"

{{range .versions}}
{{if (le . 7)}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
{{end}}
{{end}}
)

var Methods = gstbuiltin.MethodsMiner

func Load(store adt.Store, act *types.Actor) (State, error) {
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
if name != manifest.MinerKey {
Expand Down Expand Up @@ -81,6 +89,7 @@ type State interface {
// Funds locked for various reasons.
LockedFunds() (LockedFunds, error)
FeeDebt() (abi.TokenAmount, error)
InitialPledge() (abi.TokenAmount, error)

// Returns nil, nil if sector is not found
GetSector(abi.SectorNumber) (*SectorOnChainInfo, error)
Expand Down Expand Up @@ -155,7 +164,7 @@ type Partition interface {
UnprovenSectors() (bitfield.BitField, error)
}

type SectorOnChainInfo = minertypes16.SectorOnChainInfo
type SectorOnChainInfo = minertypes{{.latestVersion}}.SectorOnChainInfo

func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.RegisteredPoStProof, configWantSynthetic bool) (abi.RegisteredSealProof, error) {
// We added support for the new proofs in network version 7, and removed support for the old
Expand Down Expand Up @@ -252,13 +261,16 @@ type SectorClaim = minertypes.SectorClaim
type ExpirationExtension2 = minertypes.ExpirationExtension2
type CompactPartitionsParams = minertypes.CompactPartitionsParams
type WithdrawBalanceParams = minertypes.WithdrawBalanceParams
type MaxTerminationFeeParams = minertypes{{.latestVersion}}.MaxTerminationFeeParams
type MaxTerminationFeeReturn = minertypes{{.latestVersion}}.MaxTerminationFeeReturn
type InitialPledgeReturn = minertypes{{.latestVersion}}.InitialPledgeReturn

type PieceActivationManifest = minertypes13.PieceActivationManifest
type ProveCommitSectors3Params = minertypes13.ProveCommitSectors3Params
type SectorActivationManifest = minertypes13.SectorActivationManifest
type ProveReplicaUpdates3Params = minertypes13.ProveReplicaUpdates3Params
type SectorUpdateManifest = minertypes13.SectorUpdateManifest
type SectorOnChainInfoFlags = minertypes16.SectorOnChainInfoFlags
type SectorOnChainInfoFlags = minertypes{{.latestVersion}}.SectorOnChainInfoFlags
type VerifiedAllocationKey = minertypes13.VerifiedAllocationKey

var QAPowerMax = minertypes.QAPowerMax
Expand All @@ -274,6 +286,9 @@ const FaultDeclarationCutoff = minertypes.FaultDeclarationCutoff
const MinAggregatedSectors = minertypes.MinAggregatedSectors
const MinSectorExpiration = minertypes.MinSectorExpiration

var TermFeePledgeMultiple = minertypes{{.latestVersion}}.TermFeePledgeMultiple
var TermFeeMaxFaultFeeMultiple = minertypes{{.latestVersion}}.TermFeeMaxFaultFeeMultiple

type SectorExpiration struct {
OnTime abi.ChainEpoch

Expand Down Expand Up @@ -319,3 +334,73 @@ func AllCodes() []cid.Cid {
{{- end}}
}
}

func PledgePenaltyForContinuedFault(
nwVer network.Version,
rewardEstimate builtin.FilterEstimate,
networkQaPowerEstimate builtin.FilterEstimate,
qaSectorPower abi.StoragePower,
) (abi.TokenAmount, error) {
v, err := actorstypes.VersionForNetwork(nwVer)
if err != nil {
return big.Zero(), err
}

if v <= actorstypes.Version16 {
return minertypes16.PledgePenaltyForContinuedFault(
smoothing16.FilterEstimate{
PositionEstimate: rewardEstimate.PositionEstimate,
VelocityEstimate: rewardEstimate.VelocityEstimate,
},
smoothing16.FilterEstimate{
PositionEstimate: networkQaPowerEstimate.PositionEstimate,
VelocityEstimate: networkQaPowerEstimate.VelocityEstimate,
},
qaSectorPower,
), nil
}

switch v {
{{- range .versions}}
{{- if (gt . 16)}}
case actorstypes.Version{{.}}:
return minertypes{{.}}.PledgePenaltyForContinuedFault(
smoothing{{.}}.FilterEstimate{
PositionEstimate: rewardEstimate.PositionEstimate,
VelocityEstimate: rewardEstimate.VelocityEstimate,
},
smoothing{{.}}.FilterEstimate{
PositionEstimate: networkQaPowerEstimate.PositionEstimate,
VelocityEstimate: networkQaPowerEstimate.VelocityEstimate,
},
qaSectorPower,
), nil
{{- end}}
{{- end}}
default:
return big.Zero(), xerrors.Errorf("unsupported network version: %d", v)
}
}

func PledgePenaltyForTermination(
nwVer network.Version,
initialPledge abi.TokenAmount,
sectorAge abi.ChainEpoch,
faultFee abi.TokenAmount,
) (abi.TokenAmount, error) {
v, err := actorstypes.VersionForNetwork(nwVer)
if err != nil {
return big.Zero(), err
}

switch v {
{{- range .versions}}
{{- if (ge . 16)}}
case actorstypes.Version{{.}}:
return minertypes{{.}}.PledgePenaltyForTermination(initialPledge, sectorAge, faultFee), nil
{{- end}}
{{- end}}
default:
return big.Zero(), xerrors.Errorf("unsupported network version: %d", v)
}
}
62 changes: 62 additions & 0 deletions chain/actors/builtin/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/filecoin-project/go-state-types/abi"
actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/go-state-types/big"
gstbuiltin "github.com/filecoin-project/go-state-types/builtin"
minertypes13 "github.com/filecoin-project/go-state-types/builtin/v13/miner"
minertypes16 "github.com/filecoin-project/go-state-types/builtin/v16/miner"
smoothing16 "github.com/filecoin-project/go-state-types/builtin/v16/util/smoothing"
minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/go-state-types/dline"
Expand All @@ -27,9 +29,12 @@ import (

"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/types"
)

var Methods = gstbuiltin.MethodsMiner

func Load(store adt.Store, act *types.Actor) (State, error) {
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
if name != manifest.MinerKey {
Expand Down Expand Up @@ -165,6 +170,7 @@ type State interface {
// Funds locked for various reasons.
LockedFunds() (LockedFunds, error)
FeeDebt() (abi.TokenAmount, error)
InitialPledge() (abi.TokenAmount, error)

// Returns nil, nil if sector is not found
GetSector(abi.SectorNumber) (*SectorOnChainInfo, error)
Expand Down Expand Up @@ -336,6 +342,9 @@ type SectorClaim = minertypes.SectorClaim
type ExpirationExtension2 = minertypes.ExpirationExtension2
type CompactPartitionsParams = minertypes.CompactPartitionsParams
type WithdrawBalanceParams = minertypes.WithdrawBalanceParams
type MaxTerminationFeeParams = minertypes16.MaxTerminationFeeParams
type MaxTerminationFeeReturn = minertypes16.MaxTerminationFeeReturn
type InitialPledgeReturn = minertypes16.InitialPledgeReturn

type PieceActivationManifest = minertypes13.PieceActivationManifest
type ProveCommitSectors3Params = minertypes13.ProveCommitSectors3Params
Expand All @@ -358,6 +367,9 @@ const FaultDeclarationCutoff = minertypes.FaultDeclarationCutoff
const MinAggregatedSectors = minertypes.MinAggregatedSectors
const MinSectorExpiration = minertypes.MinSectorExpiration

var TermFeePledgeMultiple = minertypes16.TermFeePledgeMultiple
var TermFeeMaxFaultFeeMultiple = minertypes16.TermFeeMaxFaultFeeMultiple

type SectorExpiration struct {
OnTime abi.ChainEpoch

Expand Down Expand Up @@ -417,3 +429,53 @@ func AllCodes() []cid.Cid {
(&state16{}).Code(),
}
}

func PledgePenaltyForContinuedFault(
nwVer network.Version,
rewardEstimate builtin.FilterEstimate,
networkQaPowerEstimate builtin.FilterEstimate,
qaSectorPower abi.StoragePower,
) (abi.TokenAmount, error) {
v, err := actorstypes.VersionForNetwork(nwVer)
if err != nil {
return big.Zero(), err
}

if v <= actorstypes.Version16 {
return minertypes16.PledgePenaltyForContinuedFault(
smoothing16.FilterEstimate{
PositionEstimate: rewardEstimate.PositionEstimate,
VelocityEstimate: rewardEstimate.VelocityEstimate,
},
smoothing16.FilterEstimate{
PositionEstimate: networkQaPowerEstimate.PositionEstimate,
VelocityEstimate: networkQaPowerEstimate.VelocityEstimate,
},
qaSectorPower,
), nil
}

switch v {
default:
return big.Zero(), xerrors.Errorf("unsupported network version: %d", v)
}
}

func PledgePenaltyForTermination(
nwVer network.Version,
initialPledge abi.TokenAmount,
sectorAge abi.ChainEpoch,
faultFee abi.TokenAmount,
) (abi.TokenAmount, error) {
v, err := actorstypes.VersionForNetwork(nwVer)
if err != nil {
return big.Zero(), err
}

switch v {
case actorstypes.Version16:
return minertypes16.PledgePenaltyForTermination(initialPledge, sectorAge, faultFee), nil
default:
return big.Zero(), xerrors.Errorf("unsupported network version: %d", v)
}
}
8 changes: 7 additions & 1 deletion chain/actors/builtin/power/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
{{end}}
{{end}}
builtin{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin"
builtin{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin"
powertypes{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin/v{{.latestVersion}}/power"
)

var (
Expand Down Expand Up @@ -137,3 +138,8 @@ func AllCodes() []cid.Cid {
{{- end}}
}
}

type (
MinerPowerParams = powertypes{{.latestVersion}}.MinerPowerParams
MinerPowerReturn = powertypes{{.latestVersion}}.MinerPowerReturn
)
6 changes: 6 additions & 0 deletions chain/actors/builtin/power/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/go-state-types/big"
builtin16 "github.com/filecoin-project/go-state-types/builtin"
powertypes16 "github.com/filecoin-project/go-state-types/builtin/v16/power"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/go-state-types/manifest"
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
Expand Down Expand Up @@ -235,3 +236,8 @@ func AllCodes() []cid.Cid {
(&state16{}).Code(),
}
}

type (
MinerPowerParams = powertypes16.MinerPowerParams
MinerPowerReturn = powertypes16.MinerPowerReturn
)
Loading