-
Notifications
You must be signed in to change notification settings - Fork 115
/
keys.go
140 lines (108 loc) · 4.83 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package types
import (
"encoding/binary"
time "time"
sdk "github.com/cosmos/cosmos-sdk/types"
utils "github.com/cosmos/interchain-security/x/ccv/utils"
)
const (
// ModuleName defines the CCV consumer module name
ModuleName = "ccvconsumer"
// StoreKey is the store key string for IBC consumer
StoreKey = ModuleName
// RouterKey is the message route for IBC consumer
RouterKey = ModuleName
// QuerierRoute is the querier route for IBC consumer
QuerierRoute = ModuleName
// ConsumerRedistributeName the root string for the consumer-redistribution account address
ConsumerRedistributeName = "cons_redistribute"
// ConsumerToSendToProviderName is a "buffer" address for outgoing fees to be transferred to the provider chain
ConsumerToSendToProviderName = "cons_to_send_to_provider"
)
// Iota generated keys/key prefixes (as a byte), supports 256 possible values
const (
// PortByteKey defines the byte key to store the port ID in store
PortByteKey byte = iota
// LastDistributionTransmissionByteKey defines the byte key to store the last distribution transmission
LastDistributionTransmissionByteKey
// UnbondingTimeKeyString is the byte key for storing the unbonding period
UnbondingTimeByteKey
// ProviderClientKeyString is the byte key for storing the clientID of the provider client
ProviderClientByteKey
// ProviderChannelKeyString is the byte key for storing the channelID of the CCV channel
ProviderChannelByteKey
// PendingChangesKeyString is the byte key that will store any pending validator set changes
// received over CCV channel but not yet flushed over ABCI
PendingChangesByteKey
// HistoricalInfoKey is the byte prefix that will store the historical info for a given height
HistoricalInfoBytePrefix
// PacketMaturityTimePrefix is the byte prefix that will store maturity time for each received VSC packet
PacketMaturityTimeBytePrefix
// HeightValsetUpdateIDPrefix is the byte prefix that will store the mapping from block height to valset update ID
HeightValsetUpdateIDBytePrefix
// OutstandingDowntimePrefix is the byte prefix that will store the validators outstanding downtime by consensus address
OutstandingDowntimeBytePrefix
// PendingDataPacketsBytePrefix is the byte prefix for storing
// a list of data packets that cannot be sent yet to the provider
// chain either because the CCV channel is not established or
// because the client is expired
PendingDataPacketsBytePrefix
// CrossChainValidatorPrefix is the byte prefix that will store cross-chain validators by consensus address
CrossChainValidatorBytePrefix
)
// PortKey returns the key to the port ID in the store
func PortKey() []byte {
return []byte{PortByteKey}
}
// LastDistributionTransmissionKey returns the key to the last distribution transmission in the store
func LastDistributionTransmissionKey() []byte {
return []byte{LastDistributionTransmissionByteKey}
}
// UnbondingTimeKey returns the key for storing the unbonding period
func UnbondingTimeKey() []byte {
return []byte{UnbondingTimeByteKey}
}
// ProviderClientIDKey returns the key for storing clientID of the provider
func ProviderClientIDKey() []byte {
return []byte{ProviderClientByteKey}
}
// ProviderChannelKey returns the key for storing channelID of the provider chain
func ProviderChannelKey() []byte {
return []byte{ProviderChannelByteKey}
}
// PendingChangesKey returns the key for storing pending validator set changes
func PendingChangesKey() []byte {
return []byte{PendingChangesByteKey}
}
// PacketMaturityTimeKey returns the key for storing the maturity time for a given received VSC packet id
func PacketMaturityTimeKey(vscID uint64, maturityTime time.Time) []byte {
ts := uint64(maturityTime.UTC().UnixNano())
return utils.AppendMany(
// Append the prefix
[]byte{PacketMaturityTimeBytePrefix},
// Append the time
sdk.Uint64ToBigEndian(ts),
// Append the vscID
sdk.Uint64ToBigEndian(vscID),
)
}
// HeightValsetUpdateIDKey returns the key to a valset update ID for a given block height
func HeightValsetUpdateIDKey(height uint64) []byte {
hBytes := make([]byte, 8)
binary.BigEndian.PutUint64(hBytes, height)
return append([]byte{HeightValsetUpdateIDBytePrefix}, hBytes...)
}
// OutstandingDowntimeKey returns the key to a validators' outstanding downtime by consensus address
func OutstandingDowntimeKey(address sdk.ConsAddress) []byte {
return append([]byte{OutstandingDowntimeBytePrefix}, address.Bytes()...)
}
// CrossChainValidatorKey returns the key to a cross chain validator by consensus address
func CrossChainValidatorKey(addr []byte) []byte {
return append([]byte{CrossChainValidatorBytePrefix}, addr...)
}
// HistoricalInfoKey returns the key to historical info to a given block height
func HistoricalInfoKey(height int64) []byte {
hBytes := make([]byte, 8)
binary.BigEndian.PutUint64(hBytes, uint64(height))
return append([]byte{HistoricalInfoBytePrefix}, hBytes...)
}