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

R4R: Inflation bug fixes #2982

Merged
merged 13 commits into from Dec 4, 2018

Conversation

Projects
None yet
5 participants
@cwgoes
Copy link
Contributor

commented Dec 3, 2018

Closes #2967

Changes:

  • Tokens are minted for the previous block before distributing rewards
  • Inflation rate is now recalculated each block instead of each hour
  • For zero-height export, delegation withdrawal infos / validator withdrawal infos are not deleted but instead reset to height 0

Standard checklist:

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote tests
  • Updated relevant documentation (docs/)
  • Added entries in PENDING.md with issue #
  • rereviewed Files changed in the github PR explorer

For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)
@codecov

This comment has been minimized.

Copy link

commented Dec 3, 2018

Codecov Report

Merging #2982 into develop will increase coverage by 0.06%.
The diff coverage is 40%.

@@             Coverage Diff             @@
##           develop    #2982      +/-   ##
===========================================
+ Coverage     55.5%   55.57%   +0.06%     
===========================================
  Files          120      120              
  Lines         8494     8488       -6     
===========================================
+ Hits          4715     4717       +2     
+ Misses        3457     3449       -8     
  Partials       322      322

@cwgoes cwgoes requested a review from zramsay as a code owner Dec 3, 2018

@cwgoes cwgoes changed the title WIP: Inflation bug fixes (BeginBlocker ordering, hourly calculation) R4R: Inflation bug fixes (BeginBlocker ordering, hourly calculation) Dec 3, 2018

@cwgoes cwgoes added ready-for-review and removed WIP labels Dec 3, 2018

@cwgoes cwgoes changed the title R4R: Inflation bug fixes (BeginBlocker ordering, hourly calculation) R4R: Inflation bug fixes (hourly calculation) Dec 3, 2018

@cwgoes cwgoes changed the title R4R: Inflation bug fixes (hourly calculation) R4R: Inflation bug fixes Dec 3, 2018

@cwgoes

This comment has been minimized.

Copy link
Contributor Author

commented Dec 3, 2018

Interesting, one seed failing:

go test ./cmd/gaia/app -run TestGaiaSimulationAfterImport -SimulationEnabled=true -SimulationNumBlocks=50 -SimulationVerbose=true -SimulationCommit=true -SimulationSeed=981928 -v -timeout 24h

with

panic: invariant broken: loose token invariance:
	pool.LooseTokens: 78540599.9265062257
	sum of account tokens: 78540599.9265062218 [recovered]
	panic: invariant broken: loose token invariance:
	pool.LooseTokens: 78540599.9265062257
	sum of account tokens: 78540599.9265062218
@cwgoes

This comment has been minimized.

Copy link
Contributor Author

commented Dec 3, 2018

Pinned to these lines in cmd/gaia/app/export.go:

  app.assertRuntimeInvariantsWith(ctx)
  fmt.Printf("pre-deletion")

  // delete all distribution infos
  // these will be recreated in InitGenesis
  app.distrKeeper.RemoveValidatorDistInfos(ctx)
  app.distrKeeper.RemoveDelegationDistInfos(ctx)

  // assert again
  app.assertRuntimeInvariantsWith(ctx)
  fmt.Printf("post-deletion")

Fails between "pre-deletion" and "post-deletion".

Somehow, it's not safe to delete distribution infos after (theoretically) withdrawing everything from them.

@cwgoes

This comment has been minimized.

Copy link
Contributor Author

commented Dec 3, 2018

One ValidatorDistributionInfo has leftover delegator-pool stake:

--- FAIL: TestGaiaSimulationAfterImport (6.25s)
panic: valInfo: {OperatorAddr:35D5DAA716545B6F6A574E9F75061912DD08D0DF FeePoolWithdrawalHeight:50 DelAccum:{UpdateHeight:50 Accum:0.0000000000} DelPool:[{Denom:STAKE Amount:0.0000000039}] ValCommission:[]} [recovered]
	panic: valInfo: {OperatorAddr:35D5DAA716545B6F6A574E9F75061912DD08D0DF FeePoolWithdrawalHeight:50 DelAccum:{UpdateHeight:50 Accum:0.0000000000} DelPool:[{Denom:STAKE Amount:0.0000000039}] ValCommission:[]}
@cwgoes

This comment has been minimized.

Copy link
Contributor Author

commented Dec 3, 2018

OK, confirmed that all the delegation infos have zero rewards, looks like occasional DelPool can be leftover by rounding. Instead now resetting delegation info height to 0 (and not deleting).

cwgoes added some commits Dec 3, 2018

@rigelrozanski

This comment has been minimized.

Copy link
Member

commented Dec 3, 2018

Let's benchmark the actual cost per block of this!

cwgoes added some commits Dec 3, 2018

@cwgoes

This comment has been minimized.

Copy link
Contributor Author

commented Dec 3, 2018

@rigelrozanski Added benchmarks in 60cf1f4 - total for both looks like ~2200 ns.


## NextInflationRate

The target annual inflation rate is recalculated at the first block of each new
hour. The inflation is also subject to a rate change (positive or negative)
The target annual inflation rate is recalculated each block.

This comment has been minimized.

Copy link
@alexanderbez

alexanderbez Dec 3, 2018

Contributor

Does this warrant any changes to the distribution spec (e.g. Affects on Staking)?

@alexanderbez
Copy link
Contributor

left a comment

Changes look good. Not sure if any further documentation needs to be updated? Also, not sure if this has any other implications on the state machine.

@alexanderbez alexanderbez referenced this pull request Dec 3, 2018

Merged

R4R: Removal of Mandatory Self-Delegation Reward #2984

3 of 5 tasks complete
@jackzampolin

This comment has been minimized.

Copy link
Contributor

commented Dec 3, 2018

Sounds like we should get this in for GoS as #2984 depends on it?

@cwgoes

This comment has been minimized.

Copy link
Contributor Author

commented Dec 3, 2018

Sounds like we should get this in for GoS as #2984 depends on it?

Yup, and more importantly because it fixes #2967.

@rigelrozanski
Copy link
Member

left a comment

few minor comments which should be addressed still, but approving

Show resolved Hide resolved cmd/gaia/app/export.go Outdated
Show resolved Hide resolved cmd/gaia/app/export.go Outdated
Show resolved Hide resolved x/mint/minter_test.go Outdated
Show resolved Hide resolved x/mint/minter_test.go
Show resolved Hide resolved x/mint/minter.go
Show resolved Hide resolved x/mint/abci_app.go

@cwgoes cwgoes referenced this pull request Dec 4, 2018

Merged

R4R: Validator Power Dec-> Int #2958

5 of 5 tasks complete

@jackzampolin jackzampolin merged commit dfd00a6 into develop Dec 4, 2018

12 of 13 checks passed

codecov/patch 40% of diff hit (target 55.5%)
Details
ci/circleci: integration_tests Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: localnet Your tests passed on CircleCI!
Details
ci/circleci: setup_dependencies Your tests passed on CircleCI!
Details
ci/circleci: test_cover Your tests passed on CircleCI!
Details
ci/circleci: test_sim_gaia_fast Your tests passed on CircleCI!
Details
ci/circleci: test_sim_gaia_import_export Your tests passed on CircleCI!
Details
ci/circleci: test_sim_gaia_multi_seed Your tests passed on CircleCI!
Details
ci/circleci: test_sim_gaia_nondeterminism Your tests passed on CircleCI!
Details
ci/circleci: test_sim_gaia_simulation_after_import Your tests passed on CircleCI!
Details
ci/circleci: upload_coverage Your tests passed on CircleCI!
Details
codecov/project 55.57% (+0.06%) compared to d8fbae6
Details

@cwgoes cwgoes deleted the cwgoes/minter-ordering-fixes branch Dec 4, 2018

mircea-c added a commit that referenced this pull request Dec 5, 2018

Inflation bug fixes (#2982)
* PENDING.md; swap BeginBlocker ordering
* Calculate inflation every block
* Update x/mint spec
* Reset distribution info bond height instead

@rigelrozanski rigelrozanski referenced this pull request Dec 7, 2018

Closed

Gaia-9002 Crash log #3019

1 of 4 tasks complete
@hleb-albau

This comment has been minimized.

Copy link
Contributor

commented Jan 23, 2019

@cwgoes @jackzampolin is it correct, that NextAnnualProvisions() calculated using only bonded part of the tokens, but not really total supply?

// BeginBlocker
	totalSupply := k.sk.TotalPower(ctx)
	bondedRatio := k.sk.BondedRatio(ctx)
	minter.Inflation = minter.NextInflationRate(params, bondedRatio)
	minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalSupply)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.