Separate validator pub key index updates

This commit is contained in:
Christopher Goes 2018-05-31 00:41:28 +02:00
parent 0324be4189
commit 7e9192f513
No known key found for this signature in database
GPG Key ID: E828D98232D328D3
3 changed files with 6 additions and 0 deletions

View File

@ -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 {

View File

@ -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(),

View File

@ -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)
}