diff --git a/x/stake/genesis.go b/x/stake/genesis.go index e6baa099b..a2cd58bdb 100644 --- a/x/stake/genesis.go +++ b/x/stake/genesis.go @@ -35,6 +35,7 @@ func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) { // Staking assumes bonded validators are already stored, need to force update validator.PoolShares.Status = sdk.Unbonded k.setValidator(ctx, validator) + k.setValidatorByPubKeyIndex(ctx, validator) k.updateValidator(ctx, validator) } for _, bond := range data.Bonds { diff --git a/x/stake/handler.go b/x/stake/handler.go index 53653557c..6f2360adf 100644 --- a/x/stake/handler.go +++ b/x/stake/handler.go @@ -55,6 +55,7 @@ func handleMsgDeclareCandidacy(ctx sdk.Context, msg MsgDeclareCandidacy, k Keepe validator := NewValidator(msg.ValidatorAddr, msg.PubKey, msg.Description) k.setValidator(ctx, validator) + k.setValidatorByPubKeyIndex(ctx, validator) tags := sdk.NewTags( "action", []byte("declareCandidacy"), "validator", msg.ValidatorAddr.Bytes(), diff --git a/x/stake/keeper.go b/x/stake/keeper.go index 21b58c1fe..b94f392a6 100644 --- a/x/stake/keeper.go +++ b/x/stake/keeper.go @@ -65,6 +65,10 @@ func (k Keeper) setValidator(ctx sdk.Context, validator Validator) { // set main store bz := k.cdc.MustMarshalBinary(validator) store.Set(GetValidatorKey(validator.Owner), bz) +} + +func (k Keeper) setValidatorByPubKeyIndex(ctx sdk.Context, validator Validator) { + store := ctx.KVStore(k.storeKey) // set pointer by pubkey store.Set(GetValidatorByPubKeyIndexKey(validator.PubKey), validator.Owner) }