Skip to content

Commit

Permalink
feat(fip0081): implement pledge calculation change + ramp
Browse files Browse the repository at this point in the history
Closes: #12494
  • Loading branch information
rvagg committed Oct 1, 2024
1 parent c0eb132 commit d6c1307
Show file tree
Hide file tree
Showing 43 changed files with 300 additions and 63 deletions.
2 changes: 1 addition & 1 deletion build/buildconstants/params_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ var WhitelistedBlock = cid.MustParse("bafy2bzaceapyg2uyzk7vueh3xccxkuwbz3nxewjyg
var F3ManifestServerID = MustParseID("12D3KooWENMwUF9YxvQxar7uBWJtZkA6amvK4xWmKXfSiHUo2Qq7")

// The initial F3 power table CID.
var F3InitialPowerTableCID cid.Cid = cid.Undef
var F3InitialPowerTableCID = cid.Undef

const F3Enabled = true
const F3BootstrapEpoch abi.ChainEpoch = -1
Expand Down
12 changes: 12 additions & 0 deletions chain/actors/builtin/power/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ type State interface {
// MinerCounts returns the number of miners. Participating is the number
// with power above the minimum miner threshold.
MinerCounts() (participating, total uint64, err error)
// RampStartEpoch returns the epoch at which the FIP0081 pledge calculation
// change begins. At and before RampStartEpoch, we use the old calculation. At
// RampStartEpoch + RampDurationEpochs, we use 70% old rules + 30% new
// calculation.
//
// This method always returns 0 prior to actors version 15.
RampStartEpoch() int64
// RampDurationEpochs returns the number of epochs over which the new FIP0081
// pledge calculation is ramped up.
//
// This method always returns 0 prior to actors version 15.
RampDurationEpochs() uint64
MinerPower(address.Address) (Claim, bool, error)
MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error)
ListAllMiners() ([]address.Address, error)
Expand Down
12 changes: 12 additions & 0 deletions chain/actors/builtin/power/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ type State interface {
// MinerCounts returns the number of miners. Participating is the number
// with power above the minimum miner threshold.
MinerCounts() (participating, total uint64, err error)
// RampStartEpoch returns the epoch at which the FIP0081 pledge calculation
// change begins. At and before RampStartEpoch, we use the old calculation. At
// RampStartEpoch + RampDurationEpochs, we use 70% old rules + 30% new
// calculation.
//
// This method always returns 0 prior to actors version 15.
RampStartEpoch() int64
// RampDurationEpochs returns the number of epochs over which the new FIP0081
// pledge calculation is ramped up.
//
// This method always returns 0 prior to actors version 15.
RampDurationEpochs() uint64
MinerPower(address.Address) (Claim, bool, error)
MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error)
ListAllMiners() ([]address.Address, error)
Expand Down
8 changes: 8 additions & 0 deletions chain/actors/builtin/power/state.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ func (s *state{{.v}}) MinerCounts() (uint64, uint64, error) {
return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil
}

func (s *state{{.v}}) RampStartEpoch() int64 {
return {{if (ge .v 15)}}s.State.RampStartEpoch{{else}}0{{end}}
}

func (s *state{{.v}}) RampDurationEpochs() uint64 {
return {{if (ge .v 15)}}s.State.RampDurationEpochs{{else}}0{{end}}
}

func (s *state{{.v}}) ListAllMiners() ([]address.Address, error) {
claims, err := s.claims()
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v0.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v10.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v11.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v12.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v13.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v14.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v15.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v2.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v3.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v4.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v5.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v6.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v7.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v8.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions chain/actors/builtin/power/v9.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion chain/actors/builtin/reward/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ type State interface {
CumsumBaseline() (abi.StoragePower, error)
CumsumRealized() (abi.StoragePower, error)

InitialPledgeForPower(abi.StoragePower, abi.TokenAmount, *builtin.FilterEstimate, abi.TokenAmount) (abi.TokenAmount, error)
// InitialPledgeForPower computes the pledge requirement for committing new quality-adjusted power
// to the network, given the current network total and baseline power, per-epoch reward, and
// circulating token supply.
//
// Prior to actors version 15, the epochsSinceRampStart and rampDurationEpochs arguments have
// no effect. After actors version 15, these values can be derived from the power actor state
// properties RampStartEpoch and RampDurationEpochs.
InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount, epochsSinceRampStart int64, rampDurationEpochs uint64) (abi.TokenAmount, error)
PreCommitDepositForPower(builtin.FilterEstimate, abi.StoragePower) (abi.TokenAmount, error)
GetState() interface{}
}
Expand Down
9 changes: 8 additions & 1 deletion chain/actors/builtin/reward/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,14 @@ type State interface {
CumsumBaseline() (abi.StoragePower, error)
CumsumRealized() (abi.StoragePower, error)

InitialPledgeForPower(abi.StoragePower, abi.TokenAmount, *builtin.FilterEstimate, abi.TokenAmount) (abi.TokenAmount, error)
// InitialPledgeForPower computes the pledge requirement for committing new quality-adjusted power
// to the network, given the current network total and baseline power, per-epoch reward, and
// circulating token supply.
//
// Prior to actors version 15, the epochsSinceRampStart and rampDurationEpochs arguments have
// no effect. After actors version 15, these values can be derived from the power actor state
// properties RampStartEpoch and RampDurationEpochs.
InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount, epochsSinceRampStart int64, rampDurationEpochs uint64) (abi.TokenAmount, error)
PreCommitDepositForPower(builtin.FilterEstimate, abi.StoragePower) (abi.TokenAmount, error)
GetState() interface{}
}
Expand Down
20 changes: 16 additions & 4 deletions chain/actors/builtin/reward/state.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (s *state{{.v}}) CumsumRealized() (reward{{.v}}.Spacetime, error) {
return s.State.CumsumRealized, nil
}
{{if (ge .v 2)}}
func (s *state{{.v}}) InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount) (abi.TokenAmount, error) {
return miner{{.v}}.InitialPledgeForPower(
func (s *state{{.v}}) InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount, epochsSinceRampStart int64, rampDurationEpochs uint64) (abi.TokenAmount, error) {
{{if (ge .v 15)}}return miner{{.v}}.InitialPledgeForPower(
qaPower,
s.State.ThisEpochBaselinePower,
s.State.ThisEpochRewardSmoothed,
Expand All @@ -93,10 +93,22 @@ func (s *state{{.v}}) InitialPledgeForPower(qaPower abi.StoragePower, networkTot
VelocityEstimate: networkQAPower.VelocityEstimate,
},
circSupply,
epochsSinceRampStart,
rampDurationEpochs,
), nil
}
{{else}}return miner{{.v}}.InitialPledgeForPower(
qaPower,
s.State.ThisEpochBaselinePower,
s.State.ThisEpochRewardSmoothed,
smoothing{{.v}}.FilterEstimate{
PositionEstimate: networkQAPower.PositionEstimate,
VelocityEstimate: networkQAPower.VelocityEstimate,
},
circSupply,
), nil
{{end}}}
{{else}}
func (s *state0) InitialPledgeForPower(sectorWeight abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount) (abi.TokenAmount, error) {
func (s *state0) InitialPledgeForPower(sectorWeight abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount, _ int64, _ uint64) (abi.TokenAmount, error) {
return miner0.InitialPledgeForPower(
sectorWeight,
s.State.ThisEpochBaselinePower,
Expand Down
2 changes: 1 addition & 1 deletion chain/actors/builtin/reward/v0.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chain/actors/builtin/reward/v10.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chain/actors/builtin/reward/v11.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chain/actors/builtin/reward/v12.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chain/actors/builtin/reward/v13.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d6c1307

Please sign in to comment.