cosmos-sdk/x/distribution/spec/README.md

97 lines
4.6 KiB
Markdown
Raw Normal View History

# Distribution
## Overview
2018-11-11 12:51:27 -08:00
This _simple_ distribution mechanism describes a functional way to passively
2018-11-13 06:02:19 -08:00
distribute rewards between validators and delegators. Note that this mechanism does
2018-11-11 12:51:27 -08:00
not distribute funds in as precisely as active reward distribution mechanisms and
will therefore be upgraded in the future.
The mechanism operates as follows. Collected rewards are pooled globally and
divided out passively to validators and delegators. Each validator has the
opportunity to charge commission to the delegators on the rewards collected on
2018-11-11 12:51:27 -08:00
behalf of the delegators. Fees are collected directly into a global reward pool
and validator proposer-reward pool. Due to the nature of passive accounting,
whenever changes to parameters which affect the rate of reward distribution
occurs, withdrawal of rewards must also occur.
- Whenever withdrawing, one must withdraw the maximum amount they are entitled
2018-11-13 06:02:19 -08:00
to, leaving nothing in the pool.
2018-11-11 12:51:27 -08:00
- Whenever bonding, unbonding, or re-delegating tokens to an existing account, a
full withdrawal of the rewards must occur (as the rules for lazy accounting
2018-08-20 08:50:13 -07:00
change).
2018-11-11 12:51:27 -08:00
- Whenever a validator chooses to change the commission on rewards, all accumulated
commission rewards must be simultaneously withdrawn.
2018-08-28 15:23:57 -07:00
The above scenarios are covered in `hooks.md`.
The distribution mechanism outlined herein is used to lazily distribute the
following rewards between validators and associated delegators:
2018-11-11 12:51:27 -08:00
- multi-token fees to be socially distributed
- proposer reward pool
- inflated atom provisions
- validator commission on all rewards earned by their delegators stake
Fees are pooled within a global pool, as well as validator specific
2018-08-20 08:50:13 -07:00
proposer-reward pools. The mechanisms used allow for validators and delegators
to independently and lazily withdraw their rewards.
2018-11-11 12:51:27 -08:00
## Shortcomings
2018-08-23 01:02:26 -07:00
As a part of the lazy computations, each delegator holds an accumulation term
specific to each validator which is used to estimate what their approximate
2018-11-11 12:51:27 -08:00
fair portion of tokens held in the global fee pool is owed to them.
2018-08-23 01:02:26 -07:00
```
entitlement = delegator-accumulation / all-delegators-accumulation
```
Under the circumstance that there was constant and equal flow of incoming
2018-08-23 01:02:26 -07:00
reward tokens every block, this distribution mechanism would be equal to the
active distribution (distribute individually to all delegators each block).
2018-11-11 12:51:27 -08:00
However, this is unrealistic so deviations from the active distribution will
2018-08-23 01:02:26 -07:00
occur based on fluctuations of incoming reward tokens as well as timing of
2018-11-11 12:51:27 -08:00
reward withdrawal by other delegators.
2018-08-23 01:02:26 -07:00
If you happen to know that incoming rewards are about to significantly increase,
2018-08-23 01:02:26 -07:00
you are incentivized to not withdraw until after this event, increasing the
2018-11-13 06:02:19 -08:00
worth of your existing _accum_. See [#2764](https://github.com/cosmos/cosmos-sdk/issues/2764)
for further details.
## Affect on Staking
Charging commission on Atom provisions while also allowing for Atom-provisions
to be auto-bonded (distributed directly to the validators bonded stake) is
2018-11-13 06:02:19 -08:00
problematic within BPoS. Fundamentally, these two mechanisms are mutually
2018-11-14 10:26:31 -08:00
exclusive. If both commission and auto-bonding mechanisms are simultaneously
applied to the staking-token then the distribution of staking-tokens between
any validator and its delegators will change with each block. This then
necessitates a calculation for each delegation records for each block -
which is considered computationally expensive.
2018-11-13 06:02:19 -08:00
In conclusion, we can only have Atom commission and unbonded atoms
2018-08-20 08:50:13 -07:00
provisions or bonded atom provisions with no Atom commission, and we elect to
implement the former. Stakeholders wishing to rebond their provisions may elect
2018-11-11 12:53:43 -08:00
to set up a script to periodically withdraw and rebond rewards.
## Contents
1. **[Concepts](01_concepts.md)**
- [Reference Counting in F1 Fee Distribution](01_concepts.md#reference-counting-in-f1-fee-distribution)
2019-05-17 06:24:24 -07:00
2. **[State](02_state.md)**
3. **[End Block](03_end_block.md)**
4. **[Messages](04_messages.md)**
- [MsgWithdrawDelegationRewardsAll](04_messages.md#msgwithdrawdelegationrewardsall)
- [MsgWithdrawDelegationReward](04_messages.md#msgwithdrawdelegationreward)
- [MsgWithdrawValidatorRewardsAll](04_messages.md#msgwithdrawvalidatorrewardsall)
- [Common calculations ](04_messages.md#common-calculations-)
5. **[Hooks](05_hooks.md)**
- [Create or modify delegation distribution](05_hooks.md#create-or-modify-delegation-distribution)
- [Commission rate change](05_hooks.md#commission-rate-change)
- [Change in Validator State](05_hooks.md#change-in-validator-state)
Merge PR #4541: Events Tracking / Tendermint v0.32.0 Update * Update Tendermint to v0.32.0-dev0 * Initial refactor of tags * Update event types and add unit tests * Refactor context * Update module manager * Update result godoc * Implement ToABCIEvents * Update BaseApp * Minor cleanup * Fix typo * Update x/bank message handler * Update x/bank keeper * Update x/bank * Update x/bank events docs * Update x/crisis module events * Reset context with events on each message exec * Update x/distribution events and docs * Update BaseApp to not set empty events manually * Implement simple event manager * Update module manager * Update modules to use event manager * Update x/gov module to use events * Update events docs * Update gov queries and crisis app module * Update bank keeper * Add events to minting begin blocker * Update modules to use types/events.go * Cleanup x/mint * Update x/staking events * Update x/staking events * Update events to have sender part of message.sender * Fix build * Fix module unit tests * Add pending log entry * Update deps * Update x/crisis/types/events.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/bank/internal/types/events.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/distribution/types/events.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/mint/internal/types/events.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/slashing/types/events.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/staking/types/events.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/gov/handler.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/gov/handler.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/mint/abci.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/mint/abci.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/slashing/handler.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/staking/handler.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/slashing/handler.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/staking/handler.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/staking/handler.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/staking/handler.go Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Upgrade TM to v0.32.0-dev1 * Update events as strings * Update Tendermint to v0.32.0-dev2 * Fix BaseApp unit tests * Fix unit tests * Bump tendermint version to v0.32.0 * typos
2019-06-26 09:03:25 -07:00
6. **[Events](06_events.md)**
- [BeginBlocker](06_events.md#beginblocker)
- [Handlers](06_events.md#handlers)
7. **[Parameters](07_params.md)**