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: lamborghini distribution & inflation spec upgrade #1702

Merged
merged 15 commits into from
Aug 8, 2018
Merged

Conversation

rigelrozanski
Copy link
Contributor

@rigelrozanski rigelrozanski commented Jul 16, 2018

closes #967

  • Updated all relevant documentation (docs/)
  • Updated all relevant code comments
  • Wrote tests
  • Updated CHANGELOG.md
  • Updated cmd/gaia and examples/

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
Copy link

codecov bot commented Jul 16, 2018

Codecov Report

Merging #1702 into develop will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff            @@
##           develop    #1702   +/-   ##
========================================
  Coverage    63.44%   63.44%           
========================================
  Files          117      117           
  Lines         6937     6937           
========================================
  Hits          4401     4401           
  Misses        2281     2281           
  Partials       255      255

@rigelrozanski rigelrozanski changed the title WIP provisions spec upgrade WIP distribution & inflation spec upgrade Jul 16, 2018
@rigelrozanski rigelrozanski changed the title WIP distribution & inflation spec upgrade R4R: distribution & inflation spec upgrade Jul 25, 2018
and global pool. When the validator is the proposer of the round, that
validator (and their delegators) receives between 1% and 5% of fee rewards, the
reserve tax is then charged, then the remainder is distributed socially by
voting power to all validators including the proposer validator. The amount of
Copy link
Collaborator

@fedekunze fedekunze Jul 25, 2018

Choose a reason for hiding this comment

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

Is the remainder distributed to all the validators from the validator set or only to the ones who voted on the pre-commit/pre-vote phase ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All bonded validators. Not just ones that voted, the only way to not get the social distribution is to get kicked out (which will happen if you're not live enough) - I'll make this text more explicit.

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed previously, even though it may not be the best place here, it would help tremendously if some naive examples were linked somehow (similar to the ones on the cosmos.network/docs).

Copy link
Contributor Author

@rigelrozanski rigelrozanski Aug 1, 2018

Choose a reason for hiding this comment

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

Added more text to make this explicit (addressed)

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Thanks for updating the spec! I left some general comments/remarks.

This stuff can get pretty complex and difficult to just sift through and so I think examples would help greatly (those on cosmos.network/docs helped me greatly), but I know that the spec may not be the best place for those.

It might help to think of ways to introduce the notion of examples somehow.

PENDING.md Outdated
@@ -38,6 +38,7 @@ IMPROVEMENTS
* [tools] Remove `rm -rf vendor/` from `make get_vendor_deps`
* [x/auth] Recover ErrorOutOfGas panic in order to set sdk.Result attributes correctly
* [x/stake] Add revoked to human-readable validator
* [spec] Inflation and distribution specs drastically improved
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets add the issue (#967) number here 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

### Power Change

Within the current implementation all power changes ever made are indefinitely stored
within the current state. In the future this state should be trimmed on an epoch basis. Delegators
Copy link
Contributor

Choose a reason for hiding this comment

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

This this data be pruned on all nodes? Archive nodes will have to keep this, correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

It won't be pruned since it's kept in the current state. If we don't need power changes older than an epoch for any calculations, we should be able to remove them from the current state (and then nodes with pruning enabled will delete them).

Is the reason we're not doing this initially because it's complex to implement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need all the calculations in the current state for an epoch equal to what we want the maximum allowable time withdrawal your fees is.. I'm guessing at minimum this is something like a couple months and at maximum is something like a year. - There is some complexity surrounding tracking what the last required power change is but the bigger problem is figuring out what to do / the appropriate lazy mechanism which plays nice with the existing fees distribution mechanism for everyone who hasn't withdrawn their fees by that time. There are a number of options: But this is the discussion grounds for that:

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed that this merits discussion but it probably can be safely tabled to post-launch as long as we put in place the store key prefixes (block height) to prune easily in the future.

delegators. Each validator has the opportunity to charge commission to the
delegators on the fees collected on behalf of the delegators by the validators.
Fees are paid directly into a global fee pool, and validator proposer-reward
pool. Due to the nature of of passive accounting whenever changes to parameters
Copy link
Contributor

Choose a reason for hiding this comment

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

of of typo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

which affect the rate of fee distribution occurs, withdrawal of fees must also
occur.

- when withdrawing one must withdrawal the maximum amount they are entitled
Copy link
Contributor

Choose a reason for hiding this comment

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

Capitalization and punctuation should be consistent here 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed (lower bullet points from here - using lower case in bullet points be cause not sentences.

- when a validator chooses to change the commission on fees, all accumulated
commission fees must be simultaneously withdrawn.

The above scenarios are covered is `triggers.md`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Wording is a bit confusing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol thanks - was a type is -> in

- triggered-by: `stake.TxCreateValidator`

Whenever a totally new validator is added to the Tendermint validator set they
are entitled to begin earning rewards of atom provisions and fess. At this
Copy link
Contributor

Choose a reason for hiding this comment

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

fees*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

# End Block

```
EndBlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

What are these for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unnecessary - removing


Validator provisions are minted on an hourly basis (the first block of a new
hour). The annual target of between 7% and 20%. The long-term target ratio of
bonded tokens to unbonded tokens is 67%.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to describe why the exact target of 67% in a concise manner?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed - or cite the whitepaper / relevant source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree this IS the spec, it supersedes the white paper - it's not a place where choices always need to be justified. This number for instance comes out of a bunch of conversations with Jae - there is no good reason it just seems like a fine value. For y'alls record if the value is to small its a security concern, if it's to large then there isn't enough liquidity for price discovery -> 67% seems fine.

inflation = nextInflation(hrsPerYr).Round(precision)
SetInflation(inflation)

provisions = inflation * (pool.TotalSupply() / hrsPerYr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the pool.TotalSupply() here the total number of bonded tokens in the validator set?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it's the total token supply - all tokens bonded, unbonded, deposited-in-governance-proposals, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

comment addressed by cwgoes


bondedRatio = pool.BondedPool / pool.TotalSupply()

inflationRateChangePerYear = (1 - bondedRatio / params.GoalBonded) * params.InflationRateChange
Copy link
Contributor

Choose a reason for hiding this comment

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

What exactly is params.InflationRateChange?

Copy link
Contributor

Choose a reason for hiding this comment

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

Rate of change in the inflation rate (second derivative of the total supply)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

comment addressed by cwgoes

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

Many comments!

At each endblock, the fees received are sorted to the proposer, community fund,
and global pool. When the validator is the proposer of the round, that
validator (and their delegators) receives between 1% and 5% of fee rewards, the
reserve tax is then charged, then the remainder is distributed socially by
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean "socially"? Perhaps "proportionally"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well I did actually mean social distribution which means that you get coins even if you weren't the proposer - but proportional makes more sense in this instance, so I'll change, but then name is the social distribution

Copy link
Contributor

Choose a reason for hiding this comment

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

OK makes sense - if you just define "social distribution" once that's fine.

validator (and their delegators) receives between 1% and 5% of fee rewards, the
reserve tax is then charged, then the remainder is distributed socially by
voting power to all validators including the proposer validator. The amount of
proposer reward is calculated from pre-commits Tendermint messages. All
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's cite why, e.g. "in order to incentivize validators to wait and include additional pre-commits in the block".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, included.

* sumPowerPrecommitValidators / totalBondedTokens)
proposer.ProposerPool += proposerReward

communityFunding = feesCollectedDec * communityTax
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the reserve pool? Maybe "tax" is not quite the right name (nbd though).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

leaving for now - open to suggestions still

### Power Change

Within the current implementation all power changes ever made are indefinitely stored
within the current state. In the future this state should be trimmed on an epoch basis. Delegators
Copy link
Contributor

Choose a reason for hiding this comment

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

It won't be pruned since it's kept in the current state. If we don't need power changes older than an epoch for any calculations, we should be able to remove them from the current state (and then nodes with pruning enabled will delete them).

Is the reason we're not doing this initially because it's complex to implement?

- Multi-token fees to be socially distributed
- Proposer reward pool
- Inflated atom provisions
- Validator commission on delegators
Copy link
Contributor

Choose a reason for hiding this comment

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

Commission on atom provisions from delegated stake?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to commission on all rewards earned by their delegators

for that distributor had static shares (equal to the current shares), and no
recipients had ever withdrawn their entitled rewards. The projected pool
represents the anticipated recipient's entitlement to the distributors tokens
base on the current blocks token input to the distributor, and the
Copy link
Contributor

Choose a reason for hiding this comment

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

"token input" = "contributing stake"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point to clarify, no token input refers to the new input from fees/provision-reward etc. updated to say token input (for example fees reward received)

@@ -0,0 +1,396 @@
# Transactions
Copy link
Contributor

Choose a reason for hiding this comment

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

I find it really difficult to reason through the correctness of the transaction procedures in this file, likely because we're trying to implement a simple strict model with a lazy process.

I think it would be helpful if we outline for each transaction what the calculation would be in the strict, inefficient case (iterating over everything), then explain our lazy implementation, and even ideally provide a quick (rough) demonstration of equivalence.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Coming up with a good way to comprehend this efficient fee distribution module is going to be an ongoing challenge - Due to this, I agree that equivalent outcome in a "simple" module for each transaction should be documented within the spec beside the complex "efficient" situation already provided.

With regards to the example - this is a tug of worlds here - I don't think that we want to have non-spec information in the spec - to me, the example described doesn't actually belong in the spec itself HOWEVER I think it's super valuable and I think we should have it somewhere. I think maybe IN The spec we could have a non-spec section which actually works through what you're describing. - I think that this is a separate task which should be completed soon, but is a lower priority than distribution implementation to me

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't mean include an example (although that might be a good idea too), I mean include equations that demonstrate why the complex implementation reduces to the same effects as the simple one (weren't those written up somewhere previously)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or "parameterized examples"!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving this for now as we're likely moving away from pre-launch implementation however here is an issue for more discussion #1906


## Create validator distribution

- triggered-by: `stake.TxCreateValidator`
Copy link
Contributor

Choose a reason for hiding this comment

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

Every time or only when the new validator candidate is bonded?

Copy link
Contributor

Choose a reason for hiding this comment

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

(and in the latter case - then also by another validator unbonding, for example?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, do we need to anything when a validator is unbonded?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Every time or only when the new validator candidate is bonded?

Good observation, this only happens when the validator enters the bonded validator set. updated.

Also, do we need to anything when a validator is unbonded?

For other validators:
When a validator is unbonded - the power change is be recorded and thus all other's passive calculations will incorporate the changes passively as expected. So nothing additional or special is required for an unbond for them.

For the affected validator:
With regards to everyone affected by the unbond - we will need to incorporate a new mechanism to passively account for this - Just opened up an issue to think about this a bit more #1905.
I'm certain that the appropriate mechanism can be added onto what is spec'd here to account for this situation. THANK YOU FOR BRINGING THIS UP.

@@ -0,0 +1,31 @@
# Triggers
Copy link
Contributor

Choose a reason for hiding this comment

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

What about slashing events (which modify validator stake and delegation stake, and not necessarily in the same proportion)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, what about parameter changes (e.g. enacted by ParameterChangeProposals)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Slashing events is a situation that needs to be considered:

Side note: Equal slashing of delegators and validators is a design constraint of this system - we can talk about it more outside of github if you'd like.

These slashing events will need to have a new special computation not yet outlined in this spec: can be processed similarly with a new pool as per to unbonding validators. more discussion here: #1905


Parameter changes will not trigger any new changes because parameters relevant to distribution affect the tokens flowing into the distribution system but do not affect the tokens already contained within this distribution system.


## Create or modify delegation distribution

- triggered-by: `stake.TxDelegate`
Copy link
Contributor

Choose a reason for hiding this comment

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

Or TxBeginRedelegate, or TxBeginUnbonding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

included

@ValarDragon
Copy link
Contributor

I'd like to review this as well before its merged. Chris had recommended that I wait until his comments were resolved first though. Commenting so I get pinged for updates.

@rigelrozanski
Copy link
Contributor Author

Hopefully can address everything tomorrow -still focused on decimal

@cwgoes
Copy link
Contributor

cwgoes commented Aug 2, 2018

Per discussion with @rigelrozanski we'd like to consider the "piggy bank distribution" instead as a simpler approach for launch.

@rigelrozanski
Copy link
Contributor Author

Yes more on that - this spec should still be merged and reviewed further and expanded based on some of the new issues I've raised out of this. This model is still something we want - but should likely NOT be a prelaunch requirement - instead we should use the simple piggy bank model which should be spec'd out separately.

@cwgoes - I've addressed your comments, although a few of them haven't been fully addressed and I've opened two github issues for further consideration on this mechanism.
@alexanderbez - I've addressed all of your comments besides adding examples - again based on this comment - that's something we should do PRE implementation - however I'm going to hold off on that for now because I don't think we should implement this prelaunch
@ValarDragon - Probably not a good use of your time to focus on reviewing this at the moment because I think we should move away from prelaunch implementation of this spec

@rigelrozanski rigelrozanski changed the title R4R: distribution & inflation spec upgrade R4R: lamborghini distribution & inflation spec upgrade Aug 2, 2018
@rigelrozanski
Copy link
Contributor Author

Let's merge this?

@cwgoes
Copy link
Contributor

cwgoes commented Aug 8, 2018

Let's merge this?

Before we actually implement it in the future, I want to review again re: transaction correctness - but agreed, fine for now.

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

utACK

Best description of this mechanism we have at the moment, so merging. Note that transactions have not been reviewed for mathematical equivalence (against the simple model); before we actually implement this (if we do so in the future) they should be further reviewed.

@cwgoes cwgoes merged commit 7fb626f into develop Aug 8, 2018
@cwgoes cwgoes deleted the rigel/fee-spec branch August 8, 2018 10:10
chillyvee pushed a commit to chillyvee/cosmos-sdk that referenced this pull request Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

spec: fee distribution
5 participants