Distribution Module (x/distribution)
Overview
Thex/distribution module implements a passive mechanism for distributing rewards between validators and delegators. It handles fee collection, validator commission, and delegator reward distribution using the F1 fee distribution algorithm.
Purpose: Fairly distribute transaction fees and block rewards to validators and their delegators based on stake proportions.
Key Concepts
F1 Fee Distribution
Rewards are calculated per period using the F1 algorithm:- Period: Updated each time a validator’s delegation changes
- Commission: Calculated and paid when validator withdraws or is removed
- Delegator Rewards: Distributed when delegation changes or withdrawal is requested
- Slashing: Applied before rewards distribution for infractions during delegation
Reward Pool
All globally tracked parameters for distribution:0x00 -> ProtocolBuffer(FeePool)
Community Tax
A percentage of rewards goes to the community pool:State
FeePool
Global reward pool storing decimal coins:- Rewards collected and added to pool
- Distributed to validators/delegators
- Truncated to
sdk.Coinswhen distributed
Validator Distribution
Updated when:- Delegation amount changes
- Delegator withdraws from validator
- Validator withdraws commission
Delegation Distribution
Tracks starting information for calculating rewards: Storage:0x04 | ValOperatorAddr | AccAddr -> DelegatorStartingInfo
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| community_tax | string (dec) | “0.020000000000000000” | % of fees sent to community pool |
| withdraw_addr_enabled | bool | true | Allow setting custom withdraw addresses |
community_tax must be positive and cannot exceed 1.00 (100%)
Messages
MsgSetWithdrawAddress
Set a custom address for receiving rewards:- Withdraw address cannot be a module account
- Feature must be enabled via
withdraw_addr_enabledparameter - Delegator must own the account
MsgWithdrawDelegatorReward
Withdraw rewards from a specific validator:- Calculate rewards using F1 algorithm
- Apply any slashing that occurred during delegation
- Send truncated integer amount to withdraw address
- Send remainder (decimals) to community pool
- Update
DelegatorStartingInfoto current period - Decrement
ValidatorOutstandingRewards
MsgWithdrawValidatorCommission
Validator withdraws accumulated commission:- Calculate commission from
ValidatorAccumulatedCommission - Truncate to integer amount
- Send to validator’s self-delegation withdraw address
- Deduct from
ValidatorOutstandingRewards
MsgFundCommunityPool
Directly fund the community pool:BeginBlock Distribution
At each block, rewards are distributed:Reward Calculation
For Validators:Queries
Query Validator Commission
Query Community Pool
Query Rewards
Query Validator Slashes
Query Validator Outstanding Rewards
Query Parameters
Transactions
Withdraw All Rewards
Withdraw with Commission
Set Withdraw Address
gRPC Endpoints
ValidatorDistributionInfo
DelegationRewards
CommunityPool
Events
BeginBlocker Events
| Type | Attribute Key | Attribute Value |
|---|---|---|
| proposer_reward | validator | |
| proposer_reward | reward | |
| commission | amount | |
| commission | validator | |
| rewards | amount | |
| rewards | validator |
MsgWithdrawDelegatorReward Events
| Type | Attribute Key | Attribute Value |
|---|---|---|
| withdraw_rewards | amount | |
| withdraw_rewards | validator | |
| message | module | distribution |
| message | action | withdraw_delegator_reward |
| message | sender |
Code Examples
Calculate Delegator Rewards
Withdraw Rewards
Allocate Rewards to Validator
Fund Community Pool
CLI Commands Reference
| Command | Description |
|---|---|
simd query distribution commission [validator] | Query validator commission |
simd query distribution community-pool | Query community pool |
simd query distribution params | Query distribution parameters |
simd query distribution rewards [delegator] | Query delegator rewards |
simd query distribution slashes [validator] [start] [end] | Query validator slashes |
simd tx distribution fund-community-pool [amount] | Fund community pool |
simd tx distribution set-withdraw-addr [addr] | Set withdraw address |
simd tx distribution withdraw-all-rewards | Withdraw all rewards |
simd tx distribution withdraw-rewards [validator] | Withdraw validator rewards |