@@ -10,12 +10,12 @@ import (
10
10
11
11
// Projection period of expected sector block reward for deposit required to pre-commit a sector.
12
12
// This deposit is lost if the pre-commitment is not timely followed up by a commitment proof.
13
- var PreCommitDepositFactor = 20 // PARAM_SPEC
13
+ var PreCommitDepositFactor = 20
14
14
var PreCommitDepositProjectionPeriod = abi .ChainEpoch (PreCommitDepositFactor ) * builtin .EpochsInDay
15
15
16
16
// Projection period of expected sector block rewards for storage pledge required to commit a sector.
17
17
// This pledge is lost if a sector is terminated before its full committed lifetime.
18
- var InitialPledgeFactor = 20 // PARAM_SPEC
18
+ var InitialPledgeFactor = 20
19
19
var InitialPledgeProjectionPeriod = abi .ChainEpoch (InitialPledgeFactor ) * builtin .EpochsInDay
20
20
21
21
// Cap on initial pledge requirement for sectors.
@@ -26,7 +26,7 @@ var InitialPledgeMaxPerByte = big.Div(big.NewInt(1e18), big.NewInt(32<<30))
26
26
// Multiplier of share of circulating money supply for consensus pledge required to commit a sector.
27
27
// This pledge is lost if a sector is terminated before its full committed lifetime.
28
28
var InitialPledgeLockTarget = builtin.BigFrac {
29
- Numerator : big .NewInt (3 ), // PARAM_SPEC
29
+ Numerator : big .NewInt (3 ),
30
30
Denominator : big .NewInt (10 ),
31
31
}
32
32
@@ -133,25 +133,60 @@ func InitialPledgeForPower(
133
133
return big .Min (nominalPledge , pledgeCap )
134
134
}
135
135
136
- var EstimatedSingleProveCommitGasUsage = big .NewInt (49299973 ) // PARAM_SPEC
137
- var EstimatedSinglePreCommitGasUsage = big .NewInt (16433324 ) // PARAM_SPEC
138
- var BatchDiscount = builtin.BigFrac { // PARAM_SPEC
139
- Numerator : big .NewInt (1 ),
140
- Denominator : big .NewInt (20 ),
136
+ // Maximum number of lifetime days penalized when a sector is terminated.
137
+ const TerminationLifetimeCap abi.ChainEpoch = 140
138
+
139
+ // Used to compute termination fees in the base case by multiplying against initial pledge.
140
+ var TermFeePledgeMultiple = builtin.BigFrac {
141
+ Numerator : big .NewInt (85 ),
142
+ Denominator : big .NewInt (1000 ),
141
143
}
142
- var BatchBalancer = big .Mul (big .NewInt (5 ), builtin .OneNanoFIL ) // PARAM_SPEC
143
144
144
- func AggregateProveCommitNetworkFee (aggregateSize int , baseFee abi.TokenAmount ) abi.TokenAmount {
145
- return aggregateNetworkFee (aggregateSize , EstimatedSingleProveCommitGasUsage , baseFee )
145
+ // Used to ensure the termination fee for young sectors is not arbitrarily low.
146
+ var TermFeeMinPledgeMultiple = builtin.BigFrac {
147
+ Numerator : big .NewInt (2 ),
148
+ Denominator : big .NewInt (100 ),
146
149
}
147
150
148
- func AggregatePreCommitNetworkFee (aggregateSize int , baseFee abi.TokenAmount ) abi.TokenAmount {
149
- return aggregateNetworkFee (aggregateSize , EstimatedSinglePreCommitGasUsage , baseFee )
151
+ // Used to compute termination fees when the termination fee of a sector is less than the fault fee for the same sector.
152
+ var TermFeeMaxFaultFeeMultiple = builtin.BigFrac {
153
+ Numerator : big .NewInt (105 ),
154
+ Denominator : big .NewInt (100 ),
150
155
}
151
156
152
- func aggregateNetworkFee (aggregateSize int , gasUsage big.Int , baseFee abi.TokenAmount ) abi.TokenAmount {
153
- effectiveGasFee := big .Max (baseFee , BatchBalancer )
154
- networkFeeNum := big .Product (effectiveGasFee , gasUsage , big .NewInt (int64 (aggregateSize )), BatchDiscount .Numerator )
155
- networkFee := big .Div (networkFeeNum , BatchDiscount .Denominator )
156
- return networkFee
157
+ const ContinuedFaultFactorNum = 351
158
+ const ContinuedFaultFactorDenom = 100
159
+ const ContinuedFaultProjectionPeriod abi.ChainEpoch = (builtin .EpochsInDay * ContinuedFaultFactorNum ) / ContinuedFaultFactorDenom
160
+
161
+ // PledgePenaltyForContinuedFault calculates the penalty for a sector continuing faulty for another
162
+ // proving period.
163
+ // It is a projection of the expected reward earned by the sector. Also known as "FF(t)"
164
+ func PledgePenaltyForContinuedFault (rewardEstimate smoothing.FilterEstimate , networkQaPowerEstimate smoothing.FilterEstimate , qaSectorPower abi.StoragePower ) abi.TokenAmount {
165
+ return ExpectedRewardForPower (rewardEstimate , networkQaPowerEstimate , qaSectorPower , ContinuedFaultProjectionPeriod )
166
+ }
167
+
168
+ // PledgePenaltyForTermination Calculates termination fee for a given sector. Normally, it's
169
+ // calculated as a fixed percentage of the initial pledge. However, there are some special cases
170
+ // outlined in [FIP-0098](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0098.md).
171
+ func PledgePenaltyForTermination (
172
+ initialPledge abi.TokenAmount ,
173
+ sectorAge abi.ChainEpoch ,
174
+ faultFee abi.TokenAmount ,
175
+ ) abi.TokenAmount {
176
+ // Use the Percentage of the initial pledge strategy to determine the termination fee.
177
+ simpleTerminationFee :=
178
+ big .Div (big .Mul (initialPledge , TermFeePledgeMultiple .Numerator ), TermFeePledgeMultiple .Denominator )
179
+
180
+ durationTerminationFee :=
181
+ big .Div (big .Mul (big .NewInt (int64 (sectorAge )), simpleTerminationFee ), big .NewInt (int64 (TerminationLifetimeCap * builtin .EpochsInDay )))
182
+
183
+ // Apply the age adjustment for young sectors to arrive at the base termination fee.
184
+ baseTerminationFee := big .Min (simpleTerminationFee , durationTerminationFee )
185
+
186
+ // 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.
187
+ minimumFeeAbs := big .Div (big .Mul (initialPledge , TermFeeMinPledgeMultiple .Numerator ), TermFeeMinPledgeMultiple .Denominator )
188
+ minimumFeeFf := big .Div (big .Mul (faultFee , TermFeeMaxFaultFeeMultiple .Numerator ), TermFeeMaxFaultFeeMultiple .Denominator )
189
+ minimumFee := big .Max (minimumFeeAbs , minimumFeeFf )
190
+
191
+ return big .Max (baseTerminationFee , minimumFee )
157
192
}
0 commit comments