cosmos-sdk/x/slashing/abci.go
mergify[bot] 1bc7ff528c
refactor(x/slashing): audit x/slashing changes (backport #21270) (#21279)
Co-authored-by: Julián Toledano <JulianToledano@users.noreply.github.com>
2024-08-13 22:14:05 +02:00

34 lines
1020 B
Go

package slashing
import (
"context"
"cosmossdk.io/core/comet"
"cosmossdk.io/x/slashing/keeper"
"cosmossdk.io/x/slashing/types"
"github.com/cosmos/cosmos-sdk/telemetry"
)
// BeginBlocker check for infraction evidence or downtime of validators
// on every begin block
func BeginBlocker(ctx context.Context, k keeper.Keeper, cometService comet.Service) error {
defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker)
// Retrieve CometBFT info, then iterate through all validator votes
// from the last commit. For each vote, handle the validator's signature, potentially
// slashing or unbonding validators who have missed too many blocks.
params, err := k.Params.Get(ctx)
if err != nil {
return err
}
ci := cometService.CometInfo(ctx)
for _, vote := range ci.LastCommit.Votes {
err := k.HandleValidatorSignatureWithParams(ctx, params, vote.Validator.Address, vote.Validator.Power, vote.BlockIDFlag)
if err != nil {
return err
}
}
return nil
}