-
Notifications
You must be signed in to change notification settings - Fork 0
/
keys.go
65 lines (53 loc) · 2.49 KB
/
keys.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package slashing
import (
"encoding/binary"
sdk "github.com/aximchain/axc-cosmos-sdk/types"
stake "github.com/aximchain/axc-cosmos-sdk/x/stake/types"
)
// key prefix bytes
var (
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
SlashRecordKey = []byte{0x05} // Prefix for slash record
)
// stored by *Tendermint* address (not operator address)
func GetValidatorSigningInfoKey(consAddr []byte) []byte {
return append(ValidatorSigningInfoKey, consAddr...)
}
// stored by *Tendermint* address (not operator address)
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 {
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, uint64(i))
return append(GetValidatorMissedBlockBitArrayPrefixKey(v), b...)
}
// stored by *Tendermint* address (not operator address)
func GetValidatorSlashingPeriodPrefix(v sdk.ConsAddress) []byte {
return append(ValidatorSlashingPeriodKey, v.Bytes()...)
}
// stored by *Tendermint* address (not operator address) followed by start height
func GetValidatorSlashingPeriodKey(v sdk.ConsAddress, startHeight int64) []byte {
b := make([]byte, 8)
// 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))
return append(GetValidatorSlashingPeriodPrefix(v), b...)
}
func getAddrPubkeyRelationKey(address []byte) []byte {
return append(AddrPubkeyRelationKey, address...)
}
func GetSlashRecordKey(consAddr []byte, infractionType byte, infractionHeight uint64) []byte {
heightBz := make([]byte, 8)
binary.BigEndian.PutUint64(heightBz, infractionHeight)
return append(GetSlashRecordsByAddrAndTypeIndexKey(consAddr, infractionType), heightBz...)
}
func GetSlashRecordsByAddrAndTypeIndexKey(sideConsAddr []byte, infractionType byte) []byte {
return append(GetSlashRecordsByAddrIndexKey(sideConsAddr), []byte{infractionType}...)
}
func GetSlashRecordsByAddrIndexKey(sideConsAddr []byte) []byte {
return append(SlashRecordKey, sideConsAddr...)
}