chore(x/staking): audit changes (#16795)

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
atheeshp 2023-07-03 12:44:17 +05:30 committed by GitHub
parent 9863cb88a4
commit 9b237c7189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 86 additions and 123 deletions

View File

@ -62,6 +62,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
* remove `Keeper`: `IterateValidatorOutstandingRewards`, `GetValidatorOutstandingRewards`, `SetValidatorOutstandingRewards`, `DeleteValidatorOutstandingRewards`
* (x/distribution) [#16607](https://github.com/cosmos/cosmos-sdk/pull/16607) use collections for `ValidatorHistoricalRewards` state management:
* remove `Keeper`: `IterateValidatorHistoricalRewards`, `GetValidatorHistoricalRewards`, `SetValidatorHistoricalRewards`, `DeleteValidatorHistoricalRewards`, `DeleteValidatorHistoricalReward`, `DeleteAllValidatorHistoricalRewards`
* (x/auth) [#16621](https://github.com/cosmos/cosmos-sdk/pull/16621), [#16768](https://github.com/cosmos/cosmos-sdk/pull/16768) Pass address codecs to auth new keeper constructor.
* (x/auth/vesting) [#16741](https://github.com/cosmos/cosmos-sdk/pull/16741) Vesting account constructor now return an error with the result of their validate function.
* (x/staking) [#16795](https://github.com/cosmos/cosmos-sdk/pull/16795) `DelegationToDelegationResponse`, `DelegationsToDelegationResponses`, `RedelegationsToRedelegationResponses` are no longer exported.
## [v0.50.0-alpha.1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0-alpha.1) - 2023-06-30

View File

@ -1763,7 +1763,8 @@ type GenesisState struct {
UnbondingDelegations []*UnbondingDelegation `protobuf:"bytes,6,rep,name=unbonding_delegations,json=unbondingDelegations,proto3" json:"unbonding_delegations,omitempty"`
// redelegations defines the redelegations active at genesis.
Redelegations []*Redelegation `protobuf:"bytes,7,rep,name=redelegations,proto3" json:"redelegations,omitempty"`
Exported bool `protobuf:"varint,8,opt,name=exported,proto3" json:"exported,omitempty"`
// exported defines a bool to identify whether the chain dealing with exported or initialized genesis.
Exported bool `protobuf:"varint,8,opt,name=exported,proto3" json:"exported,omitempty"`
}
func (x *GenesisState) Reset() {

View File

@ -37,6 +37,7 @@ message GenesisState {
// redelegations defines the redelegations active at genesis.
repeated Redelegation redelegations = 7 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
// exported defines a bool to identify whether the chain dealing with exported or initialized genesis.
bool exported = 8;
}

View File

@ -134,13 +134,13 @@ $ %s query staking validators
return cmd
}
// GetCmdQueryValidatorUnbondingDelegations implements the query all unbonding delegatations from a validator command.
// GetCmdQueryValidatorUnbondingDelegations implements the query all unbonding delegations from a validator command.
func GetCmdQueryValidatorUnbondingDelegations() *cobra.Command {
bech32PrefixValAddr := sdk.GetConfig().GetBech32ValidatorAddrPrefix()
cmd := &cobra.Command{
Use: "unbonding-delegations-from [validator-addr]",
Short: "Query all unbonding delegatations from a validator",
Short: "Query all unbonding delegations from a validator",
Long: strings.TrimSpace(
fmt.Sprintf(`Query delegations that are unbonding _from_ a validator.
@ -188,14 +188,14 @@ $ %s query staking unbonding-delegations-from %s1gghjut3ccd8ay0zduzj64hwre2fxs9l
return cmd
}
// GetCmdQueryValidatorRedelegations implements the query all redelegatations
// GetCmdQueryValidatorRedelegations implements the query all redelegations
// from a validator command.
func GetCmdQueryValidatorRedelegations() *cobra.Command {
bech32PrefixValAddr := sdk.GetConfig().GetBech32ValidatorAddrPrefix()
cmd := &cobra.Command{
Use: "redelegations-from [validator-addr]",
Short: "Query all outgoing redelegatations from a validator",
Short: "Query all outgoing redelegations from a validator",
Long: strings.TrimSpace(
fmt.Sprintf(`Query delegations that are redelegating _from_ a validator.

View File

@ -17,7 +17,7 @@ func (k *Keeper) BeginBlocker(ctx context.Context) error {
return k.TrackHistoricalInfo(ctx)
}
// Called every block, update validator set
// EndBlocker called at every block, update validator set
func (k *Keeper) EndBlocker(ctx context.Context) ([]abci.ValidatorUpdate, error) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
return k.BlockValidatorUpdates(ctx)

View File

@ -11,7 +11,7 @@ import (
// Validator Set
// iterate through the validator set and perform the provided function
// IterateValidators iterates through the validator set and perform the provided function
func (k Keeper) IterateValidators(ctx context.Context, fn func(index int64, validator types.ValidatorI) (stop bool)) error {
store := k.storeService.OpenKVStore(ctx)
iterator, err := store.Iterator(types.ValidatorsKey, storetypes.PrefixEndBytes(types.ValidatorsKey))
@ -38,7 +38,7 @@ func (k Keeper) IterateValidators(ctx context.Context, fn func(index int64, vali
return nil
}
// iterate through the bonded validator set and perform the provided function
// IterateBondedValidatorsByPower iterates through the bonded validator set and perform the provided function
func (k Keeper) IterateBondedValidatorsByPower(ctx context.Context, fn func(index int64, validator types.ValidatorI) (stop bool)) error {
store := k.storeService.OpenKVStore(ctx)
maxValidators, err := k.MaxValidators(ctx)
@ -69,7 +69,7 @@ func (k Keeper) IterateBondedValidatorsByPower(ctx context.Context, fn func(inde
return nil
}
// iterate through the active validator set and perform the provided function
// IterateLastValidators iterates through the active validator set and perform the provided function
func (k Keeper) IterateLastValidators(ctx context.Context, fn func(index int64, validator types.ValidatorI) (stop bool)) error {
iterator, err := k.LastValidatorsIterator(ctx)
if err != nil {
@ -108,12 +108,12 @@ func (k Keeper) ValidatorByConsAddr(ctx context.Context, addr sdk.ConsAddress) (
// Delegation Set
// Returns self as it is both a validatorset and delegationset
// GetValidatorSet returns self as it is both a validatorset and delegationset
func (k Keeper) GetValidatorSet() types.ValidatorSet {
return k
}
// Delegation get the delegation interface for a particular set of delegator and validator addresses
// Delegation gets the delegation interface for a particular set of delegator and validator addresses
func (k Keeper) Delegation(ctx context.Context, addrDel sdk.AccAddress, addrVal sdk.ValAddress) (types.DelegationI, error) {
bond, err := k.GetDelegation(ctx, addrDel, addrVal)
if err != nil {
@ -123,7 +123,7 @@ func (k Keeper) Delegation(ctx context.Context, addrDel sdk.AccAddress, addrVal
return bond, nil
}
// iterate through all of the delegations from a delegator
// IterateDelegations iterates through all of the delegations from a delegator
func (k Keeper) IterateDelegations(ctx context.Context, delAddr sdk.AccAddress,
fn func(index int64, del types.DelegationI) (stop bool),
) error {
@ -151,7 +151,7 @@ func (k Keeper) IterateDelegations(ctx context.Context, delAddr sdk.AccAddress,
return nil
}
// return all delegations used during genesis dump
// GetAllSDKDelegations returns all delegations used during genesis dump
// TODO: remove this func, change all usage for iterate functionality
func (k Keeper) GetAllSDKDelegations(ctx context.Context) (delegations []types.Delegation, err error) {
store := k.storeService.OpenKVStore(ctx)

View File

@ -352,7 +352,7 @@ func (k Keeper) IterateDelegatorRedelegations(ctx context.Context, delegator sdk
return nil
}
// HasMaxUnbondingDelegationEntries - check if unbonding delegation has maximum number of entries.
// HasMaxUnbondingDelegationEntries checks if unbonding delegation has maximum number of entries.
func (k Keeper) HasMaxUnbondingDelegationEntries(ctx context.Context, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) (bool, error) {
ubd, err := k.GetUnbondingDelegation(ctx, delegatorAddr, validatorAddr)
if err != nil && !errors.Is(err, types.ErrNoUnbondingDelegation) {
@ -616,7 +616,7 @@ func (k Keeper) HasReceivingRedelegation(ctx context.Context, delAddr sdk.AccAdd
return iterator.Valid(), nil
}
// HasMaxRedelegationEntries checks if redelegation has maximum number of entries.
// HasMaxRedelegationEntries checks if the redelegation entries reached maximum limit.
func (k Keeper) HasMaxRedelegationEntries(ctx context.Context, delegatorAddr sdk.AccAddress, validatorSrcAddr, validatorDstAddr sdk.ValAddress) (bool, error) {
red, err := k.GetRedelegation(ctx, delegatorAddr, validatorSrcAddr, validatorDstAddr)
if err != nil {
@ -634,7 +634,7 @@ func (k Keeper) HasMaxRedelegationEntries(ctx context.Context, delegatorAddr sdk
return len(red.Entries) >= int(maxEntries), nil
}
// SetRedelegation set a redelegation and associated index.
// SetRedelegation sets a redelegation and associated index.
func (k Keeper) SetRedelegation(ctx context.Context, red types.Redelegation) error {
delegatorAddress, err := k.authKeeper.AddressCodec().StringToBytes(red.DelegatorAddress)
if err != nil {
@ -1319,7 +1319,7 @@ func (k Keeper) CompleteRedelegation(
}
// ValidateUnbondAmount validates that a given unbond or redelegation amount is
// valied based on upon the converted shares. If the amount is valid, the total
// valid based on upon the converted shares. If the amount is valid, the total
// amount of respective shares is returned, otherwise an error is returned.
func (k Keeper) ValidateUnbondAmount(
ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amt math.Int,

View File

@ -133,7 +133,7 @@ func (k Querier) ValidatorDelegations(ctx context.Context, req *types.QueryValid
pageRes = pageResponse
}
delResponses, err := DelegationsToDelegationResponses(ctx, k.Keeper, dels)
delResponses, err := delegationsToDelegationResponses(ctx, k.Keeper, dels)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@ -234,7 +234,7 @@ func (k Querier) Delegation(ctx context.Context, req *types.QueryDelegationReque
req.DelegatorAddr, req.ValidatorAddr)
}
delResponse, err := DelegationToDelegationResponse(ctx, k.Keeper, delegation)
delResponse, err := delegationToDelegationResponse(ctx, k.Keeper, delegation)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@ -242,7 +242,7 @@ func (k Querier) Delegation(ctx context.Context, req *types.QueryDelegationReque
return &types.QueryDelegationResponse{DelegationResponse: &delResponse}, nil
}
// UnbondingDelegation queries unbonding info for give validator delegator pair
// UnbondingDelegation queries unbonding info for given validator delegator pair
func (k Querier) UnbondingDelegation(ctx context.Context, req *types.QueryUnbondingDelegationRequest) (*types.QueryUnbondingDelegationResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
@ -276,7 +276,7 @@ func (k Querier) UnbondingDelegation(ctx context.Context, req *types.QueryUnbond
return &types.QueryUnbondingDelegationResponse{Unbond: unbond}, nil
}
// DelegatorDelegations queries all delegations of a give delegator address
// DelegatorDelegations queries all delegations of a given delegator address
func (k Querier) DelegatorDelegations(ctx context.Context, req *types.QueryDelegatorDelegationsRequest) (*types.QueryDelegatorDelegationsResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
@ -306,7 +306,7 @@ func (k Querier) DelegatorDelegations(ctx context.Context, req *types.QueryDeleg
return nil, status.Error(codes.Internal, err.Error())
}
delegationResps, err := DelegationsToDelegationResponses(ctx, k.Keeper, delegations)
delegationResps, err := delegationsToDelegationResponses(ctx, k.Keeper, delegations)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@ -420,7 +420,7 @@ func (k Querier) Redelegations(ctx context.Context, req *types.QueryRedelegation
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
redelResponses, err := RedelegationsToRedelegationResponses(ctx, k.Keeper, redels)
redelResponses, err := redelegationsToRedelegationResponses(ctx, k.Keeper, redels)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@ -564,7 +564,7 @@ func queryAllRedelegations(store storetypes.KVStore, k Querier, req *types.Query
// util
func DelegationToDelegationResponse(ctx context.Context, k *Keeper, del types.Delegation) (types.DelegationResponse, error) {
func delegationToDelegationResponse(ctx context.Context, k *Keeper, del types.Delegation) (types.DelegationResponse, error) {
val, err := k.GetValidator(ctx, del.GetValidatorAddr())
if err != nil {
return types.DelegationResponse{}, err
@ -588,11 +588,11 @@ func DelegationToDelegationResponse(ctx context.Context, k *Keeper, del types.De
), nil
}
func DelegationsToDelegationResponses(ctx context.Context, k *Keeper, delegations types.Delegations) (types.DelegationResponses, error) {
func delegationsToDelegationResponses(ctx context.Context, k *Keeper, delegations types.Delegations) (types.DelegationResponses, error) {
resp := make(types.DelegationResponses, len(delegations))
for i, del := range delegations {
delResp, err := DelegationToDelegationResponse(ctx, k, del)
delResp, err := delegationToDelegationResponse(ctx, k, del)
if err != nil {
return nil, err
}
@ -603,7 +603,7 @@ func DelegationsToDelegationResponses(ctx context.Context, k *Keeper, delegation
return resp, nil
}
func RedelegationsToRedelegationResponses(ctx context.Context, k *Keeper, redels types.Redelegations) (types.RedelegationResponses, error) {
func redelegationsToRedelegationResponses(ctx context.Context, k *Keeper, redels types.Redelegations) (types.RedelegationResponses, error) {
resp := make(types.RedelegationResponses, len(redels))
for i, redel := range redels {

View File

@ -46,11 +46,9 @@ func (k Keeper) DeleteHistoricalInfo(ctx context.Context, height int64) error {
return store.Delete(key)
}
// IterateHistoricalInfo provides an interator over all stored HistoricalInfo
//
// objects. For each HistoricalInfo object, cb will be called. If the cb returns
//
// true, the iterator will close and stop.
// IterateHistoricalInfo provides an iterator over all stored HistoricalInfo
// objects. For each HistoricalInfo object, cb will be called. If the cb returns
// true, the iterator will break and close.
func (k Keeper) IterateHistoricalInfo(ctx context.Context, cb func(types.HistoricalInfo) bool) error {
store := k.storeService.OpenKVStore(ctx)
iterator, err := store.Iterator(types.HistoricalInfoKey, storetypes.PrefixEndBytes(types.HistoricalInfoKey))

View File

@ -79,7 +79,7 @@ func (k *Keeper) Hooks() types.StakingHooks {
return k.hooks
}
// SetHooks Set the validator hooks. In contrast to other receivers, this method must take a pointer due to nature
// SetHooks sets the validator hooks. In contrast to other receivers, this method must take a pointer due to nature
// of the hooks interface and SDK start up sequence.
func (k *Keeper) SetHooks(sh types.StakingHooks) {
if k.hooks != nil {
@ -89,7 +89,7 @@ func (k *Keeper) SetHooks(sh types.StakingHooks) {
k.hooks = sh
}
// GetLastTotalPower Load the last total validator power.
// GetLastTotalPower loads the last total validator power.
func (k Keeper) GetLastTotalPower(ctx context.Context) (math.Int, error) {
store := k.storeService.OpenKVStore(ctx)
bz, err := store.Get(types.LastTotalPowerKey)
@ -110,7 +110,7 @@ func (k Keeper) GetLastTotalPower(ctx context.Context) (math.Int, error) {
return ip.Int, nil
}
// SetLastTotalPower Set the last total validator power.
// SetLastTotalPower sets the last total validator power.
func (k Keeper) SetLastTotalPower(ctx context.Context, power math.Int) error {
store := k.storeService.OpenKVStore(ctx)
bz, err := k.cdc.Marshal(&sdk.IntProto{Int: power})

View File

@ -16,7 +16,7 @@ type Migrator struct {
legacySubspace exported.Subspace
}
// NewMigrator returns a new Migrator.
// NewMigrator returns a new Migrator instance.
func NewMigrator(keeper *Keeper, legacySubspace exported.Subspace) Migrator {
return Migrator{
keeper: keeper,

View File

@ -23,7 +23,7 @@ type msgServer struct {
*Keeper
}
// NewMsgServerImpl returns an implementation of the bank MsgServer interface
// NewMsgServerImpl returns an implementation of the staking MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper *Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
@ -301,7 +301,7 @@ func (k msgServer) Delegate(ctx context.Context, msg *types.MsgDelegate) (*types
return &types.MsgDelegateResponse{}, nil
}
// BeginRedelegate defines a method for performing a redelegation of coins from a delegator and source validator to a destination validator
// BeginRedelegate defines a method for performing a redelegation of coins from a source validator to a destination validator of given delegator
func (k msgServer) BeginRedelegate(ctx context.Context, msg *types.MsgBeginRedelegate) (*types.MsgBeginRedelegateResponse, error) {
valSrcAddr, err := sdk.ValAddressFromBech32(msg.ValidatorSrcAddress)
if err != nil {
@ -576,6 +576,7 @@ func (k msgServer) CancelUnbondingDelegation(ctx context.Context, msg *types.Msg
return &types.MsgCancelUnbondingDelegationResponse{}, nil
}
// UpdateParams defines a method to perform updation of params exist in x/staking module.
func (k msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.authority != msg.Authority {
return nil, errorsmod.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority)

View File

@ -67,7 +67,7 @@ func (k Keeper) SetParams(ctx context.Context, params types.Params) error {
return store.Set(types.ParamsKey, bz)
}
// GetParams sets the x/staking module parameters.
// GetParams gets the x/staking module parameters.
func (k Keeper) GetParams(ctx context.Context) (params types.Params, err error) {
store := k.storeService.OpenKVStore(ctx)
bz, err := store.Get(types.ParamsKey)

View File

@ -41,7 +41,7 @@ func (k Keeper) notBondedTokensToBonded(ctx context.Context, tokens math.Int) er
return k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.NotBondedPoolName, types.BondedPoolName, coins)
}
// burnBondedTokens removes coins from the bonded pool module account
// burnBondedTokens burns coins from the bonded pool module account
func (k Keeper) burnBondedTokens(ctx context.Context, amt math.Int) error {
if !amt.IsPositive() {
// skip as no coins need to be burned
@ -58,7 +58,7 @@ func (k Keeper) burnBondedTokens(ctx context.Context, amt math.Int) error {
return k.bankKeeper.BurnCoins(ctx, types.BondedPoolName, coins)
}
// burnNotBondedTokens removes coins from the not bonded pool module account
// burnNotBondedTokens burns coins from the not bonded pool module account
func (k Keeper) burnNotBondedTokens(ctx context.Context, amt math.Int) error {
if !amt.IsPositive() {
// skip as no coins need to be burned

View File

@ -8,12 +8,12 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// TokensToConsensusPower - convert input tokens to potential consensus-engine power
// TokensToConsensusPower converts input tokens to potential consensus-engine power
func (k Keeper) TokensToConsensusPower(ctx context.Context, tokens math.Int) int64 {
return sdk.TokensToConsensusPower(tokens, k.PowerReduction(ctx))
}
// TokensFromConsensusPower - convert input power to tokens
// TokensFromConsensusPower converts input power to tokens
func (k Keeper) TokensFromConsensusPower(ctx context.Context, power int64) math.Int {
return sdk.TokensFromConsensusPower(power, k.PowerReduction(ctx))
}

View File

@ -9,7 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
// Return all validators that a delegator is bonded to. If maxRetrieve is supplied, the respective amount will be returned.
// GetDelegatorValidators returns all validators that a delegator is bonded to. If maxRetrieve is supplied, the respective amount will be returned.
func (k Keeper) GetDelegatorValidators(
ctx context.Context, delegatorAddr sdk.AccAddress, maxRetrieve uint32,
) (types.Validators, error) {
@ -39,7 +39,7 @@ func (k Keeper) GetDelegatorValidators(
return validators[:i], nil // trim
}
// return a validator that a delegator is bonded to
// GetDelegatorValidator returns a validator that a delegator is bonded to
func (k Keeper) GetDelegatorValidator(
ctx context.Context, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
) (validator types.Validator, err error) {
@ -51,7 +51,7 @@ func (k Keeper) GetDelegatorValidator(
return k.GetValidator(ctx, delegation.GetValidatorAddr())
}
// return all delegations for a delegator
// GetAllDelegatorDelegations returns all delegations of a delegator
func (k Keeper) GetAllDelegatorDelegations(ctx context.Context, delegator sdk.AccAddress) ([]types.Delegation, error) {
delegations := make([]types.Delegation, 0)
@ -76,7 +76,7 @@ func (k Keeper) GetAllDelegatorDelegations(ctx context.Context, delegator sdk.Ac
return delegations, nil
}
// return all unbonding-delegations for a delegator
// GetAllUnbondingDelegations returns all unbonding-delegations of a delegator
func (k Keeper) GetAllUnbondingDelegations(ctx context.Context, delegator sdk.AccAddress) ([]types.UnbondingDelegation, error) {
unbondingDelegations := make([]types.UnbondingDelegation, 0)
@ -101,7 +101,7 @@ func (k Keeper) GetAllUnbondingDelegations(ctx context.Context, delegator sdk.Ac
return unbondingDelegations, nil
}
// return all redelegations for a delegator
// GetAllRedelegations returns all redelegations of a delegator
func (k Keeper) GetAllRedelegations(
ctx context.Context, delegator sdk.AccAddress, srcValAddress, dstValAddress sdk.ValAddress,
) ([]types.Redelegation, error) {

View File

@ -31,7 +31,7 @@ import (
// CONTRACT:
//
// Infraction was committed at the current height or at a past height,
// not at a height in the future
// but not at a height in the future
func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, infractionHeight, power int64, slashFactor math.LegacyDec) (math.Int, error) {
logger := k.Logger(ctx)
sdkCtx := sdk.UnwrapSDKContext(ctx)

View File

@ -10,7 +10,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
// does a certain by-power index record exist
// ValidatorByPowerIndexExists does a certain by-power index record exist
func ValidatorByPowerIndexExists(ctx context.Context, keeper *Keeper, power []byte) bool {
store := keeper.storeService.OpenKVStore(ctx)
has, err := store.Has(power)
@ -20,7 +20,7 @@ func ValidatorByPowerIndexExists(ctx context.Context, keeper *Keeper, power []by
return has
}
// update validator for testing
// TestingUpdateValidator updates a validator for testing
func TestingUpdateValidator(keeper *Keeper, ctx sdk.Context, validator types.Validator, apply bool) types.Validator {
err := keeper.SetValidator(ctx, validator)
if err != nil {

View File

@ -41,6 +41,8 @@ func (k Keeper) DeleteUnbondingIndex(ctx context.Context, id uint64) error {
return store.Delete(types.GetUnbondingIndexKey(id))
}
// GetUnbondingType returns the enum type of unbonding which is any of
// {UnbondingDelegation | Redelegation | ValidatorUnbonding}
func (k Keeper) GetUnbondingType(ctx context.Context, id uint64) (unbondingType types.UnbondingType, err error) {
store := k.storeService.OpenKVStore(ctx)
@ -56,6 +58,8 @@ func (k Keeper) GetUnbondingType(ctx context.Context, id uint64) (unbondingType
return types.UnbondingType(binary.BigEndian.Uint64(bz)), nil
}
// SetUnbondingType sets the enum type of unbonding which is any of
// {UnbondingDelegation | Redelegation | ValidatorUnbonding}
func (k Keeper) SetUnbondingType(ctx context.Context, id uint64, unbondingType types.UnbondingType) error {
store := k.storeService.OpenKVStore(ctx)
@ -159,8 +163,9 @@ func (k Keeper) GetValidatorByUnbondingID(ctx context.Context, id uint64) (val t
return val, nil
}
// SetUnbondingDelegationByUnbondingID sets an index to look up an UnbondingDelegation by the unbondingID of an UnbondingDelegationEntry that it contains
// Note, it does not set the unbonding delegation itself, use SetUnbondingDelegation(ctx, ubd) for that
// SetUnbondingDelegationByUnbondingID sets an index to look up an UnbondingDelegation
// by the unbondingID of an UnbondingDelegationEntry that it contains Note, it does not
// set the unbonding delegation itself, use SetUnbondingDelegation(ctx, ubd) for that
func (k Keeper) SetUnbondingDelegationByUnbondingID(ctx context.Context, ubd types.UnbondingDelegation, id uint64) error {
store := k.storeService.OpenKVStore(ctx)
delAddr, err := k.authKeeper.AddressCodec().StringToBytes(ubd.DelegatorAddress)

View File

@ -17,7 +17,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
// get a single validator
// GetValidator gets a single validator
func (k Keeper) GetValidator(ctx context.Context, addr sdk.ValAddress) (validator types.Validator, err error) {
store := k.storeService.OpenKVStore(ctx)
value, err := store.Get(types.GetValidatorKey(addr))
@ -41,7 +41,7 @@ func (k Keeper) mustGetValidator(ctx context.Context, addr sdk.ValAddress) types
return validator
}
// get a single validator by consensus address
// GetValidatorByConsAddr gets a single validator by consensus address
func (k Keeper) GetValidatorByConsAddr(ctx context.Context, consAddr sdk.ConsAddress) (validator types.Validator, err error) {
store := k.storeService.OpenKVStore(ctx)
opAddr, err := store.Get(types.GetValidatorByConsAddrKey(consAddr))
@ -65,14 +65,14 @@ func (k Keeper) mustGetValidatorByConsAddr(ctx context.Context, consAddr sdk.Con
return validator
}
// set the main record holding validator details
// SetValidator sets the main record holding validator details
func (k Keeper) SetValidator(ctx context.Context, validator types.Validator) error {
store := k.storeService.OpenKVStore(ctx)
bz := types.MustMarshalValidator(k.cdc, &validator)
return store.Set(types.GetValidatorKey(validator.GetOperator()), bz)
}
// validator index
// SetValidatorByConsAddr sets a validator by conesensus address
func (k Keeper) SetValidatorByConsAddr(ctx context.Context, validator types.Validator) error {
consPk, err := validator.GetConsAddr()
if err != nil {
@ -82,7 +82,7 @@ func (k Keeper) SetValidatorByConsAddr(ctx context.Context, validator types.Vali
return store.Set(types.GetValidatorByConsAddrKey(consPk), validator.GetOperator())
}
// validator index
// SetValidatorByPowerIndex sets a validator by power index
func (k Keeper) SetValidatorByPowerIndex(ctx context.Context, validator types.Validator) error {
// jailed validators are not kept in the power index
if validator.Jailed {
@ -93,19 +93,19 @@ func (k Keeper) SetValidatorByPowerIndex(ctx context.Context, validator types.Va
return store.Set(types.GetValidatorsByPowerIndexKey(validator, k.PowerReduction(ctx)), validator.GetOperator())
}
// validator index
// DeleteValidatorByPowerIndex deletes a record by power index
func (k Keeper) DeleteValidatorByPowerIndex(ctx context.Context, validator types.Validator) error {
store := k.storeService.OpenKVStore(ctx)
return store.Delete(types.GetValidatorsByPowerIndexKey(validator, k.PowerReduction(ctx)))
}
// validator index
// SetNewValidatorByPowerIndex adds new entry by power index
func (k Keeper) SetNewValidatorByPowerIndex(ctx context.Context, validator types.Validator) error {
store := k.storeService.OpenKVStore(ctx)
return store.Set(types.GetValidatorsByPowerIndexKey(validator, k.PowerReduction(ctx)), validator.GetOperator())
}
// Update the tokens of an existing validator, update the validators power index key
// AddValidatorTokensAndShares updates the tokens of an existing validator, updates the validators power index key
func (k Keeper) AddValidatorTokensAndShares(ctx context.Context, validator types.Validator,
tokensToAdd math.Int,
) (valOut types.Validator, addedShares math.LegacyDec, err error) {
@ -124,7 +124,7 @@ func (k Keeper) AddValidatorTokensAndShares(ctx context.Context, validator types
return validator, addedShares, err
}
// Update the tokens of an existing validator, update the validators power index key
// RemoveValidatorTokensAndShares updates the tokens of an existing validator, updates the validators power index key
func (k Keeper) RemoveValidatorTokensAndShares(ctx context.Context, validator types.Validator,
sharesToRemove math.LegacyDec,
) (valOut types.Validator, removedTokens math.Int, err error) {
@ -142,7 +142,7 @@ func (k Keeper) RemoveValidatorTokensAndShares(ctx context.Context, validator ty
return validator, removedTokens, err
}
// Update the tokens of an existing validator, update the validators power index key
// RemoveValidatorTokens updates the tokens of an existing validator, updates the validators power index key
func (k Keeper) RemoveValidatorTokens(ctx context.Context,
validator types.Validator, tokensToRemove math.Int,
) (types.Validator, error) {
@ -190,7 +190,7 @@ func (k Keeper) UpdateValidatorCommission(ctx context.Context,
return commission, nil
}
// remove the validator record and associated indexes
// RemoveValidator removes the validator record and associated indexes
// except for the bonded validator index which is only handled in ApplyAndReturnTendermintUpdates
func (k Keeper) RemoveValidator(ctx context.Context, address sdk.ValAddress) error {
// first retrieve the old validator record
@ -235,7 +235,7 @@ func (k Keeper) RemoveValidator(ctx context.Context, address sdk.ValAddress) err
// get groups of validators
// get the set of all validators with no limits, used during genesis dump
// GetAllValidators gets the set of all validators with no limits, used during genesis dump
func (k Keeper) GetAllValidators(ctx context.Context) (validators []types.Validator, err error) {
store := k.storeService.OpenKVStore(ctx)
@ -256,7 +256,7 @@ func (k Keeper) GetAllValidators(ctx context.Context) (validators []types.Valida
return validators, nil
}
// return a given amount of all the validators
// GetValidators returns a given amount of all the validators
func (k Keeper) GetValidators(ctx context.Context, maxRetrieve uint32) (validators []types.Validator, err error) {
store := k.storeService.OpenKVStore(ctx)
validators = make([]types.Validator, maxRetrieve)
@ -279,7 +279,7 @@ func (k Keeper) GetValidators(ctx context.Context, maxRetrieve uint32) (validato
return validators[:i], nil // trim if the array length < maxRetrieve
}
// get the current group of bonded validators sorted by power-rank
// GetBondedValidatorsByPower gets the current group of bonded validators sorted by power-rank
func (k Keeper) GetBondedValidatorsByPower(ctx context.Context) ([]types.Validator, error) {
maxValidators, err := k.MaxValidators(ctx)
if err != nil {
@ -307,7 +307,7 @@ func (k Keeper) GetBondedValidatorsByPower(ctx context.Context) ([]types.Validat
return validators[:i], nil // trim
}
// returns an iterator for the current validator power store
// ValidatorsPowerStoreIterator returns an iterator for the current validator power store
func (k Keeper) ValidatorsPowerStoreIterator(ctx context.Context) (corestore.Iterator, error) {
store := k.storeService.OpenKVStore(ctx)
return store.ReverseIterator(types.ValidatorsByPowerIndexKey, storetypes.PrefixEndBytes(types.ValidatorsByPowerIndexKey))
@ -315,7 +315,7 @@ func (k Keeper) ValidatorsPowerStoreIterator(ctx context.Context) (corestore.Ite
// Last Validator Index
// Load the last validator power.
// GetLastValidatorPower loads the last validator power.
// Returns zero if the operator was not a validator last block.
func (k Keeper) GetLastValidatorPower(ctx context.Context, operator sdk.ValAddress) (power int64, err error) {
store := k.storeService.OpenKVStore(ctx)
@ -337,7 +337,7 @@ func (k Keeper) GetLastValidatorPower(ctx context.Context, operator sdk.ValAddre
return intV.GetValue(), nil
}
// Set the last validator power.
// SetLastValidatorPower sets the last validator power.
func (k Keeper) SetLastValidatorPower(ctx context.Context, operator sdk.ValAddress, power int64) error {
store := k.storeService.OpenKVStore(ctx)
bz, err := k.cdc.Marshal(&gogotypes.Int64Value{Value: power})
@ -347,19 +347,19 @@ func (k Keeper) SetLastValidatorPower(ctx context.Context, operator sdk.ValAddre
return store.Set(types.GetLastValidatorPowerKey(operator), bz)
}
// Delete the last validator power.
// DeleteLastValidatorPower deletes the last validator power.
func (k Keeper) DeleteLastValidatorPower(ctx context.Context, operator sdk.ValAddress) error {
store := k.storeService.OpenKVStore(ctx)
return store.Delete(types.GetLastValidatorPowerKey(operator))
}
// returns an iterator for the consensus validators in the last block
// lastValidatorsIterator returns an iterator for the consensus validators in the last block
func (k Keeper) LastValidatorsIterator(ctx context.Context) (corestore.Iterator, error) {
store := k.storeService.OpenKVStore(ctx)
return store.Iterator(types.LastValidatorPowerKey, storetypes.PrefixEndBytes(types.LastValidatorPowerKey))
}
// Iterate over last validator powers.
// IterateLastValidatorPowers iterates over last validator powers.
func (k Keeper) IterateLastValidatorPowers(ctx context.Context, handler func(operator sdk.ValAddress, power int64) (stop bool)) error {
iter, err := k.LastValidatorsIterator(ctx)
if err != nil {
@ -382,7 +382,7 @@ func (k Keeper) IterateLastValidatorPowers(ctx context.Context, handler func(ope
return nil
}
// get the group of the bonded validators
// GetLastValidators gets the group of the bonded validators
func (k Keeper) GetLastValidators(ctx context.Context) (validators []types.Validator, err error) {
store := k.storeService.OpenKVStore(ctx)
@ -591,6 +591,7 @@ func (k Keeper) UnbondAllMatureValidators(ctx context.Context) error {
return nil
}
// IsValidatorJailed checks and returns boolean of a validator status jailed or not.
func (k Keeper) IsValidatorJailed(ctx context.Context, addr sdk.ConsAddress) (bool, error) {
v, err := k.GetValidatorByConsAddr(ctx, addr)
if err != nil {

View File

@ -44,7 +44,8 @@ type GenesisState struct {
UnbondingDelegations []UnbondingDelegation `protobuf:"bytes,6,rep,name=unbonding_delegations,json=unbondingDelegations,proto3" json:"unbonding_delegations"`
// redelegations defines the redelegations active at genesis.
Redelegations []Redelegation `protobuf:"bytes,7,rep,name=redelegations,proto3" json:"redelegations"`
Exported bool `protobuf:"varint,8,opt,name=exported,proto3" json:"exported,omitempty"`
// exported defines a bool to identify whether the chain dealing with exported or initialized genesis.
Exported bool `protobuf:"varint,8,opt,name=exported,proto3" json:"exported,omitempty"`
}
func (m *GenesisState) Reset() { *m = GenesisState{} }

View File

@ -44,18 +44,6 @@ func NewMsgCreateValidator(
}, nil
}
// GetSigners implements the sdk.Msg interface. It returns the address(es) that
// must sign over msg.GetSignBytes().
// If the validator address is not same as delegator's, then the validator must
// sign the msg as well.
func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress {
valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress)
valAccAddr := sdk.AccAddress(valAddr)
return []sdk.AccAddress{valAccAddr}
}
// Validate validates the MsgCreateValidator sdk msg.
func (msg MsgCreateValidator) Validate() error {
// note that unmarshaling from bech32 ensures both non-empty and valid
@ -114,12 +102,6 @@ func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRat
}
}
// GetSigners implements the sdk.Msg interface.
func (msg MsgEditValidator) GetSigners() []sdk.AccAddress {
valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress)
return []sdk.AccAddress{sdk.AccAddress(valAddr)}
}
// NewMsgDelegate creates a new MsgDelegate instance.
func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) *MsgDelegate {
return &MsgDelegate{
@ -129,12 +111,6 @@ func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.C
}
}
// GetSigners implements the sdk.Msg interface.
func (msg MsgDelegate) GetSigners() []sdk.AccAddress {
delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress)
return []sdk.AccAddress{delegator}
}
// NewMsgBeginRedelegate creates a new MsgBeginRedelegate instance.
func NewMsgBeginRedelegate(
delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, amount sdk.Coin,
@ -147,12 +123,6 @@ func NewMsgBeginRedelegate(
}
}
// GetSigners implements the sdk.Msg interface
func (msg MsgBeginRedelegate) GetSigners() []sdk.AccAddress {
delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress)
return []sdk.AccAddress{delegator}
}
// NewMsgUndelegate creates a new MsgUndelegate instance.
func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) *MsgUndelegate {
return &MsgUndelegate{
@ -162,12 +132,6 @@ func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk
}
}
// GetSigners implements the sdk.Msg interface.
func (msg MsgUndelegate) GetSigners() []sdk.AccAddress {
delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress)
return []sdk.AccAddress{delegator}
}
// NewMsgCancelUnbondingDelegation creates a new MsgCancelUnbondingDelegation instance.
func NewMsgCancelUnbondingDelegation(delAddr sdk.AccAddress, valAddr sdk.ValAddress, creationHeight int64, amount sdk.Coin) *MsgCancelUnbondingDelegation {
return &MsgCancelUnbondingDelegation{
@ -177,15 +141,3 @@ func NewMsgCancelUnbondingDelegation(delAddr sdk.AccAddress, valAddr sdk.ValAddr
CreationHeight: creationHeight,
}
}
// GetSigners implements the sdk.Msg interface.
func (msg MsgCancelUnbondingDelegation) GetSigners() []sdk.AccAddress {
delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress)
return []sdk.AccAddress{delegator}
}
// GetSigners returns the expected signers for a MsgUpdateParams message
func (m MsgUpdateParams) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}