Skip to content

Commit

Permalink
feat: reduce validator in queue order
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code committed Nov 1, 2023
1 parent 52cae60 commit f010a55
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions x/staking/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,25 @@ import (
fxstakingtypes "github.com/functionx/fx-core/v6/x/staking/types"
)

var validatorExistQueue = []sdk.ValAddress{}

func (k Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate {
if ctx.BlockHeight()%2000 == 0 && len(ctx.VoteInfos()) > 5 {
for _, valAddress := range validatorExistQueue {
validator, found := k.GetValidator(ctx, valAddress)
if !found || validator.GetStatus() != types.Bonded {
continue
}
operator := validator.GetOperator()
delegation := k.Delegation(ctx, operator.Bytes(), operator)
_, err := k.Undelegate(ctx, operator.Bytes(), operator, delegation.GetShares())
if err != nil {
k.Logger(ctx).Error("undelegate error", "operator", operator.String(), "shares", delegation.GetShares().String(), "error", err.Error())
}
break
}
}

// staking EndBlocker
valUpdates := staking.EndBlocker(ctx, k.Keeper)

Expand Down

0 comments on commit f010a55

Please sign in to comment.