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