remove GetValidatorByConsPubKey
This commit is contained in:
parent
14792f2b23
commit
afe179ebb3
|
@ -292,6 +292,11 @@ func ConsAddressFromBech32(address string) (addr ConsAddress, err error) {
|
|||
return ConsAddress(bz), nil
|
||||
}
|
||||
|
||||
// get ConsAddress from pubkey
|
||||
func GetConsAddress(pubkey crypto.PubKey) ConsAddress {
|
||||
return ConsAddress(pubkey.Address())
|
||||
}
|
||||
|
||||
// Returns boolean for whether two ConsAddress are Equal
|
||||
func (ca ConsAddress) Equals(ca2 ConsAddress) bool {
|
||||
if ca.Empty() && ca2.Empty() {
|
||||
|
|
|
@ -68,10 +68,9 @@ type ValidatorSet interface {
|
|||
IterateValidatorsBonded(Context,
|
||||
func(index int64, validator Validator) (stop bool))
|
||||
|
||||
Validator(Context, ValAddress) Validator // get a particular validator by operator address
|
||||
ValidatorByConsPubKey(Context, crypto.PubKey) Validator // get a particular validator by consensus PubKey
|
||||
ValidatorByConsAddr(Context, ConsAddress) Validator // get a particular validator by consensus address
|
||||
TotalPower(Context) Dec // total power of the validator set
|
||||
Validator(Context, ValAddress) Validator // get a particular validator by operator address
|
||||
ValidatorByConsAddr(Context, ConsAddress) Validator // get a particular validator by consensus address
|
||||
TotalPower(Context) Dec // total power of the validator set
|
||||
|
||||
// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
|
||||
Slash(Context, ConsAddress, int64, int64, Dec)
|
||||
|
|
|
@ -167,7 +167,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
require.Equal(t, keeper.SignedBlocksWindow(ctx)-keeper.MinSignedPerWindow(ctx), info.SignedBlocksCounter)
|
||||
|
||||
// validator should be bonded still
|
||||
validator, _ := sk.GetValidatorByConsPubKey(ctx, val)
|
||||
validator, _ := sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Bonded, validator.GetStatus())
|
||||
pool := sk.GetPool(ctx)
|
||||
require.Equal(t, amtInt, pool.BondedTokens.RoundInt64())
|
||||
|
@ -181,7 +181,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
require.Equal(t, keeper.SignedBlocksWindow(ctx)-keeper.MinSignedPerWindow(ctx)-1, info.SignedBlocksCounter)
|
||||
|
||||
// validator should have been jailed
|
||||
validator, _ = sk.GetValidatorByConsPubKey(ctx, val)
|
||||
validator, _ = sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Unbonding, validator.GetStatus())
|
||||
|
||||
// unrevocation should fail prior to jail expiration
|
||||
|
@ -194,7 +194,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
require.True(t, got.IsOK())
|
||||
|
||||
// validator should be rebonded now
|
||||
validator, _ = sk.GetValidatorByConsPubKey(ctx, val)
|
||||
validator, _ = sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Bonded, validator.GetStatus())
|
||||
|
||||
// validator should have been slashed
|
||||
|
@ -212,7 +212,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
height++
|
||||
ctx = ctx.WithBlockHeight(height)
|
||||
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, false)
|
||||
validator, _ = sk.GetValidatorByConsPubKey(ctx, val)
|
||||
validator, _ = sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Bonded, validator.GetStatus())
|
||||
|
||||
// 500 signed blocks
|
||||
|
@ -228,7 +228,7 @@ func TestHandleAbsentValidator(t *testing.T) {
|
|||
ctx = ctx.WithBlockHeight(height)
|
||||
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, false)
|
||||
}
|
||||
validator, _ = sk.GetValidatorByConsPubKey(ctx, val)
|
||||
validator, _ = sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Unbonding, validator.GetStatus())
|
||||
}
|
||||
|
||||
|
@ -263,7 +263,7 @@ func TestHandleNewValidator(t *testing.T) {
|
|||
require.Equal(t, time.Unix(0, 0).UTC(), info.JailedUntil)
|
||||
|
||||
// validator should be bonded still, should not have been jailed or slashed
|
||||
validator, _ := sk.GetValidatorByConsPubKey(ctx, val)
|
||||
validator, _ := sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Bonded, validator.GetStatus())
|
||||
pool := sk.GetPool(ctx)
|
||||
require.Equal(t, int64(100), pool.BondedTokens.RoundInt64())
|
||||
|
@ -297,7 +297,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
|
|||
}
|
||||
|
||||
// validator should have been jailed and slashed
|
||||
validator, _ := sk.GetValidatorByConsPubKey(ctx, val)
|
||||
validator, _ := sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, sdk.Unbonding, validator.GetStatus())
|
||||
|
||||
// validator should have been slashed
|
||||
|
@ -308,7 +308,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
|
|||
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, false)
|
||||
|
||||
// validator should not have been slashed twice
|
||||
validator, _ = sk.GetValidatorByConsPubKey(ctx, val)
|
||||
validator, _ = sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(val))
|
||||
require.Equal(t, amtInt-1, validator.GetTokens().RoundInt64())
|
||||
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ func TestBeginBlocker(t *testing.T) {
|
|||
}
|
||||
|
||||
// validator should be jailed
|
||||
validator, found := sk.GetValidatorByConsPubKey(ctx, pk)
|
||||
validator, found := sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(pk))
|
||||
require.True(t, found)
|
||||
require.Equal(t, sdk.Unbonding, validator.GetStatus())
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k
|
|||
if found {
|
||||
return ErrValidatorOwnerExists(k.Codespace()).Result()
|
||||
}
|
||||
_, found = k.GetValidatorByConsPubKey(ctx, msg.PubKey)
|
||||
_, found = k.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(msg.PubKey))
|
||||
if found {
|
||||
return ErrValidatorPubKeyExists(k.Codespace()).Result()
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
||||
// Implements ValidatorSet
|
||||
|
@ -67,15 +66,6 @@ func (k Keeper) ValidatorByConsAddr(ctx sdk.Context, addr sdk.ConsAddress) sdk.V
|
|||
return val
|
||||
}
|
||||
|
||||
// get the sdk.validator for a particular pubkey
|
||||
func (k Keeper) ValidatorByConsPubKey(ctx sdk.Context, consPubKey crypto.PubKey) sdk.Validator {
|
||||
val, found := k.GetValidatorByConsPubKey(ctx, consPubKey)
|
||||
if !found {
|
||||
return nil
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
// total power from the bond
|
||||
func (k Keeper) TotalPower(ctx sdk.Context) sdk.Dec {
|
||||
pool := k.GetPool(ctx)
|
||||
|
|
|
@ -473,7 +473,7 @@ func TestSlashBoth(t *testing.T) {
|
|||
// slash validator
|
||||
ctx = ctx.WithBlockHeight(12)
|
||||
oldPool := keeper.GetPool(ctx)
|
||||
validator, found := keeper.GetValidatorByConsPubKey(ctx, PKs[0])
|
||||
validator, found := keeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(PKs[0]))
|
||||
require.True(t, found)
|
||||
consAddr0 := sdk.ConsAddress(PKs[0].Address())
|
||||
keeper.Slash(ctx, consAddr0, 10, 10, fraction)
|
||||
|
@ -490,7 +490,7 @@ func TestSlashBoth(t *testing.T) {
|
|||
// bonded tokens burned
|
||||
require.Equal(t, int64(3), oldPool.BondedTokens.Sub(newPool.BondedTokens).RoundInt64())
|
||||
// read updated validator
|
||||
validator, found = keeper.GetValidatorByConsPubKey(ctx, PKs[0])
|
||||
validator, found = keeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(PKs[0]))
|
||||
require.True(t, found)
|
||||
// power not decreased, all stake was bonded since
|
||||
require.Equal(t, sdk.NewDec(10), validator.GetPower())
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
|
@ -68,17 +67,6 @@ func (k Keeper) GetValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress
|
|||
return k.GetValidator(ctx, opAddr)
|
||||
}
|
||||
|
||||
// get a single validator by pubkey
|
||||
func (k Keeper) GetValidatorByConsPubKey(ctx sdk.Context, consPubKey crypto.PubKey) (validator types.Validator, found bool) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
consAddr := sdk.ConsAddress(consPubKey.Address())
|
||||
opAddr := store.Get(GetValidatorByConsAddrKey(consAddr))
|
||||
if opAddr == nil {
|
||||
return validator, false
|
||||
}
|
||||
return k.GetValidator(ctx, opAddr)
|
||||
}
|
||||
|
||||
// set the main record holding validator details
|
||||
func (k Keeper) SetValidator(ctx sdk.Context, validator types.Validator) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
|
|
|
@ -314,7 +314,7 @@ func TestValidatorBasics(t *testing.T) {
|
|||
resVal, found = keeper.GetValidatorByConsAddr(ctx, sdk.ConsAddress(PKs[0].Address()))
|
||||
require.True(t, found)
|
||||
assert.True(ValEq(t, validators[0], resVal))
|
||||
resVal, found = keeper.GetValidatorByConsPubKey(ctx, PKs[0])
|
||||
resVal, found = keeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(PKs[0]))
|
||||
require.True(t, found)
|
||||
assert.True(ValEq(t, validators[0], resVal))
|
||||
|
||||
|
|
Loading…
Reference in New Issue