forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR cosmos#3281: Staking Spec Upgrade
* remove kv seperation for marshalling * pending * cleanup * cleanup x2 * pending * working * minor refactors * entry structs defined * uncompiled mechanism written * add many compile fixes * code compiles * fix test compile errors * test cover passes * ... * multiple entries fix * ... * more design fix * working * fix test cover bug * Update PENDING.md * update comment around queue completion for redelegations/ubds * basic spec updates * spec folder cleanup * cleanup docs folder cont. * ... * find-replace and folder rename * supplimentary find/replace * pending * supplimentary * pending * few undos, stakingd -> staked * to staking -> to stake * undos * most staking -> most stake * ... * undos * simplestake->simplestaking * ... * pending update * capital letter replacements * ... * working * staking doc updates from rigel/delegation-index branch * spec-spec * spec-spec * LooseTokens -> NotBondedTokens * staking state.md updates * updates to hook and endblock spec * Update docs/gaia/gaiacli.md Co-Authored-By: rigelrozanski <[email protected]> * Update docs/gaia/validators/validator-setup.md Co-Authored-By: rigelrozanski <[email protected]> * Update docs/gaia/validators/validator-setup.md Co-Authored-By: rigelrozanski <[email protected]> * comment undo * remove ErrConflictingRedelegation * @cwgoes comments are resolved * further updates to endblock and state * msg json update * working transaction updates * working * complete transaction rewrite * PENDING.md * typo * add todo * address @jackzampolin @cwgoes comments * couple leftover comments, rename * Update x/staking/types/pool.go Co-Authored-By: rigelrozanski <[email protected]> * cwgoes additions * cwgoes suggestions x2
- Loading branch information
1 parent
332a5a3
commit 7f789d2
Showing
49 changed files
with
504 additions
and
656 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Specification of Specifications | ||
|
||
This file intends to outline the common structure for specifications within | ||
this directory. | ||
|
||
## Tense | ||
|
||
For consistency, specs should be written in passive present tense. | ||
|
||
## Common Layout | ||
|
||
The following generalized structure should be used to breakdown specifications | ||
for modules. Note that not all files may be required depending on the modules | ||
function | ||
|
||
- `overview.md` - describe module | ||
- `state.md` - specify and describe structures expected to marshalled into the store, and their keys | ||
- `state_transitions.md` - standard state transition operations triggered by by hooks, messages, etc. | ||
- `end_block.md` - specify any end-block operations | ||
- `begin_block.md` - specify any begin-block operations | ||
- `messages.md` - specify message structure and expected state machine behaviour | ||
- `hooks.md` - describe available hooks to be called by/from this module | ||
- `tags.md` - list and describe event tags used | ||
|
||
### Notation for key-value mapping | ||
|
||
Within `state.md` the following notation `->` should be used to describe key to | ||
value mapping: | ||
|
||
``` | ||
key -> value | ||
``` | ||
|
||
to represent byte concatenation the `|` may be used. In addition, encoding | ||
type may be specified, for example: | ||
|
||
``` | ||
0x00 | addressBytes | address2Bytes -> amino(value_object) | ||
``` | ||
|
||
Additionally, index mappings may be specified by mapping to the `nil` value, for example: | ||
|
||
``` | ||
0x01 | address2Bytes | addressBytes -> nil | ||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
## Transactions | ||
## Messages | ||
|
||
### MsgSend | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
docs/spec/distribution/transactions.md → docs/spec/distribution/messages.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Transactions | ||
# Messages | ||
|
||
## MsgWithdrawDelegationRewardsAll | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
docs/spec/governance/transactions.md → docs/spec/governance/messages.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Implementation (2/2) | ||
|
||
## Transactions | ||
## Messages | ||
|
||
### Proposal Submission | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
TODO | ||
|
||
The reserve pool is the pool of collected funds for use by governance taken via the `CommunityTax`. | ||
Currently with the SDK, tokens collected by the CommunityTax are accounted for but unspendable. | ||
|
4 changes: 2 additions & 2 deletions
4
docs/spec/slashing/transactions.md → docs/spec/slashing/messages.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
- `state.md` needs updates to include | ||
- LastValidatorPower | ||
- LastTotalPower | ||
- state for the queues: UnbondingDelegation, UnbondingValidator, Redelegation | ||
- introduce `state_transitions.md` to describe validator/delegator state | ||
transitions which are called from transactions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,62 @@ | ||
# End-Block | ||
|
||
## Unbonding Validator Queue | ||
|
||
For all unbonding validators that have finished their unbonding period, this switches their validator.Status | ||
from sdk.Unbonding to sdk.Unbonded if they still have any delegation left. Otherwise, it deletes it from state. | ||
|
||
```golang | ||
validatorQueue(currTime time.Time): | ||
// unbonding validators are in ordered queue from oldest to newest | ||
for all unbondingValidators whose CompleteTime < currTime: | ||
validator = GetValidator(unbondingValidator.ValidatorAddr) | ||
if validator.DelegatorShares == 0 { | ||
RemoveValidator(unbondingValidator) | ||
} else { | ||
validator.Status = sdk.Unbonded | ||
SetValidator(unbondingValidator) | ||
} | ||
return | ||
``` | ||
Each abci end block call, the operations to update queues and validator set | ||
changes are specified to execute. | ||
|
||
## Validator Set Changes | ||
|
||
The Tendermint validator set may be updated by state transitions that run at | ||
the end of every block. The Tendermint validator set may be changed by | ||
validators either being jailed due to inactivity/unexpected behaviour (covered | ||
in slashing) or changed in validator power. Determining which validator set | ||
changes must be made occurs during staking transactions (and slashing | ||
transactions) - during end-block the already accounted changes are applied and | ||
the changes cleared | ||
|
||
```golang | ||
EndBlock() ValidatorSetChanges | ||
vsc = GetValidTendermintUpdates() | ||
ClearTendermintUpdates() | ||
return vsc | ||
``` | ||
|
||
## CompleteUnbonding | ||
|
||
Complete the unbonding and transfer the coins to the delegate. Realize any | ||
slashing that occurred during the unbonding period. | ||
|
||
```golang | ||
unbondingQueue(currTime time.Time): | ||
// unbondings are in ordered queue from oldest to newest | ||
for all unbondings whose CompleteTime < currTime: | ||
validator = GetValidator(unbonding.ValidatorAddr) | ||
AddCoins(unbonding.DelegatorAddr, unbonding.Balance) | ||
removeUnbondingDelegation(unbonding) | ||
return | ||
``` | ||
|
||
## CompleteRedelegation | ||
|
||
Note that unlike CompleteUnbonding slashing of redelegating shares does not | ||
take place during completion. Slashing on redelegated shares takes place | ||
actively as a slashing occurs. The redelegation completion queue serves simply to | ||
clean up state, as redelegations older than an unbonding period need not be kept, | ||
as that is the max time that their old validator's evidence can be used to slash them. | ||
|
||
```golang | ||
redelegationQueue(currTime time.Time): | ||
// redelegations are in ordered queue from oldest to newest | ||
for all redelegations whose CompleteTime < currTime: | ||
removeRedelegation(redelegation) | ||
return | ||
``` | ||
The staking validator set is updated during this process by state transitions | ||
that run at the end of every block. As a part of this process any updated | ||
validators are also returned back to Tendermint for inclusion in the Tendermint | ||
validator set which is responsible for validating Tendermint messages at the | ||
consensus layer. Operations are as following: | ||
|
||
- the new validator set is taken as the top `params.MaxValidators` number of | ||
validators retrieved from the ValidatorsByPower index | ||
- the previous validator set is compared with the new validator set | ||
- missing validators begin unbonding | ||
- new validator are instantly bonded | ||
|
||
In all cases, any validators leaving or entering the bonded validator set or | ||
changing balances and staying within the bonded validator set incur an update | ||
message which is passed back to Tendermint. | ||
|
||
## Queues | ||
|
||
Within staking, certain state-transitions are not instantaneous but take place | ||
over a duration of time (typically the unbonding period). When these | ||
transitions are mature certain operations must take place in order to complete | ||
the state operation. This is achieved through the use of queues which are | ||
checked/processed at the end of each block. | ||
|
||
### Unbonding Validators | ||
|
||
When a validator is kicked out of the bonded validator set (either through | ||
being jailed, or not having sufficient bonded tokens) it begins the unbonding | ||
process along with all its delegations begin unbonding (while still being | ||
delegated to this validator). At this point the validator is said to be an | ||
unbonding validator, whereby it will mature to become an "unbonded validator" | ||
after the unbonding period has passed. | ||
|
||
Each block the validator queue is to be checked for mature unbonding | ||
validators. For all unbonding validators that have finished their unbonding | ||
period, the validator.Status is switched from sdk.Unbonding to sdk.Unbonded. | ||
If at this switch they do not have any delegation left the validator object | ||
instead just deleted from state. | ||
|
||
### Unbonding Delegations | ||
|
||
Complete the unbonding of all mature `UnbondingDelegations.Entries` within the | ||
`UnbondingDelegations` queue with the following procedure: | ||
- transfer the balance coins to the delegator's wallet address | ||
- remove the mature entry from `UnbondingDelegation.Entries` | ||
- remove the `UnbondingDelegation` object from the store if there are no | ||
remaining entries. | ||
|
||
### Redelegations | ||
|
||
Complete the unbonding of all mature `Redelegation.Entries` within the | ||
`Redelegations` queue with the following procedure: | ||
- remove the mature entry from `Redelegation.Entries` | ||
- remove the `Redelegation` object from the store if there are no | ||
remaining entries. |
Oops, something went wrong.