Skip to content

Commit 0f961f7

Browse files
docs(x/staking): update readme (backport #22216) (#22221)
Co-authored-by: Julián Toledano <[email protected]>
1 parent f4d3000 commit 0f961f7

File tree

2 files changed

+45
-43
lines changed

2 files changed

+45
-43
lines changed

x/staking/README.md

+38-38
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,20 @@ Pool is used for tracking bonded and not-bonded token supply of the bond denomin
6969
LastTotalPower tracks the total amounts of bonded tokens recorded during the previous end block.
7070
Store entries prefixed with "Last" must remain unchanged until EndBlock.
7171

72-
* LastTotalPower: `0x12 -> ProtocolBuffer(math.Int)`
72+
* LastTotalPower: `collections.NewPrefix(18)`
7373

7474
### UnbondingID
7575

7676
UnbondingID stores the ID of the latest unbonding operation. It enables creating unique IDs for unbonding operations, i.e., UnbondingID is incremented every time a new unbonding operation (validator unbonding, unbonding delegation, redelegation) is initiated.
7777

78-
* UnbondingID: `0x37 -> uint64`
78+
* UnbondingID: `55`
7979

8080
### Params
8181

8282
The staking module stores its params in state with the prefix of `0x51`,
8383
it can be updated with governance or the address with authority.
8484

85-
* Params: `0x51 | ProtocolBuffer(Params)`
85+
* Params: `81`
8686

8787
```protobuf reference
8888
https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/staking/proto/cosmos/staking/v1beta1/staking.proto#L300-L328
@@ -117,18 +117,18 @@ required lookups for slashing and validator-set updates. A third special index
117117
throughout each block, unlike the first two indices which mirror the validator
118118
records within a block.
119119

120-
* Validators: `0x21 | OperatorAddrLen (1 byte) | OperatorAddr -> ProtocolBuffer(validator)`
121-
* ValidatorsByConsAddr: `0x22 | ConsAddrLen (1 byte) | ConsAddr -> OperatorAddr`
122-
* ValidatorsByPower: `0x23 | BigEndian(ConsensusPower) | OperatorAddrLen (1 byte) | OperatorAddr -> OperatorAddr`
123-
* LastValidatorsPower: `0x11 | OperatorAddrLen (1 byte) | OperatorAddr -> ProtocolBuffer(ConsensusPower)`
124-
* ValidatorsByUnbondingID: `0x38 | UnbondingID -> 0x21 | OperatorAddrLen (1 byte) | OperatorAddr`
120+
* Validators: `33 | OperatorAddrLen (1 byte) | OperatorAddr -> ProtocolBuffer(validator)`
121+
* ValidatorsByConsAddr: `34 | ConsAddrLen (1 byte) | ConsAddr -> OperatorAddr`
122+
* ValidatorsByPower: `23 | BigEndian(ConsensusPower) | OperatorAddrLen (1 byte) | OperatorAddr -> OperatorAddr`
123+
* LastValidatorsPower: `17 | OperatorAddrLen (1 byte) | OperatorAddr -> ProtocolBuffer(ConsensusPower)`
124+
* UnbondingIndex: `56 | UnbondingID -> 21 | OperatorAddrLen (1 byte) | OperatorAddr`
125125

126126
`Validators` is the primary index - it ensures that each operator can have only one
127127
associated validator, where the public key of that validator can change in the
128128
future. Delegators can refer to the immutable operator of the validator, without
129129
concern for the changing public key.
130130

131-
`ValidatorsByUnbondingID` is an additional index that enables lookups for
131+
`UnbondingIndex` is an additional index that enables lookups for
132132
validators by the unbonding IDs corresponding to their current unbonding.
133133

134134
`ValidatorByConsAddr` is an additional index that enables lookups for slashing.
@@ -161,9 +161,9 @@ https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/staking/proto/cosmos
161161
### Delegation
162162

163163
Delegations are identified by combining `DelegatorAddr` (the address of the delegator)
164-
with the `ValidatorAddr` Delegators are indexed in the store as follows:
164+
with the `ValidatorAddr`. Delegators are indexed in the store as follows:
165165

166-
* Delegation: `0x31 | DelegatorAddrLen (1 byte) | DelegatorAddr | ValidatorAddrLen (1 byte) | ValidatorAddr -> ProtocolBuffer(delegation)`
166+
* Delegation: `49 | DelegatorAddrLen (1 byte) | DelegatorAddr | ValidatorAddrLen (1 byte) | ValidatorAddr -> ProtocolBuffer(delegation)`
167167

168168
Stake holders may delegate coins to validators; under this circumstance their
169169
funds are held in a `Delegation` data structure. It is owned by one
@@ -183,7 +183,7 @@ validator and the number of shares issued so far:
183183
`Shares per Token = validator.TotalShares() / validator.Tokens()`
184184

185185
Only the number of shares received is stored on the DelegationEntry. When a delegator then
186-
Undelegates, the token amount they receive is calculated from the number of shares they currently
186+
undelegates, the token amount they receive is calculated from the number of shares they currently
187187
hold and the inverse exchange rate:
188188

189189
`Tokens per Share = validator.Tokens() / validatorShares()`
@@ -201,17 +201,17 @@ detected.
201201

202202
`UnbondingDelegation` are indexed in the store as:
203203

204-
* UnbondingDelegation: `0x32 | DelegatorAddrLen (1 byte) | DelegatorAddr | ValidatorAddrLen (1 byte) | ValidatorAddr -> ProtocolBuffer(unbondingDelegation)`
205-
* UnbondingDelegationsFromValidator: `0x33 | ValidatorAddrLen (1 byte) | ValidatorAddr | DelegatorAddrLen (1 byte) | DelegatorAddr -> nil`
206-
* UnbondingDelegationByUnbondingId: `0x38 | UnbondingId -> 0x32 | DelegatorAddrLen (1 byte) | DelegatorAddr | ValidatorAddrLen (1 byte) | ValidatorAddr`
204+
* UnbondingDelegation: `50 | DelegatorAddrLen (1 byte) | DelegatorAddr | ValidatorAddrLen (1 byte) | ValidatorAddr -> ProtocolBuffer(unbondingDelegation)`
205+
* UnbondingDelegationByValIndex: `51 | ValidatorAddrLen (1 byte) | ValidatorAddr | DelegatorAddrLen (1 byte) | DelegatorAddr -> nil`
206+
* UnbondingIndex: `56 | UnbondingId -> 0x32 | DelegatorAddrLen (1 byte) | DelegatorAddr | ValidatorAddrLen (1 byte) | ValidatorAddr`
207207
`UnbondingDelegation` is used in queries, to lookup all unbonding delegations for
208208
a given delegator.
209209

210-
`UnbondingDelegationsFromValidator` is used in slashing, to lookup all
210+
`UnbondingDelegationByValIndex` is used in slashing, to lookup all
211211
unbonding delegations associated with a given validator that need to be
212212
slashed.
213213

214-
`UnbondingDelegationByUnbondingId` is an additional index that enables
214+
`UnbondingIndex` is an additional index that enables
215215
lookups for unbonding delegations by the unbonding IDs of the containing
216216
unbonding delegation entries.
217217

@@ -232,23 +232,23 @@ committed by the source validator.
232232

233233
`Redelegation` are indexed in the store as:
234234

235-
* Redelegations: `0x34 | DelegatorAddrLen (1 byte) | DelegatorAddr | ValidatorAddrLen (1 byte) | ValidatorSrcAddr | ValidatorDstAddr -> ProtocolBuffer(redelegation)`
236-
* RedelegationsBySrc: `0x35 | ValidatorSrcAddrLen (1 byte) | ValidatorSrcAddr | ValidatorDstAddrLen (1 byte) | ValidatorDstAddr | DelegatorAddrLen (1 byte) | DelegatorAddr -> nil`
237-
* RedelegationsByDst: `0x36 | ValidatorDstAddrLen (1 byte) | ValidatorDstAddr | ValidatorSrcAddrLen (1 byte) | ValidatorSrcAddr | DelegatorAddrLen (1 byte) | DelegatorAddr -> nil`
238-
* RedelegationByUnbondingId: `0x38 | UnbondingId -> 0x34 | DelegatorAddrLen (1 byte) | DelegatorAddr | ValidatorAddrLen (1 byte) | ValidatorSrcAddr | ValidatorDstAddr`
235+
* Redelegations: `52 | DelegatorAddrLen (1 byte) | DelegatorAddr | ValidatorAddrLen (1 byte) | ValidatorSrcAddr | ValidatorDstAddrLen (1 byte) | ValidatorDstAddr -> ProtocolBuffer(redelegation)`
236+
* RedelegationsByValSrc: `53 | ValidatorSrcAddrLen (1 byte) | ValidatorSrcAddr | ValidatorDstAddrLen (1 byte) | ValidatorDstAddr | DelegatorAddrLen (1 byte) | DelegatorAddr -> nil`
237+
* RedelegationsByValDst: `54 | ValidatorDstAddrLen (1 byte) | ValidatorDstAddr | ValidatorSrcAddrLen (1 byte) | ValidatorSrcAddr | DelegatorAddrLen (1 byte) | DelegatorAddr -> nil`
238+
* RedelegationByUnbondingId: `56 | UnbondingId -> 0x34 | DelegatorAddrLen (1 byte) | DelegatorAddr | ValidatorAddrLen (1 byte) | ValidatorSrcAddr | ValidatorDstAddr`
239239

240240
`Redelegations` is used for queries, to lookup all redelegations for a given
241241
delegator.
242242

243-
`RedelegationsBySrc` is used for slashing based on the `ValidatorSrcAddr`.
243+
`RedelegationsByValSrc` is used for slashing based on the `ValidatorSrcAddr`.
244244

245-
`RedelegationsByDst` is used for slashing based on the `ValidatorDstAddr`
245+
`RedelegationsByValDst` is used for slashing based on the `ValidatorDstAddr`
246246

247247
The first map here is used for queries, to lookup all redelegations for a given
248248
delegator. The second map is used for slashing based on the `ValidatorSrcAddr`,
249249
while the third map is for slashing based on the `ValidatorDstAddr`.
250250

251-
`RedelegationByUnbondingId` is an additional index that enables
251+
`UnbondingIndex` is an additional index that enables
252252
lookups for redelegations by the unbonding IDs of the containing
253253
redelegation entries.
254254

@@ -317,7 +317,7 @@ element.
317317
For the purpose of tracking progress of unbonding delegations the unbonding
318318
delegations queue is kept.
319319

320-
* UnbondingDelegation: `0x41 | format(time) -> []DVPair`
320+
* UnbondingQueue: `65 | format(time) -> []DVPair`
321321

322322
```protobuf reference
323323
https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/staking/proto/cosmos/staking/v1beta1/staking.proto#L159-L173
@@ -328,7 +328,7 @@ https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/staking/proto/cosmos
328328
For the purpose of tracking progress of redelegations the redelegation queue is
329329
kept.
330330

331-
* RedelegationQueue: `0x42 | format(time) -> []DVVTriplet`
331+
* RedelegationQueue: `66 | format(time) -> []DVVTriplet`
332332

333333
```protobuf reference
334334
https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/staking/proto/cosmos/staking/v1beta1/staking.proto#L175-L191
@@ -339,7 +339,7 @@ https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/staking/proto/cosmos
339339
For the purpose of tracking progress of unbonding validators the validator
340340
queue is kept.
341341

342-
* ValidatorQueueTime: `0x43 | format(time) -> []sdk.ValAddress`
342+
* ValidatorQueue: `67 | format(time) -> []sdk.ValAddress`
343343

344344
The stored object by each key is an array of validator operator addresses from
345345
which the validator object can be accessed. Typically it is expected that only
@@ -348,7 +348,7 @@ that multiple validators exist in the queue at the same location.
348348

349349
#### ValidatorConsensusKeyRotationRecordQueueKey
350350

351-
For the purpose of tracking progress or consensus pubkey rotations the `ValidatorConsensusKeyRotationRecordQueueKey` kept.
351+
For the purpose of tracking progress of consensus pubkey rotations, the `ValidatorConsensusKeyRotationRecordQueueKey` is kept.
352352

353353
* ValidatorConsensusKeyRotationRecordQueueKey: `103 | format(time) -> types.ValAddrsOfRotatedConsKeys`
354354

@@ -361,9 +361,6 @@ the present store info and append the `ValAddress` to the array and set it back
361361
https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/staking/proto/cosmos/staking/v1beta1/staking.proto#L420-L424
362362
```
363363

364-
365-
366-
367364
## State Transitions
368365

369366
### Validators
@@ -401,7 +398,7 @@ When a validator begins the unbonding process the following operations occur:
401398
#### Unbonding to Unbonded
402399

403400
A validator moves from unbonding to unbonded when the `ValidatorQueue` object
404-
moves from bonded to unbonded
401+
moves from bonded to unbonded.
405402

406403
* update the `Validator` object for this validator
407404
* set `validator.Status` to `Unbonded`
@@ -423,7 +420,7 @@ Jailed validators are not present in any of the following stores:
423420

424421
#### Delegate
425422

426-
When a delegation occurs both the validator and the delegation objects are affected
423+
When a delegation occurs both the validator and the delegation objects are affected.
427424

428425
* determine the delegators shares based on tokens delegated and the validator's exchange rate
429426
* remove tokens from the sending account
@@ -894,10 +891,12 @@ following hooks can registered with staking:
894891
* called when a delegation is created
895892
* `BeforeDelegationSharesModified(Context, AccAddress, ValAddress) error`
896893
* called when a delegation's shares are modified
897-
* `AfterDelegationModified(Context, AccAddress, ValAddress) error`
898-
* called when a delegation is created or modified
899894
* `BeforeDelegationRemoved(Context, AccAddress, ValAddress) error`
900895
* called when a delegation is removed
896+
* `AfterDelegationModified(Context, AccAddress, ValAddress) error`
897+
* called when a delegation is created or modified
898+
* `BeforeValidatorSlashed(Context, sdk.ValAddress, math.LegacyDec) error`
899+
* called when a validator is slashed
901900
* `AfterUnbondingInitiated(Context, UnbondingID)`
902901
* called when an unbonding operation (validator unbonding, unbonding delegation, redelegation) was initiated
903902
* `AfterConsensusPubKeyUpdate(ctx Context, oldpubkey, newpubkey types.PubKey, fee sdk.Coin)`
@@ -916,11 +915,9 @@ The staking module emits the following events:
916915
| complete_unbonding | validator | {validatorAddress} |
917916
| complete_unbonding | delegator | {delegatorAddress} |
918917
| complete_redelegation | amount | {totalRedelegationAmount} |
918+
| complete_redelegation | delegator | {delegatorAddress} |
919919
| complete_redelegation | source_validator | {srcValidatorAddress} |
920920
| complete_redelegation | destination_validator | {dstValidatorAddress} |
921-
| complete_redelegation | delegator | {delegatorAddress} |
922-
923-
## Msg's
924921

925922
### MsgCreateValidator
926923

@@ -947,7 +944,9 @@ The staking module emits the following events:
947944
| Type | Attribute Key | Attribute Value |
948945
| -------- | ------------- | ------------------ |
949946
| delegate | validator | {validatorAddress} |
947+
| delegate | delegator | {delegatorAddress} |
950948
| delegate | amount | {delegationAmount} |
949+
| delegate | new_shares | {newShares} |
951950
| message | module | staking |
952951
| message | action | delegate |
953952
| message | sender | {senderAddress} |
@@ -957,6 +956,7 @@ The staking module emits the following events:
957956
| Type | Attribute Key | Attribute Value |
958957
| ------- | ------------------- | ------------------ |
959958
| unbond | validator | {validatorAddress} |
959+
| unbond | delegator | {delegatorAddress} |
960960
| unbond | amount | {unbondAmount} |
961961
| unbond | completion_time [0] | {completionTime} |
962962
| message | module | staking |

x/staking/types/params.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ const (
1919
// TODO: Justify our choice of default here.
2020
DefaultUnbondingTime time.Duration = time.Hour * 24 * 7 * 3
2121

22-
// Default maximum number of bonded validators
22+
// DefaultMaxValidators is the default maximum number of bonded validators.
2323
DefaultMaxValidators uint32 = 100
2424

25-
// Default maximum entries in a UBD/RED pair
25+
// DefaultMaxEntries is the default maximum number of entries
26+
// in a UBD (Unbonding Delegation) or RED (Redelegation) pair.
2627
DefaultMaxEntries uint32 = 7
2728
)
2829

@@ -63,7 +64,7 @@ func DefaultParams() Params {
6364
)
6465
}
6566

66-
// unmarshal the current staking params value from store key or panic
67+
// MustUnmarshalParams unmarshal the current staking params value from store key or panic
6768
func MustUnmarshalParams(cdc *codec.LegacyAmino, value []byte) Params {
6869
params, err := UnmarshalParams(cdc, value)
6970
if err != nil {
@@ -73,7 +74,7 @@ func MustUnmarshalParams(cdc *codec.LegacyAmino, value []byte) Params {
7374
return params
7475
}
7576

76-
// unmarshal the current staking params value from store key
77+
// UnmarshalParams unmarshal the current staking params value from store key
7778
func UnmarshalParams(cdc *codec.LegacyAmino, value []byte) (params Params, err error) {
7879
err = cdc.Unmarshal(value, &params)
7980
if err != nil {
@@ -83,7 +84,7 @@ func UnmarshalParams(cdc *codec.LegacyAmino, value []byte) (params Params, err e
8384
return
8485
}
8586

86-
// validate a set of params
87+
// Validate validates a set of params
8788
func (p Params) Validate() error {
8889
if err := validateUnbondingTime(p.UnbondingTime); err != nil {
8990
return err
@@ -181,6 +182,7 @@ func validateBondDenom(i interface{}) error {
181182
return nil
182183
}
183184

185+
// ValidatePowerReduction validates the PowerReduction parameter.
184186
func ValidatePowerReduction(i interface{}) error {
185187
v, ok := i.(math.Int)
186188
if !ok {

0 commit comments

Comments
 (0)