bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 40쪽
idator_address: cosmosvaloper1..
total:
- amount: "1000000.000000000000000000"
denom: stake
```
##### slashes
The `slashes` command allows users to query all slashes for a given block range.
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd query distribution slashes [validator] [start-height] [end-height] [flags]
```
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd query distribution slashes cosmosvaloper1... 1 1000
```
Example Output:
```yml theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
pagination:
next_key: null
total: "0"
slashes:
- validator_period: 20,
fraction: "0.009999999999999999"
```
##### validator-outstanding-rewards
The `validator-outstanding-rewards` command allows users to query all outstanding (un-withdrawn) rewards for a validator and all their delegations.
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd query distribution validator-outstanding-rewards [validator] [flags]
```
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd query distribution validator-outstanding-rewards cosmosvaloper1...
```
Example Output:
```yml theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
rewards:
- amount: "1000000.000000000000000000"
denom: stake
```
##### validator-distribution-info
The `validator-distribution-info` command allows users to query validator commission and self-delegation rewards for validator.
```shell expandable theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd query distribution validator-distribution-info cosmosvaloper1...
```
Example Output:
```yml theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
commission:
- amount: "100000.000000000000000000"
denom: stake
operator_address: cosmosvaloper1...
self_bond_rewards:
- amount: "100000.000000000000000000"
denom: stake
```
##### validator-historical-rewards
The `validator-historical-rewards` command allows users to query historical rewards for a validator at a specific period.
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd query distribution validator-historical-rewards [validator] [period] [flags]
```
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd query distribution validator-historical-rewards cosmosvaloper1... 5
```
Example Output:
```yml theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
rewards:
cumulative_reward_ratio:
- amount: "1000000.000000000000000000"
denom: stake
reference_count: 2
```
##### validator-current-rewards
The `validator-current-rewards` command allows users to query current rewards for a validator.
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd query distribution validator-current-rewards [validator] [flags]
```
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd query distribution validator-current-rewards cosmosvaloper1...
```
Example Output:
```yml theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
rewards:
period: "3"
rewards:
- amount: "1000000.000000000000000000"
denom: stake
```
##### delegator-starting-info
The `delegator-starting-info` command allows users to query the starting info for a delegator on a given validator.
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd query distribution delegator-starting-info [delegator-address] [validator-address] [flags]
```
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd query distribution delegator-starting-info cosmos1... cosmosvaloper1...
```
Example Output:
```yml theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
starting_info:
creation_height: "10"
previous_period: "2"
stake: "1000000.000000000000000000"
```
#### Transactions
The `tx` commands allow users to interact with the `distribution` module.
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd tx distribution --help
```
##### fund-community-pool
The `fund-community-pool` command allows users to send funds to the community pool.
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd tx distribution fund-community-pool [amount] [flags]
```
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd tx distribution fund-community-pool 100stake --from cosmos1...
```
##### set-withdraw-addr
The `set-withdraw-addr` command allows users to set the withdraw address for rewards associated with a delegator address.
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd tx distribution set-withdraw-addr [withdraw-addr] [flags]
```
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd tx distribution set-withdraw-addr cosmos1... --from cosmos1...
```
##### withdraw-all-rewards
The `withdraw-all-rewards` command allows users to withdraw all rewards for a delegator.
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd tx distribution withdraw-all-rewards [flags]
```
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd tx distribution withdraw-all-rewards --from cosmos1...
```
##### withdraw-rewards
The `withdraw-rewards` command allows users to withdraw all rewards from a given delegation address,
and optionally withdraw validator commission if the delegation address given is a validator operator and the user proves the `--commission` flag.
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd tx distribution withdraw-rewards [validator-addr] [flags]
```
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
simd tx distribution withdraw-rewards cosmosvaloper1... --from cosmos1... --commission
```
### gRPC
A user can query the `distribution` module using gRPC endpoints.
#### Params
The `Params` endpoint allows users to query parameters of the `distribution` module.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
localhost:9090 \
cosmos.distribution.v1beta1.Query/Params
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"params": {
"communityTax": "20000000000000000",
"baseProposerReward": "00000000000000000",
"bonusProposerReward": "00000000000000000",
"withdrawAddrEnabled": true
}
}
```
#### ValidatorDistributionInfo
The `ValidatorDistributionInfo` queries validator commission and self-delegation rewards for validator.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
-d '{"validator_address":"cosmosvalop1..."}' \
localhost:9090 \
cosmos.distribution.v1beta1.Query/ValidatorDistributionInfo
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"commission": {
"commission": [
{
"denom": "stake",
"amount": "1000000000000000"
}
]
},
"self_bond_rewards": [
{
"denom": "stake",
"amount": "1000000000000000"
}
],
"validator_address": "cosmosvalop1..."
}
```
#### ValidatorOutstandingRewards
The `ValidatorOutstandingRewards` endpoint allows users to query rewards of a validator address.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
-d '{"validator_address":"cosmosvalop1.."}' \
localhost:9090 \
cosmos.distribution.v1beta1.Query/ValidatorOutstandingRewards
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"rewards": {
"rewards": [
{
"denom": "stake",
"amount": "1000000000000000"
}
]
}
}
```
#### ValidatorCommission
The `ValidatorCommission` endpoint allows users to query accumulated commission for a validator.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
-d '{"validator_address":"cosmosvalop1.."}' \
localhost:9090 \
cosmos.distribution.v1beta1.Query/ValidatorCommission
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"commission": {
"commission": [
{
"denom": "stake",
"amount": "1000000000000000"
}
]
}
}
```
#### ValidatorSlashes
The `ValidatorSlashes` endpoint allows users to query slash events of a validator.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
-d '{"validator_address":"cosmosvalop1.."}' \
localhost:9090 \
cosmos.distribution.v1beta1.Query/ValidatorSlashes
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"slashes": [
{
"validator_period": "20",
"fraction": "0.009999999999999999"
}
],
"pagination": {
"total": "1"
}
}
```
#### DelegationRewards
The `DelegationRewards` endpoint allows users to query the total rewards accrued by a delegation.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
-d '{"delegator_address":"cosmos1...","validator_address":"cosmosvalop1..."}' \
localhost:9090 \
cosmos.distribution.v1beta1.Query/DelegationRewards
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"rewards": [
{
"denom": "stake",
"amount": "1000000000000000"
}
]
}
```
#### DelegationTotalRewards
The `DelegationTotalRewards` endpoint allows users to query the total rewards accrued by each validator.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
-d '{"delegator_address":"cosmos1..."}' \
localhost:9090 \
cosmos.distribution.v1beta1.Query/DelegationTotalRewards
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"rewards": [
{
"validatorAddress": "cosmosvaloper1...",
"reward": [
{
"denom": "stake",
"amount": "1000000000000000"
}
]
}
],
"total": [
{
"denom": "stake",
"amount": "1000000000000000"
}
]
}
```
#### DelegatorValidators
The `DelegatorValidators` endpoint allows users to query all validators for given delegator.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
-d '{"delegator_address":"cosmos1..."}' \
localhost:9090 \
cosmos.distribution.v1beta1.Query/DelegatorValidators
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"validators": ["cosmosvaloper1..."]
}
```
#### DelegatorWithdrawAddress
The `DelegatorWithdrawAddress` endpoint allows users to query the withdraw address of a delegator.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
-d '{"delegator_address":"cosmos1..."}' \
localhost:9090 \
cosmos.distribution.v1beta1.Query/DelegatorWithdrawAddress
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"withdrawAddress": "cosmos1..."
}
```
#### CommunityPool
The `CommunityPool` endpoint allows users to query the community pool coins.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
localhost:9090 \
cosmos.distribution.v1beta1.Query/CommunityPool
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"pool": [
{
"denom": "stake",
"amount": "1000000000000000000"
}
]
}
```
#### ValidatorHistoricalRewards
The `ValidatorHistoricalRewards` endpoint allows users to query historical rewards for a validator at a specific period. This is useful for debugging reward calculations by inspecting internal distribution state.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
-d '{"validator_address":"cosmosvaloper1...","period":"5"}' \
localhost:9090 \
cosmos.distribution.v1beta1.Query/ValidatorHistoricalRewards
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"rewards": {
"cumulativeRewardRatio": [
{
"denom": "stake",
"amount": "1000000000000000"
}
],
"referenceCount": 2
}
}
```
#### ValidatorCurrentRewards
The `ValidatorCurrentRewards` endpoint allows users to query current rewards for a validator.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
-d '{"validator_address":"cosmosvaloper1..."}' \
localhost:9090 \
cosmos.distribution.v1beta1.Query/ValidatorCurrentRewards
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"rewards": {
"rewards": [
{
"denom": "stake",
"amount": "1000000000000000"
}
],
"period": "3"
}
}
```
#### DelegatorStartingInfo
The `DelegatorStartingInfo` endpoint allows users to query the starting info for a delegator on a given validator. Combined with `ValidatorHistoricalRewards`, this enables verification of reward calculations by retrieving the previous period and stake, then looking up cumulative reward ratios for that period.
Example:
```shell theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
grpcurl -plaintext \
-d '{"delegator_address":"cosmos1...","validator_address":"cosmosvaloper1..."}' \
localhost:9090 \
cosmos.distribution.v1beta1.Query/DelegatorStartingInfo
```
Example Output:
```json theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
{
"startingInfo": {
"previousPeriod": "2",
"stake": "1000000000000000000",
"creationHeight": "10"
}
}
```
# x/epochs
Source: https://docs.cosmos.network/sdk/latest/modules/epochs/README
## Abstract
Often in the SDK, we would like to run certain code every-so often. The
purpose of `epochs` module is to allow other modules to set that they
would like to be signaled once every period. So another module can
specify it wants to execute code once a week, starting at UTC-time = x.
`epochs` creates a generalized epoch interface to other modules so that
they can easily be signaled upon such events.
## Contents
1. **[Concept](#concepts)**
2. **[State](#state)**
3. **[Events](#events)**
4. **[Keeper](#keepers)**
5. **[Hooks](#hooks)**
6. **[Queries](#queries)**
## Concepts
The epochs module defines on-chain timers that execute at fixed time intervals.
Other SDK modules can then register logic to be executed at the timer ticks.
We refer to the period in between two timer ticks as an "epoch".
Every timer has a unique identifier.
Every epoch will have a start time, and an end time, where `end time = start time + timer interval`.
On mainnet, we only utilize one identifier, with a time interval of `one day`.
The timer will tick at the first block whose block time is greater than the timer end time,
and set the start as the prior timer end time. (Notably, it's not set to the block time!)
This means that if the chain has been down for a while, you will get one timer tick per block,
until the timer has caught up.
## State
The Epochs module keeps a single `EpochInfo` per identifier.
This contains the current state of the timer with the corresponding identifier.
Its fields are modified at every timer tick.
EpochInfos are initialized as part of genesis initialization or upgrade logic,
and are only modified on begin blockers.
## Events
The `epochs` module emits the following events:
### BeginBlocker
| Type | Attribute Key | Attribute Value |
| - | - | - |
| epoch\_start | epoch\_number | `{epoch\_number}` |
| epoch\_start | start\_time | `{start\_time}` |
### EndBlocker
| Type | Attribute Key | Attribute Value |
| - | - | - |
| epoch\_end | epoch\_number | `{epoch\_number}` |
## Keepers
### Keeper functions
Epochs keeper module provides utility functions to manage epochs.
## Hooks
```go theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
// the first block whose timestamp is after the duration is counted as the end of the epoch
AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64)
// new epoch is next block of epoch end block
BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64)
```
### How modules receive hooks
On hook receiver function of other modules, they need to filter
`epochIdentifier` and only do executions for only specific
epochIdentifier. Filtering epochIdentifier could be in `Params` of other
modules so that they can be modified by governance.
This is the standard dev UX of this:
```golang theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
func (k MyModuleKeeper)
AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) {
params := k.GetParams(ctx)
if epochIdentifier == params.DistrEpochIdentifier {
// my logic
}
}
```
### Panic isolation
If a given epoch hook panics, its state update is reverted, but we keep
proceeding through the remaining hooks. This allows more advanced epoch
logic to be used, without concern over state machine halting, or halting
subsequent modules.
This does mean that if there is behavior you expect from a prior epoch
hook, and that epoch hook reverted, your hook may also have an issue. So
do keep in mind "what if a prior hook didn't get executed" in the safety
checks you consider for a new epoch hook.
## Queries
The Epochs module provides the following queries to check the module's state.
```protobuf theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
service Query {
// EpochInfos provide running epochInfos
rpc EpochInfos(QueryEpochsInfoRequest) returns (QueryEpochsInfoResponse) {}
// CurrentEpoch provide current epoch of specified identifier
rpc CurrentEpoch(QueryCurrentEpochRequest) returns (QueryCurrentEpochResponse) {}
}
```
### Epoch Infos
Query the currently running epochInfos
```sh theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
<appd> query epochs epoch-infos
```
<Accordion>
**Example**
An example output:
```sh expandable theme={"theme":{"light":"github-light-high-contrast","dark":"github-dark-high-contrast"}}
epochs:
- current_epoch: "183"
current_epoch_start_height: "2438409"
current_epoch_start_time: "2021-12-18T17:16:09.898160996Z"
duration: 86400s
epoch_counting_started: true
identifier: day
start_time: "2021-06-18T17:00:00Z"
- current_epoch: "26"
current_epoch_start_height: "2424854"
current_epoch_start_time: "2021-12-17T17:02:07.229632445Z"
duration: 604800s
epoch_counting_started: true
identifier: week
start_time: "2021-06-프로젝트로 돌아가기