2019-12-02 17:58:14 -08:00
|
|
|
package evidence
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-07-17 08:34:37 -07:00
|
|
|
"time"
|
2019-12-02 17:58:14 -08:00
|
|
|
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2020-06-14 02:58:48 -07:00
|
|
|
|
2020-09-08 09:33:53 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/telemetry"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-06-14 02:58:48 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/evidence/keeper"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/evidence/types"
|
2019-12-02 17:58:14 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// BeginBlocker iterates through and handles any newly discovered evidence of
|
|
|
|
// misbehavior submitted by Tendermint. Currently, only equivocation is handled.
|
2020-06-14 02:58:48 -07:00
|
|
|
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
|
2020-07-17 12:33:50 -07:00
|
|
|
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
|
2020-06-18 11:12:44 -07:00
|
|
|
|
2019-12-02 17:58:14 -08:00
|
|
|
for _, tmEvidence := range req.ByzantineValidators {
|
|
|
|
switch tmEvidence.Type {
|
2020-09-08 09:33:53 -07:00
|
|
|
// It's still ongoing discussion how should we treat and slash attacks with
|
|
|
|
// premeditation. So for now we agree to treat them in the same way.
|
|
|
|
case abci.EvidenceType_DUPLICATE_VOTE, abci.EvidenceType_LIGHT_CLIENT_ATTACK:
|
|
|
|
evidence := types.FromABCIEvidence(tmEvidence)
|
|
|
|
k.HandleEquivocationEvidence(ctx, evidence.(*types.Equivocation))
|
2019-12-02 17:58:14 -08:00
|
|
|
|
|
|
|
default:
|
|
|
|
k.Logger(ctx).Error(fmt.Sprintf("ignored unknown evidence type: %s", tmEvidence.Type))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|