Skip to content

Commit

Permalink
fix unjail on PoA (#136)
Browse files Browse the repository at this point in the history
* fix unjail on PoA

* fix unjail on PoA
  • Loading branch information
zjg555543 authored May 18, 2023
1 parent ea5b5ab commit 418fd81
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion x/slashing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package slashing
import (
sdk "github.com/okx/okbchain/libs/cosmos-sdk/types"
sdkerrors "github.com/okx/okbchain/libs/cosmos-sdk/types/errors"
types2 "github.com/okx/okbchain/libs/tendermint/types"
"github.com/okx/okbchain/x/common"
"github.com/okx/okbchain/x/slashing/internal/types"
)

Expand All @@ -29,7 +31,12 @@ func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) (*sdk.Result, err
return nil, sdkerrors.Wrapf(ErrNoValidatorForAddress, "Unjail failed")
}

if validator.GetMinSelfDelegation().IsZero() {
checkSelfDelegation := true
if types2.HigherThanEarth(ctx.BlockHeight()) && k.GetStakingKeeper().ParamsConsensusType(ctx) == common.PoA {
checkSelfDelegation = false
}

if checkSelfDelegation && validator.GetMinSelfDelegation().IsZero() {
return nil, sdkerrors.Wrapf(ErrMissingSelfDelegation, "Unjail failed")
}

Expand Down
3 changes: 3 additions & 0 deletions x/slashing/internal/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package types
import (
sdk "github.com/okx/okbchain/libs/cosmos-sdk/types"
authexported "github.com/okx/okbchain/libs/cosmos-sdk/x/auth/exported"
"github.com/okx/okbchain/x/common"
"github.com/okx/okbchain/x/params"
stakingexported "github.com/okx/okbchain/x/staking/exported"
)
Expand Down Expand Up @@ -46,6 +47,8 @@ type StakingKeeper interface {

//Append abandoned validator to staking keeper
AppendAbandonedValidatorAddrs(ctx sdk.Context, ConsAddr sdk.ConsAddress)

ParamsConsensusType(ctx sdk.Context) (consensusType common.ConsensusType)
}

// StakingHooks event hooks for staking validator object (noalias)
Expand Down
5 changes: 5 additions & 0 deletions x/staking/keeper/val_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

sdk "github.com/okx/okbchain/libs/cosmos-sdk/types"
abci "github.com/okx/okbchain/libs/tendermint/abci/types"
"github.com/okx/okbchain/x/common"
"github.com/okx/okbchain/x/staking/types"
)

Expand Down Expand Up @@ -244,6 +245,10 @@ func (k Keeper) unjailValidator(ctx sdk.Context, validator types.Validator) {
validator.Jailed = false
k.SetValidator(ctx, validator)
k.SetValidatorByPowerIndex(ctx, validator)

if k.ParamsConsensusType(ctx) == common.PoA {
k.SetProposeValidator(ctx, validator.OperatorAddress, true)
}
}

// bondValidator performs all the store operations for when a validator status becomes bonded
Expand Down

0 comments on commit 418fd81

Please sign in to comment.