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
12 changes: 9 additions & 3 deletions builtin/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ var MethodsPower = struct {
CurrentTotalPowerMinerRawPowerExported abi.MethodNum
CurrentTotalPowerMinerCountExported abi.MethodNum
CurrentTotalPowerMinerConsensusCountExported abi.MethodNum
MinerPowerExported abi.MethodNum
}{
MethodConstructor,
2,
Expand All @@ -190,6 +191,7 @@ var MethodsPower = struct {
MustGenerateFRCMethodNum("MinerRawPower"),
MustGenerateFRCMethodNum("MinerCount"),
MustGenerateFRCMethodNum("MinerConsensusCount"),
MustGenerateFRCMethodNum("MinerPower"),
}

var MethodsMiner = struct {
Expand Down Expand Up @@ -241,9 +243,11 @@ var MethodsMiner = struct {
GetPeerIDExported abi.MethodNum
GetMultiaddrsExported abi.MethodNum
// MovePartitionsExported abi.MethodNum
ProveCommitSectors3 abi.MethodNum
ProveReplicaUpdates3 abi.MethodNum
ProveCommitSectorsNI abi.MethodNum
ProveCommitSectors3 abi.MethodNum
ProveReplicaUpdates3 abi.MethodNum
ProveCommitSectorsNI abi.MethodNum
MaxTerminationFeeExported abi.MethodNum
InitialPledgeExported abi.MethodNum
}{
MethodConstructor,
2,
Expand Down Expand Up @@ -296,6 +300,8 @@ var MethodsMiner = struct {
34,
35,
36,
MustGenerateFRCMethodNum("MaxTerminationFee"),
MustGenerateFRCMethodNum("InitialPledge"),
}

var MethodsVerifiedRegistry = struct {
Expand Down
2 changes: 2 additions & 0 deletions builtin/v16/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func main() {
power.MinerRawPowerReturn{},
// other types
power.CronEvent{},
power.MinerPowerReturn{},
); err != nil {
panic(err)
}
Expand Down Expand Up @@ -217,6 +218,7 @@ func main() {
miner.SectorClaim{},
miner.SectorNIActivationInfo{},
miner.ProveCommitSectorsNIParams{},
miner.MaxTerminationFeeParams{},
); err != nil {
panic(err)
}
Expand Down
70 changes: 70 additions & 0 deletions builtin/v16/miner/cbor_gen.go

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

9 changes: 9 additions & 0 deletions builtin/v16/miner/miner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,12 @@ type ProveCommitSectorsNIParams struct {
}

type ProveCommitSectorsNIReturn = batch.BatchReturn

type MaxTerminationFeeParams struct {
Power abi.StoragePower
InitialPledge abi.TokenAmount
}

type MaxTerminationFeeReturn = abi.TokenAmount

type InitialPledgeReturn = abi.TokenAmount
71 changes: 53 additions & 18 deletions builtin/v16/miner/monies.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (

// Projection period of expected sector block reward for deposit required to pre-commit a sector.
// This deposit is lost if the pre-commitment is not timely followed up by a commitment proof.
var PreCommitDepositFactor = 20 // PARAM_SPEC
var PreCommitDepositFactor = 20
var PreCommitDepositProjectionPeriod = abi.ChainEpoch(PreCommitDepositFactor) * builtin.EpochsInDay

// Projection period of expected sector block rewards for storage pledge required to commit a sector.
// This pledge is lost if a sector is terminated before its full committed lifetime.
var InitialPledgeFactor = 20 // PARAM_SPEC
var InitialPledgeFactor = 20
var InitialPledgeProjectionPeriod = abi.ChainEpoch(InitialPledgeFactor) * builtin.EpochsInDay

// Cap on initial pledge requirement for sectors.
Expand All @@ -26,7 +26,7 @@ var InitialPledgeMaxPerByte = big.Div(big.NewInt(1e18), big.NewInt(32<<30))
// Multiplier of share of circulating money supply for consensus pledge required to commit a sector.
// This pledge is lost if a sector is terminated before its full committed lifetime.
var InitialPledgeLockTarget = builtin.BigFrac{
Numerator: big.NewInt(3), // PARAM_SPEC
Numerator: big.NewInt(3),
Denominator: big.NewInt(10),
}

Expand Down Expand Up @@ -133,25 +133,60 @@ func InitialPledgeForPower(
return big.Min(nominalPledge, pledgeCap)
}

var EstimatedSingleProveCommitGasUsage = big.NewInt(49299973) // PARAM_SPEC
var EstimatedSinglePreCommitGasUsage = big.NewInt(16433324) // PARAM_SPEC
var BatchDiscount = builtin.BigFrac{ // PARAM_SPEC
Numerator: big.NewInt(1),
Denominator: big.NewInt(20),
// Maximum number of lifetime days penalized when a sector is terminated.
const TerminationLifetimeCap abi.ChainEpoch = 140

// Used to compute termination fees in the base case by multiplying against initial pledge.
var TermFeePledgeMultiple = builtin.BigFrac{
Numerator: big.NewInt(85),
Denominator: big.NewInt(1000),
}
var BatchBalancer = big.Mul(big.NewInt(5), builtin.OneNanoFIL) // PARAM_SPEC

func AggregateProveCommitNetworkFee(aggregateSize int, baseFee abi.TokenAmount) abi.TokenAmount {
return aggregateNetworkFee(aggregateSize, EstimatedSingleProveCommitGasUsage, baseFee)
// Used to ensure the termination fee for young sectors is not arbitrarily low.
var TermFeeMinPledgeMultiple = builtin.BigFrac{
Numerator: big.NewInt(2),
Denominator: big.NewInt(100),
}

func AggregatePreCommitNetworkFee(aggregateSize int, baseFee abi.TokenAmount) abi.TokenAmount {
return aggregateNetworkFee(aggregateSize, EstimatedSinglePreCommitGasUsage, baseFee)
// Used to compute termination fees when the termination fee of a sector is less than the fault fee for the same sector.
var TermFeeMaxFaultFeeMultiple = builtin.BigFrac{
Numerator: big.NewInt(105),
Denominator: big.NewInt(100),
}

func aggregateNetworkFee(aggregateSize int, gasUsage big.Int, baseFee abi.TokenAmount) abi.TokenAmount {
effectiveGasFee := big.Max(baseFee, BatchBalancer)
networkFeeNum := big.Product(effectiveGasFee, gasUsage, big.NewInt(int64(aggregateSize)), BatchDiscount.Numerator)
networkFee := big.Div(networkFeeNum, BatchDiscount.Denominator)
return networkFee
const ContinuedFaultFactorNum = 351
const ContinuedFaultFactorDenom = 100
const ContinuedFaultProjectionPeriod abi.ChainEpoch = (builtin.EpochsInDay * ContinuedFaultFactorNum) / ContinuedFaultFactorDenom

// PledgePenaltyForContinuedFault calculates the penalty for a sector continuing faulty for another
// proving period.
// It is a projection of the expected reward earned by the sector. Also known as "FF(t)"
func PledgePenaltyForContinuedFault(rewardEstimate smoothing.FilterEstimate, networkQaPowerEstimate smoothing.FilterEstimate, qaSectorPower abi.StoragePower) abi.TokenAmount {
return ExpectedRewardForPower(rewardEstimate, networkQaPowerEstimate, qaSectorPower, ContinuedFaultProjectionPeriod)
}

// PledgePenaltyForTermination Calculates termination fee for a given sector. Normally, it's
// calculated as a fixed percentage of the initial pledge. However, there are some special cases
// outlined in [FIP-0098](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0098.md).
func PledgePenaltyForTermination(
initialPledge abi.TokenAmount,
sectorAge abi.ChainEpoch,
faultFee abi.TokenAmount,
) abi.TokenAmount {
// Use the Percentage of the initial pledge strategy to determine the termination fee.
simpleTerminationFee :=
big.Div(big.Mul(initialPledge, TermFeePledgeMultiple.Numerator), TermFeePledgeMultiple.Denominator)

durationTerminationFee :=
big.Div(big.Mul(big.NewInt(int64(sectorAge)), simpleTerminationFee), big.NewInt(int64(TerminationLifetimeCap*builtin.EpochsInDay)))

// Apply the age adjustment for young sectors to arrive at the base termination fee.
baseTerminationFee := big.Min(simpleTerminationFee, durationTerminationFee)

// Calculate the minimum allowed fee (a lower bound on the termination fee) by comparing the absolute minimum termination fee value against the fault fee. Whatever result is Larger sets the lower bound for the termination fee.
minimumFeeAbs := big.Div(big.Mul(initialPledge, TermFeeMinPledgeMultiple.Numerator), TermFeeMinPledgeMultiple.Denominator)
minimumFeeFf := big.Div(big.Mul(faultFee, TermFeeMaxFaultFeeMultiple.Numerator), TermFeeMaxFaultFeeMultiple.Denominator)
minimumFee := big.Max(minimumFeeAbs, minimumFeeFf)

return big.Max(baseTerminationFee, minimumFee)
}
Loading
Loading