Merge Pr #5506: Refactor use of parameters in x/distribution to match module spec
This commit is contained in:
parent
6024115667
commit
bf41deac62
|
@ -39,6 +39,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||||
|
|
||||||
### State Machine Breaking
|
### State Machine Breaking
|
||||||
|
|
||||||
|
* (genesis) [\#5506](https://github.com/cosmos/cosmos-sdk/pull/5506) The `x/distribution` genesis state
|
||||||
|
now includes `params` instead of individual parameters.
|
||||||
* (genesis) [\#5017](https://github.com/cosmos/cosmos-sdk/pull/5017) The `x/genaccounts` module has been
|
* (genesis) [\#5017](https://github.com/cosmos/cosmos-sdk/pull/5017) The `x/genaccounts` module has been
|
||||||
deprecated and all components removed except the `legacy/` package. This requires changes to the
|
deprecated and all components removed except the `legacy/` package. This requires changes to the
|
||||||
genesis state. Namely, `accounts` now exist under `app_state.auth.accounts`. The corresponding migration
|
genesis state. Namely, `accounts` now exist under `app_state.auth.accounts`. The corresponding migration
|
||||||
|
@ -50,6 +52,8 @@ logic has been implemented for v0.38 target version. Applications can migrate vi
|
||||||
|
|
||||||
### API Breaking Changes
|
### API Breaking Changes
|
||||||
|
|
||||||
|
* (modules) [\#5506](https://github.com/cosmos/cosmos-sdk/pull/5506) Remove individual setters of `x/distribution` parameters.
|
||||||
|
Instead, follow the module spec in getting parameters, setting new value(s) and finally calling `SetParams`.
|
||||||
* (types) [\#5495](https://github.com/cosmos/cosmos-sdk/pull/5495) Remove redundant `(Must)Bech32ify*` and `(Must)Get*KeyBech32`
|
* (types) [\#5495](https://github.com/cosmos/cosmos-sdk/pull/5495) Remove redundant `(Must)Bech32ify*` and `(Must)Get*KeyBech32`
|
||||||
functions in favor of `(Must)Bech32ifyPubKey` and `(Must)GetPubKeyFromBech32` respectively, both of
|
functions in favor of `(Must)Bech32ifyPubKey` and `(Must)GetPubKeyFromBech32` respectively, both of
|
||||||
which take a `Bech32PubKeyType` (string).
|
which take a `Bech32PubKeyType` (string).
|
||||||
|
@ -245,6 +249,8 @@ to detail this new feature and how state transitions occur.
|
||||||
* (docs/interfaces/) Add documentation on building interfaces for the Cosmos SDK.
|
* (docs/interfaces/) Add documentation on building interfaces for the Cosmos SDK.
|
||||||
* Redesigned user interface that features new dynamically generated sidebar, build-time code embedding from GitHub, new homepage as well as many other improvements.
|
* Redesigned user interface that features new dynamically generated sidebar, build-time code embedding from GitHub, new homepage as well as many other improvements.
|
||||||
* (types) [\#5428](https://github.com/cosmos/cosmos-sdk/pull/5428) Add `Mod` (modulo) method and `RelativePow` (exponentation) function for `Uint`.
|
* (types) [\#5428](https://github.com/cosmos/cosmos-sdk/pull/5428) Add `Mod` (modulo) method and `RelativePow` (exponentation) function for `Uint`.
|
||||||
|
* (modules) [\#5506](https://github.com/cosmos/cosmos-sdk/pull/5506) Remove redundancy in `x/distribution`s use of parameters. There
|
||||||
|
now exists a single `Params` type with a getter and setter along with a getter for each individual parameter.
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
// nolint
|
// nolint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultParamspace = keeper.DefaultParamspace
|
|
||||||
ModuleName = types.ModuleName
|
ModuleName = types.ModuleName
|
||||||
StoreKey = types.StoreKey
|
StoreKey = types.StoreKey
|
||||||
RouterKey = types.RouterKey
|
RouterKey = types.RouterKey
|
||||||
|
@ -24,10 +23,7 @@ const (
|
||||||
QueryDelegatorValidators = types.QueryDelegatorValidators
|
QueryDelegatorValidators = types.QueryDelegatorValidators
|
||||||
QueryWithdrawAddr = types.QueryWithdrawAddr
|
QueryWithdrawAddr = types.QueryWithdrawAddr
|
||||||
QueryCommunityPool = types.QueryCommunityPool
|
QueryCommunityPool = types.QueryCommunityPool
|
||||||
ParamCommunityTax = types.ParamCommunityTax
|
DefaultParamspace = types.DefaultParamspace
|
||||||
ParamBaseProposerReward = types.ParamBaseProposerReward
|
|
||||||
ParamBonusProposerReward = types.ParamBonusProposerReward
|
|
||||||
ParamWithdrawAddrEnabled = types.ParamWithdrawAddrEnabled
|
|
||||||
TypeMsgFundCommunityPool = types.TypeMsgFundCommunityPool
|
TypeMsgFundCommunityPool = types.TypeMsgFundCommunityPool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,29 +36,30 @@ var (
|
||||||
ReferenceCountInvariant = keeper.ReferenceCountInvariant
|
ReferenceCountInvariant = keeper.ReferenceCountInvariant
|
||||||
ModuleAccountInvariant = keeper.ModuleAccountInvariant
|
ModuleAccountInvariant = keeper.ModuleAccountInvariant
|
||||||
NewKeeper = keeper.NewKeeper
|
NewKeeper = keeper.NewKeeper
|
||||||
GetValidatorOutstandingRewardsAddress = keeper.GetValidatorOutstandingRewardsAddress
|
GetValidatorOutstandingRewardsAddress = types.GetValidatorOutstandingRewardsAddress
|
||||||
GetDelegatorWithdrawInfoAddress = keeper.GetDelegatorWithdrawInfoAddress
|
GetDelegatorWithdrawInfoAddress = types.GetDelegatorWithdrawInfoAddress
|
||||||
GetDelegatorStartingInfoAddresses = keeper.GetDelegatorStartingInfoAddresses
|
GetDelegatorStartingInfoAddresses = types.GetDelegatorStartingInfoAddresses
|
||||||
GetValidatorHistoricalRewardsAddressPeriod = keeper.GetValidatorHistoricalRewardsAddressPeriod
|
GetValidatorHistoricalRewardsAddressPeriod = types.GetValidatorHistoricalRewardsAddressPeriod
|
||||||
GetValidatorCurrentRewardsAddress = keeper.GetValidatorCurrentRewardsAddress
|
GetValidatorCurrentRewardsAddress = types.GetValidatorCurrentRewardsAddress
|
||||||
GetValidatorAccumulatedCommissionAddress = keeper.GetValidatorAccumulatedCommissionAddress
|
GetValidatorAccumulatedCommissionAddress = types.GetValidatorAccumulatedCommissionAddress
|
||||||
GetValidatorSlashEventAddressHeight = keeper.GetValidatorSlashEventAddressHeight
|
GetValidatorSlashEventAddressHeight = types.GetValidatorSlashEventAddressHeight
|
||||||
GetValidatorOutstandingRewardsKey = keeper.GetValidatorOutstandingRewardsKey
|
GetValidatorOutstandingRewardsKey = types.GetValidatorOutstandingRewardsKey
|
||||||
GetDelegatorWithdrawAddrKey = keeper.GetDelegatorWithdrawAddrKey
|
GetDelegatorWithdrawAddrKey = types.GetDelegatorWithdrawAddrKey
|
||||||
GetDelegatorStartingInfoKey = keeper.GetDelegatorStartingInfoKey
|
GetDelegatorStartingInfoKey = types.GetDelegatorStartingInfoKey
|
||||||
GetValidatorHistoricalRewardsPrefix = keeper.GetValidatorHistoricalRewardsPrefix
|
GetValidatorHistoricalRewardsPrefix = types.GetValidatorHistoricalRewardsPrefix
|
||||||
GetValidatorHistoricalRewardsKey = keeper.GetValidatorHistoricalRewardsKey
|
GetValidatorHistoricalRewardsKey = types.GetValidatorHistoricalRewardsKey
|
||||||
GetValidatorCurrentRewardsKey = keeper.GetValidatorCurrentRewardsKey
|
GetValidatorCurrentRewardsKey = types.GetValidatorCurrentRewardsKey
|
||||||
GetValidatorAccumulatedCommissionKey = keeper.GetValidatorAccumulatedCommissionKey
|
GetValidatorAccumulatedCommissionKey = types.GetValidatorAccumulatedCommissionKey
|
||||||
GetValidatorSlashEventPrefix = keeper.GetValidatorSlashEventPrefix
|
GetValidatorSlashEventPrefix = types.GetValidatorSlashEventPrefix
|
||||||
GetValidatorSlashEventKeyPrefix = keeper.GetValidatorSlashEventKeyPrefix
|
GetValidatorSlashEventKeyPrefix = types.GetValidatorSlashEventKeyPrefix
|
||||||
GetValidatorSlashEventKey = keeper.GetValidatorSlashEventKey
|
GetValidatorSlashEventKey = types.GetValidatorSlashEventKey
|
||||||
ParamKeyTable = keeper.ParamKeyTable
|
|
||||||
HandleCommunityPoolSpendProposal = keeper.HandleCommunityPoolSpendProposal
|
HandleCommunityPoolSpendProposal = keeper.HandleCommunityPoolSpendProposal
|
||||||
NewQuerier = keeper.NewQuerier
|
NewQuerier = keeper.NewQuerier
|
||||||
MakeTestCodec = keeper.MakeTestCodec
|
MakeTestCodec = keeper.MakeTestCodec
|
||||||
CreateTestInputDefault = keeper.CreateTestInputDefault
|
CreateTestInputDefault = keeper.CreateTestInputDefault
|
||||||
CreateTestInputAdvanced = keeper.CreateTestInputAdvanced
|
CreateTestInputAdvanced = keeper.CreateTestInputAdvanced
|
||||||
|
ParamKeyTable = types.ParamKeyTable
|
||||||
|
DefaultParams = types.DefaultParams
|
||||||
RegisterCodec = types.RegisterCodec
|
RegisterCodec = types.RegisterCodec
|
||||||
NewDelegatorStartingInfo = types.NewDelegatorStartingInfo
|
NewDelegatorStartingInfo = types.NewDelegatorStartingInfo
|
||||||
ErrEmptyDelegatorAddr = types.ErrEmptyDelegatorAddr
|
ErrEmptyDelegatorAddr = types.ErrEmptyDelegatorAddr
|
||||||
|
@ -100,20 +97,19 @@ var (
|
||||||
NewValidatorSlashEvent = types.NewValidatorSlashEvent
|
NewValidatorSlashEvent = types.NewValidatorSlashEvent
|
||||||
|
|
||||||
// variable aliases
|
// variable aliases
|
||||||
FeePoolKey = keeper.FeePoolKey
|
FeePoolKey = types.FeePoolKey
|
||||||
ProposerKey = keeper.ProposerKey
|
ProposerKey = types.ProposerKey
|
||||||
ValidatorOutstandingRewardsPrefix = keeper.ValidatorOutstandingRewardsPrefix
|
ValidatorOutstandingRewardsPrefix = types.ValidatorOutstandingRewardsPrefix
|
||||||
DelegatorWithdrawAddrPrefix = keeper.DelegatorWithdrawAddrPrefix
|
DelegatorWithdrawAddrPrefix = types.DelegatorWithdrawAddrPrefix
|
||||||
DelegatorStartingInfoPrefix = keeper.DelegatorStartingInfoPrefix
|
DelegatorStartingInfoPrefix = types.DelegatorStartingInfoPrefix
|
||||||
ValidatorHistoricalRewardsPrefix = keeper.ValidatorHistoricalRewardsPrefix
|
ValidatorHistoricalRewardsPrefix = types.ValidatorHistoricalRewardsPrefix
|
||||||
ValidatorCurrentRewardsPrefix = keeper.ValidatorCurrentRewardsPrefix
|
ValidatorCurrentRewardsPrefix = types.ValidatorCurrentRewardsPrefix
|
||||||
ValidatorAccumulatedCommissionPrefix = keeper.ValidatorAccumulatedCommissionPrefix
|
ValidatorAccumulatedCommissionPrefix = types.ValidatorAccumulatedCommissionPrefix
|
||||||
ValidatorSlashEventPrefix = keeper.ValidatorSlashEventPrefix
|
ValidatorSlashEventPrefix = types.ValidatorSlashEventPrefix
|
||||||
ParamStoreKeyCommunityTax = keeper.ParamStoreKeyCommunityTax
|
ParamStoreKeyCommunityTax = types.ParamStoreKeyCommunityTax
|
||||||
ParamStoreKeyBaseProposerReward = keeper.ParamStoreKeyBaseProposerReward
|
ParamStoreKeyBaseProposerReward = types.ParamStoreKeyBaseProposerReward
|
||||||
ParamStoreKeyBonusProposerReward = keeper.ParamStoreKeyBonusProposerReward
|
ParamStoreKeyBonusProposerReward = types.ParamStoreKeyBonusProposerReward
|
||||||
ParamStoreKeyWithdrawAddrEnabled = keeper.ParamStoreKeyWithdrawAddrEnabled
|
ParamStoreKeyWithdrawAddrEnabled = types.ParamStoreKeyWithdrawAddrEnabled
|
||||||
TestAddrs = keeper.TestAddrs
|
|
||||||
ModuleCdc = types.ModuleCdc
|
ModuleCdc = types.ModuleCdc
|
||||||
EventTypeSetWithdrawAddress = types.EventTypeSetWithdrawAddress
|
EventTypeSetWithdrawAddress = types.EventTypeSetWithdrawAddress
|
||||||
EventTypeRewards = types.EventTypeRewards
|
EventTypeRewards = types.EventTypeRewards
|
||||||
|
@ -139,6 +135,7 @@ type (
|
||||||
ValidatorCurrentRewardsRecord = types.ValidatorCurrentRewardsRecord
|
ValidatorCurrentRewardsRecord = types.ValidatorCurrentRewardsRecord
|
||||||
DelegatorStartingInfoRecord = types.DelegatorStartingInfoRecord
|
DelegatorStartingInfoRecord = types.DelegatorStartingInfoRecord
|
||||||
ValidatorSlashEventRecord = types.ValidatorSlashEventRecord
|
ValidatorSlashEventRecord = types.ValidatorSlashEventRecord
|
||||||
|
Params = types.Params
|
||||||
GenesisState = types.GenesisState
|
GenesisState = types.GenesisState
|
||||||
MsgSetWithdrawAddress = types.MsgSetWithdrawAddress
|
MsgSetWithdrawAddress = types.MsgSetWithdrawAddress
|
||||||
MsgWithdrawDelegatorReward = types.MsgWithdrawDelegatorReward
|
MsgWithdrawDelegatorReward = types.MsgWithdrawDelegatorReward
|
||||||
|
|
|
@ -47,10 +47,18 @@ func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||||
Short: "Query distribution params",
|
Short: "Query distribution params",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||||
params, err := common.QueryParams(cliCtx, queryRoute)
|
|
||||||
|
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParams)
|
||||||
|
res, _, err := cliCtx.QueryWithData(route, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var params types.Params
|
||||||
|
if err := cdc.UnmarshalJSON(res, ¶ms); err != nil {
|
||||||
|
return fmt.Errorf("failed to unmarshal params: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return cliCtx.PrintOutput(params)
|
return cliCtx.PrintOutput(params)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,38 +8,6 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// QueryParams actually queries distribution params.
|
|
||||||
func QueryParams(cliCtx context.CLIContext, queryRoute string) (PrettyParams, error) {
|
|
||||||
route := fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamCommunityTax)
|
|
||||||
|
|
||||||
retCommunityTax, _, err := cliCtx.QueryWithData(route, []byte{})
|
|
||||||
if err != nil {
|
|
||||||
return PrettyParams{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamBaseProposerReward)
|
|
||||||
retBaseProposerReward, _, err := cliCtx.QueryWithData(route, []byte{})
|
|
||||||
if err != nil {
|
|
||||||
return PrettyParams{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamBonusProposerReward)
|
|
||||||
retBonusProposerReward, _, err := cliCtx.QueryWithData(route, []byte{})
|
|
||||||
if err != nil {
|
|
||||||
return PrettyParams{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
route = fmt.Sprintf("custom/%s/params/%s", queryRoute, types.ParamWithdrawAddrEnabled)
|
|
||||||
retWithdrawAddrEnabled, _, err := cliCtx.QueryWithData(route, []byte{})
|
|
||||||
if err != nil {
|
|
||||||
return PrettyParams{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return NewPrettyParams(
|
|
||||||
retCommunityTax, retBaseProposerReward, retBonusProposerReward, retWithdrawAddrEnabled,
|
|
||||||
), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryDelegatorTotalRewards queries delegator total rewards.
|
// QueryDelegatorTotalRewards queries delegator total rewards.
|
||||||
func QueryDelegatorTotalRewards(cliCtx context.CLIContext, queryRoute, delAddr string) ([]byte, error) {
|
func QueryDelegatorTotalRewards(cliCtx context.CLIContext, queryRoute, delAddr string) ([]byte, error) {
|
||||||
delegatorAddr, err := sdk.AccAddressFromBech32(delAddr)
|
delegatorAddr, err := sdk.AccAddressFromBech32(delAddr)
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Convenience struct for CLI output
|
|
||||||
type PrettyParams struct {
|
|
||||||
CommunityTax json.RawMessage `json:"community_tax"`
|
|
||||||
BaseProposerReward json.RawMessage `json:"base_proposer_reward"`
|
|
||||||
BonusProposerReward json.RawMessage `json:"bonus_proposer_reward"`
|
|
||||||
WithdrawAddrEnabled json.RawMessage `json:"withdraw_addr_enabled"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct a new PrettyParams
|
|
||||||
func NewPrettyParams(communityTax json.RawMessage, baseProposerReward json.RawMessage, bonusProposerReward json.RawMessage, withdrawAddrEnabled json.RawMessage) PrettyParams {
|
|
||||||
return PrettyParams{
|
|
||||||
CommunityTax: communityTax,
|
|
||||||
BaseProposerReward: baseProposerReward,
|
|
||||||
BonusProposerReward: bonusProposerReward,
|
|
||||||
WithdrawAddrEnabled: withdrawAddrEnabled,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pp PrettyParams) String() string {
|
|
||||||
return fmt.Sprintf(`Distribution Params:
|
|
||||||
Community Tax: %s
|
|
||||||
Base Proposer Reward: %s
|
|
||||||
Bonus Proposer Reward: %s
|
|
||||||
Withdraw Addr Enabled: %s`, pp.CommunityTax,
|
|
||||||
pp.BaseProposerReward, pp.BonusProposerReward, pp.WithdrawAddrEnabled)
|
|
||||||
|
|
||||||
}
|
|
|
@ -216,13 +216,15 @@ func paramsHandlerFn(cliCtx context.CLIContext, queryRoute string) http.HandlerF
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
params, err := common.QueryParams(cliCtx, queryRoute)
|
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParams)
|
||||||
|
res, height, err := cliCtx.QueryWithData(route, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rest.PostProcessResponse(w, cliCtx, params)
|
cliCtx = cliCtx.WithHeight(height)
|
||||||
|
rest.PostProcessResponse(w, cliCtx, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper
|
||||||
var moduleHoldings sdk.DecCoins
|
var moduleHoldings sdk.DecCoins
|
||||||
|
|
||||||
keeper.SetFeePool(ctx, data.FeePool)
|
keeper.SetFeePool(ctx, data.FeePool)
|
||||||
keeper.SetCommunityTax(ctx, data.CommunityTax)
|
keeper.SetParams(ctx, data.Params)
|
||||||
keeper.SetBaseProposerReward(ctx, data.BaseProposerReward)
|
|
||||||
keeper.SetBonusProposerReward(ctx, data.BonusProposerReward)
|
|
||||||
keeper.SetWithdrawAddrEnabled(ctx, data.WithdrawAddrEnabled)
|
|
||||||
|
|
||||||
for _, dwi := range data.DelegatorWithdrawInfos {
|
for _, dwi := range data.DelegatorWithdrawInfos {
|
||||||
keeper.SetDelegatorWithdrawAddr(ctx, dwi.DelegatorAddress, dwi.WithdrawAddress)
|
keeper.SetDelegatorWithdrawAddr(ctx, dwi.DelegatorAddress, dwi.WithdrawAddress)
|
||||||
|
@ -61,10 +58,8 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper
|
||||||
// ExportGenesis returns a GenesisState for a given context and keeper.
|
// ExportGenesis returns a GenesisState for a given context and keeper.
|
||||||
func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
|
func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
|
||||||
feePool := keeper.GetFeePool(ctx)
|
feePool := keeper.GetFeePool(ctx)
|
||||||
communityTax := keeper.GetCommunityTax(ctx)
|
params := keeper.GetParams(ctx)
|
||||||
baseProposerRewards := keeper.GetBaseProposerReward(ctx)
|
|
||||||
bonusProposerRewards := keeper.GetBonusProposerReward(ctx)
|
|
||||||
withdrawAddrEnabled := keeper.GetWithdrawAddrEnabled(ctx)
|
|
||||||
dwi := make([]types.DelegatorWithdrawInfo, 0)
|
dwi := make([]types.DelegatorWithdrawInfo, 0)
|
||||||
keeper.IterateDelegatorWithdrawAddrs(ctx, func(del sdk.AccAddress, addr sdk.AccAddress) (stop bool) {
|
keeper.IterateDelegatorWithdrawAddrs(ctx, func(del sdk.AccAddress, addr sdk.AccAddress) (stop bool) {
|
||||||
dwi = append(dwi, types.DelegatorWithdrawInfo{
|
dwi = append(dwi, types.DelegatorWithdrawInfo{
|
||||||
|
@ -73,6 +68,7 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
|
||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
pp := keeper.GetPreviousProposerConsAddr(ctx)
|
pp := keeper.GetPreviousProposerConsAddr(ctx)
|
||||||
outstanding := make([]types.ValidatorOutstandingRewardsRecord, 0)
|
outstanding := make([]types.ValidatorOutstandingRewardsRecord, 0)
|
||||||
keeper.IterateValidatorOutstandingRewards(ctx,
|
keeper.IterateValidatorOutstandingRewards(ctx,
|
||||||
|
@ -84,6 +80,7 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
acc := make([]types.ValidatorAccumulatedCommissionRecord, 0)
|
acc := make([]types.ValidatorAccumulatedCommissionRecord, 0)
|
||||||
keeper.IterateValidatorAccumulatedCommissions(ctx,
|
keeper.IterateValidatorAccumulatedCommissions(ctx,
|
||||||
func(addr sdk.ValAddress, commission types.ValidatorAccumulatedCommission) (stop bool) {
|
func(addr sdk.ValAddress, commission types.ValidatorAccumulatedCommission) (stop bool) {
|
||||||
|
@ -94,6 +91,7 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
his := make([]types.ValidatorHistoricalRewardsRecord, 0)
|
his := make([]types.ValidatorHistoricalRewardsRecord, 0)
|
||||||
keeper.IterateValidatorHistoricalRewards(ctx,
|
keeper.IterateValidatorHistoricalRewards(ctx,
|
||||||
func(val sdk.ValAddress, period uint64, rewards types.ValidatorHistoricalRewards) (stop bool) {
|
func(val sdk.ValAddress, period uint64, rewards types.ValidatorHistoricalRewards) (stop bool) {
|
||||||
|
@ -105,6 +103,7 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
cur := make([]types.ValidatorCurrentRewardsRecord, 0)
|
cur := make([]types.ValidatorCurrentRewardsRecord, 0)
|
||||||
keeper.IterateValidatorCurrentRewards(ctx,
|
keeper.IterateValidatorCurrentRewards(ctx,
|
||||||
func(val sdk.ValAddress, rewards types.ValidatorCurrentRewards) (stop bool) {
|
func(val sdk.ValAddress, rewards types.ValidatorCurrentRewards) (stop bool) {
|
||||||
|
@ -126,6 +125,7 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
slashes := make([]types.ValidatorSlashEventRecord, 0)
|
slashes := make([]types.ValidatorSlashEventRecord, 0)
|
||||||
keeper.IterateValidatorSlashEvents(ctx,
|
keeper.IterateValidatorSlashEvents(ctx,
|
||||||
func(val sdk.ValAddress, height uint64, event types.ValidatorSlashEvent) (stop bool) {
|
func(val sdk.ValAddress, height uint64, event types.ValidatorSlashEvent) (stop bool) {
|
||||||
|
@ -138,6 +138,6 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return types.NewGenesisState(feePool, communityTax, baseProposerRewards, bonusProposerRewards, withdrawAddrEnabled,
|
|
||||||
dwi, pp, outstanding, acc, his, cur, dels, slashes)
|
return types.NewGenesisState(params, feePool, dwi, pp, outstanding, acc, his, cur, dels, slashes)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,15 @@ func NewKeeper(
|
||||||
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
|
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set KeyTable if it has not already been set
|
||||||
|
if !paramSpace.HasKeyTable() {
|
||||||
|
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
|
||||||
|
}
|
||||||
|
|
||||||
return Keeper{
|
return Keeper{
|
||||||
storeKey: key,
|
storeKey: key,
|
||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
paramSpace: paramSpace.WithKeyTable(ParamKeyTable()),
|
paramSpace: paramSpace,
|
||||||
stakingKeeper: sk,
|
stakingKeeper: sk,
|
||||||
supplyKeeper: supplyKeeper,
|
supplyKeeper: supplyKeeper,
|
||||||
feeCollectorName: feeCollectorName,
|
feeCollectorName: feeCollectorName,
|
||||||
|
|
|
@ -13,12 +13,15 @@ import (
|
||||||
func TestSetWithdrawAddr(t *testing.T) {
|
func TestSetWithdrawAddr(t *testing.T) {
|
||||||
ctx, _, keeper, _, _ := CreateTestInputDefault(t, false, 1000)
|
ctx, _, keeper, _, _ := CreateTestInputDefault(t, false, 1000)
|
||||||
|
|
||||||
keeper.SetWithdrawAddrEnabled(ctx, false)
|
params := keeper.GetParams(ctx)
|
||||||
|
params.WithdrawAddrEnabled = false
|
||||||
|
keeper.SetParams(ctx, params)
|
||||||
|
|
||||||
err := keeper.SetWithdrawAddr(ctx, delAddr1, delAddr2)
|
err := keeper.SetWithdrawAddr(ctx, delAddr1, delAddr2)
|
||||||
require.NotNil(t, err)
|
require.NotNil(t, err)
|
||||||
|
|
||||||
keeper.SetWithdrawAddrEnabled(ctx, true)
|
params.WithdrawAddrEnabled = true
|
||||||
|
keeper.SetParams(ctx, params)
|
||||||
|
|
||||||
err = keeper.SetWithdrawAddr(ctx, delAddr1, delAddr2)
|
err = keeper.SetWithdrawAddr(ctx, delAddr1, delAddr2)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
|
@ -1,193 +0,0 @@
|
||||||
package keeper
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/binary"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// default paramspace for params keeper
|
|
||||||
DefaultParamspace = types.ModuleName
|
|
||||||
)
|
|
||||||
|
|
||||||
// Keys for distribution store
|
|
||||||
// Items are stored with the following key: values
|
|
||||||
//
|
|
||||||
// - 0x00<proposalID_Bytes>: FeePol
|
|
||||||
//
|
|
||||||
// - 0x01: sdk.ConsAddress
|
|
||||||
//
|
|
||||||
// - 0x02<valAddr_Bytes>: ValidatorOutstandingRewards
|
|
||||||
//
|
|
||||||
// - 0x03<accAddr_Bytes>: sdk.AccAddress
|
|
||||||
//
|
|
||||||
// - 0x04<valAddr_Bytes><accAddr_Bytes>: DelegatorStartingInfo
|
|
||||||
//
|
|
||||||
// - 0x05<valAddr_Bytes><period_Bytes>: ValidatorHistoricalRewards
|
|
||||||
//
|
|
||||||
// - 0x06<valAddr_Bytes>: ValidatorCurrentRewards
|
|
||||||
//
|
|
||||||
// - 0x07<valAddr_Bytes>: ValidatorCurrentRewards
|
|
||||||
//
|
|
||||||
// - 0x08<valAddr_Bytes><height>: ValidatorSlashEvent
|
|
||||||
var (
|
|
||||||
FeePoolKey = []byte{0x00} // key for global distribution state
|
|
||||||
ProposerKey = []byte{0x01} // key for the proposer operator address
|
|
||||||
ValidatorOutstandingRewardsPrefix = []byte{0x02} // key for outstanding rewards
|
|
||||||
|
|
||||||
DelegatorWithdrawAddrPrefix = []byte{0x03} // key for delegator withdraw address
|
|
||||||
DelegatorStartingInfoPrefix = []byte{0x04} // key for delegator starting info
|
|
||||||
ValidatorHistoricalRewardsPrefix = []byte{0x05} // key for historical validators rewards / stake
|
|
||||||
ValidatorCurrentRewardsPrefix = []byte{0x06} // key for current validator rewards
|
|
||||||
ValidatorAccumulatedCommissionPrefix = []byte{0x07} // key for accumulated validator commission
|
|
||||||
ValidatorSlashEventPrefix = []byte{0x08} // key for validator slash fraction
|
|
||||||
|
|
||||||
ParamStoreKeyCommunityTax = []byte("communitytax")
|
|
||||||
ParamStoreKeyBaseProposerReward = []byte("baseproposerreward")
|
|
||||||
ParamStoreKeyBonusProposerReward = []byte("bonusproposerreward")
|
|
||||||
ParamStoreKeyWithdrawAddrEnabled = []byte("withdrawaddrenabled")
|
|
||||||
)
|
|
||||||
|
|
||||||
// gets an address from a validator's outstanding rewards key
|
|
||||||
func GetValidatorOutstandingRewardsAddress(key []byte) (valAddr sdk.ValAddress) {
|
|
||||||
addr := key[1:]
|
|
||||||
if len(addr) != sdk.AddrLen {
|
|
||||||
panic("unexpected key length")
|
|
||||||
}
|
|
||||||
return sdk.ValAddress(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets an address from a delegator's withdraw info key
|
|
||||||
func GetDelegatorWithdrawInfoAddress(key []byte) (delAddr sdk.AccAddress) {
|
|
||||||
addr := key[1:]
|
|
||||||
if len(addr) != sdk.AddrLen {
|
|
||||||
panic("unexpected key length")
|
|
||||||
}
|
|
||||||
return sdk.AccAddress(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the addresses from a delegator starting info key
|
|
||||||
func GetDelegatorStartingInfoAddresses(key []byte) (valAddr sdk.ValAddress, delAddr sdk.AccAddress) {
|
|
||||||
addr := key[1 : 1+sdk.AddrLen]
|
|
||||||
if len(addr) != sdk.AddrLen {
|
|
||||||
panic("unexpected key length")
|
|
||||||
}
|
|
||||||
valAddr = sdk.ValAddress(addr)
|
|
||||||
addr = key[1+sdk.AddrLen:]
|
|
||||||
if len(addr) != sdk.AddrLen {
|
|
||||||
panic("unexpected key length")
|
|
||||||
}
|
|
||||||
delAddr = sdk.AccAddress(addr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the address & period from a validator's historical rewards key
|
|
||||||
func GetValidatorHistoricalRewardsAddressPeriod(key []byte) (valAddr sdk.ValAddress, period uint64) {
|
|
||||||
addr := key[1 : 1+sdk.AddrLen]
|
|
||||||
if len(addr) != sdk.AddrLen {
|
|
||||||
panic("unexpected key length")
|
|
||||||
}
|
|
||||||
valAddr = sdk.ValAddress(addr)
|
|
||||||
b := key[1+sdk.AddrLen:]
|
|
||||||
if len(b) != 8 {
|
|
||||||
panic("unexpected key length")
|
|
||||||
}
|
|
||||||
period = binary.LittleEndian.Uint64(b)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the address from a validator's current rewards key
|
|
||||||
func GetValidatorCurrentRewardsAddress(key []byte) (valAddr sdk.ValAddress) {
|
|
||||||
addr := key[1:]
|
|
||||||
if len(addr) != sdk.AddrLen {
|
|
||||||
panic("unexpected key length")
|
|
||||||
}
|
|
||||||
return sdk.ValAddress(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the address from a validator's accumulated commission key
|
|
||||||
func GetValidatorAccumulatedCommissionAddress(key []byte) (valAddr sdk.ValAddress) {
|
|
||||||
addr := key[1:]
|
|
||||||
if len(addr) != sdk.AddrLen {
|
|
||||||
panic("unexpected key length")
|
|
||||||
}
|
|
||||||
return sdk.ValAddress(addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the height from a validator's slash event key
|
|
||||||
func GetValidatorSlashEventAddressHeight(key []byte) (valAddr sdk.ValAddress, height uint64) {
|
|
||||||
addr := key[1 : 1+sdk.AddrLen]
|
|
||||||
if len(addr) != sdk.AddrLen {
|
|
||||||
panic("unexpected key length")
|
|
||||||
}
|
|
||||||
valAddr = sdk.ValAddress(addr)
|
|
||||||
startB := 1 + sdk.AddrLen
|
|
||||||
b := key[startB : startB+8] // the next 8 bytes represent the height
|
|
||||||
height = binary.BigEndian.Uint64(b)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the outstanding rewards key for a validator
|
|
||||||
func GetValidatorOutstandingRewardsKey(valAddr sdk.ValAddress) []byte {
|
|
||||||
return append(ValidatorOutstandingRewardsPrefix, valAddr.Bytes()...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the key for a delegator's withdraw addr
|
|
||||||
func GetDelegatorWithdrawAddrKey(delAddr sdk.AccAddress) []byte {
|
|
||||||
return append(DelegatorWithdrawAddrPrefix, delAddr.Bytes()...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the key for a delegator's starting info
|
|
||||||
func GetDelegatorStartingInfoKey(v sdk.ValAddress, d sdk.AccAddress) []byte {
|
|
||||||
return append(append(DelegatorStartingInfoPrefix, v.Bytes()...), d.Bytes()...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the prefix key for a validator's historical rewards
|
|
||||||
func GetValidatorHistoricalRewardsPrefix(v sdk.ValAddress) []byte {
|
|
||||||
return append(ValidatorHistoricalRewardsPrefix, v.Bytes()...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the key for a validator's historical rewards
|
|
||||||
func GetValidatorHistoricalRewardsKey(v sdk.ValAddress, k uint64) []byte {
|
|
||||||
b := make([]byte, 8)
|
|
||||||
binary.LittleEndian.PutUint64(b, k)
|
|
||||||
return append(append(ValidatorHistoricalRewardsPrefix, v.Bytes()...), b...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the key for a validator's current rewards
|
|
||||||
func GetValidatorCurrentRewardsKey(v sdk.ValAddress) []byte {
|
|
||||||
return append(ValidatorCurrentRewardsPrefix, v.Bytes()...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the key for a validator's current commission
|
|
||||||
func GetValidatorAccumulatedCommissionKey(v sdk.ValAddress) []byte {
|
|
||||||
return append(ValidatorAccumulatedCommissionPrefix, v.Bytes()...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the prefix key for a validator's slash fractions
|
|
||||||
func GetValidatorSlashEventPrefix(v sdk.ValAddress) []byte {
|
|
||||||
return append(ValidatorSlashEventPrefix, v.Bytes()...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the prefix key for a validator's slash fraction (ValidatorSlashEventPrefix + height)
|
|
||||||
func GetValidatorSlashEventKeyPrefix(v sdk.ValAddress, height uint64) []byte {
|
|
||||||
heightBz := make([]byte, 8)
|
|
||||||
binary.BigEndian.PutUint64(heightBz, height)
|
|
||||||
return append(
|
|
||||||
ValidatorSlashEventPrefix,
|
|
||||||
append(
|
|
||||||
v.Bytes(),
|
|
||||||
heightBz...,
|
|
||||||
)...,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the key for a validator's slash fraction
|
|
||||||
func GetValidatorSlashEventKey(v sdk.ValAddress, height, period uint64) []byte {
|
|
||||||
periodBz := make([]byte, 8)
|
|
||||||
binary.BigEndian.PutUint64(periodBz, period)
|
|
||||||
prefix := GetValidatorSlashEventKeyPrefix(v, height)
|
|
||||||
return append(prefix, periodBz...)
|
|
||||||
}
|
|
|
@ -1,127 +1,43 @@
|
||||||
package keeper
|
package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/params"
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// type declaration for parameters
|
// GetParams returns the total set of distribution parameters.
|
||||||
func ParamKeyTable() params.KeyTable {
|
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
|
||||||
return params.NewKeyTable(
|
k.paramSpace.GetParamSet(ctx, ¶ms)
|
||||||
params.NewParamSetPair(ParamStoreKeyCommunityTax, sdk.Dec{}, validateCommunityTax),
|
return params
|
||||||
params.NewParamSetPair(ParamStoreKeyBaseProposerReward, sdk.Dec{}, validateBaseProposerReward),
|
|
||||||
params.NewParamSetPair(ParamStoreKeyBonusProposerReward, sdk.Dec{}, validateBonusProposerReward),
|
|
||||||
params.NewParamSetPair(ParamStoreKeyWithdrawAddrEnabled, false, validateWithdrawAddrEnabled),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateCommunityTax(i interface{}) error {
|
// SetParams sets the distribution parameters to the param space.
|
||||||
v, ok := i.(sdk.Dec)
|
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
||||||
if !ok {
|
k.paramSpace.SetParamSet(ctx, ¶ms)
|
||||||
return fmt.Errorf("invalid parameter type: %T", i)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.IsNegative() {
|
// GetCommunityTax returns the current distribution community tax.
|
||||||
return fmt.Errorf("community tax must be positive: %s", v)
|
func (k Keeper) GetCommunityTax(ctx sdk.Context) (percent sdk.Dec) {
|
||||||
}
|
k.paramSpace.Get(ctx, types.ParamStoreKeyCommunityTax, &percent)
|
||||||
if v.GT(sdk.OneDec()) {
|
|
||||||
return fmt.Errorf("community tax too large: %s", v)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateBaseProposerReward(i interface{}) error {
|
|
||||||
v, ok := i.(sdk.Dec)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("invalid parameter type: %T", i)
|
|
||||||
}
|
|
||||||
|
|
||||||
if v.IsNegative() {
|
|
||||||
return fmt.Errorf("base proposer reward must be positive: %s", v)
|
|
||||||
}
|
|
||||||
if v.GT(sdk.OneDec()) {
|
|
||||||
return fmt.Errorf("base proposer reward too large: %s", v)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateBonusProposerReward(i interface{}) error {
|
|
||||||
v, ok := i.(sdk.Dec)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("invalid parameter type: %T", i)
|
|
||||||
}
|
|
||||||
|
|
||||||
if v.IsNegative() {
|
|
||||||
return fmt.Errorf("bonus proposer reward must be positive: %s", v)
|
|
||||||
}
|
|
||||||
if v.GT(sdk.OneDec()) {
|
|
||||||
return fmt.Errorf("bonus proposer reward too large: %s", v)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateWithdrawAddrEnabled(i interface{}) error {
|
|
||||||
_, ok := i.(bool)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("invalid parameter type: %T", i)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns the current CommunityTax rate from the global param store
|
|
||||||
// nolint: errcheck
|
|
||||||
func (k Keeper) GetCommunityTax(ctx sdk.Context) sdk.Dec {
|
|
||||||
var percent sdk.Dec
|
|
||||||
k.paramSpace.Get(ctx, ParamStoreKeyCommunityTax, &percent)
|
|
||||||
return percent
|
return percent
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: errcheck
|
// GetBaseProposerReward returns the current distribution base proposer rate.
|
||||||
func (k Keeper) SetCommunityTax(ctx sdk.Context, percent sdk.Dec) {
|
func (k Keeper) GetBaseProposerReward(ctx sdk.Context) (percent sdk.Dec) {
|
||||||
k.paramSpace.Set(ctx, ParamStoreKeyCommunityTax, &percent)
|
k.paramSpace.Get(ctx, types.ParamStoreKeyBaseProposerReward, &percent)
|
||||||
}
|
|
||||||
|
|
||||||
// returns the current BaseProposerReward rate from the global param store
|
|
||||||
// nolint: errcheck
|
|
||||||
func (k Keeper) GetBaseProposerReward(ctx sdk.Context) sdk.Dec {
|
|
||||||
var percent sdk.Dec
|
|
||||||
k.paramSpace.Get(ctx, ParamStoreKeyBaseProposerReward, &percent)
|
|
||||||
return percent
|
return percent
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: errcheck
|
// GetBonusProposerReward returns the current distribution bonus proposer reward
|
||||||
func (k Keeper) SetBaseProposerReward(ctx sdk.Context, percent sdk.Dec) {
|
// rate.
|
||||||
k.paramSpace.Set(ctx, ParamStoreKeyBaseProposerReward, &percent)
|
func (k Keeper) GetBonusProposerReward(ctx sdk.Context) (percent sdk.Dec) {
|
||||||
}
|
k.paramSpace.Get(ctx, types.ParamStoreKeyBonusProposerReward, &percent)
|
||||||
|
|
||||||
// returns the current BaseProposerReward rate from the global param store
|
|
||||||
// nolint: errcheck
|
|
||||||
func (k Keeper) GetBonusProposerReward(ctx sdk.Context) sdk.Dec {
|
|
||||||
var percent sdk.Dec
|
|
||||||
k.paramSpace.Get(ctx, ParamStoreKeyBonusProposerReward, &percent)
|
|
||||||
return percent
|
return percent
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: errcheck
|
// GetWithdrawAddrEnabled returns the current distribution withdraw address
|
||||||
func (k Keeper) SetBonusProposerReward(ctx sdk.Context, percent sdk.Dec) {
|
// enabled parameter.
|
||||||
k.paramSpace.Set(ctx, ParamStoreKeyBonusProposerReward, &percent)
|
func (k Keeper) GetWithdrawAddrEnabled(ctx sdk.Context) (enabled bool) {
|
||||||
}
|
k.paramSpace.Get(ctx, types.ParamStoreKeyWithdrawAddrEnabled, &enabled)
|
||||||
|
|
||||||
// returns the current WithdrawAddrEnabled
|
|
||||||
// nolint: errcheck
|
|
||||||
func (k Keeper) GetWithdrawAddrEnabled(ctx sdk.Context) bool {
|
|
||||||
var enabled bool
|
|
||||||
k.paramSpace.Get(ctx, ParamStoreKeyWithdrawAddrEnabled, &enabled)
|
|
||||||
return enabled
|
return enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: errcheck
|
|
||||||
func (k Keeper) SetWithdrawAddrEnabled(ctx sdk.Context, enabled bool) {
|
|
||||||
k.paramSpace.Set(ctx, ParamStoreKeyWithdrawAddrEnabled, &enabled)
|
|
||||||
}
|
|
||||||
|
|
|
@ -49,38 +49,14 @@ func NewQuerier(k Keeper) sdk.Querier {
|
||||||
}
|
}
|
||||||
|
|
||||||
func queryParams(ctx sdk.Context, path []string, req abci.RequestQuery, k Keeper) ([]byte, error) {
|
func queryParams(ctx sdk.Context, path []string, req abci.RequestQuery, k Keeper) ([]byte, error) {
|
||||||
switch path[0] {
|
params := k.GetParams(ctx)
|
||||||
case types.ParamCommunityTax:
|
|
||||||
bz, err := codec.MarshalJSONIndent(k.cdc, k.GetCommunityTax(ctx))
|
res, err := codec.MarshalJSONIndent(k.cdc, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
||||||
}
|
}
|
||||||
return bz, nil
|
|
||||||
|
|
||||||
case types.ParamBaseProposerReward:
|
return res, nil
|
||||||
bz, err := codec.MarshalJSONIndent(k.cdc, k.GetBaseProposerReward(ctx))
|
|
||||||
if err != nil {
|
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
|
||||||
}
|
|
||||||
return bz, nil
|
|
||||||
|
|
||||||
case types.ParamBonusProposerReward:
|
|
||||||
bz, err := codec.MarshalJSONIndent(k.cdc, k.GetBonusProposerReward(ctx))
|
|
||||||
if err != nil {
|
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
|
||||||
}
|
|
||||||
return bz, nil
|
|
||||||
|
|
||||||
case types.ParamWithdrawAddrEnabled:
|
|
||||||
bz, err := codec.MarshalJSONIndent(k.cdc, k.GetWithdrawAddrEnabled(ctx))
|
|
||||||
if err != nil {
|
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
|
||||||
}
|
|
||||||
return bz, nil
|
|
||||||
|
|
||||||
default:
|
|
||||||
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "%s is not a valid query request path", req.Path)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func queryValidatorOutstandingRewards(ctx sdk.Context, path []string, req abci.RequestQuery, k Keeper) ([]byte, error) {
|
func queryValidatorOutstandingRewards(ctx sdk.Context, path []string, req abci.RequestQuery, k Keeper) ([]byte, error) {
|
||||||
|
|
|
@ -17,45 +17,14 @@ import (
|
||||||
|
|
||||||
const custom = "custom"
|
const custom = "custom"
|
||||||
|
|
||||||
func getQueriedParams(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier) (communityTax sdk.Dec, baseProposerReward sdk.Dec, bonusProposerReward sdk.Dec, withdrawAddrEnabled bool) {
|
func getQueriedParams(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier) types.Params {
|
||||||
|
var params types.Params
|
||||||
|
|
||||||
query := abci.RequestQuery{
|
bz, err := querier(ctx, []string{types.QueryParams}, abci.RequestQuery{})
|
||||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryParams, types.ParamCommunityTax}, "/"),
|
|
||||||
Data: []byte{},
|
|
||||||
}
|
|
||||||
|
|
||||||
bz, err := querier(ctx, []string{types.QueryParams, types.ParamCommunityTax}, query)
|
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Nil(t, cdc.UnmarshalJSON(bz, &communityTax))
|
require.Nil(t, cdc.UnmarshalJSON(bz, ¶ms))
|
||||||
|
|
||||||
query = abci.RequestQuery{
|
return params
|
||||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryParams, types.ParamBaseProposerReward}, "/"),
|
|
||||||
Data: []byte{},
|
|
||||||
}
|
|
||||||
|
|
||||||
bz, err = querier(ctx, []string{types.QueryParams, types.ParamBaseProposerReward}, query)
|
|
||||||
require.Nil(t, err)
|
|
||||||
require.Nil(t, cdc.UnmarshalJSON(bz, &baseProposerReward))
|
|
||||||
|
|
||||||
query = abci.RequestQuery{
|
|
||||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryParams, types.ParamBonusProposerReward}, "/"),
|
|
||||||
Data: []byte{},
|
|
||||||
}
|
|
||||||
|
|
||||||
bz, err = querier(ctx, []string{types.QueryParams, types.ParamBonusProposerReward}, query)
|
|
||||||
require.Nil(t, err)
|
|
||||||
require.Nil(t, cdc.UnmarshalJSON(bz, &bonusProposerReward))
|
|
||||||
|
|
||||||
query = abci.RequestQuery{
|
|
||||||
Path: strings.Join([]string{custom, types.QuerierRoute, types.QueryParams, types.ParamWithdrawAddrEnabled}, "/"),
|
|
||||||
Data: []byte{},
|
|
||||||
}
|
|
||||||
|
|
||||||
bz, err = querier(ctx, []string{types.QueryParams, types.ParamWithdrawAddrEnabled}, query)
|
|
||||||
require.Nil(t, err)
|
|
||||||
require.Nil(t, cdc.UnmarshalJSON(bz, &withdrawAddrEnabled))
|
|
||||||
|
|
||||||
return communityTax, baseProposerReward, bonusProposerReward, withdrawAddrEnabled
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getQueriedValidatorOutstandingRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, validatorAddr sdk.ValAddress) (outstandingRewards sdk.DecCoins) {
|
func getQueriedValidatorOutstandingRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier, validatorAddr sdk.ValAddress) (outstandingRewards sdk.DecCoins) {
|
||||||
|
@ -144,19 +113,20 @@ func TestQueries(t *testing.T) {
|
||||||
querier := NewQuerier(keeper)
|
querier := NewQuerier(keeper)
|
||||||
|
|
||||||
// test param queries
|
// test param queries
|
||||||
communityTax := sdk.NewDecWithPrec(3, 1)
|
params := types.Params{
|
||||||
baseProposerReward := sdk.NewDecWithPrec(2, 1)
|
CommunityTax: sdk.NewDecWithPrec(3, 1),
|
||||||
bonusProposerReward := sdk.NewDecWithPrec(1, 1)
|
BaseProposerReward: sdk.NewDecWithPrec(2, 1),
|
||||||
withdrawAddrEnabled := true
|
BonusProposerReward: sdk.NewDecWithPrec(1, 1),
|
||||||
keeper.SetCommunityTax(ctx, communityTax)
|
WithdrawAddrEnabled: true,
|
||||||
keeper.SetBaseProposerReward(ctx, baseProposerReward)
|
}
|
||||||
keeper.SetBonusProposerReward(ctx, bonusProposerReward)
|
|
||||||
keeper.SetWithdrawAddrEnabled(ctx, withdrawAddrEnabled)
|
keeper.SetParams(ctx, params)
|
||||||
retCommunityTax, retBaseProposerReward, retBonusProposerReward, retWithdrawAddrEnabled := getQueriedParams(t, ctx, cdc, querier)
|
|
||||||
require.Equal(t, communityTax, retCommunityTax)
|
paramsRes := getQueriedParams(t, ctx, cdc, querier)
|
||||||
require.Equal(t, baseProposerReward, retBaseProposerReward)
|
require.Equal(t, params.CommunityTax, paramsRes.CommunityTax)
|
||||||
require.Equal(t, bonusProposerReward, retBonusProposerReward)
|
require.Equal(t, params.BaseProposerReward, paramsRes.BaseProposerReward)
|
||||||
require.Equal(t, withdrawAddrEnabled, retWithdrawAddrEnabled)
|
require.Equal(t, params.BonusProposerReward, paramsRes.BonusProposerReward)
|
||||||
|
require.Equal(t, params.WithdrawAddrEnabled, paramsRes.WithdrawAddrEnabled)
|
||||||
|
|
||||||
// test outstanding rewards query
|
// test outstanding rewards query
|
||||||
outstandingRewards := sdk.DecCoins{{Denom: "mytoken", Amount: sdk.NewDec(3)}, {Denom: "myothertoken", Amount: sdk.NewDecWithPrec(3, 7)}}
|
outstandingRewards := sdk.DecCoins{{Denom: "mytoken", Amount: sdk.NewDec(3)}, {Denom: "myothertoken", Amount: sdk.NewDecWithPrec(3, 7)}}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
// get the delegator withdraw address, defaulting to the delegator address
|
// get the delegator withdraw address, defaulting to the delegator address
|
||||||
func (k Keeper) GetDelegatorWithdrawAddr(ctx sdk.Context, delAddr sdk.AccAddress) sdk.AccAddress {
|
func (k Keeper) GetDelegatorWithdrawAddr(ctx sdk.Context, delAddr sdk.AccAddress) sdk.AccAddress {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := store.Get(GetDelegatorWithdrawAddrKey(delAddr))
|
b := store.Get(types.GetDelegatorWithdrawAddrKey(delAddr))
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return delAddr
|
return delAddr
|
||||||
}
|
}
|
||||||
|
@ -18,23 +18,23 @@ func (k Keeper) GetDelegatorWithdrawAddr(ctx sdk.Context, delAddr sdk.AccAddress
|
||||||
// set the delegator withdraw address
|
// set the delegator withdraw address
|
||||||
func (k Keeper) SetDelegatorWithdrawAddr(ctx sdk.Context, delAddr, withdrawAddr sdk.AccAddress) {
|
func (k Keeper) SetDelegatorWithdrawAddr(ctx sdk.Context, delAddr, withdrawAddr sdk.AccAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
store.Set(GetDelegatorWithdrawAddrKey(delAddr), withdrawAddr.Bytes())
|
store.Set(types.GetDelegatorWithdrawAddrKey(delAddr), withdrawAddr.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete a delegator withdraw addr
|
// delete a delegator withdraw addr
|
||||||
func (k Keeper) DeleteDelegatorWithdrawAddr(ctx sdk.Context, delAddr, withdrawAddr sdk.AccAddress) {
|
func (k Keeper) DeleteDelegatorWithdrawAddr(ctx sdk.Context, delAddr, withdrawAddr sdk.AccAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
store.Delete(GetDelegatorWithdrawAddrKey(delAddr))
|
store.Delete(types.GetDelegatorWithdrawAddrKey(delAddr))
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate over delegator withdraw addrs
|
// iterate over delegator withdraw addrs
|
||||||
func (k Keeper) IterateDelegatorWithdrawAddrs(ctx sdk.Context, handler func(del sdk.AccAddress, addr sdk.AccAddress) (stop bool)) {
|
func (k Keeper) IterateDelegatorWithdrawAddrs(ctx sdk.Context, handler func(del sdk.AccAddress, addr sdk.AccAddress) (stop bool)) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, DelegatorWithdrawAddrPrefix)
|
iter := sdk.KVStorePrefixIterator(store, types.DelegatorWithdrawAddrPrefix)
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
addr := sdk.AccAddress(iter.Value())
|
addr := sdk.AccAddress(iter.Value())
|
||||||
del := GetDelegatorWithdrawInfoAddress(iter.Key())
|
del := types.GetDelegatorWithdrawInfoAddress(iter.Key())
|
||||||
if handler(del, addr) {
|
if handler(del, addr) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func (k Keeper) IterateDelegatorWithdrawAddrs(ctx sdk.Context, handler func(del
|
||||||
// get the global fee pool distribution info
|
// get the global fee pool distribution info
|
||||||
func (k Keeper) GetFeePool(ctx sdk.Context) (feePool types.FeePool) {
|
func (k Keeper) GetFeePool(ctx sdk.Context) (feePool types.FeePool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := store.Get(FeePoolKey)
|
b := store.Get(types.FeePoolKey)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
panic("Stored fee pool should not have been nil")
|
panic("Stored fee pool should not have been nil")
|
||||||
}
|
}
|
||||||
|
@ -56,13 +56,13 @@ func (k Keeper) GetFeePool(ctx sdk.Context) (feePool types.FeePool) {
|
||||||
func (k Keeper) SetFeePool(ctx sdk.Context, feePool types.FeePool) {
|
func (k Keeper) SetFeePool(ctx sdk.Context, feePool types.FeePool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := k.cdc.MustMarshalBinaryLengthPrefixed(feePool)
|
b := k.cdc.MustMarshalBinaryLengthPrefixed(feePool)
|
||||||
store.Set(FeePoolKey, b)
|
store.Set(types.FeePoolKey, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the proposer public key for this block
|
// get the proposer public key for this block
|
||||||
func (k Keeper) GetPreviousProposerConsAddr(ctx sdk.Context) (consAddr sdk.ConsAddress) {
|
func (k Keeper) GetPreviousProposerConsAddr(ctx sdk.Context) (consAddr sdk.ConsAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := store.Get(ProposerKey)
|
b := store.Get(types.ProposerKey)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
panic("Previous proposer not set")
|
panic("Previous proposer not set")
|
||||||
}
|
}
|
||||||
|
@ -74,13 +74,13 @@ func (k Keeper) GetPreviousProposerConsAddr(ctx sdk.Context) (consAddr sdk.ConsA
|
||||||
func (k Keeper) SetPreviousProposerConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) {
|
func (k Keeper) SetPreviousProposerConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := k.cdc.MustMarshalBinaryLengthPrefixed(consAddr)
|
b := k.cdc.MustMarshalBinaryLengthPrefixed(consAddr)
|
||||||
store.Set(ProposerKey, b)
|
store.Set(types.ProposerKey, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the starting info associated with a delegator
|
// get the starting info associated with a delegator
|
||||||
func (k Keeper) GetDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress) (period types.DelegatorStartingInfo) {
|
func (k Keeper) GetDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress) (period types.DelegatorStartingInfo) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := store.Get(GetDelegatorStartingInfoKey(val, del))
|
b := store.Get(types.GetDelegatorStartingInfoKey(val, del))
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &period)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &period)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -89,30 +89,30 @@ func (k Keeper) GetDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, de
|
||||||
func (k Keeper) SetDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress, period types.DelegatorStartingInfo) {
|
func (k Keeper) SetDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress, period types.DelegatorStartingInfo) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := k.cdc.MustMarshalBinaryLengthPrefixed(period)
|
b := k.cdc.MustMarshalBinaryLengthPrefixed(period)
|
||||||
store.Set(GetDelegatorStartingInfoKey(val, del), b)
|
store.Set(types.GetDelegatorStartingInfoKey(val, del), b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check existence of the starting info associated with a delegator
|
// check existence of the starting info associated with a delegator
|
||||||
func (k Keeper) HasDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress) bool {
|
func (k Keeper) HasDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress) bool {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
return store.Has(GetDelegatorStartingInfoKey(val, del))
|
return store.Has(types.GetDelegatorStartingInfoKey(val, del))
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete the starting info associated with a delegator
|
// delete the starting info associated with a delegator
|
||||||
func (k Keeper) DeleteDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress) {
|
func (k Keeper) DeleteDelegatorStartingInfo(ctx sdk.Context, val sdk.ValAddress, del sdk.AccAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
store.Delete(GetDelegatorStartingInfoKey(val, del))
|
store.Delete(types.GetDelegatorStartingInfoKey(val, del))
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate over delegator starting infos
|
// iterate over delegator starting infos
|
||||||
func (k Keeper) IterateDelegatorStartingInfos(ctx sdk.Context, handler func(val sdk.ValAddress, del sdk.AccAddress, info types.DelegatorStartingInfo) (stop bool)) {
|
func (k Keeper) IterateDelegatorStartingInfos(ctx sdk.Context, handler func(val sdk.ValAddress, del sdk.AccAddress, info types.DelegatorStartingInfo) (stop bool)) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, DelegatorStartingInfoPrefix)
|
iter := sdk.KVStorePrefixIterator(store, types.DelegatorStartingInfoPrefix)
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
var info types.DelegatorStartingInfo
|
var info types.DelegatorStartingInfo
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &info)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &info)
|
||||||
val, del := GetDelegatorStartingInfoAddresses(iter.Key())
|
val, del := types.GetDelegatorStartingInfoAddresses(iter.Key())
|
||||||
if handler(val, del, info) {
|
if handler(val, del, info) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ func (k Keeper) IterateDelegatorStartingInfos(ctx sdk.Context, handler func(val
|
||||||
// get historical rewards for a particular period
|
// get historical rewards for a particular period
|
||||||
func (k Keeper) GetValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddress, period uint64) (rewards types.ValidatorHistoricalRewards) {
|
func (k Keeper) GetValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddress, period uint64) (rewards types.ValidatorHistoricalRewards) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := store.Get(GetValidatorHistoricalRewardsKey(val, period))
|
b := store.Get(types.GetValidatorHistoricalRewardsKey(val, period))
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &rewards)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &rewards)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -131,18 +131,18 @@ func (k Keeper) GetValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddres
|
||||||
func (k Keeper) SetValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddress, period uint64, rewards types.ValidatorHistoricalRewards) {
|
func (k Keeper) SetValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddress, period uint64, rewards types.ValidatorHistoricalRewards) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := k.cdc.MustMarshalBinaryLengthPrefixed(rewards)
|
b := k.cdc.MustMarshalBinaryLengthPrefixed(rewards)
|
||||||
store.Set(GetValidatorHistoricalRewardsKey(val, period), b)
|
store.Set(types.GetValidatorHistoricalRewardsKey(val, period), b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate over historical rewards
|
// iterate over historical rewards
|
||||||
func (k Keeper) IterateValidatorHistoricalRewards(ctx sdk.Context, handler func(val sdk.ValAddress, period uint64, rewards types.ValidatorHistoricalRewards) (stop bool)) {
|
func (k Keeper) IterateValidatorHistoricalRewards(ctx sdk.Context, handler func(val sdk.ValAddress, period uint64, rewards types.ValidatorHistoricalRewards) (stop bool)) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, ValidatorHistoricalRewardsPrefix)
|
iter := sdk.KVStorePrefixIterator(store, types.ValidatorHistoricalRewardsPrefix)
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
var rewards types.ValidatorHistoricalRewards
|
var rewards types.ValidatorHistoricalRewards
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &rewards)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &rewards)
|
||||||
addr, period := GetValidatorHistoricalRewardsAddressPeriod(iter.Key())
|
addr, period := types.GetValidatorHistoricalRewardsAddressPeriod(iter.Key())
|
||||||
if handler(addr, period, rewards) {
|
if handler(addr, period, rewards) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -152,13 +152,13 @@ func (k Keeper) IterateValidatorHistoricalRewards(ctx sdk.Context, handler func(
|
||||||
// delete a historical reward
|
// delete a historical reward
|
||||||
func (k Keeper) DeleteValidatorHistoricalReward(ctx sdk.Context, val sdk.ValAddress, period uint64) {
|
func (k Keeper) DeleteValidatorHistoricalReward(ctx sdk.Context, val sdk.ValAddress, period uint64) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
store.Delete(GetValidatorHistoricalRewardsKey(val, period))
|
store.Delete(types.GetValidatorHistoricalRewardsKey(val, period))
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete historical rewards for a validator
|
// delete historical rewards for a validator
|
||||||
func (k Keeper) DeleteValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddress) {
|
func (k Keeper) DeleteValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, GetValidatorHistoricalRewardsPrefix(val))
|
iter := sdk.KVStorePrefixIterator(store, types.GetValidatorHistoricalRewardsPrefix(val))
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
store.Delete(iter.Key())
|
store.Delete(iter.Key())
|
||||||
|
@ -168,7 +168,7 @@ func (k Keeper) DeleteValidatorHistoricalRewards(ctx sdk.Context, val sdk.ValAdd
|
||||||
// delete all historical rewards
|
// delete all historical rewards
|
||||||
func (k Keeper) DeleteAllValidatorHistoricalRewards(ctx sdk.Context) {
|
func (k Keeper) DeleteAllValidatorHistoricalRewards(ctx sdk.Context) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, ValidatorHistoricalRewardsPrefix)
|
iter := sdk.KVStorePrefixIterator(store, types.ValidatorHistoricalRewardsPrefix)
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
store.Delete(iter.Key())
|
store.Delete(iter.Key())
|
||||||
|
@ -178,7 +178,7 @@ func (k Keeper) DeleteAllValidatorHistoricalRewards(ctx sdk.Context) {
|
||||||
// historical reference count (used for testcases)
|
// historical reference count (used for testcases)
|
||||||
func (k Keeper) GetValidatorHistoricalReferenceCount(ctx sdk.Context) (count uint64) {
|
func (k Keeper) GetValidatorHistoricalReferenceCount(ctx sdk.Context) (count uint64) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, ValidatorHistoricalRewardsPrefix)
|
iter := sdk.KVStorePrefixIterator(store, types.ValidatorHistoricalRewardsPrefix)
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
var rewards types.ValidatorHistoricalRewards
|
var rewards types.ValidatorHistoricalRewards
|
||||||
|
@ -191,7 +191,7 @@ func (k Keeper) GetValidatorHistoricalReferenceCount(ctx sdk.Context) (count uin
|
||||||
// get current rewards for a validator
|
// get current rewards for a validator
|
||||||
func (k Keeper) GetValidatorCurrentRewards(ctx sdk.Context, val sdk.ValAddress) (rewards types.ValidatorCurrentRewards) {
|
func (k Keeper) GetValidatorCurrentRewards(ctx sdk.Context, val sdk.ValAddress) (rewards types.ValidatorCurrentRewards) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := store.Get(GetValidatorCurrentRewardsKey(val))
|
b := store.Get(types.GetValidatorCurrentRewardsKey(val))
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &rewards)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &rewards)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -200,24 +200,24 @@ func (k Keeper) GetValidatorCurrentRewards(ctx sdk.Context, val sdk.ValAddress)
|
||||||
func (k Keeper) SetValidatorCurrentRewards(ctx sdk.Context, val sdk.ValAddress, rewards types.ValidatorCurrentRewards) {
|
func (k Keeper) SetValidatorCurrentRewards(ctx sdk.Context, val sdk.ValAddress, rewards types.ValidatorCurrentRewards) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := k.cdc.MustMarshalBinaryLengthPrefixed(rewards)
|
b := k.cdc.MustMarshalBinaryLengthPrefixed(rewards)
|
||||||
store.Set(GetValidatorCurrentRewardsKey(val), b)
|
store.Set(types.GetValidatorCurrentRewardsKey(val), b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete current rewards for a validator
|
// delete current rewards for a validator
|
||||||
func (k Keeper) DeleteValidatorCurrentRewards(ctx sdk.Context, val sdk.ValAddress) {
|
func (k Keeper) DeleteValidatorCurrentRewards(ctx sdk.Context, val sdk.ValAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
store.Delete(GetValidatorCurrentRewardsKey(val))
|
store.Delete(types.GetValidatorCurrentRewardsKey(val))
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate over current rewards
|
// iterate over current rewards
|
||||||
func (k Keeper) IterateValidatorCurrentRewards(ctx sdk.Context, handler func(val sdk.ValAddress, rewards types.ValidatorCurrentRewards) (stop bool)) {
|
func (k Keeper) IterateValidatorCurrentRewards(ctx sdk.Context, handler func(val sdk.ValAddress, rewards types.ValidatorCurrentRewards) (stop bool)) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, ValidatorCurrentRewardsPrefix)
|
iter := sdk.KVStorePrefixIterator(store, types.ValidatorCurrentRewardsPrefix)
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
var rewards types.ValidatorCurrentRewards
|
var rewards types.ValidatorCurrentRewards
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &rewards)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &rewards)
|
||||||
addr := GetValidatorCurrentRewardsAddress(iter.Key())
|
addr := types.GetValidatorCurrentRewardsAddress(iter.Key())
|
||||||
if handler(addr, rewards) {
|
if handler(addr, rewards) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ func (k Keeper) IterateValidatorCurrentRewards(ctx sdk.Context, handler func(val
|
||||||
// get accumulated commission for a validator
|
// get accumulated commission for a validator
|
||||||
func (k Keeper) GetValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAddress) (commission types.ValidatorAccumulatedCommission) {
|
func (k Keeper) GetValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAddress) (commission types.ValidatorAccumulatedCommission) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := store.Get(GetValidatorAccumulatedCommissionKey(val))
|
b := store.Get(types.GetValidatorAccumulatedCommissionKey(val))
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return types.ValidatorAccumulatedCommission{}
|
return types.ValidatorAccumulatedCommission{}
|
||||||
}
|
}
|
||||||
|
@ -246,24 +246,24 @@ func (k Keeper) SetValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAd
|
||||||
bz = k.cdc.MustMarshalBinaryLengthPrefixed(commission)
|
bz = k.cdc.MustMarshalBinaryLengthPrefixed(commission)
|
||||||
}
|
}
|
||||||
|
|
||||||
store.Set(GetValidatorAccumulatedCommissionKey(val), bz)
|
store.Set(types.GetValidatorAccumulatedCommissionKey(val), bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete accumulated commission for a validator
|
// delete accumulated commission for a validator
|
||||||
func (k Keeper) DeleteValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAddress) {
|
func (k Keeper) DeleteValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
store.Delete(GetValidatorAccumulatedCommissionKey(val))
|
store.Delete(types.GetValidatorAccumulatedCommissionKey(val))
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate over accumulated commissions
|
// iterate over accumulated commissions
|
||||||
func (k Keeper) IterateValidatorAccumulatedCommissions(ctx sdk.Context, handler func(val sdk.ValAddress, commission types.ValidatorAccumulatedCommission) (stop bool)) {
|
func (k Keeper) IterateValidatorAccumulatedCommissions(ctx sdk.Context, handler func(val sdk.ValAddress, commission types.ValidatorAccumulatedCommission) (stop bool)) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, ValidatorAccumulatedCommissionPrefix)
|
iter := sdk.KVStorePrefixIterator(store, types.ValidatorAccumulatedCommissionPrefix)
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
var commission types.ValidatorAccumulatedCommission
|
var commission types.ValidatorAccumulatedCommission
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &commission)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &commission)
|
||||||
addr := GetValidatorAccumulatedCommissionAddress(iter.Key())
|
addr := types.GetValidatorAccumulatedCommissionAddress(iter.Key())
|
||||||
if handler(addr, commission) {
|
if handler(addr, commission) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ func (k Keeper) IterateValidatorAccumulatedCommissions(ctx sdk.Context, handler
|
||||||
// get validator outstanding rewards
|
// get validator outstanding rewards
|
||||||
func (k Keeper) GetValidatorOutstandingRewards(ctx sdk.Context, val sdk.ValAddress) (rewards types.ValidatorOutstandingRewards) {
|
func (k Keeper) GetValidatorOutstandingRewards(ctx sdk.Context, val sdk.ValAddress) (rewards types.ValidatorOutstandingRewards) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := store.Get(GetValidatorOutstandingRewardsKey(val))
|
b := store.Get(types.GetValidatorOutstandingRewardsKey(val))
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &rewards)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &rewards)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -282,24 +282,24 @@ func (k Keeper) GetValidatorOutstandingRewards(ctx sdk.Context, val sdk.ValAddre
|
||||||
func (k Keeper) SetValidatorOutstandingRewards(ctx sdk.Context, val sdk.ValAddress, rewards types.ValidatorOutstandingRewards) {
|
func (k Keeper) SetValidatorOutstandingRewards(ctx sdk.Context, val sdk.ValAddress, rewards types.ValidatorOutstandingRewards) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := k.cdc.MustMarshalBinaryLengthPrefixed(rewards)
|
b := k.cdc.MustMarshalBinaryLengthPrefixed(rewards)
|
||||||
store.Set(GetValidatorOutstandingRewardsKey(val), b)
|
store.Set(types.GetValidatorOutstandingRewardsKey(val), b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete validator outstanding rewards
|
// delete validator outstanding rewards
|
||||||
func (k Keeper) DeleteValidatorOutstandingRewards(ctx sdk.Context, val sdk.ValAddress) {
|
func (k Keeper) DeleteValidatorOutstandingRewards(ctx sdk.Context, val sdk.ValAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
store.Delete(GetValidatorOutstandingRewardsKey(val))
|
store.Delete(types.GetValidatorOutstandingRewardsKey(val))
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate validator outstanding rewards
|
// iterate validator outstanding rewards
|
||||||
func (k Keeper) IterateValidatorOutstandingRewards(ctx sdk.Context, handler func(val sdk.ValAddress, rewards types.ValidatorOutstandingRewards) (stop bool)) {
|
func (k Keeper) IterateValidatorOutstandingRewards(ctx sdk.Context, handler func(val sdk.ValAddress, rewards types.ValidatorOutstandingRewards) (stop bool)) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, ValidatorOutstandingRewardsPrefix)
|
iter := sdk.KVStorePrefixIterator(store, types.ValidatorOutstandingRewardsPrefix)
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
var rewards types.ValidatorOutstandingRewards
|
var rewards types.ValidatorOutstandingRewards
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &rewards)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &rewards)
|
||||||
addr := GetValidatorOutstandingRewardsAddress(iter.Key())
|
addr := types.GetValidatorOutstandingRewardsAddress(iter.Key())
|
||||||
if handler(addr, rewards) {
|
if handler(addr, rewards) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -309,7 +309,7 @@ func (k Keeper) IterateValidatorOutstandingRewards(ctx sdk.Context, handler func
|
||||||
// get slash event for height
|
// get slash event for height
|
||||||
func (k Keeper) GetValidatorSlashEvent(ctx sdk.Context, val sdk.ValAddress, height, period uint64) (event types.ValidatorSlashEvent, found bool) {
|
func (k Keeper) GetValidatorSlashEvent(ctx sdk.Context, val sdk.ValAddress, height, period uint64) (event types.ValidatorSlashEvent, found bool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := store.Get(GetValidatorSlashEventKey(val, height, period))
|
b := store.Get(types.GetValidatorSlashEventKey(val, height, period))
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return types.ValidatorSlashEvent{}, false
|
return types.ValidatorSlashEvent{}, false
|
||||||
}
|
}
|
||||||
|
@ -321,7 +321,7 @@ func (k Keeper) GetValidatorSlashEvent(ctx sdk.Context, val sdk.ValAddress, heig
|
||||||
func (k Keeper) SetValidatorSlashEvent(ctx sdk.Context, val sdk.ValAddress, height, period uint64, event types.ValidatorSlashEvent) {
|
func (k Keeper) SetValidatorSlashEvent(ctx sdk.Context, val sdk.ValAddress, height, period uint64, event types.ValidatorSlashEvent) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := k.cdc.MustMarshalBinaryLengthPrefixed(event)
|
b := k.cdc.MustMarshalBinaryLengthPrefixed(event)
|
||||||
store.Set(GetValidatorSlashEventKey(val, height, period), b)
|
store.Set(types.GetValidatorSlashEventKey(val, height, period), b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate over slash events between heights, inclusive
|
// iterate over slash events between heights, inclusive
|
||||||
|
@ -329,14 +329,14 @@ func (k Keeper) IterateValidatorSlashEventsBetween(ctx sdk.Context, val sdk.ValA
|
||||||
handler func(height uint64, event types.ValidatorSlashEvent) (stop bool)) {
|
handler func(height uint64, event types.ValidatorSlashEvent) (stop bool)) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := store.Iterator(
|
iter := store.Iterator(
|
||||||
GetValidatorSlashEventKeyPrefix(val, startingHeight),
|
types.GetValidatorSlashEventKeyPrefix(val, startingHeight),
|
||||||
GetValidatorSlashEventKeyPrefix(val, endingHeight+1),
|
types.GetValidatorSlashEventKeyPrefix(val, endingHeight+1),
|
||||||
)
|
)
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
var event types.ValidatorSlashEvent
|
var event types.ValidatorSlashEvent
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &event)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &event)
|
||||||
_, height := GetValidatorSlashEventAddressHeight(iter.Key())
|
_, height := types.GetValidatorSlashEventAddressHeight(iter.Key())
|
||||||
if handler(height, event) {
|
if handler(height, event) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -346,12 +346,12 @@ func (k Keeper) IterateValidatorSlashEventsBetween(ctx sdk.Context, val sdk.ValA
|
||||||
// iterate over all slash events
|
// iterate over all slash events
|
||||||
func (k Keeper) IterateValidatorSlashEvents(ctx sdk.Context, handler func(val sdk.ValAddress, height uint64, event types.ValidatorSlashEvent) (stop bool)) {
|
func (k Keeper) IterateValidatorSlashEvents(ctx sdk.Context, handler func(val sdk.ValAddress, height uint64, event types.ValidatorSlashEvent) (stop bool)) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, ValidatorSlashEventPrefix)
|
iter := sdk.KVStorePrefixIterator(store, types.ValidatorSlashEventPrefix)
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
var event types.ValidatorSlashEvent
|
var event types.ValidatorSlashEvent
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &event)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &event)
|
||||||
val, height := GetValidatorSlashEventAddressHeight(iter.Key())
|
val, height := types.GetValidatorSlashEventAddressHeight(iter.Key())
|
||||||
if handler(val, height, event) {
|
if handler(val, height, event) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,7 @@ func (k Keeper) IterateValidatorSlashEvents(ctx sdk.Context, handler func(val sd
|
||||||
// delete slash events for a particular validator
|
// delete slash events for a particular validator
|
||||||
func (k Keeper) DeleteValidatorSlashEvents(ctx sdk.Context, val sdk.ValAddress) {
|
func (k Keeper) DeleteValidatorSlashEvents(ctx sdk.Context, val sdk.ValAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, GetValidatorSlashEventPrefix(val))
|
iter := sdk.KVStorePrefixIterator(store, types.GetValidatorSlashEventPrefix(val))
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
store.Delete(iter.Key())
|
store.Delete(iter.Key())
|
||||||
|
@ -371,7 +371,7 @@ func (k Keeper) DeleteValidatorSlashEvents(ctx sdk.Context, val sdk.ValAddress)
|
||||||
// delete all slash events
|
// delete all slash events
|
||||||
func (k Keeper) DeleteAllValidatorSlashEvents(ctx sdk.Context) {
|
func (k Keeper) DeleteAllValidatorSlashEvents(ctx sdk.Context) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
iter := sdk.KVStorePrefixIterator(store, ValidatorSlashEventPrefix)
|
iter := sdk.KVStorePrefixIterator(store, types.ValidatorSlashEventPrefix)
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
store.Delete(iter.Key())
|
store.Delete(iter.Key())
|
||||||
|
|
|
@ -135,7 +135,7 @@ func CreateTestInputAdvanced(t *testing.T, isCheckTx bool, initPower int64,
|
||||||
sk := staking.NewKeeper(cdc, keyStaking, supplyKeeper, pk.Subspace(staking.DefaultParamspace))
|
sk := staking.NewKeeper(cdc, keyStaking, supplyKeeper, pk.Subspace(staking.DefaultParamspace))
|
||||||
sk.SetParams(ctx, staking.DefaultParams())
|
sk.SetParams(ctx, staking.DefaultParams())
|
||||||
|
|
||||||
keeper := NewKeeper(cdc, keyDistr, pk.Subspace(DefaultParamspace), sk, supplyKeeper, auth.FeeCollectorName, blacklistedAddrs)
|
keeper := NewKeeper(cdc, keyDistr, pk.Subspace(types.DefaultParamspace), sk, supplyKeeper, auth.FeeCollectorName, blacklistedAddrs)
|
||||||
|
|
||||||
initCoins := sdk.NewCoins(sdk.NewCoin(sk.BondDenom(ctx), initTokens))
|
initCoins := sdk.NewCoins(sdk.NewCoin(sk.BondDenom(ctx), initTokens))
|
||||||
totalSupply := sdk.NewCoins(sdk.NewCoin(sk.BondDenom(ctx), initTokens.MulRaw(int64(len(TestAddrs)))))
|
totalSupply := sdk.NewCoins(sdk.NewCoin(sk.BondDenom(ctx), initTokens.MulRaw(int64(len(TestAddrs)))))
|
||||||
|
@ -158,9 +158,12 @@ func CreateTestInputAdvanced(t *testing.T, isCheckTx bool, initPower int64,
|
||||||
|
|
||||||
// set genesis items required for distribution
|
// set genesis items required for distribution
|
||||||
keeper.SetFeePool(ctx, types.InitialFeePool())
|
keeper.SetFeePool(ctx, types.InitialFeePool())
|
||||||
keeper.SetCommunityTax(ctx, communityTax)
|
|
||||||
keeper.SetBaseProposerReward(ctx, sdk.NewDecWithPrec(1, 2))
|
params := types.DefaultParams()
|
||||||
keeper.SetBonusProposerReward(ctx, sdk.NewDecWithPrec(4, 2))
|
params.CommunityTax = communityTax
|
||||||
|
params.BaseProposerReward = sdk.NewDecWithPrec(1, 2)
|
||||||
|
params.BonusProposerReward = sdk.NewDecWithPrec(4, 2)
|
||||||
|
keeper.SetParams(ctx, params)
|
||||||
|
|
||||||
return ctx, accountKeeper, bankKeeper, keeper, sk, pk, supplyKeeper
|
return ctx, accountKeeper, bankKeeper, keeper, sk, pk, supplyKeeper
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package v0_38
|
||||||
|
|
||||||
|
// DONTCOVER
|
||||||
|
// nolint
|
||||||
|
|
||||||
|
import (
|
||||||
|
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_36"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Migrate accepts exported genesis state from v0.36 or v0.37 and migrates it to
|
||||||
|
// v0.38 genesis state. All entries are identical except for parameters.
|
||||||
|
func Migrate(oldGenState v036distr.GenesisState) GenesisState {
|
||||||
|
params := Params{
|
||||||
|
CommunityTax: oldGenState.CommunityTax,
|
||||||
|
BaseProposerReward: oldGenState.BaseProposerReward,
|
||||||
|
BonusProposerReward: oldGenState.BonusProposerReward,
|
||||||
|
WithdrawAddrEnabled: oldGenState.WithdrawAddrEnabled,
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewGenesisState(
|
||||||
|
params, oldGenState.FeePool,
|
||||||
|
oldGenState.DelegatorWithdrawInfos, oldGenState.PreviousProposer,
|
||||||
|
oldGenState.OutstandingRewards, oldGenState.ValidatorAccumulatedCommissions,
|
||||||
|
oldGenState.ValidatorHistoricalRewards, oldGenState.ValidatorCurrentRewards,
|
||||||
|
oldGenState.DelegatorStartingInfos, oldGenState.ValidatorSlashEvents,
|
||||||
|
)
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package v0_38
|
||||||
|
|
||||||
|
import (
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34"
|
||||||
|
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_36"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
GenesisState struct {
|
||||||
|
Params Params `json:"params" yaml:"params"`
|
||||||
|
FeePool v034distr.FeePool `json:"fee_pool"`
|
||||||
|
DelegatorWithdrawInfos []v034distr.DelegatorWithdrawInfo `json:"delegator_withdraw_infos"`
|
||||||
|
PreviousProposer sdk.ConsAddress `json:"previous_proposer" yaml:"previous_proposer"`
|
||||||
|
OutstandingRewards []v034distr.ValidatorOutstandingRewardsRecord `json:"outstanding_rewards"`
|
||||||
|
ValidatorAccumulatedCommissions []v034distr.ValidatorAccumulatedCommissionRecord `json:"validator_accumulated_commissions"`
|
||||||
|
ValidatorHistoricalRewards []v034distr.ValidatorHistoricalRewardsRecord `json:"validator_historical_rewards"`
|
||||||
|
ValidatorCurrentRewards []v034distr.ValidatorCurrentRewardsRecord `json:"validator_current_rewards"`
|
||||||
|
DelegatorStartingInfos []v034distr.DelegatorStartingInfoRecord `json:"delegator_starting_infos"`
|
||||||
|
ValidatorSlashEvents []v036distr.ValidatorSlashEventRecord `json:"validator_slash_events" yaml:"validator_slash_events"`
|
||||||
|
}
|
||||||
|
|
||||||
|
Params struct {
|
||||||
|
CommunityTax sdk.Dec `json:"community_tax" yaml:"community_tax"`
|
||||||
|
BaseProposerReward sdk.Dec `json:"base_proposer_reward" yaml:"base_proposer_reward"`
|
||||||
|
BonusProposerReward sdk.Dec `json:"bonus_proposer_reward" yaml:"bonus_proposer_reward"`
|
||||||
|
WithdrawAddrEnabled bool `json:"withdraw_addr_enabled" yaml:"withdraw_addr_enabled"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewGenesisState(
|
||||||
|
params Params, feePool v034distr.FeePool, dwis []v034distr.DelegatorWithdrawInfo, pp sdk.ConsAddress,
|
||||||
|
r []v034distr.ValidatorOutstandingRewardsRecord, acc []v034distr.ValidatorAccumulatedCommissionRecord,
|
||||||
|
historical []v034distr.ValidatorHistoricalRewardsRecord, cur []v034distr.ValidatorCurrentRewardsRecord,
|
||||||
|
dels []v034distr.DelegatorStartingInfoRecord, slashes []v036distr.ValidatorSlashEventRecord,
|
||||||
|
) GenesisState {
|
||||||
|
|
||||||
|
return GenesisState{
|
||||||
|
FeePool: feePool,
|
||||||
|
Params: params,
|
||||||
|
DelegatorWithdrawInfos: dwis,
|
||||||
|
PreviousProposer: pp,
|
||||||
|
OutstandingRewards: r,
|
||||||
|
ValidatorAccumulatedCommissions: acc,
|
||||||
|
ValidatorHistoricalRewards: historical,
|
||||||
|
ValidatorCurrentRewards: cur,
|
||||||
|
DelegatorStartingInfos: dels,
|
||||||
|
ValidatorSlashEvents: slashes,
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,56 +9,55 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DecodeStore unmarshals the KVPair's Value to the corresponding distribution type
|
// DecodeStore unmarshals the KVPair's Value to the corresponding distribution type
|
||||||
func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string {
|
func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string {
|
||||||
switch {
|
switch {
|
||||||
case bytes.Equal(kvA.Key[:1], keeper.FeePoolKey):
|
case bytes.Equal(kvA.Key[:1], types.FeePoolKey):
|
||||||
var feePoolA, feePoolB types.FeePool
|
var feePoolA, feePoolB types.FeePool
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &feePoolA)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &feePoolA)
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &feePoolB)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &feePoolB)
|
||||||
return fmt.Sprintf("%v\n%v", feePoolA, feePoolB)
|
return fmt.Sprintf("%v\n%v", feePoolA, feePoolB)
|
||||||
|
|
||||||
case bytes.Equal(kvA.Key[:1], keeper.ProposerKey):
|
case bytes.Equal(kvA.Key[:1], types.ProposerKey):
|
||||||
return fmt.Sprintf("%v\n%v", sdk.ConsAddress(kvA.Value), sdk.ConsAddress(kvB.Value))
|
return fmt.Sprintf("%v\n%v", sdk.ConsAddress(kvA.Value), sdk.ConsAddress(kvB.Value))
|
||||||
|
|
||||||
case bytes.Equal(kvA.Key[:1], keeper.ValidatorOutstandingRewardsPrefix):
|
case bytes.Equal(kvA.Key[:1], types.ValidatorOutstandingRewardsPrefix):
|
||||||
var rewardsA, rewardsB types.ValidatorOutstandingRewards
|
var rewardsA, rewardsB types.ValidatorOutstandingRewards
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &rewardsA)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &rewardsA)
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &rewardsB)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &rewardsB)
|
||||||
return fmt.Sprintf("%v\n%v", rewardsA, rewardsB)
|
return fmt.Sprintf("%v\n%v", rewardsA, rewardsB)
|
||||||
|
|
||||||
case bytes.Equal(kvA.Key[:1], keeper.DelegatorWithdrawAddrPrefix):
|
case bytes.Equal(kvA.Key[:1], types.DelegatorWithdrawAddrPrefix):
|
||||||
return fmt.Sprintf("%v\n%v", sdk.AccAddress(kvA.Value), sdk.AccAddress(kvB.Value))
|
return fmt.Sprintf("%v\n%v", sdk.AccAddress(kvA.Value), sdk.AccAddress(kvB.Value))
|
||||||
|
|
||||||
case bytes.Equal(kvA.Key[:1], keeper.DelegatorStartingInfoPrefix):
|
case bytes.Equal(kvA.Key[:1], types.DelegatorStartingInfoPrefix):
|
||||||
var infoA, infoB types.DelegatorStartingInfo
|
var infoA, infoB types.DelegatorStartingInfo
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &infoA)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &infoA)
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &infoB)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &infoB)
|
||||||
return fmt.Sprintf("%v\n%v", infoA, infoB)
|
return fmt.Sprintf("%v\n%v", infoA, infoB)
|
||||||
|
|
||||||
case bytes.Equal(kvA.Key[:1], keeper.ValidatorHistoricalRewardsPrefix):
|
case bytes.Equal(kvA.Key[:1], types.ValidatorHistoricalRewardsPrefix):
|
||||||
var rewardsA, rewardsB types.ValidatorHistoricalRewards
|
var rewardsA, rewardsB types.ValidatorHistoricalRewards
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &rewardsA)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &rewardsA)
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &rewardsB)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &rewardsB)
|
||||||
return fmt.Sprintf("%v\n%v", rewardsA, rewardsB)
|
return fmt.Sprintf("%v\n%v", rewardsA, rewardsB)
|
||||||
|
|
||||||
case bytes.Equal(kvA.Key[:1], keeper.ValidatorCurrentRewardsPrefix):
|
case bytes.Equal(kvA.Key[:1], types.ValidatorCurrentRewardsPrefix):
|
||||||
var rewardsA, rewardsB types.ValidatorCurrentRewards
|
var rewardsA, rewardsB types.ValidatorCurrentRewards
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &rewardsA)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &rewardsA)
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &rewardsB)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &rewardsB)
|
||||||
return fmt.Sprintf("%v\n%v", rewardsA, rewardsB)
|
return fmt.Sprintf("%v\n%v", rewardsA, rewardsB)
|
||||||
|
|
||||||
case bytes.Equal(kvA.Key[:1], keeper.ValidatorAccumulatedCommissionPrefix):
|
case bytes.Equal(kvA.Key[:1], types.ValidatorAccumulatedCommissionPrefix):
|
||||||
var commissionA, commissionB types.ValidatorAccumulatedCommission
|
var commissionA, commissionB types.ValidatorAccumulatedCommission
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &commissionA)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &commissionA)
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &commissionB)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &commissionB)
|
||||||
return fmt.Sprintf("%v\n%v", commissionA, commissionB)
|
return fmt.Sprintf("%v\n%v", commissionA, commissionB)
|
||||||
|
|
||||||
case bytes.Equal(kvA.Key[:1], keeper.ValidatorSlashEventPrefix):
|
case bytes.Equal(kvA.Key[:1], types.ValidatorSlashEventPrefix):
|
||||||
var eventA, eventB types.ValidatorSlashEvent
|
var eventA, eventB types.ValidatorSlashEvent
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &eventA)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &eventA)
|
||||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &eventB)
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &eventB)
|
||||||
|
|
|
@ -44,8 +44,8 @@ func TestDecodeDistributionStore(t *testing.T) {
|
||||||
slashEvent := types.NewValidatorSlashEvent(10, sdk.OneDec())
|
slashEvent := types.NewValidatorSlashEvent(10, sdk.OneDec())
|
||||||
|
|
||||||
kvPairs := cmn.KVPairs{
|
kvPairs := cmn.KVPairs{
|
||||||
cmn.KVPair{Key: keeper.FeePoolKey, Value: cdc.MustMarshalBinaryLengthPrefixed(feePool)},
|
cmn.KVPair{Key: types.FeePoolKey, Value: cdc.MustMarshalBinaryLengthPrefixed(feePool)},
|
||||||
cmn.KVPair{Key: keeper.ProposerKey, Value: consAddr1.Bytes()},
|
cmn.KVPair{Key: types.ProposerKey, Value: consAddr1.Bytes()},
|
||||||
cmn.KVPair{Key: keeper.GetValidatorOutstandingRewardsKey(valAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(outstanding)},
|
cmn.KVPair{Key: keeper.GetValidatorOutstandingRewardsKey(valAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(outstanding)},
|
||||||
cmn.KVPair{Key: keeper.GetDelegatorWithdrawAddrKey(delAddr1), Value: delAddr1.Bytes()},
|
cmn.KVPair{Key: keeper.GetDelegatorWithdrawAddrKey(delAddr1), Value: delAddr1.Bytes()},
|
||||||
cmn.KVPair{Key: keeper.GetDelegatorStartingInfoKey(valAddr1, delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(info)},
|
cmn.KVPair{Key: keeper.GetDelegatorStartingInfoKey(valAddr1, delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(info)},
|
||||||
|
|
|
@ -69,10 +69,12 @@ func RandomizedGenState(simState *module.SimulationState) {
|
||||||
|
|
||||||
distrGenesis := types.GenesisState{
|
distrGenesis := types.GenesisState{
|
||||||
FeePool: types.InitialFeePool(),
|
FeePool: types.InitialFeePool(),
|
||||||
|
Params: types.Params{
|
||||||
CommunityTax: communityTax,
|
CommunityTax: communityTax,
|
||||||
BaseProposerReward: baseProposerReward,
|
BaseProposerReward: baseProposerReward,
|
||||||
BonusProposerReward: bonusProposerReward,
|
BonusProposerReward: bonusProposerReward,
|
||||||
WithdrawAddrEnabled: withdrawEnabled,
|
WithdrawAddrEnabled: withdrawEnabled,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Selected randomly generated distribution parameters:\n%s\n", codec.MustMarshalJSONIndent(simState.Cdc, distrGenesis))
|
fmt.Printf("Selected randomly generated distribution parameters:\n%s\n", codec.MustMarshalJSONIndent(simState.Cdc, distrGenesis))
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,11 +53,8 @@ type ValidatorSlashEventRecord struct {
|
||||||
|
|
||||||
// GenesisState - all distribution state that must be provided at genesis
|
// GenesisState - all distribution state that must be provided at genesis
|
||||||
type GenesisState struct {
|
type GenesisState struct {
|
||||||
|
Params Params `json:"params" yaml:"params"`
|
||||||
FeePool FeePool `json:"fee_pool" yaml:"fee_pool"`
|
FeePool FeePool `json:"fee_pool" yaml:"fee_pool"`
|
||||||
CommunityTax sdk.Dec `json:"community_tax" yaml:"community_tax"`
|
|
||||||
BaseProposerReward sdk.Dec `json:"base_proposer_reward" yaml:"base_proposer_reward"`
|
|
||||||
BonusProposerReward sdk.Dec `json:"bonus_proposer_reward" yaml:"bonus_proposer_reward"`
|
|
||||||
WithdrawAddrEnabled bool `json:"withdraw_addr_enabled" yaml:"withdraw_addr_enabled"`
|
|
||||||
DelegatorWithdrawInfos []DelegatorWithdrawInfo `json:"delegator_withdraw_infos" yaml:"delegator_withdraw_infos"`
|
DelegatorWithdrawInfos []DelegatorWithdrawInfo `json:"delegator_withdraw_infos" yaml:"delegator_withdraw_infos"`
|
||||||
PreviousProposer sdk.ConsAddress `json:"previous_proposer" yaml:"previous_proposer"`
|
PreviousProposer sdk.ConsAddress `json:"previous_proposer" yaml:"previous_proposer"`
|
||||||
OutstandingRewards []ValidatorOutstandingRewardsRecord `json:"outstanding_rewards" yaml:"outstanding_rewards"`
|
OutstandingRewards []ValidatorOutstandingRewardsRecord `json:"outstanding_rewards" yaml:"outstanding_rewards"`
|
||||||
|
@ -70,18 +65,15 @@ type GenesisState struct {
|
||||||
ValidatorSlashEvents []ValidatorSlashEventRecord `json:"validator_slash_events" yaml:"validator_slash_events"`
|
ValidatorSlashEvents []ValidatorSlashEventRecord `json:"validator_slash_events" yaml:"validator_slash_events"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGenesisState(feePool FeePool, communityTax, baseProposerReward, bonusProposerReward sdk.Dec,
|
func NewGenesisState(
|
||||||
withdrawAddrEnabled bool, dwis []DelegatorWithdrawInfo, pp sdk.ConsAddress, r []ValidatorOutstandingRewardsRecord,
|
params Params, fp FeePool, dwis []DelegatorWithdrawInfo, pp sdk.ConsAddress, r []ValidatorOutstandingRewardsRecord,
|
||||||
acc []ValidatorAccumulatedCommissionRecord, historical []ValidatorHistoricalRewardsRecord,
|
acc []ValidatorAccumulatedCommissionRecord, historical []ValidatorHistoricalRewardsRecord,
|
||||||
cur []ValidatorCurrentRewardsRecord, dels []DelegatorStartingInfoRecord,
|
cur []ValidatorCurrentRewardsRecord, dels []DelegatorStartingInfoRecord, slashes []ValidatorSlashEventRecord,
|
||||||
slashes []ValidatorSlashEventRecord) GenesisState {
|
) GenesisState {
|
||||||
|
|
||||||
return GenesisState{
|
return GenesisState{
|
||||||
FeePool: feePool,
|
Params: params,
|
||||||
CommunityTax: communityTax,
|
FeePool: fp,
|
||||||
BaseProposerReward: baseProposerReward,
|
|
||||||
BonusProposerReward: bonusProposerReward,
|
|
||||||
WithdrawAddrEnabled: withdrawAddrEnabled,
|
|
||||||
DelegatorWithdrawInfos: dwis,
|
DelegatorWithdrawInfos: dwis,
|
||||||
PreviousProposer: pp,
|
PreviousProposer: pp,
|
||||||
OutstandingRewards: r,
|
OutstandingRewards: r,
|
||||||
|
@ -97,10 +89,7 @@ func NewGenesisState(feePool FeePool, communityTax, baseProposerReward, bonusPro
|
||||||
func DefaultGenesisState() GenesisState {
|
func DefaultGenesisState() GenesisState {
|
||||||
return GenesisState{
|
return GenesisState{
|
||||||
FeePool: InitialFeePool(),
|
FeePool: InitialFeePool(),
|
||||||
CommunityTax: sdk.NewDecWithPrec(2, 2), // 2%
|
Params: DefaultParams(),
|
||||||
BaseProposerReward: sdk.NewDecWithPrec(1, 2), // 1%
|
|
||||||
BonusProposerReward: sdk.NewDecWithPrec(4, 2), // 4%
|
|
||||||
WithdrawAddrEnabled: true,
|
|
||||||
DelegatorWithdrawInfos: []DelegatorWithdrawInfo{},
|
DelegatorWithdrawInfos: []DelegatorWithdrawInfo{},
|
||||||
PreviousProposer: nil,
|
PreviousProposer: nil,
|
||||||
OutstandingRewards: []ValidatorOutstandingRewardsRecord{},
|
OutstandingRewards: []ValidatorOutstandingRewardsRecord{},
|
||||||
|
@ -113,24 +102,9 @@ func DefaultGenesisState() GenesisState {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateGenesis validates the genesis state of distribution genesis input
|
// ValidateGenesis validates the genesis state of distribution genesis input
|
||||||
func ValidateGenesis(data GenesisState) error {
|
func ValidateGenesis(gs GenesisState) error {
|
||||||
if data.CommunityTax.IsNegative() || data.CommunityTax.GT(sdk.OneDec()) {
|
if err := gs.Params.ValidateBasic(); err != nil {
|
||||||
return fmt.Errorf("mint parameter CommunityTax should non-negative and "+
|
return err
|
||||||
"less than one, is %s", data.CommunityTax.String())
|
|
||||||
}
|
}
|
||||||
if data.BaseProposerReward.IsNegative() {
|
return gs.FeePool.ValidateGenesis()
|
||||||
return fmt.Errorf("mint parameter BaseProposerReward should be positive, is %s",
|
|
||||||
data.BaseProposerReward.String())
|
|
||||||
}
|
|
||||||
if data.BonusProposerReward.IsNegative() {
|
|
||||||
return fmt.Errorf("mint parameter BonusProposerReward should be positive, is %s",
|
|
||||||
data.BonusProposerReward.String())
|
|
||||||
}
|
|
||||||
if (data.BaseProposerReward.Add(data.BonusProposerReward)).
|
|
||||||
GT(sdk.OneDec()) {
|
|
||||||
return fmt.Errorf("mint parameters BaseProposerReward and "+
|
|
||||||
"BonusProposerReward cannot add to be greater than one, "+
|
|
||||||
"adds to %s", data.BaseProposerReward.Add(data.BonusProposerReward).String())
|
|
||||||
}
|
|
||||||
return data.FeePool.ValidateGenesis()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ModuleName is the module name constant used in many places
|
// ModuleName is the module name constant used in many places
|
||||||
ModuleName = "distribution"
|
ModuleName = "distribution"
|
||||||
|
@ -13,3 +19,175 @@ const (
|
||||||
// QuerierRoute is the querier route for distribution
|
// QuerierRoute is the querier route for distribution
|
||||||
QuerierRoute = ModuleName
|
QuerierRoute = ModuleName
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Keys for distribution store
|
||||||
|
// Items are stored with the following key: values
|
||||||
|
//
|
||||||
|
// - 0x00<proposalID_Bytes>: FeePol
|
||||||
|
//
|
||||||
|
// - 0x01: sdk.ConsAddress
|
||||||
|
//
|
||||||
|
// - 0x02<valAddr_Bytes>: ValidatorOutstandingRewards
|
||||||
|
//
|
||||||
|
// - 0x03<accAddr_Bytes>: sdk.AccAddress
|
||||||
|
//
|
||||||
|
// - 0x04<valAddr_Bytes><accAddr_Bytes>: DelegatorStartingInfo
|
||||||
|
//
|
||||||
|
// - 0x05<valAddr_Bytes><period_Bytes>: ValidatorHistoricalRewards
|
||||||
|
//
|
||||||
|
// - 0x06<valAddr_Bytes>: ValidatorCurrentRewards
|
||||||
|
//
|
||||||
|
// - 0x07<valAddr_Bytes>: ValidatorCurrentRewards
|
||||||
|
//
|
||||||
|
// - 0x08<valAddr_Bytes><height>: ValidatorSlashEvent
|
||||||
|
var (
|
||||||
|
FeePoolKey = []byte{0x00} // key for global distribution state
|
||||||
|
ProposerKey = []byte{0x01} // key for the proposer operator address
|
||||||
|
ValidatorOutstandingRewardsPrefix = []byte{0x02} // key for outstanding rewards
|
||||||
|
|
||||||
|
DelegatorWithdrawAddrPrefix = []byte{0x03} // key for delegator withdraw address
|
||||||
|
DelegatorStartingInfoPrefix = []byte{0x04} // key for delegator starting info
|
||||||
|
ValidatorHistoricalRewardsPrefix = []byte{0x05} // key for historical validators rewards / stake
|
||||||
|
ValidatorCurrentRewardsPrefix = []byte{0x06} // key for current validator rewards
|
||||||
|
ValidatorAccumulatedCommissionPrefix = []byte{0x07} // key for accumulated validator commission
|
||||||
|
ValidatorSlashEventPrefix = []byte{0x08} // key for validator slash fraction
|
||||||
|
)
|
||||||
|
|
||||||
|
// gets an address from a validator's outstanding rewards key
|
||||||
|
func GetValidatorOutstandingRewardsAddress(key []byte) (valAddr sdk.ValAddress) {
|
||||||
|
addr := key[1:]
|
||||||
|
if len(addr) != sdk.AddrLen {
|
||||||
|
panic("unexpected key length")
|
||||||
|
}
|
||||||
|
return sdk.ValAddress(addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets an address from a delegator's withdraw info key
|
||||||
|
func GetDelegatorWithdrawInfoAddress(key []byte) (delAddr sdk.AccAddress) {
|
||||||
|
addr := key[1:]
|
||||||
|
if len(addr) != sdk.AddrLen {
|
||||||
|
panic("unexpected key length")
|
||||||
|
}
|
||||||
|
return sdk.AccAddress(addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the addresses from a delegator starting info key
|
||||||
|
func GetDelegatorStartingInfoAddresses(key []byte) (valAddr sdk.ValAddress, delAddr sdk.AccAddress) {
|
||||||
|
addr := key[1 : 1+sdk.AddrLen]
|
||||||
|
if len(addr) != sdk.AddrLen {
|
||||||
|
panic("unexpected key length")
|
||||||
|
}
|
||||||
|
valAddr = sdk.ValAddress(addr)
|
||||||
|
addr = key[1+sdk.AddrLen:]
|
||||||
|
if len(addr) != sdk.AddrLen {
|
||||||
|
panic("unexpected key length")
|
||||||
|
}
|
||||||
|
delAddr = sdk.AccAddress(addr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the address & period from a validator's historical rewards key
|
||||||
|
func GetValidatorHistoricalRewardsAddressPeriod(key []byte) (valAddr sdk.ValAddress, period uint64) {
|
||||||
|
addr := key[1 : 1+sdk.AddrLen]
|
||||||
|
if len(addr) != sdk.AddrLen {
|
||||||
|
panic("unexpected key length")
|
||||||
|
}
|
||||||
|
valAddr = sdk.ValAddress(addr)
|
||||||
|
b := key[1+sdk.AddrLen:]
|
||||||
|
if len(b) != 8 {
|
||||||
|
panic("unexpected key length")
|
||||||
|
}
|
||||||
|
period = binary.LittleEndian.Uint64(b)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the address from a validator's current rewards key
|
||||||
|
func GetValidatorCurrentRewardsAddress(key []byte) (valAddr sdk.ValAddress) {
|
||||||
|
addr := key[1:]
|
||||||
|
if len(addr) != sdk.AddrLen {
|
||||||
|
panic("unexpected key length")
|
||||||
|
}
|
||||||
|
return sdk.ValAddress(addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the address from a validator's accumulated commission key
|
||||||
|
func GetValidatorAccumulatedCommissionAddress(key []byte) (valAddr sdk.ValAddress) {
|
||||||
|
addr := key[1:]
|
||||||
|
if len(addr) != sdk.AddrLen {
|
||||||
|
panic("unexpected key length")
|
||||||
|
}
|
||||||
|
return sdk.ValAddress(addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the height from a validator's slash event key
|
||||||
|
func GetValidatorSlashEventAddressHeight(key []byte) (valAddr sdk.ValAddress, height uint64) {
|
||||||
|
addr := key[1 : 1+sdk.AddrLen]
|
||||||
|
if len(addr) != sdk.AddrLen {
|
||||||
|
panic("unexpected key length")
|
||||||
|
}
|
||||||
|
valAddr = sdk.ValAddress(addr)
|
||||||
|
startB := 1 + sdk.AddrLen
|
||||||
|
b := key[startB : startB+8] // the next 8 bytes represent the height
|
||||||
|
height = binary.BigEndian.Uint64(b)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the outstanding rewards key for a validator
|
||||||
|
func GetValidatorOutstandingRewardsKey(valAddr sdk.ValAddress) []byte {
|
||||||
|
return append(ValidatorOutstandingRewardsPrefix, valAddr.Bytes()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the key for a delegator's withdraw addr
|
||||||
|
func GetDelegatorWithdrawAddrKey(delAddr sdk.AccAddress) []byte {
|
||||||
|
return append(DelegatorWithdrawAddrPrefix, delAddr.Bytes()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the key for a delegator's starting info
|
||||||
|
func GetDelegatorStartingInfoKey(v sdk.ValAddress, d sdk.AccAddress) []byte {
|
||||||
|
return append(append(DelegatorStartingInfoPrefix, v.Bytes()...), d.Bytes()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the prefix key for a validator's historical rewards
|
||||||
|
func GetValidatorHistoricalRewardsPrefix(v sdk.ValAddress) []byte {
|
||||||
|
return append(ValidatorHistoricalRewardsPrefix, v.Bytes()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the key for a validator's historical rewards
|
||||||
|
func GetValidatorHistoricalRewardsKey(v sdk.ValAddress, k uint64) []byte {
|
||||||
|
b := make([]byte, 8)
|
||||||
|
binary.LittleEndian.PutUint64(b, k)
|
||||||
|
return append(append(ValidatorHistoricalRewardsPrefix, v.Bytes()...), b...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the key for a validator's current rewards
|
||||||
|
func GetValidatorCurrentRewardsKey(v sdk.ValAddress) []byte {
|
||||||
|
return append(ValidatorCurrentRewardsPrefix, v.Bytes()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the key for a validator's current commission
|
||||||
|
func GetValidatorAccumulatedCommissionKey(v sdk.ValAddress) []byte {
|
||||||
|
return append(ValidatorAccumulatedCommissionPrefix, v.Bytes()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the prefix key for a validator's slash fractions
|
||||||
|
func GetValidatorSlashEventPrefix(v sdk.ValAddress) []byte {
|
||||||
|
return append(ValidatorSlashEventPrefix, v.Bytes()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the prefix key for a validator's slash fraction (ValidatorSlashEventPrefix + height)
|
||||||
|
func GetValidatorSlashEventKeyPrefix(v sdk.ValAddress, height uint64) []byte {
|
||||||
|
heightBz := make([]byte, 8)
|
||||||
|
binary.BigEndian.PutUint64(heightBz, height)
|
||||||
|
return append(
|
||||||
|
ValidatorSlashEventPrefix,
|
||||||
|
append(v.Bytes(), heightBz...)...,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gets the key for a validator's slash fraction
|
||||||
|
func GetValidatorSlashEventKey(v sdk.ValAddress, height, period uint64) []byte {
|
||||||
|
periodBz := make([]byte, 8)
|
||||||
|
binary.BigEndian.PutUint64(periodBz, period)
|
||||||
|
prefix := GetValidatorSlashEventKeyPrefix(v, height)
|
||||||
|
return append(prefix, periodBz...)
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,143 @@
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/params"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// default paramspace for params keeper
|
||||||
|
DefaultParamspace = ModuleName
|
||||||
|
)
|
||||||
|
|
||||||
|
// Parameter keys
|
||||||
|
var (
|
||||||
|
ParamStoreKeyCommunityTax = []byte("communitytax")
|
||||||
|
ParamStoreKeyBaseProposerReward = []byte("baseproposerreward")
|
||||||
|
ParamStoreKeyBonusProposerReward = []byte("bonusproposerreward")
|
||||||
|
ParamStoreKeyWithdrawAddrEnabled = []byte("withdrawaddrenabled")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Params defines the set of distribution parameters.
|
||||||
|
type Params struct {
|
||||||
|
CommunityTax sdk.Dec `json:"community_tax" yaml:"community_tax"`
|
||||||
|
BaseProposerReward sdk.Dec `json:"base_proposer_reward" yaml:"base_proposer_reward"`
|
||||||
|
BonusProposerReward sdk.Dec `json:"bonus_proposer_reward" yaml:"bonus_proposer_reward"`
|
||||||
|
WithdrawAddrEnabled bool `json:"withdraw_addr_enabled" yaml:"withdraw_addr_enabled"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParamKeyTable returns the parameter key table.
|
||||||
|
func ParamKeyTable() params.KeyTable {
|
||||||
|
return params.NewKeyTable().RegisterParamSet(&Params{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultParams returns default distribution parameters
|
||||||
|
func DefaultParams() Params {
|
||||||
|
return Params{
|
||||||
|
CommunityTax: sdk.NewDecWithPrec(2, 2), // 2%
|
||||||
|
BaseProposerReward: sdk.NewDecWithPrec(1, 2), // 1%
|
||||||
|
BonusProposerReward: sdk.NewDecWithPrec(4, 2), // 4%
|
||||||
|
WithdrawAddrEnabled: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) String() string {
|
||||||
|
out, _ := yaml.Marshal(p)
|
||||||
|
return string(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParamSetPairs returns the parameter set pairs.
|
||||||
|
func (p *Params) ParamSetPairs() params.ParamSetPairs {
|
||||||
|
return params.ParamSetPairs{
|
||||||
|
params.NewParamSetPair(ParamStoreKeyCommunityTax, &p.CommunityTax, validateCommunityTax),
|
||||||
|
params.NewParamSetPair(ParamStoreKeyBaseProposerReward, &p.BaseProposerReward, validateBaseProposerReward),
|
||||||
|
params.NewParamSetPair(ParamStoreKeyBonusProposerReward, &p.BonusProposerReward, validateBonusProposerReward),
|
||||||
|
params.NewParamSetPair(ParamStoreKeyWithdrawAddrEnabled, &p.WithdrawAddrEnabled, validateWithdrawAddrEnabled),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidateBasic performs basic validation on distribution parameters.
|
||||||
|
func (p Params) ValidateBasic() error {
|
||||||
|
if p.CommunityTax.IsNegative() || p.CommunityTax.GT(sdk.OneDec()) {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"community tax should non-negative and less than one: %s", p.CommunityTax,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if p.BaseProposerReward.IsNegative() {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"base proposer reward should be positive: %s", p.BaseProposerReward,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if p.BonusProposerReward.IsNegative() {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"bonus proposer reward should be positive: %s", p.BonusProposerReward,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if v := p.BaseProposerReward.Add(p.BonusProposerReward); v.GT(sdk.OneDec()) {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"sum of base and bonus proposer reward cannot greater than one: %s", v,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateCommunityTax(i interface{}) error {
|
||||||
|
v, ok := i.(sdk.Dec)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("invalid parameter type: %T", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.IsNegative() {
|
||||||
|
return fmt.Errorf("community tax must be positive: %s", v)
|
||||||
|
}
|
||||||
|
if v.GT(sdk.OneDec()) {
|
||||||
|
return fmt.Errorf("community tax too large: %s", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateBaseProposerReward(i interface{}) error {
|
||||||
|
v, ok := i.(sdk.Dec)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("invalid parameter type: %T", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.IsNegative() {
|
||||||
|
return fmt.Errorf("base proposer reward must be positive: %s", v)
|
||||||
|
}
|
||||||
|
if v.GT(sdk.OneDec()) {
|
||||||
|
return fmt.Errorf("base proposer reward too large: %s", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateBonusProposerReward(i interface{}) error {
|
||||||
|
v, ok := i.(sdk.Dec)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("invalid parameter type: %T", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.IsNegative() {
|
||||||
|
return fmt.Errorf("bonus proposer reward must be positive: %s", v)
|
||||||
|
}
|
||||||
|
if v.GT(sdk.OneDec()) {
|
||||||
|
return fmt.Errorf("bonus proposer reward too large: %s", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateWithdrawAddrEnabled(i interface{}) error {
|
||||||
|
_, ok := i.(bool)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("invalid parameter type: %T", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -13,11 +13,6 @@ const (
|
||||||
QueryDelegatorValidators = "delegator_validators"
|
QueryDelegatorValidators = "delegator_validators"
|
||||||
QueryWithdrawAddr = "withdraw_addr"
|
QueryWithdrawAddr = "withdraw_addr"
|
||||||
QueryCommunityPool = "community_pool"
|
QueryCommunityPool = "community_pool"
|
||||||
|
|
||||||
ParamCommunityTax = "community_tax"
|
|
||||||
ParamBaseProposerReward = "base_proposer_reward"
|
|
||||||
ParamBonusProposerReward = "bonus_proposer_reward"
|
|
||||||
ParamWithdrawAddrEnabled = "withdraw_addr_enabled"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// params for query 'custom/distr/validator_outstanding_rewards'
|
// params for query 'custom/distr/validator_outstanding_rewards'
|
||||||
|
|
|
@ -36,14 +36,9 @@ func ParamKeyTable() params.KeyTable {
|
||||||
return params.NewKeyTable().RegisterParamSet(&Params{})
|
return params.NewKeyTable().RegisterParamSet(&Params{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Params) MarshalYAML() (interface{}, error) {
|
|
||||||
bz, err := yaml.Marshal(p)
|
|
||||||
return string(bz), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p Params) String() string {
|
func (p Params) String() string {
|
||||||
out, _ := p.MarshalYAML()
|
out, _ := yaml.Marshal(p)
|
||||||
return out.(string)
|
return string(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParamSetPairs returns the parameter set pairs.
|
// ParamSetPairs returns the parameter set pairs.
|
||||||
|
|
Loading…
Reference in New Issue