Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Rename validator.GetJailed() to validator.IsJailed() #3245 #4017

Merged
merged 2 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pending/breaking/sdk/3245-Rename-validato
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#3245 Rename validator.GetJailed() to validator.IsJailed()
2 changes: 1 addition & 1 deletion types/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (b BondStatus) Equal(b2 BondStatus) bool {

// validator for a delegated proof of stake system
type Validator interface {
GetJailed() bool // whether the validator is jailed
IsJailed() bool // whether the validator is jailed
GetMoniker() string // moniker of the validator
GetStatus() BondStatus // status of the validator
GetOperator() ValAddress // operator address to receive/return validators coins
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) sdk.Result {
}

// cannot be unjailed if not jailed
if !validator.GetJailed() {
if !validator.IsJailed() {
return ErrValidatorNotJailed(k.codespace).Result()
}

Expand Down
4 changes: 2 additions & 2 deletions x/slashing/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestCannotUnjailUnlessMeetMinSelfDelegation(t *testing.T) {
undelegateMsg := staking.NewMsgUndelegate(sdk.AccAddress(addr), addr, unbondAmt)
got = staking.NewHandler(sk)(ctx, undelegateMsg)

require.True(t, sk.Validator(ctx, addr).GetJailed())
require.True(t, sk.Validator(ctx, addr).IsJailed())

// assert non-jailed validator can't be unjailed
got = slh(ctx, NewMsgUnjail(addr))
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestJailedValidatorDelegations(t *testing.T) {
// verify validator still exists and is jailed
validator, found := stakingKeeper.GetValidator(ctx, valAddr)
require.True(t, found)
require.True(t, validator.GetJailed())
require.True(t, validator.IsJailed())

// verify the validator cannot unjail itself
got = NewHandler(slashingKeeper)(ctx, NewMsgUnjail(valAddr))
Expand Down
4 changes: 2 additions & 2 deletions x/slashing/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractio

// Jail validator if not already jailed
// begin unbonding validator if not already unbonding (tombstone)
if !validator.GetJailed() {
if !validator.IsJailed() {
k.validatorSet.Jail(ctx, consAddr)
}

Expand Down Expand Up @@ -172,7 +172,7 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, addr crypto.Address, p
// if we are past the minimum height and the validator has missed too many blocks, punish them
if height > minHeight && signInfo.MissedBlocksCounter > maxMissed {
validator := k.validatorSet.ValidatorByConsAddr(ctx, consAddr)
if validator != nil && !validator.GetJailed() {
if validator != nil && !validator.IsJailed() {

// Downtime confirmed: slash and jail the validator
logger.Info(fmt.Sprintf("Validator %s past min height of %d and below signed blocks threshold of %d",
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestHandleDoubleSign(t *testing.T) {
keeper.handleDoubleSign(ctx, val.Address(), 0, time.Unix(0, 0), power)

// should be jailed
require.True(t, sk.Validator(ctx, operatorAddr).GetJailed())
require.True(t, sk.Validator(ctx, operatorAddr).IsJailed())

// tokens should be decreased
newTokens := sk.Validator(ctx, operatorAddr).GetTokens()
Expand Down
6 changes: 3 additions & 3 deletions x/staking/keeper/slash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ func TestRevocation(t *testing.T) {
// initial state
val, found := keeper.GetValidator(ctx, addr)
require.True(t, found)
require.False(t, val.GetJailed())
require.False(t, val.IsJailed())

// test jail
keeper.Jail(ctx, consAddr)
val, found = keeper.GetValidator(ctx, addr)
require.True(t, found)
require.True(t, val.GetJailed())
require.True(t, val.IsJailed())

// test unjail
keeper.Unjail(ctx, consAddr)
val, found = keeper.GetValidator(ctx, addr)
require.True(t, found)
require.False(t, val.GetJailed())
require.False(t, val.IsJailed())
}

// tests slashUnbondingDelegation
Expand Down
2 changes: 1 addition & 1 deletion x/staking/types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func (v Validator) PotentialTendermintPower() int64 {
var _ sdk.Validator = Validator{}

// nolint - for sdk.Validator
func (v Validator) GetJailed() bool { return v.Jailed }
func (v Validator) IsJailed() bool { return v.Jailed }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we need getters for all these public members 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For implementing the interface Validator ?

type Validator interface {
	IsJailed() bool                                 // whether the validator is jailed
	GetMoniker() string                             // moniker of the validator
	GetStatus() BondStatus                          // status of the validator
	GetOperator() ValAddress                        // operator address to receive/return validators coins
	GetConsPubKey() crypto.PubKey                   // validation consensus pubkey
	GetConsAddr() ConsAddress                       // validation consensus address
	GetTokens() Int                                 // validation tokens
	GetBondedTokens() Int                           // validator bonded tokens
	GetTendermintPower() int64                      // validation power in tendermint
	GetCommission() Dec                             // validator commission rate
	GetMinSelfDelegation() Int                      // validator minimum self delegation
	GetDelegatorShares() Dec                        // total outstanding delegator shares
	TokensFromShares(Dec) Dec                       // token worth of provided delegator shares
	TokensFromSharesTruncated(Dec) Dec              // token worth of provided delegator shares, truncated
	SharesFromTokens(amt Int) (Dec, Error)          // shares worth of delegator's bond
	SharesFromTokensTruncated(amt Int) (Dec, Error) // truncated shares worth of delegator's bond
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's because we have an interface 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough

func (v Validator) GetMoniker() string { return v.Description.Moniker }
func (v Validator) GetStatus() sdk.BondStatus { return v.Status }
func (v Validator) GetOperator() sdk.ValAddress { return v.OperatorAddress }
Expand Down