2019-06-05 16:26:17 -07:00
|
|
|
package types
|
2018-08-31 17:01:23 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2018-12-19 11:58:30 -08:00
|
|
|
const (
|
2019-07-19 06:43:38 -07:00
|
|
|
// ModuleName is the name of the module
|
2019-06-05 16:26:17 -07:00
|
|
|
ModuleName = "slashing"
|
|
|
|
|
2018-12-19 11:58:30 -08:00
|
|
|
// StoreKey is the store key string for slashing
|
2019-02-07 17:41:23 -08:00
|
|
|
StoreKey = ModuleName
|
2018-12-19 11:58:30 -08:00
|
|
|
|
|
|
|
// RouterKey is the message route for slashing
|
2019-02-07 17:41:23 -08:00
|
|
|
RouterKey = ModuleName
|
2018-12-19 11:58:30 -08:00
|
|
|
|
|
|
|
// QuerierRoute is the querier route for slashing
|
2019-02-07 17:41:23 -08:00
|
|
|
QuerierRoute = ModuleName
|
2018-12-19 11:58:30 -08:00
|
|
|
)
|
|
|
|
|
2019-06-28 11:20:36 -07:00
|
|
|
// Keys for slashing store
|
|
|
|
// Items are stored with the following key: values
|
|
|
|
//
|
|
|
|
// - 0x01<consAddress_Bytes>: ValidatorSigningInfo
|
|
|
|
//
|
|
|
|
// - 0x02<consAddress_Bytes><period_Bytes>: bool
|
|
|
|
//
|
|
|
|
// - 0x03<accAddr_Bytes>: crypto.PubKey
|
2018-08-31 17:01:23 -07:00
|
|
|
var (
|
2020-05-13 14:23:00 -07:00
|
|
|
ValidatorSigningInfoKeyPrefix = []byte{0x01} // Prefix for signing info
|
|
|
|
ValidatorMissedBlockBitArrayKeyPrefix = []byte{0x02} // Prefix for missed block bit array
|
|
|
|
AddrPubkeyRelationKeyPrefix = []byte{0x03} // Prefix for address-pubkey relation
|
2018-08-31 17:01:23 -07:00
|
|
|
)
|
|
|
|
|
2020-05-13 14:23:00 -07:00
|
|
|
// ValidatorSigningInfoKey - stored by *Consensus* address (not operator address)
|
|
|
|
func ValidatorSigningInfoKey(v sdk.ConsAddress) []byte {
|
|
|
|
return append(ValidatorSigningInfoKeyPrefix, v.Bytes()...)
|
2018-08-31 17:01:23 -07:00
|
|
|
}
|
|
|
|
|
2020-05-13 14:23:00 -07:00
|
|
|
// ValidatorSigningInfoAddress - extract the address from a validator signing info key
|
|
|
|
func ValidatorSigningInfoAddress(key []byte) (v sdk.ConsAddress) {
|
2018-11-08 16:28:28 -08:00
|
|
|
addr := key[1:]
|
|
|
|
if len(addr) != sdk.AddrLen {
|
|
|
|
panic("unexpected key length")
|
|
|
|
}
|
|
|
|
return sdk.ConsAddress(addr)
|
|
|
|
}
|
|
|
|
|
2020-05-13 14:23:00 -07:00
|
|
|
// ValidatorMissedBlockBitArrayPrefixKey - stored by *Consensus* address (not operator address)
|
|
|
|
func ValidatorMissedBlockBitArrayPrefixKey(v sdk.ConsAddress) []byte {
|
|
|
|
return append(ValidatorMissedBlockBitArrayKeyPrefix, v.Bytes()...)
|
2018-10-15 12:20:37 -07:00
|
|
|
}
|
|
|
|
|
2020-05-13 14:23:00 -07:00
|
|
|
// ValidatorMissedBlockBitArrayKey - stored by *Consensus* address (not operator address)
|
|
|
|
func ValidatorMissedBlockBitArrayKey(v sdk.ConsAddress, i int64) []byte {
|
2018-08-31 17:01:23 -07:00
|
|
|
b := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(b, uint64(i))
|
2020-05-13 14:23:00 -07:00
|
|
|
return append(ValidatorMissedBlockBitArrayPrefixKey(v), b...)
|
2018-08-31 17:01:23 -07:00
|
|
|
}
|
|
|
|
|
2020-05-13 14:23:00 -07:00
|
|
|
// AddrPubkeyRelationKey gets pubkey relation key used to get the pubkey from the address
|
|
|
|
func AddrPubkeyRelationKey(address []byte) []byte {
|
|
|
|
return append(AddrPubkeyRelationKeyPrefix, address...)
|
2018-08-31 17:01:23 -07:00
|
|
|
}
|