|
| 1 | +package miner_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + abi "github.com/filecoin-project/go-state-types/abi" |
| 7 | + "github.com/filecoin-project/go-state-types/big" |
| 8 | + "github.com/filecoin-project/go-state-types/builtin/v15/miner" |
| 9 | + "github.com/filecoin-project/go-state-types/builtin/v15/util/smoothing" |
| 10 | +) |
| 11 | + |
| 12 | +// See filecoin-project/builtin-actors actors/miner/tests/fip0081_initial_pledge.rs |
| 13 | +func TestInitialPledgeForPowerFip0081(t *testing.T) { |
| 14 | + filPrecision := big.NewInt(1_000_000_000_000_000_000) |
| 15 | + |
| 16 | + epochTargetReward := abi.TokenAmount(big.Zero()) |
| 17 | + qaSectorPower := abi.StoragePower(big.NewInt(1 << 36)) |
| 18 | + networkQAPower := abi.StoragePower(big.NewInt(1 << 10)) |
| 19 | + powerRateOfChange := abi.StoragePower(big.NewInt(1 << 10)) |
| 20 | + rewardEstimate := smoothing.FilterEstimate{ |
| 21 | + PositionEstimate: epochTargetReward, |
| 22 | + VelocityEstimate: big.Zero(), |
| 23 | + } |
| 24 | + powerEstimate := smoothing.FilterEstimate{ |
| 25 | + PositionEstimate: networkQAPower, |
| 26 | + VelocityEstimate: powerRateOfChange, |
| 27 | + } |
| 28 | + circulatingSupply := abi.TokenAmount(filPrecision) |
| 29 | + |
| 30 | + testCases := []struct { |
| 31 | + name string |
| 32 | + qaSectorPower abi.StoragePower |
| 33 | + rewardEstimate smoothing.FilterEstimate |
| 34 | + powerEstimate smoothing.FilterEstimate |
| 35 | + circulatingSupply abi.TokenAmount |
| 36 | + epochsSinceRampStart int64 |
| 37 | + rampDurationEpochs uint64 |
| 38 | + expectedInitialPledge abi.TokenAmount |
| 39 | + }{ |
| 40 | + { |
| 41 | + name: "pre-ramp where 'baseline power' dominates (negative epochsSinceRampStart)", |
| 42 | + qaSectorPower: qaSectorPower, |
| 43 | + rewardEstimate: rewardEstimate, |
| 44 | + powerEstimate: powerEstimate, |
| 45 | + circulatingSupply: circulatingSupply, |
| 46 | + epochsSinceRampStart: -100, |
| 47 | + rampDurationEpochs: 100, |
| 48 | + expectedInitialPledge: big.Add(big.Div(big.Mul(big.NewInt(1500), filPrecision), big.NewInt(10000)), big.NewInt(1)), |
| 49 | + }, |
| 50 | + { |
| 51 | + name: "zero ramp duration", |
| 52 | + qaSectorPower: qaSectorPower, |
| 53 | + rewardEstimate: rewardEstimate, |
| 54 | + powerEstimate: powerEstimate, |
| 55 | + circulatingSupply: circulatingSupply, |
| 56 | + epochsSinceRampStart: 0, |
| 57 | + rampDurationEpochs: 0, |
| 58 | + expectedInitialPledge: big.Add(big.Div(big.Mul(big.NewInt(1950), filPrecision), big.NewInt(10000)), big.NewInt(1)), |
| 59 | + }, |
| 60 | + { |
| 61 | + name: "zero ramp duration (10 epochs since)", |
| 62 | + qaSectorPower: qaSectorPower, |
| 63 | + rewardEstimate: rewardEstimate, |
| 64 | + powerEstimate: powerEstimate, |
| 65 | + circulatingSupply: circulatingSupply, |
| 66 | + epochsSinceRampStart: 10, |
| 67 | + rampDurationEpochs: 0, |
| 68 | + expectedInitialPledge: big.Add(big.Div(big.Mul(big.NewInt(1950), filPrecision), big.NewInt(10000)), big.NewInt(1)), |
| 69 | + }, |
| 70 | + { |
| 71 | + name: "pre-ramp where 'baseline power' dominates", |
| 72 | + qaSectorPower: qaSectorPower, |
| 73 | + rewardEstimate: rewardEstimate, |
| 74 | + powerEstimate: powerEstimate, |
| 75 | + circulatingSupply: circulatingSupply, |
| 76 | + epochsSinceRampStart: 0, |
| 77 | + rampDurationEpochs: 100, |
| 78 | + expectedInitialPledge: big.Add(big.Div(big.Mul(big.NewInt(1500), filPrecision), big.NewInt(10000)), big.NewInt(1)), |
| 79 | + }, |
| 80 | + { |
| 81 | + name: "on-ramp where 'baseline power' is at 85% and `simple power` is at 15%", |
| 82 | + qaSectorPower: qaSectorPower, |
| 83 | + rewardEstimate: rewardEstimate, |
| 84 | + powerEstimate: powerEstimate, |
| 85 | + circulatingSupply: circulatingSupply, |
| 86 | + epochsSinceRampStart: 50, |
| 87 | + rampDurationEpochs: 100, |
| 88 | + expectedInitialPledge: big.Add(big.Div(big.Mul(big.NewInt(1725), filPrecision), big.NewInt(10000)), big.NewInt(1)), |
| 89 | + }, |
| 90 | + { |
| 91 | + name: "after-ramp where 'baseline power' is at 70% and `simple power` is at 30%", |
| 92 | + qaSectorPower: qaSectorPower, |
| 93 | + rewardEstimate: rewardEstimate, |
| 94 | + powerEstimate: powerEstimate, |
| 95 | + circulatingSupply: circulatingSupply, |
| 96 | + epochsSinceRampStart: 150, |
| 97 | + rampDurationEpochs: 100, |
| 98 | + expectedInitialPledge: big.Add(big.Div(big.Mul(big.NewInt(1950), filPrecision), big.NewInt(10000)), big.NewInt(1)), |
| 99 | + }, |
| 100 | + { |
| 101 | + name: "on-ramp where 'baseline power' has reduced effect (97%)", |
| 102 | + qaSectorPower: qaSectorPower, |
| 103 | + rewardEstimate: rewardEstimate, |
| 104 | + powerEstimate: powerEstimate, |
| 105 | + circulatingSupply: circulatingSupply, |
| 106 | + epochsSinceRampStart: 10, |
| 107 | + rampDurationEpochs: 100, |
| 108 | + expectedInitialPledge: big.Add(big.Div(big.Mul(big.NewInt(1545), filPrecision), big.NewInt(10000)), big.NewInt(1)), |
| 109 | + }, |
| 110 | + { |
| 111 | + name: "on-ramp, first epoch, pledge should be 97% 'baseline' + 3% simple", |
| 112 | + qaSectorPower: qaSectorPower, |
| 113 | + rewardEstimate: rewardEstimate, |
| 114 | + powerEstimate: powerEstimate, |
| 115 | + circulatingSupply: circulatingSupply, |
| 116 | + epochsSinceRampStart: 1, |
| 117 | + rampDurationEpochs: 10, |
| 118 | + expectedInitialPledge: big.Add(big.Div(big.Mul(big.NewInt(1545), filPrecision), big.NewInt(10000)), big.NewInt(1)), |
| 119 | + }, |
| 120 | + { |
| 121 | + name: "validate pledges 1 epoch before and after ramp start: before ramp start", |
| 122 | + qaSectorPower: qaSectorPower, |
| 123 | + rewardEstimate: rewardEstimate, |
| 124 | + powerEstimate: powerEstimate, |
| 125 | + circulatingSupply: circulatingSupply, |
| 126 | + epochsSinceRampStart: -1, |
| 127 | + rampDurationEpochs: 10, |
| 128 | + expectedInitialPledge: big.Add(big.Div(big.Mul(big.NewInt(1500), filPrecision), big.NewInt(10000)), big.NewInt(1)), |
| 129 | + }, |
| 130 | + { |
| 131 | + name: "validate pledges 1 epoch before and after ramp start: at ramp start", |
| 132 | + qaSectorPower: qaSectorPower, |
| 133 | + rewardEstimate: rewardEstimate, |
| 134 | + powerEstimate: powerEstimate, |
| 135 | + circulatingSupply: circulatingSupply, |
| 136 | + epochsSinceRampStart: 0, |
| 137 | + rampDurationEpochs: 10, |
| 138 | + expectedInitialPledge: big.Add(big.Div(big.Mul(big.NewInt(1500), filPrecision), big.NewInt(10000)), big.NewInt(1)), |
| 139 | + }, |
| 140 | + { |
| 141 | + name: "validate pledges 1 epoch before and after ramp start: on ramp start", |
| 142 | + qaSectorPower: qaSectorPower, |
| 143 | + rewardEstimate: rewardEstimate, |
| 144 | + powerEstimate: powerEstimate, |
| 145 | + circulatingSupply: circulatingSupply, |
| 146 | + epochsSinceRampStart: 1, |
| 147 | + rampDurationEpochs: 10, |
| 148 | + expectedInitialPledge: big.Add(big.Div(big.Mul(big.NewInt(1545), filPrecision), big.NewInt(10000)), big.NewInt(1)), |
| 149 | + }, |
| 150 | + { |
| 151 | + name: "post-ramp where 'baseline power' has reduced effect (70%)", |
| 152 | + qaSectorPower: qaSectorPower, |
| 153 | + rewardEstimate: rewardEstimate, |
| 154 | + powerEstimate: powerEstimate, |
| 155 | + circulatingSupply: circulatingSupply, |
| 156 | + epochsSinceRampStart: 500, |
| 157 | + rampDurationEpochs: 100, |
| 158 | + expectedInitialPledge: big.Add(big.Div(big.Mul(big.NewInt(1950), filPrecision), big.NewInt(10000)), big.NewInt(1)), |
| 159 | + }, |
| 160 | + } |
| 161 | + |
| 162 | + for _, tc := range testCases { |
| 163 | + t.Run(tc.name, func(t *testing.T) { |
| 164 | + initialPledge := miner.InitialPledgeForPower( |
| 165 | + tc.qaSectorPower, |
| 166 | + abi.StoragePower(big.NewInt(1<<37)), |
| 167 | + tc.rewardEstimate, |
| 168 | + tc.powerEstimate, |
| 169 | + tc.circulatingSupply, |
| 170 | + tc.epochsSinceRampStart, |
| 171 | + tc.rampDurationEpochs, |
| 172 | + ) |
| 173 | + if !initialPledge.Equals(tc.expectedInitialPledge) { |
| 174 | + t.Fatalf("expected initial pledge %v, got %v", tc.expectedInitialPledge, initialPledge) |
| 175 | + } |
| 176 | + }) |
| 177 | + } |
| 178 | +} |
0 commit comments