Remove ValidatorByPubKey, don't marshal sdk.Address
This commit is contained in:
parent
4e266013a8
commit
5f03e370c3
|
@ -56,12 +56,11 @@ type ValidatorSet interface {
|
|||
IterateValidatorsBonded(Context,
|
||||
func(index int64, validator Validator) (stop bool))
|
||||
|
||||
Validator(Context, Address) Validator // get a particular validator by owner address
|
||||
ValidatorByPubKey(Context, crypto.PubKey) Validator // get a particular validator by public key
|
||||
TotalPower(Context) Rat // total power of the validator set
|
||||
Slash(Context, crypto.PubKey, int64, Rat) // slash the validator and delegators of the validator, specifying offence height & slash fraction
|
||||
Revoke(Context, crypto.PubKey) // revoke a validator
|
||||
Unrevoke(Context, crypto.PubKey) // unrevoke a validator
|
||||
Validator(Context, Address) Validator // get a particular validator by owner address
|
||||
TotalPower(Context) Rat // total power of the validator set
|
||||
Slash(Context, crypto.PubKey, int64, Rat) // slash the validator and delegators of the validator, specifying offence height & slash fraction
|
||||
Revoke(Context, crypto.PubKey) // revoke a validator
|
||||
Unrevoke(Context, crypto.PubKey) // unrevoke a validator
|
||||
}
|
||||
|
||||
//_______________________________________________________________________________
|
||||
|
|
|
@ -62,7 +62,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
require.Equal(t, int64(0), info.StartHeight)
|
||||
require.Equal(t, SignedBlocksWindow-50, info.SignedBlocksCounter)
|
||||
// validator should be bonded still
|
||||
validator := sk.ValidatorByPubKey(ctx, val)
|
||||
validator, _ := sk.GetValidatorByPubKey(ctx, val)
|
||||
require.Equal(t, sdk.Bonded, validator.GetStatus())
|
||||
pool := sk.GetPool(ctx)
|
||||
require.Equal(t, int64(100), pool.BondedTokens)
|
||||
|
@ -74,7 +74,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
require.Equal(t, int64(0), info.StartHeight)
|
||||
require.Equal(t, SignedBlocksWindow-51, info.SignedBlocksCounter)
|
||||
// validator should have been revoked
|
||||
validator = sk.ValidatorByPubKey(ctx, val)
|
||||
validator, _ = sk.GetValidatorByPubKey(ctx, val)
|
||||
require.Equal(t, sdk.Unbonded, validator.GetStatus())
|
||||
// unrevocation should fail prior to jail expiration
|
||||
got = slh(ctx, NewMsgUnrevoke(addr))
|
||||
|
@ -84,7 +84,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
got = slh(ctx, NewMsgUnrevoke(addr))
|
||||
require.True(t, got.IsOK())
|
||||
// validator should be rebonded now
|
||||
validator = sk.ValidatorByPubKey(ctx, val)
|
||||
validator, _ = sk.GetValidatorByPubKey(ctx, val)
|
||||
require.Equal(t, sdk.Bonded, validator.GetStatus())
|
||||
// validator should have been slashed
|
||||
pool = sk.GetPool(ctx)
|
||||
|
@ -98,7 +98,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
height++
|
||||
ctx = ctx.WithBlockHeight(height)
|
||||
keeper.handleValidatorSignature(ctx, val, false)
|
||||
validator = sk.ValidatorByPubKey(ctx, val)
|
||||
validator, _ = sk.GetValidatorByPubKey(ctx, val)
|
||||
require.Equal(t, sdk.Bonded, validator.GetStatus())
|
||||
// validator should be revoked again after 100 unsigned blocks
|
||||
nextHeight := height + 100
|
||||
|
@ -106,6 +106,6 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
ctx = ctx.WithBlockHeight(height)
|
||||
keeper.handleValidatorSignature(ctx, val, false)
|
||||
}
|
||||
validator = sk.ValidatorByPubKey(ctx, val)
|
||||
validator, _ = sk.GetValidatorByPubKey(ctx, val)
|
||||
require.Equal(t, sdk.Unbonded, validator.GetStatus())
|
||||
}
|
||||
|
|
|
@ -42,12 +42,10 @@ func (k Keeper) GetValidator(ctx sdk.Context, addr sdk.Address) (validator Valid
|
|||
// get a single validator by pubkey
|
||||
func (k Keeper) GetValidatorByPubKey(ctx sdk.Context, pubkey crypto.PubKey) (validator Validator, found bool) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
b := store.Get(GetValidatorByPubKeyKey(pubkey))
|
||||
if b == nil {
|
||||
addr := store.Get(GetValidatorByPubKeyKey(pubkey))
|
||||
if addr == nil {
|
||||
return validator, false
|
||||
}
|
||||
var addr sdk.Address
|
||||
k.cdc.MustUnmarshalBinary(b, &addr)
|
||||
return k.getValidator(store, addr)
|
||||
}
|
||||
|
||||
|
@ -68,8 +66,7 @@ func (k Keeper) setValidator(ctx sdk.Context, validator Validator) {
|
|||
bz := k.cdc.MustMarshalBinary(validator)
|
||||
store.Set(GetValidatorKey(validator.Owner), bz)
|
||||
// set pointer by pubkey
|
||||
bz = k.cdc.MustMarshalBinary(validator.Owner)
|
||||
store.Set(GetValidatorByPubKeyKey(validator.PubKey), bz)
|
||||
store.Set(GetValidatorByPubKeyKey(validator.PubKey), validator.Owner)
|
||||
}
|
||||
|
||||
// Get the set of all validators with no limits, used during genesis dump
|
||||
|
@ -740,15 +737,6 @@ func (k Keeper) Validator(ctx sdk.Context, addr sdk.Address) sdk.Validator {
|
|||
return val
|
||||
}
|
||||
|
||||
// get the sdk.validator for a particular pubkey
|
||||
func (k Keeper) ValidatorByPubKey(ctx sdk.Context, pubkey crypto.PubKey) sdk.Validator {
|
||||
val, found := k.GetValidatorByPubKey(ctx, pubkey)
|
||||
if !found {
|
||||
return nil
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
// total power from the bond
|
||||
func (k Keeper) TotalPower(ctx sdk.Context) sdk.Rat {
|
||||
pool := k.GetPool(ctx)
|
||||
|
|
Loading…
Reference in New Issue