Skip to content

Commit

Permalink
Revert "feat: #254 Jail pigeons after timeout (#898)"
Browse files Browse the repository at this point in the history
This reverts commit 95d8603.
  • Loading branch information
ToasterTheBrave committed Jul 5, 2023
1 parent 95d8603 commit d7eeb7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
20 changes: 4 additions & 16 deletions x/valset/keeper/keep_alive.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import (

const (
// TODO: make this a param
defaultKeepAliveDuration = 5 * time.Minute
cValidatorJailedErrorMessage = "validator is jailed"
cValidatorNotBondedErrorMessage = "validator is not bonded"
cJailingImminentThreshold = time.Second * 30
defaultKeepAliveDuration = 5 * time.Minute
)

type keepAliveData struct {
Expand All @@ -28,10 +25,7 @@ type keepAliveData struct {

func (k Keeper) KeepValidatorAlive(ctx sdk.Context, valAddr sdk.ValAddress) error {
if err := k.CanAcceptValidator(ctx, valAddr); err != nil {
// Make sure we allow validators to keep alive even if jailed
// or not bonded.
// https://github.com/VolumeFi/paloma/issues/254
if whoops.Is(err, ErrValidatorWithAddrNotFound) {
if !errors.Is(err, ErrValidatorNotInKeepAlive) {
return err
}
}
Expand Down Expand Up @@ -63,18 +57,12 @@ func (k Keeper) ValidatorAliveUntil(ctx sdk.Context, valAddr sdk.ValAddress) (ti
if !store.Has(valAddr) {
return time.Time{}, ErrValidatorNotInKeepAlive.Format(valAddr)
}

dataBz := store.Get(valAddr)
var data keepAliveData
err := json.Unmarshal(dataBz, &data)
if err != nil {
return time.Time{}, err
}

if data.AliveUntil.UTC().Sub(ctx.BlockTime().UTC()) < cJailingImminentThreshold {
k.Logger(ctx).Info("Validator TTL is about to run out. Jailing is imminent.", "validator-address", data.ValAddr)
}

return data.AliveUntil, nil
}

Expand All @@ -86,11 +74,11 @@ func (k Keeper) CanAcceptValidator(ctx sdk.Context, valAddr sdk.ValAddress) erro
}

if stakingVal.IsJailed() {
return ErrValidatorCannotBePigeon.Format(valAddr.String()).WrapS(cValidatorJailedErrorMessage)
return ErrValidatorCannotBePigeon.Format(valAddr.String()).WrapS("validator is jailed")
}

if !stakingVal.IsBonded() {
return ErrValidatorCannotBePigeon.Format(valAddr.String()).WrapS(cValidatorNotBondedErrorMessage)
return ErrValidatorCannotBePigeon.Format(valAddr.String()).WrapS("validator is not bonded")
}

return nil
Expand Down
12 changes: 3 additions & 9 deletions x/valset/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package valset
import (
"encoding/json"
"fmt"
"time"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -20,13 +19,10 @@ import (
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
nextJailTick = time.Now().UTC().Add(cJailTickInterval)
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
)

const cJailTickInterval = time.Minute

// ----------------------------------------------------------------------------
// AppModuleBasic
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -168,12 +164,10 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val
}
}

if ctx.BlockHeight() > 50 && time.Now().UTC().After(nextJailTick) {
if ctx.BlockHeight() > 50 && ctx.BlockHeight()%10 == 0 {
if err := am.keeper.JailInactiveValidators(ctx); err != nil {
am.keeper.Logger(ctx).Error("error while jailing inactive validators", "error", err)
}

nextJailTick = time.Now().UTC().Add(cJailTickInterval)
}
return []abci.ValidatorUpdate{}
}

0 comments on commit d7eeb7d

Please sign in to comment.