diff --git a/keeper/staking_hooks.go b/keeper/staking_hooks.go index f8241b1..2939657 100644 --- a/keeper/staking_hooks.go +++ b/keeper/staking_hooks.go @@ -37,7 +37,6 @@ func (h Hooks) BeforeValidatorModified(ctx context.Context, valAddr sdk.ValAddre return nil } - // we increase by 5 for when we actually check this in the end blocker return h.k.CheckForJailedValidators.Set(ctx, valAddr.String(), sdkCtx.BlockHeight()) } diff --git a/module/abci.go b/module/abci.go index 304e6ab..693eae6 100644 --- a/module/abci.go +++ b/module/abci.go @@ -11,9 +11,9 @@ import ( ) func (am AppModule) EndBlocker(ctx context.Context) error { - if err := am.handleBeforeJailedValidators(ctx); err != nil { - return err - } + // if err := am.handleBeforeJailedValidators(ctx); err != nil { + // return err + // } return nil } @@ -89,95 +89,3 @@ func (am AppModule) BeginBlocker(ctx context.Context) error { return nil } - -func (am AppModule) handleBeforeJailedValidators(ctx context.Context) error { - sk := am.keeper.GetStakingKeeper() - sdkCtx := sdk.UnwrapSDKContext(ctx) - curHeight := sdkCtx.BlockHeight() - bt := sdkCtx.BlockTime() - logger := am.keeper.Logger() - - iterator, err := am.keeper.CheckForJailedValidators.Iterate(ctx, nil) - if err != nil { - return err - } - defer iterator.Close() - - // Why? we don't want it in the store w/ the val state change in x/staking - for ; iterator.Valid(); iterator.Next() { - valOperAddr, err := iterator.Key() - if err != nil { - return err - } - - height, err := iterator.Value() - if err != nil { - return err - } - - // .Error for viewability - logger.Error("EndBlocker BeforeJailedValidators", "operator", valOperAddr, "height", height) - - valAddr, err := sk.ValidatorAddressCodec().StringToBytes(valOperAddr) - if err != nil { - return err - } - - val, err := sk.GetValidator(ctx, valAddr) - if err != nil { - return err - } - - consBz, err := val.GetConsAddr() - if err != nil { - return err - } - - si, err := am.keeper.GetSlashingKeeper().GetValidatorSigningInfo(ctx, consBz) - if err != nil { - return err - } - - if height == curHeight { - // if si.JailedUntil.After(bt) is false, then we remove from the keeper store (false positive for the val modification wrt jailing from staking hook) - if !si.JailedUntil.After(bt) { - logger.Error("EndBlocker BeforeJailedValidators validator was not jailed, removing from cache", - "height", height, "blockHeight", curHeight, "si.JailedUntil", si.JailedUntil, "block_time", bt, "operator", valOperAddr, - ) - if err := am.keeper.CheckForJailedValidators.Remove(ctx, valOperAddr); err != nil { - return err - } - - continue - } - - logger.Error("handleBeforeJailedValidators deleting jailed validator", "height", height, "blockHeight", curHeight) - - if err := sk.DeleteValidatorByPowerIndex(ctx, val); err != nil { - return err - } - if err := sk.DeleteLastValidatorPower(ctx, valAddr); err != nil { - return err - } - - val.Jailed = false - if err := sk.SetValidator(ctx, val); err != nil { - return err - } - } else if height+2 == curHeight { - // Why is staking / slashing not handling this for us anyways? - logger.Error("handleBeforeJailedValidators setting val to jailed", "height", height, "blockHeight", curHeight) - - val.Jailed = true - if err := sk.SetValidator(ctx, val); err != nil { - return err - } - - if err := am.keeper.CheckForJailedValidators.Remove(ctx, valOperAddr); err != nil { - return err - } - } - } - - return nil -}