2018-08-31 17:01:23 -07:00
|
|
|
package slashing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-10-05 10:56:17 -07:00
|
|
|
stake "github.com/cosmos/cosmos-sdk/x/stake/types"
|
2018-08-31 17:01:23 -07:00
|
|
|
)
|
|
|
|
|
2018-12-19 11:58:30 -08:00
|
|
|
const (
|
|
|
|
// StoreKey is the store key string for slashing
|
|
|
|
StoreKey = "slashing"
|
|
|
|
|
|
|
|
// RouterKey is the message route for slashing
|
|
|
|
RouterKey = "slashing"
|
|
|
|
|
|
|
|
// QuerierRoute is the querier route for slashing
|
|
|
|
QuerierRoute = "slashing"
|
|
|
|
)
|
|
|
|
|
2018-08-31 17:01:23 -07:00
|
|
|
// key prefix bytes
|
|
|
|
var (
|
2018-10-15 12:20:37 -07:00
|
|
|
ValidatorSigningInfoKey = []byte{0x01} // Prefix for signing info
|
|
|
|
ValidatorMissedBlockBitArrayKey = []byte{0x02} // Prefix for missed block bit array
|
|
|
|
ValidatorSlashingPeriodKey = []byte{0x03} // Prefix for slashing period
|
|
|
|
AddrPubkeyRelationKey = []byte{0x04} // Prefix for address-pubkey relation
|
2018-08-31 17:01:23 -07:00
|
|
|
)
|
|
|
|
|
2018-09-08 01:44:58 -07:00
|
|
|
// stored by *Tendermint* address (not operator address)
|
2018-08-31 17:01:23 -07:00
|
|
|
func GetValidatorSigningInfoKey(v sdk.ConsAddress) []byte {
|
|
|
|
return append(ValidatorSigningInfoKey, v.Bytes()...)
|
|
|
|
}
|
|
|
|
|
2018-11-08 16:28:28 -08:00
|
|
|
// extract the address from a validator signing info key
|
|
|
|
func GetValidatorSigningInfoAddress(key []byte) (v sdk.ConsAddress) {
|
|
|
|
addr := key[1:]
|
|
|
|
if len(addr) != sdk.AddrLen {
|
|
|
|
panic("unexpected key length")
|
|
|
|
}
|
|
|
|
return sdk.ConsAddress(addr)
|
|
|
|
}
|
|
|
|
|
2018-09-08 01:44:58 -07:00
|
|
|
// stored by *Tendermint* address (not operator address)
|
2018-10-15 12:20:37 -07:00
|
|
|
func GetValidatorMissedBlockBitArrayPrefixKey(v sdk.ConsAddress) []byte {
|
|
|
|
return append(ValidatorMissedBlockBitArrayKey, v.Bytes()...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// stored by *Tendermint* address (not operator address)
|
|
|
|
func GetValidatorMissedBlockBitArrayKey(v sdk.ConsAddress, i int64) []byte {
|
2018-08-31 17:01:23 -07:00
|
|
|
b := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(b, uint64(i))
|
2018-10-15 12:20:37 -07:00
|
|
|
return append(GetValidatorMissedBlockBitArrayPrefixKey(v), b...)
|
2018-08-31 17:01:23 -07:00
|
|
|
}
|
|
|
|
|
2018-09-08 01:44:58 -07:00
|
|
|
// stored by *Tendermint* address (not operator address)
|
2018-08-31 17:01:23 -07:00
|
|
|
func GetValidatorSlashingPeriodPrefix(v sdk.ConsAddress) []byte {
|
|
|
|
return append(ValidatorSlashingPeriodKey, v.Bytes()...)
|
|
|
|
}
|
|
|
|
|
2018-09-08 01:44:58 -07:00
|
|
|
// stored by *Tendermint* address (not operator address) followed by start height
|
2018-08-31 17:01:23 -07:00
|
|
|
func GetValidatorSlashingPeriodKey(v sdk.ConsAddress, startHeight int64) []byte {
|
|
|
|
b := make([]byte, 8)
|
2018-10-05 10:56:17 -07:00
|
|
|
// this needs to be height + ValidatorUpdateDelay because the slashing period for genesis validators starts at height -ValidatorUpdateDelay
|
|
|
|
binary.BigEndian.PutUint64(b, uint64(startHeight+stake.ValidatorUpdateDelay))
|
2018-08-31 17:01:23 -07:00
|
|
|
return append(GetValidatorSlashingPeriodPrefix(v), b...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getAddrPubkeyRelationKey(address []byte) []byte {
|
|
|
|
return append(AddrPubkeyRelationKey, address...)
|
|
|
|
}
|