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: Staking Spec Upgrade #3281

Merged
merged 78 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
dff6681
remove kv seperation for marshalling
rigelrozanski Jan 5, 2019
1170ee3
pending
rigelrozanski Jan 5, 2019
4b90e7f
cleanup
rigelrozanski Jan 6, 2019
017dab1
cleanup x2
rigelrozanski Jan 6, 2019
270fe04
pending
rigelrozanski Jan 6, 2019
9436a19
working
rigelrozanski Jan 6, 2019
3a656a2
minor refactors
rigelrozanski Jan 6, 2019
e1e2469
entry structs defined
rigelrozanski Jan 6, 2019
7ad6dd7
uncompiled mechanism written
rigelrozanski Jan 7, 2019
cae553e
add many compile fixes
rigelrozanski Jan 7, 2019
a2cb204
Merge remote-tracking branch 'origin/develop' into rigel/delegation-i…
rigelrozanski Jan 7, 2019
e48fb95
code compiles
rigelrozanski Jan 8, 2019
e490924
fix test compile errors
rigelrozanski Jan 8, 2019
9dd1181
test cover passes
rigelrozanski Jan 8, 2019
b4d5117
...
rigelrozanski Jan 9, 2019
36761e6
Merge remote-tracking branch 'origin/develop' into rigel/delegation-i…
rigelrozanski Jan 9, 2019
31a526e
Merge remote-tracking branch 'origin/develop' into rigel/delegation-i…
rigelrozanski Jan 9, 2019
33ce0f3
multiple entries fix
rigelrozanski Jan 9, 2019
41a4285
...
rigelrozanski Jan 9, 2019
96a28d5
more design fix
rigelrozanski Jan 9, 2019
8f20ed7
working
rigelrozanski Jan 9, 2019
069c5a4
fix test cover bug
rigelrozanski Jan 10, 2019
c161cb5
Update PENDING.md
rigelrozanski Jan 10, 2019
c83b910
Merge branch 'develop' into rigel/delegation-index
rigelrozanski Jan 10, 2019
f13afea
update comment around queue completion for redelegations/ubds
rigelrozanski Jan 10, 2019
d1a2ff7
Merge remote-tracking branch 'refs/remotes/origin/rigel/delegation-in…
rigelrozanski Jan 10, 2019
8906710
basic spec updates
rigelrozanski Jan 10, 2019
0e10245
spec folder cleanup
rigelrozanski Jan 11, 2019
e0565c0
cleanup docs folder cont.
rigelrozanski Jan 11, 2019
806ee83
...
rigelrozanski Jan 11, 2019
86da904
find-replace and folder rename
rigelrozanski Jan 11, 2019
4638869
supplimentary find/replace
rigelrozanski Jan 11, 2019
a28f2a9
pending
rigelrozanski Jan 11, 2019
f56e266
supplimentary
rigelrozanski Jan 11, 2019
2588411
pending
rigelrozanski Jan 11, 2019
cb42272
few undos, stakingd -> staked
rigelrozanski Jan 11, 2019
aea0ed5
to staking -> to stake
rigelrozanski Jan 11, 2019
2285d37
undos
rigelrozanski Jan 11, 2019
1352080
most staking -> most stake
rigelrozanski Jan 11, 2019
927dcb8
...
rigelrozanski Jan 11, 2019
e40d31a
undos
rigelrozanski Jan 11, 2019
c862fc8
simplestake->simplestaking
rigelrozanski Jan 11, 2019
5182eb7
...
rigelrozanski Jan 11, 2019
01c68a7
pending update
rigelrozanski Jan 11, 2019
1bae8cf
capital letter replacements
rigelrozanski Jan 11, 2019
9b9fb74
...
rigelrozanski Jan 11, 2019
179aa32
Merge remote-tracking branch 'origin/rigel/stake-to-staking' into rig…
rigelrozanski Jan 11, 2019
4161174
working
rigelrozanski Jan 11, 2019
5ae7245
staking doc updates from rigel/delegation-index branch
rigelrozanski Jan 11, 2019
4f86c38
spec-spec
rigelrozanski Jan 11, 2019
695830b
spec-spec
rigelrozanski Jan 11, 2019
ab5c4db
LooseTokens -> NotBondedTokens
rigelrozanski Jan 11, 2019
aa927df
staking state.md updates
rigelrozanski Jan 11, 2019
6a1a50f
updates to hook and endblock spec
rigelrozanski Jan 11, 2019
54234ec
Update docs/gaia/gaiacli.md
fedekunze Jan 11, 2019
4af7684
Update docs/gaia/validators/validator-setup.md
fedekunze Jan 11, 2019
8116a30
Update docs/gaia/validators/validator-setup.md
fedekunze Jan 11, 2019
2a3be17
comment undo
rigelrozanski Jan 11, 2019
59b64c9
remove ErrConflictingRedelegation
rigelrozanski Jan 11, 2019
03631dd
@cwgoes comments are resolved
rigelrozanski Jan 11, 2019
7fd4b52
Merge remote-tracking branch 'origin/develop' into rigel/delegation-i…
rigelrozanski Jan 11, 2019
1b862ed
Merge remote-tracking branch 'origin/rigel/stake-to-staking' into rig…
rigelrozanski Jan 11, 2019
3bae7ed
Merge remote-tracking branch 'origin/develop' into rigel/stakin-spec-…
rigelrozanski Jan 11, 2019
a586335
further updates to endblock and state
rigelrozanski Jan 12, 2019
8d39d92
msg json update
rigelrozanski Jan 12, 2019
17b215f
working transaction updates
rigelrozanski Jan 12, 2019
ba0e739
working
rigelrozanski Jan 12, 2019
5331076
complete transaction rewrite
rigelrozanski Jan 12, 2019
bd4fdc3
PENDING.md
rigelrozanski Jan 12, 2019
7e428aa
Merge branch 'rigel/delegation-index' into rigel/stakin-spec-upgrade
rigelrozanski Jan 12, 2019
149a407
typo
rigelrozanski Jan 12, 2019
16036c8
add todo
rigelrozanski Jan 14, 2019
f5d21c0
Merge remote-tracking branch 'origin/develop' into rigel/stakin-spec-…
rigelrozanski Jan 19, 2019
db3b4a0
address @jackzampolin @cwgoes comments
rigelrozanski Jan 19, 2019
7ad6dd0
couple leftover comments, rename
rigelrozanski Jan 19, 2019
457658f
Update x/staking/types/pool.go
fedekunze Jan 19, 2019
88cc1d6
cwgoes additions
rigelrozanski Jan 21, 2019
2dd902a
cwgoes suggestions x2
rigelrozanski Jan 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ BREAKING CHANGES
* [gaia-lite] [\#2182] Renamed and merged all redelegations endpoints into `/staking/redelegations`
* [\#3176](https://github.com/cosmos/cosmos-sdk/issues/3176) `tx/sign` endpoint now expects `BaseReq` fields as nested object.
* [\#2222] all endpoints renamed from `/stake` -> `/staking`
* [\#1268] `LooseTokens` -> `NotBondedTokens`
* [\#3289] misc renames:
* `Validator.UnbondingMinTime` -> `Validator.UnbondingCompletionTime`
* `Delegation` -> `Value` in `MsgCreateValidator` and `MsgDelegate`
Expand All @@ -31,9 +32,10 @@ BREAKING CHANGES
* [\#3064](https://github.com/cosmos/cosmos-sdk/issues/3064) Sanitize `sdk.Coin` denom. Coins denoms are now case insensitive, i.e. 100fooToken equals to 100FOOTOKEN.
* [\#3195](https://github.com/cosmos/cosmos-sdk/issues/3195) Allows custom configuration for syncable strategy
* [\#3242](https://github.com/cosmos/cosmos-sdk/issues/3242) Fix infinite gas
meter utilization during aborted ante handler executions.
* [\#2222] [x/staking] `/stake` -> `/staking` module rename
* \#3292 [x/distribution] Enable or disable withdraw addresses with a parameter in the param store
meter utilization during aborted ante handler executions.
* [x/distribution] \#3292 Enable or disable withdraw addresses with a parameter in the param store
* [staking] \#2222 `/stake` -> `/staking` module rename
* [staking] \#1268 `LooseTokens` -> `NotBondedTokens`
* [staking] \#1402 Redelegation and unbonding-delegation structs changed to include multiple an array of entries
* [staking] \#3289 misc renames:
* `Validator.UnbondingMinTime` -> `Validator.UnbondingCompletionTime`
Expand Down Expand Up @@ -109,7 +111,8 @@ IMPROVEMENTS
slashing, and staking modules.
* [\#3093](https://github.com/cosmos/cosmos-sdk/issues/3093) Ante handler does no longer read all accounts in one go when processing signatures as signature
verification may fail before last signature is checked.
* [x/stake] \#1402 Add for multiple simultaneous redelegations or unbonding-delegations within an unbonding period
* [staking] \#1402 Add for multiple simultaneous redelegations or unbonding-delegations within an unbonding period
* [staking] \#1268 staking spec rewrite

* Tendermint

Expand Down
8 changes: 4 additions & 4 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,12 @@ func TestPoolParamsQuery(t *testing.T) {
pool := getStakingPool(t, port)

initialPool := staking.InitialPool()
initialPool.LooseTokens = initialPool.LooseTokens.Add(sdk.NewInt(100))
initialPool.BondedTokens = initialPool.BondedTokens.Add(sdk.NewInt(100)) // Delegate tx on GaiaAppGenState
initialPool.LooseTokens = initialPool.LooseTokens.Add(sdk.NewInt(50)) // freeFermionsAcc = 50 on GaiaAppGenState
initialPool.NotBondedTokens = initialPool.NotBondedTokens.Add(sdk.NewInt(100))
initialPool.BondedTokens = initialPool.BondedTokens.Add(sdk.NewInt(100)) // Delegate tx on GaiaAppGenState
initialPool.NotBondedTokens = initialPool.NotBondedTokens.Add(sdk.NewInt(50)) // freeFermionsAcc = 50 on GaiaAppGenState

require.Equal(t, initialPool.BondedTokens, pool.BondedTokens)
require.Equal(t, initialPool.LooseTokens, pool.LooseTokens)
require.Equal(t, initialPool.NotBondedTokens, pool.NotBondedTokens)
}

func TestValidatorsQuery(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func InitializeTestLCD(
accAuth.Coins = sdk.Coins{sdk.NewInt64Coin(stakingTypes.DefaultBondDenom, 100)}
acc := gapp.NewGenesisAccount(&accAuth)
genesisState.Accounts = append(genesisState.Accounts, acc)
genesisState.StakingData.Pool.LooseTokens = genesisState.StakingData.Pool.LooseTokens.Add(sdk.NewInt(100))
genesisState.StakingData.Pool.NotBondedTokens = genesisState.StakingData.Pool.NotBondedTokens.Add(sdk.NewInt(100))
}

appState, err := codec.MarshalJSONIndent(cdc, genesisState)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func GaiaAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []js
for _, acc := range genesisState.Accounts {
for _, coin := range acc.Coins {
if coin.Denom == bondDenom {
stakingData.Pool.LooseTokens = stakingData.Pool.LooseTokens.
stakingData.Pool.NotBondedTokens = stakingData.Pool.NotBondedTokens.
Add(coin.Amount) // increase the supply
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func makeGenesisState(t *testing.T, genTxs []auth.StdTx) GenesisState {
acc := auth.NewBaseAccountWithAddress(sdk.AccAddress(msg.ValidatorAddr))
acc.Coins = sdk.Coins{sdk.NewInt64Coin(bondDenom, 150)}
genAccs[i] = NewGenesisAccount(&acc)
stakingData.Pool.LooseTokens = stakingData.Pool.LooseTokens.Add(sdk.NewInt(150)) // increase the supply
stakingData.Pool.NotBondedTokens = stakingData.Pool.NotBondedTokens.Add(sdk.NewInt(150)) // increase the supply
}

// create the final app state
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func appStateFn(r *rand.Rand, accs []simulation.Account, genesisTimestamp time.T
delegations = append(delegations, delegation)
}

stakingGenesis.Pool.LooseTokens = sdk.NewInt((amount * numAccs) + (numInitiallyBonded * amount))
stakingGenesis.Pool.NotBondedTokens = sdk.NewInt((amount * numAccs) + (numInitiallyBonded * amount))
stakingGenesis.Validators = validators
stakingGenesis.Bonds = delegations

Expand Down
4 changes: 2 additions & 2 deletions docs/gaia/gaiacli.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,9 @@ gaiacli query staking pool

With the `pool` command you will get the values for:

- Loose and bonded tokens
- Not-bonded and bonded tokens
- Token supply
- Current anual inflation and the block in which the last inflation was processed
- Current annual inflation and the block in which the last inflation was processed
- Last recorded bonded shares

##### Query Delegations To Validator
Expand Down
45 changes: 45 additions & 0 deletions docs/spec/SPEC-SPEC.md
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.

rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
## 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

rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
### 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.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Transactions
## Messages

### MsgSend

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Transactions
# Messages

## MsgWithdrawDelegationRewardsAll

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Implementation (2/2)

## Transactions
## Messages

### Proposal Submission

Expand Down
52 changes: 0 additions & 52 deletions docs/spec/inflation/end_block.md

This file was deleted.

21 changes: 0 additions & 21 deletions docs/spec/inflation/state.md

This file was deleted.

2 changes: 0 additions & 2 deletions docs/spec/other/other.md

This file was deleted.

3 changes: 3 additions & 0 deletions docs/spec/reserve-pool/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TODO
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved

The reserve pool is the pool of collected funds for use by governance taken via the `CommunityTax`
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Transactions
## Messages

In this section we describe the processing of transactions for the `slashing` module.
In this section we describe the processing of messages for the `slashing` module.

### Unjail

Expand Down
7 changes: 7 additions & 0 deletions docs/spec/staking/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
- `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
120 changes: 57 additions & 63 deletions docs/spec/staking/end_block.md
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
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved

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
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved

Within staking, certain state-transitions are not instantaneous but take place
of a duration of time (typically the unbonding period). When these transitions
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
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 begin the unbonding
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
process - as well as all its delegations begin unbonding while still being
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
delegated to this validator. At this point the validator is said to an
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
unbonding validator, whereby it will mature to become an unbonded
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
validator after the unbonding period has passed.
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved

Each block the validator queue is to be checked for mature unbonding
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
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.
Loading