Staking Module (x/staking)
Overview
Thex/staking module enables Cosmos SDK-based blockchains to support an advanced Proof-of-Stake (PoS) system where token holders can become validators or delegate tokens to validators.
Purpose: Manage validator set, handle delegations, and facilitate the Proof-of-Stake consensus mechanism.
Key Features
- Validator Management: Create, edit, and track validators
- Delegation: Delegate tokens to validators for staking rewards
- Unbonding: Safely unbond tokens with time delay
- Redelegation: Move delegations between validators instantly
- Slashing Integration: Penalize validator misbehavior
- Dynamic Validator Set: Automatically update active validators
Validator States
Validators can be in one of three states:Unbonded
- Not in active set
- Cannot sign blocks
- Do not earn rewards
- Can receive delegations
Bonded
- In active set
- Sign blocks and receive rewards
- Can be slashed for misbehavior
- Delegations have unbonding period
Unbonding
- Leaving active set
- All delegations begin unbonding
- Still slashable during unbonding period
- Duration defined by
UnbondingTimeparameter
State
Pool
Tracks bonded and not-bonded token supply:- BondedPool: Tokens from bonded validators
- NotBondedPool: Tokens from unbonding/unbonded validators
Validators
Storage Keys:Delegation
Storage:0x31 | DelegatorAddr | ValidatorAddr -> ProtocolBuffer(delegation)
Delegator Shares
Shares are issued based on exchange rate:UnbondingDelegation
Storage:0x32 | DelegatorAddr | ValidatorAddr -> ProtocolBuffer(unbondingDelegation)
Redelegation
Storage:0x34 | DelegatorAddr | ValidatorSrcAddr | ValidatorDstAddr -> ProtocolBuffer(redelegation)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| UnbondingTime | Duration | 1814400s (21 days) | Time for unbonding completion |
| MaxValidators | uint32 | 100 | Maximum active validators |
| MaxEntries | uint32 | 7 | Max unbonding/redelegation entries |
| HistoricalEntries | uint32 | 10000 | Historical info entries to persist |
| BondDenom | string | ”stake” | Denomination for staking |
| MinCommissionRate | Dec | ”0” | Minimum validator commission rate |
Messages
MsgCreateValidator
Create a new validator:MsgEditValidator
Edit validator description and commission:MsgDelegate
Delegate tokens to a validator:MsgUndelegate
Unbond delegation from validator:MsgBeginRedelegate
Redelegate tokens to different validator:MsgCancelUnbondingDelegation
Cancel unbonding and re-delegate:Queries
Query Validator
Query Validators
Query Delegation
Query Delegations
Query Unbonding Delegation
Query Redelegation
Query Pool
Query Parameters
Query Historical Info
gRPC Endpoints
Validator
Validators
Delegation
Pool
Events
MsgCreateValidator
| Type | Attribute Key | Attribute Value |
|---|---|---|
| create_validator | validator | |
| create_validator | amount | |
| message | module | staking |
| message | action | create_validator |
| message | sender |
MsgDelegate
| Type | Attribute Key | Attribute Value |
|---|---|---|
| delegate | validator | |
| delegate | amount | |
| message | module | staking |
| message | action | delegate |
| message | sender |
EndBlocker
| Type | Attribute Key | Attribute Value |
|---|---|---|
| complete_unbonding | amount | |
| complete_unbonding | validator | |
| complete_unbonding | delegator | |
| complete_redelegation | amount | |
| complete_redelegation | source_validator | |
| complete_redelegation | destination_validator |
Code Examples
Create Validator
Delegate Tokens
Query Delegation
Unbond Delegation
Redelegate
Hooks
The staking module provides hooks for other modules:CLI Commands Reference
| Command | Description |
|---|---|
simd query staking validator [addr] | Query validator |
simd query staking validators | Query all validators |
simd query staking delegation [del] [val] | Query delegation |
simd query staking delegations [delegator] | Query delegations |
simd query staking unbonding-delegation [del] [val] | Query unbonding |
simd query staking pool | Query staking pool |
simd query staking params | Query parameters |
simd tx staking create-validator | Create validator |
simd tx staking edit-validator | Edit validator |
simd tx staking delegate [val] [amount] | Delegate tokens |
simd tx staking unbond [val] [amount] | Unbond delegation |
simd tx staking redelegate [src] [dst] [amount] | Redelegate tokens |