Minor cleanup
This commit is contained in:
parent
1f5fe29c25
commit
dd75cd3049
@ -1,9 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
// status of a validator
|
||||
@ -48,22 +46,6 @@ type Validator interface {
|
||||
GetBondHeight() int64 // height in which the validator became active
|
||||
}
|
||||
|
||||
// validator which fulfills abci validator interface for use in Tendermint
|
||||
func ABCIValidator(v Validator) abci.Validator {
|
||||
return abci.Validator{
|
||||
Address: v.GetPubKey().Address(),
|
||||
Power: v.GetPower().RoundInt64(),
|
||||
}
|
||||
}
|
||||
|
||||
// validator which fulfills abci validator update interface for use in Tendermint
|
||||
func ABCIValidatorUpdate(v Validator) abci.ValidatorUpdate {
|
||||
return abci.ValidatorUpdate{
|
||||
PubKey: tmtypes.TM2PB.PubKey(v.GetPubKey()),
|
||||
Power: v.GetPower().RoundInt64(),
|
||||
}
|
||||
}
|
||||
|
||||
// properties for the set of all validators
|
||||
type ValidatorSet interface {
|
||||
// iterate through validator by owner-AccAddress, execute func for each validator
|
||||
|
||||
@ -49,7 +49,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res [
|
||||
vals := keeper.GetValidatorsBonded(ctx)
|
||||
res = make([]abci.ValidatorUpdate, len(vals))
|
||||
for i, val := range vals {
|
||||
res[i] = sdk.ABCIValidatorUpdate(val)
|
||||
res[i] = val.ABCIValidatorUpdate()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ func TestInitGenesis(t *testing.T) {
|
||||
|
||||
abcivals := make([]abci.ValidatorUpdate, len(vals))
|
||||
for i, val := range validators {
|
||||
abcivals[i] = sdk.ABCIValidatorUpdate(val)
|
||||
abcivals[i] = val.ABCIValidatorUpdate()
|
||||
}
|
||||
|
||||
require.Equal(t, abcivals, vals)
|
||||
@ -94,7 +94,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
|
||||
|
||||
abcivals := make([]abci.ValidatorUpdate, 100)
|
||||
for i, val := range validators[:100] {
|
||||
abcivals[i] = sdk.ABCIValidatorUpdate(val)
|
||||
abcivals[i] = val.ABCIValidatorUpdate()
|
||||
}
|
||||
|
||||
require.Equal(t, abcivals, vals)
|
||||
|
||||
@ -256,7 +256,7 @@ func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) type
|
||||
case powerIncreasing && !validator.Jailed &&
|
||||
(oldFound && oldValidator.Status == sdk.Bonded):
|
||||
|
||||
bz := k.cdc.MustMarshalBinary(sdk.ABCIValidatorUpdate(validator))
|
||||
bz := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdate())
|
||||
store.Set(GetTendermintUpdatesKey(validator.Operator), bz)
|
||||
|
||||
if cliffPower != nil {
|
||||
@ -292,7 +292,7 @@ func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) type
|
||||
|
||||
// if decreased in power but still bonded, update Tendermint validator
|
||||
if oldFound && oldValidator.BondedTokens().GT(validator.BondedTokens()) {
|
||||
bz := k.cdc.MustMarshalBinary(sdk.ABCIValidatorUpdate(validator))
|
||||
bz := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdate())
|
||||
store.Set(GetTendermintUpdatesKey(validator.Operator), bz)
|
||||
}
|
||||
}
|
||||
@ -671,7 +671,7 @@ func (k Keeper) bondValidator(ctx sdk.Context, validator types.Validator) types.
|
||||
store.Set(GetValidatorsBondedIndexKey(validator.Operator), []byte{})
|
||||
|
||||
// add to accumulated changes for tendermint
|
||||
bzABCI := k.cdc.MustMarshalBinary(sdk.ABCIValidatorUpdate(validator))
|
||||
bzABCI := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdate())
|
||||
store.Set(GetTendermintUpdatesKey(validator.Operator), bzABCI)
|
||||
|
||||
// call the bond hook if present
|
||||
|
||||
@ -309,14 +309,6 @@ func (d Description) EnsureLength() (Description, sdk.Error) {
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// ABCIValidator returns an abci.Validator from a staked validator type.
|
||||
func (v Validator) ABCIValidator() abci.Validator {
|
||||
return abci.Validator{
|
||||
Address: v.PubKey.Address(),
|
||||
Power: v.BondedTokens().RoundInt64(),
|
||||
}
|
||||
}
|
||||
|
||||
// ABCIValidatorUpdate returns an abci.ValidatorUpdate from a staked validator type
|
||||
// with the full validator power
|
||||
func (v Validator) ABCIValidatorUpdate() abci.ValidatorUpdate {
|
||||
|
||||
@ -53,11 +53,11 @@ func TestUpdateDescription(t *testing.T) {
|
||||
require.Equal(t, d, d3)
|
||||
}
|
||||
|
||||
func TestABCIValidator(t *testing.T) {
|
||||
func TestABCIValidatorUpdate(t *testing.T) {
|
||||
validator := NewValidator(addr1, pk1, Description{})
|
||||
|
||||
abciVal := validator.ABCIValidator()
|
||||
require.Equal(t, addr1, sdk.ValAddress(abciVal.Address))
|
||||
abciVal := validator.ABCIValidatorUpdate()
|
||||
require.Equal(t, tmtypes.TM2PB.PubKey(pk1), abciVal.PubKey)
|
||||
require.Equal(t, validator.BondedTokens().RoundInt64(), abciVal.Power)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user