Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fip0081): initialPledge calculation & ramp, plus migration tests #12526

Merged
merged 3 commits into from
Oct 3, 2024

Conversation

rvagg
Copy link
Member

@rvagg rvagg commented Sep 30, 2024

Initial draft, need to add some tests.

Depends on:

Also has #12525 because it was in my path to this.

@rvagg rvagg self-assigned this Sep 30, 2024
@rvagg rvagg force-pushed the rvagg/0081 branch 2 times, most recently from 3832644 to 72cdd3f Compare September 30, 2024 08:08
@rvagg
Copy link
Member Author

rvagg commented Sep 30, 2024

@ZenGround0 I'm having a bit of trouble testing pledge in here. I can observe the change in pledge value if I log values of internal calculation during the ramp period:

preMigrationPledge, err := clientApi.StateMinerInitialPledgeForSector(ctx, abi.ChainEpoch(builtin.EpochsInYear), abi.SectorSize(2<<10), 0, preMigrationTs.Key())
req.NoError(err)
for i := 0; ; i++ {
head := testClient.WaitTillChain(ctx, kit.HeightAtLeast(nv24epoch+abi.ChainEpoch(i*5)))
if head.Height() > nv24epoch+200 {
break
}
postMigrationPledge, err := clientApi.StateMinerInitialPledgeForSector(ctx, abi.ChainEpoch(builtin.EpochsInYear), abi.SectorSize(2<<10), 0, head.Key())
req.NoError(err)
t.Logf("@%d: preMigrationPledge: %s, postMigrationPledge: %s", head.Height(), preMigrationPledge, postMigrationPledge)
}
}
(logging not included in this PR, but if I do it in go-state-types where the calculation is done I can see it).

But the value I get is capped by the InitialPledgeMaxPerByte value for the power being pledged: https://github.com/filecoin-project/go-state-types/blob/f1e9746dbeaaa0411bf8d704420a584a21656f23/builtin/v15/miner/monies.go#L131-L134

Consistently the cap ends up being ~66% of the uncapped pledge.

Got any suggestions for reducing this? I'm guessing it's to do with baseline power, but I'm actually not sure. How can we budge the state-sourced pledge inputs in an itest?

@rvagg
Copy link
Member Author

rvagg commented Sep 30, 2024

btw InitialPledgeMaxPerByte is a var so I can mess with it directly, but that's not exactly ideal for testing, I'd like to be modifying as few runtime pseudo-constants as possible.

@rvagg
Copy link
Member Author

rvagg commented Sep 30, 2024

I've pushed another commit here that applies the InitialPledgeMaxPerByte hack to make it work, then observe the pledge calculation before, during and after activation & ramp period. We also implement a form of StateMinerInitialPledgeForSector that pulls in the pledge calculation from miner14, so we can run the calculation with the same inputs and get both pre-FIP0081 and post-FIP0081 values and compare them.

  • Before migration: we should see no difference between the two
  • After migration and during ramp: we should see an increasing difference between the two calculations
  • After the ramp: we should still see an increasing distance because the new calculation includes the 30% simple component

Additionally, by capturing rate of change of this delta during and after the ramp we can look at the average rate of change and assert that it should be less after the ramp. I'd like to apply some kind of % to this but that's probably a bridge too far here. We end up with numbers like 0.000080 during and 0.000030 after the ramp; which seems reasonable to me I think.

In our test, the migration is at epoch 100, and the ramp is for 200 epochs.

Eyeballing the outputs seems reasonable I think: (click to see full log)
Pledge @7: 112287402045 (pre-fip-0081: 112287402045, rate of change: 0.000000)
Pledge @12: 111917456893 (pre-fip-0081: 111917456893, rate of change: 0.000000)
Pledge @17: 111557577612 (pre-fip-0081: 111557577612, rate of change: 0.000000)
Pledge @22: 111207342519 (pre-fip-0081: 111207342519, rate of change: 0.000000)
Pledge @27: 110866356178 (pre-fip-0081: 110866356178, rate of change: 0.000000)
Pledge @32: 110534261666 (pre-fip-0081: 110534261666, rate of change: 0.000000)
Pledge @37: 110210705121 (pre-fip-0081: 110210705121, rate of change: 0.000000)
Pledge @42: 109895360296 (pre-fip-0081: 109895360296, rate of change: 0.000000)
Pledge @47: 109587922739 (pre-fip-0081: 109587922739, rate of change: 0.000000)
Pledge @52: 109288100733 (pre-fip-0081: 109288100733, rate of change: 0.000000)
Pledge @57: 108995627567 (pre-fip-0081: 108995627567, rate of change: 0.000000)
Pledge @62: 108710238299 (pre-fip-0081: 108710238299, rate of change: 0.000000)
Pledge @67: 108431694581 (pre-fip-0081: 108431694581, rate of change: 0.000000)
Pledge @72: 108159760324 (pre-fip-0081: 108159760324, rate of change: 0.000000)
Pledge @77: 107894220765 (pre-fip-0081: 107894220765, rate of change: 0.000000)
Pledge @82: 107634860856 (pre-fip-0081: 107634860856, rate of change: 0.000000)
Pledge @87: 107381484875 (pre-fip-0081: 107381484875, rate of change: 0.000000)
Pledge @92: 107133910661 (pre-fip-0081: 107133910661, rate of change: 0.000000)
Pledge @97: 106891951580 (pre-fip-0081: 106891951580, rate of change: 0.000000)
Pledge @102: 106657061673 (pre-fip-0081: 106655441404, rate of change: 0.000015)
Pledge @107: 106429859252 (pre-fip-0081: 106424219774, rate of change: 0.000038)
Pledge @112: 106208620960 (pre-fip-0081: 106198127046, rate of change: 0.000046)
Pledge @117: 105991977308 (pre-fip-0081: 105977015703, rate of change: 0.000042)
Pledge @123: 105781820052 (pre-fip-0081: 105760748250, rate of change: 0.000058)
Pledge @127: 105574809671 (pre-fip-0081: 105549187056, rate of change: 0.000044)
Pledge @132: 105373440009 (pre-fip-0081: 105342198665, rate of change: 0.000054)
Pledge @137: 105176456011 (pre-fip-0081: 105139667030, rate of change: 0.000053)
Pledge @142: 104984473239 (pre-fip-0081: 104941468601, rate of change: 0.000060)
Pledge @147: 104796079148 (pre-fip-0081: 104747490696, rate of change: 0.000054)
Pledge @152: 104613022985 (pre-fip-0081: 104557627413, rate of change: 0.000066)
Pledge @157: 104432749958 (pre-fip-0081: 104371768356, rate of change: 0.000054)
Pledge @162: 104257812778 (pre-fip-0081: 104189820021, rate of change: 0.000068)
Pledge @167: 104086321831 (pre-fip-0081: 104011683952, rate of change: 0.000065)
Pledge @172: 103920091497 (pre-fip-0081: 103837269258, rate of change: 0.000080)
Pledge @177: 103755938794 (pre-fip-0081: 103666480122, rate of change: 0.000065)
Pledge @182: 103596694433 (pre-fip-0081: 103499236824, rate of change: 0.000079)
Pledge @187: 103440187312 (pre-fip-0081: 103335454796, rate of change: 0.000072)
Pledge @192: 103288036699 (pre-fip-0081: 103175055058, rate of change: 0.000082)
Pledge @197: 103138411264 (pre-fip-0081: 103017960688, rate of change: 0.000074)
Pledge @202: 102992999292 (pre-fip-0081: 102864098367, rate of change: 0.000084)
Pledge @207: 102850876753 (pre-fip-0081: 102713399532, rate of change: 0.000085)
Pledge @212: 102712054901 (pre-fip-0081: 102565790484, rate of change: 0.000088)
Pledge @217: 102575529912 (pre-fip-0081: 102421207554, rate of change: 0.000081)
Pledge @222: 102444360649 (pre-fip-0081: 102279590618, rate of change: 0.000104)
Pledge @227: 102316042044 (pre-fip-0081: 102140875798, rate of change: 0.000104)
Pledge @232: 102189148431 (pre-fip-0081: 102004994925, rate of change: 0.000090)
Pledge @237: 102065207769 (pre-fip-0081: 101871899637, rate of change: 0.000092)
Pledge @243: 101945359778 (pre-fip-0081: 101741529895, rate of change: 0.000106)
Pledge @247: 101825268820 (pre-fip-0081: 101613832989, rate of change: 0.000077)
Pledge @252: 101711260765 (pre-fip-0081: 101488760499, rate of change: 0.000112)
Pledge @257: 101597547746 (pre-fip-0081: 101366255061, rate of change: 0.000089)
Pledge @262: 101488199043 (pre-fip-0081: 101246272784, rate of change: 0.000108)
Pledge @267: 101379885717 (pre-fip-0081: 101128763250, rate of change: 0.000094)
Pledge @272: 101275113248 (pre-fip-0081: 101013681743, rate of change: 0.000105)
Pledge @277: 101172622745 (pre-fip-0081: 100900985386, rate of change: 0.000104)
Pledge @282: 101073224621 (pre-fip-0081: 100790628404, rate of change: 0.000112)
Pledge @287: 100976465944 (pre-fip-0081: 100682572260, rate of change: 0.000115)
Pledge @292: 100881899300 (pre-fip-0081: 100576771176, rate of change: 0.000115)
Pledge @297: 100788825875 (pre-fip-0081: 100473188634, rate of change: 0.000108)
Pledge @302: 100695446438 (pre-fip-0081: 100371785022, rate of change: 0.000083)
Pledge @307: 100598616335 (pre-fip-0081: 100272523531, rate of change: 0.000027)
Pledge @312: 100503654685 (pre-fip-0081: 100175367994, rate of change: 0.000025)
Pledge @317: 100411389989 (pre-fip-0081: 100080284966, rate of change: 0.000031)
Pledge @322: 100320283567 (pre-fip-0081: 99987237319, rate of change: 0.000022)
Pledge @327: 100231590408 (pre-fip-0081: 99896194392, rate of change: 0.000027)
Pledge @332: 100145690433 (pre-fip-0081: 99807124744, rate of change: 0.000035)
Pledge @337: 100061283251 (pre-fip-0081: 99719994422, rate of change: 0.000030)
Pledge @342: 99979384487 (pre-fip-0081: 99634774988, rate of change: 0.000036)
Pledge @347: 99898922730 (pre-fip-0081: 99551434585, rate of change: 0.000032)
Pledge @352: 99819877961 (pre-fip-0081: 99469944272, rate of change: 0.000027)
Pledge @357: 99742027202 (pre-fip-0081: 99390275441, rate of change: 0.000021)
Pledge @362: 99667578344 (pre-fip-0081: 99312405318, rate of change: 0.000037)
Pledge @367: 99595470498 (pre-fip-0081: 99236305052, rate of change: 0.000043)
Pledge @372: 99524070493 (pre-fip-0081: 99161945210, rate of change: 0.000033)
Pledge @377: 99456943315 (pre-fip-0081: 99089308050, rate of change: 0.000058)
Pledge @382: 99389482781 (pre-fip-0081: 99018359088, rate of change: 0.000038)
Pledge @387: 99322093530 (pre-fip-0081: 98949075062, rate of change: 0.000022)
Pledge @392: 99257313876 (pre-fip-0081: 98881437976, rate of change: 0.000031)
Pledge @397: 99192198136 (pre-fip-0081: 98815418544, rate of change: 0.000012)
Pledge @402: 99131380972 (pre-fip-0081: 98751004580, rate of change: 0.000039)
Pledge @407: 99070006323 (pre-fip-0081: 98688163669, rate of change: 0.000017)
Pledge @412: 99012279230 (pre-fip-0081: 98626883848, rate of change: 0.000038)
Pledge @417: 98954166803 (pre-fip-0081: 98567135438, rate of change: 0.000019)
Pledge @422: 98900201346 (pre-fip-0081: 98508908331, rate of change: 0.000046)
Pledge @427: 98844325497 (pre-fip-0081: 98452169159, rate of change: 0.000011)
Pledge @432: 98791419784 (pre-fip-0081: 98396909612, rate of change: 0.000026)
Pledge @437: 98740885551 (pre-fip-0081: 98343109530, rate of change: 0.000035)
Pledge @442: 98691399539 (pre-fip-0081: 98290747504, rate of change: 0.000031)
Pledge @447: 98643316900 (pre-fip-0081: 98239806357, rate of change: 0.000031)
Pledge @452: 98596985476 (pre-fip-0081: 98190269328, rate of change: 0.000035)
Pledge @457: 98551112122 (pre-fip-0081: 98142116240, rate of change: 0.000025)
Pledge @462: 98506778075 (pre-fip-0081: 98095332815, rate of change: 0.000027)
Pledge @467: 98462706312 (pre-fip-0081: 98049899643, rate of change: 0.000016)
Pledge @472: 98422474245 (pre-fip-0081: 98005809126, rate of change: 0.000041)
Pledge @477: 98382647884 (pre-fip-0081: 97963037484, rate of change: 0.000032)
Pledge @482: 98344111036 (pre-fip-0081: 97921571462, rate of change: 0.000032)
Pledge @487: 98305438712 (pre-fip-0081: 97881392624, rate of change: 0.000017)
Pledge @492: 98269268574 (pre-fip-0081: 97842492620, rate of change: 0.000030)
Pledge @497: 98235045247 (pre-fip-0081: 97804855780, rate of change: 0.000037)
Pledge @502: 98200137592 (pre-fip-0081: 97768461654, rate of change: 0.000017)

Average rate of change during ramp: 0.000080
Average rate of change after ramp: 0.000027

Plotting the whole series looks like this:

Screenshot 2024-09-30 at 9 51 53 PM

Also the "rate of change", which is more like "rate of change in the delta between pre and post FIP-0081 calculation", we can see the ramp at work:

Screenshot 2024-09-30 at 9 49 28 PM

@rvagg rvagg force-pushed the rvagg/0081 branch 4 times, most recently from a4eb091 to 0bba2ea Compare October 1, 2024 05:14
@rvagg rvagg marked this pull request as ready for review October 1, 2024 05:15
@rvagg rvagg requested a review from ZenGround0 October 1, 2024 05:15
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvagg rvagg changed the title FIP0081 InitialPledge calculation + ramp feat(fip0081): initialPledge calculation & ramp, plus migration tests Oct 1, 2024
@github-actions github-actions bot dismissed their stale review October 1, 2024 05:16

PR title now matches the required format.

@ZenGround0
Copy link
Contributor

Thanks for the nice analysis I'll take a look at the code.

If you wanted to think more about avoiding the cap resetting thing the levers you can play with are

  • making sector size smaller
  • making network power bigger
  • moving forward in time so network baseline is bigger
  • making the circulating supply smaller
    But your approach seems ok as it is.

build/buildconstants/params_calibnet.go Show resolved Hide resolved
build/builtin_actors_gen.go Outdated Show resolved Hide resolved
chain/consensus/filcns/upgrades.go Show resolved Hide resolved
chain/consensus/filcns/upgrades.go Outdated Show resolved Hide resolved
chain/consensus/filcns/upgrades.go Outdated Show resolved Hide resolved
chain/gen/genesis/miners.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
node/impl/full/state.go Show resolved Hide resolved
itests/kit/node_unmanaged.go Show resolved Hide resolved
Copy link
Contributor

@ZenGround0 ZenGround0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM I'll do a final review once all dependencies are landed before approving

itests/migration_test.go Outdated Show resolved Hide resolved
itests/migration_test.go Show resolved Hide resolved
@rvagg rvagg requested a review from ZenGround0 October 2, 2024 04:30
@rvagg
Copy link
Member Author

rvagg commented Oct 3, 2024

Removed my commit with the custom actors build and added the tagged build from https://github.com/filecoin-project/builtin-actors/releases/tag/v15.0.0-rc1; also updated go-state-types to @master, once we get a tag I'll update that commit here to the tagged version and then this should be good to land.

@rvagg rvagg enabled auto-merge (rebase) October 3, 2024 10:49
@rvagg rvagg merged commit 49d6c8a into master Oct 3, 2024
82 of 83 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ☑️ Done (Archive)
Development

Successfully merging this pull request may close these issues.

2 participants