Skip to content

Commit

Permalink
remove all ABCI stuff, not needed. SDK handles next block now w/ patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Apr 16, 2024
1 parent 2e0ad04 commit de23fd4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 96 deletions.
1 change: 0 additions & 1 deletion keeper/staking_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
98 changes: 3 additions & 95 deletions module/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

0 comments on commit de23fd4

Please sign in to comment.