2018-05-23 13:25:56 -07:00
|
|
|
package slashing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-06-28 17:54:47 -07:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2018-05-30 20:43:54 -07:00
|
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
2018-12-10 06:27:25 -08:00
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-05-23 13:25:56 -07:00
|
|
|
)
|
|
|
|
|
2018-06-04 16:42:01 -07:00
|
|
|
// slashing begin block functionality
|
2019-04-05 13:20:58 -07:00
|
|
|
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) sdk.Tags {
|
2019-02-07 17:41:23 -08:00
|
|
|
|
|
|
|
// Iterate over all the validators which *should* have signed this block
|
2018-10-12 04:15:13 -07:00
|
|
|
// store whether or not they have actually signed it and slash/unbond any
|
2018-06-29 20:34:55 -07:00
|
|
|
// which have missed too many blocks in a row (downtime slashing)
|
2018-10-03 08:48:23 -07:00
|
|
|
for _, voteInfo := range req.LastCommitInfo.GetVotes() {
|
2019-06-05 16:26:17 -07:00
|
|
|
sk.HandleValidatorSignature(ctx, voteInfo.Validator.Address, voteInfo.Validator.Power, voteInfo.SignedLastBlock)
|
2018-06-29 20:34:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through any newly discovered evidence of infraction
|
|
|
|
// Slash any validators (and since-unbonded stake within the unbonding period)
|
|
|
|
// who contributed to valid infractions
|
2018-06-01 14:24:48 -07:00
|
|
|
for _, evidence := range req.ByzantineValidators {
|
2018-06-28 09:08:29 -07:00
|
|
|
switch evidence.Type {
|
2018-06-04 16:42:01 -07:00
|
|
|
case tmtypes.ABCIEvidenceTypeDuplicateVote:
|
2019-06-05 16:26:17 -07:00
|
|
|
sk.HandleDoubleSign(ctx, evidence.Validator.Address, evidence.Height, evidence.Time, evidence.Validator.Power)
|
2018-06-01 14:24:48 -07:00
|
|
|
default:
|
2019-04-15 20:58:06 -07:00
|
|
|
sk.Logger(ctx).Error(fmt.Sprintf("ignored unknown evidence type: %s", evidence.Type))
|
2018-05-23 13:25:56 -07:00
|
|
|
}
|
|
|
|
}
|
2018-06-01 14:24:48 -07:00
|
|
|
|
2019-04-05 13:20:58 -07:00
|
|
|
return sdk.EmptyTags()
|
2018-05-23 13:25:56 -07:00
|
|
|
}
|