2018-05-23 13:25:56 -07:00
|
|
|
package slashing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
abci "github.com/tendermint/abci/types"
|
2018-05-30 20:43:54 -07:00
|
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
2018-05-23 13:25:56 -07:00
|
|
|
)
|
|
|
|
|
2018-06-04 16:42:01 -07:00
|
|
|
// slashing begin block functionality
|
2018-06-01 14:24:48 -07:00
|
|
|
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) (tags sdk.Tags) {
|
|
|
|
// Tag the height
|
|
|
|
heightBytes := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(heightBytes, uint64(req.Header.Height))
|
|
|
|
tags = sdk.NewTags("height", heightBytes)
|
|
|
|
|
|
|
|
// Deal with any equivocation evidence
|
|
|
|
for _, evidence := range req.ByzantineValidators {
|
2018-06-04 16:42:01 -07:00
|
|
|
pk, err := tmtypes.PB2TM.PubKey(evidence.Validator.PubKey)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-06-01 14:24:48 -07:00
|
|
|
switch string(evidence.Type) {
|
2018-06-04 16:42:01 -07:00
|
|
|
case tmtypes.ABCIEvidenceTypeDuplicateVote:
|
2018-06-01 14:24:48 -07:00
|
|
|
sk.handleDoubleSign(ctx, evidence.Height, evidence.Time, pk)
|
|
|
|
default:
|
2018-06-13 12:13:22 -07:00
|
|
|
ctx.Logger().With("module", "x/slashing").Error(fmt.Sprintf("ignored unknown evidence type: %s", string(evidence.Type)))
|
2018-05-23 13:25:56 -07:00
|
|
|
}
|
|
|
|
}
|
2018-06-01 14:24:48 -07:00
|
|
|
|
2018-06-04 16:42:01 -07:00
|
|
|
// Iterate over all the validators which *should* have signed this block
|
|
|
|
for _, validator := range req.Validators {
|
|
|
|
present := validator.SignedLastBlock
|
|
|
|
pubkey, err := tmtypes.PB2TM.PubKey(validator.Validator.PubKey)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2018-06-01 14:24:48 -07:00
|
|
|
}
|
|
|
|
sk.handleValidatorSignature(ctx, pubkey, present)
|
2018-06-04 16:42:01 -07:00
|
|
|
}
|
|
|
|
|
2018-06-01 14:24:48 -07:00
|
|
|
return
|
2018-05-23 13:25:56 -07:00
|
|
|
}
|