-
Notifications
You must be signed in to change notification settings - Fork 585
/
client.go
243 lines (211 loc) · 6.59 KB
/
client.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package exported
import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
proto "github.com/gogo/protobuf/proto"
)
// Status represents the status of a client
type Status string
const (
// TypeClientMisbehaviour is the shared evidence misbehaviour type
TypeClientMisbehaviour string = "client_misbehaviour"
// Solomachine is used to indicate that the light client is a solo machine.
Solomachine string = "06-solomachine"
// Tendermint is used to indicate that the client uses the Tendermint Consensus Algorithm.
Tendermint string = "07-tendermint"
// Localhost is the client type for a localhost client. It is also used as the clientID
// for the localhost client.
Localhost string = "09-localhost"
// Active is a status type of a client. An active client is allowed to be used.
Active Status = "Active"
// Frozen is a status type of a client. A frozen client is not allowed to be used.
Frozen Status = "Frozen"
// Expired is a status type of a client. An expired client is not allowed to be used.
Expired Status = "Expired"
// Unknown indicates there was an error in determining the status of a client.
Unknown Status = "Unknown"
)
// ClientState defines the required common functions for light clients.
type ClientState interface {
proto.Message
ClientType() string
GetLatestHeight() Height
Validate() error
// Initialization function
// Clients must validate the initial consensus state, and may store any client-specific metadata
// necessary for correct light client operation
Initialize(sdk.Context, codec.BinaryCodec, sdk.KVStore, ConsensusState) error
// Status function
// Clients must return their status. Only Active clients are allowed to process packets.
Status(ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryCodec) Status
// Genesis function
ExportMetadata(sdk.KVStore) []GenesisMetadata
// Update and Misbehaviour functions
CheckHeaderAndUpdateState(sdk.Context, codec.BinaryCodec, sdk.KVStore, Header) (ClientState, ConsensusState, error)
CheckMisbehaviourAndUpdateState(sdk.Context, codec.BinaryCodec, sdk.KVStore, Misbehaviour) (ClientState, error)
CheckSubstituteAndUpdateState(ctx sdk.Context, cdc codec.BinaryCodec, subjectClientStore, substituteClientStore sdk.KVStore, substituteClient ClientState) (ClientState, error)
// Upgrade functions
// NOTE: proof heights are not included as upgrade to a new revision is expected to pass only on the last
// height committed by the current revision. Clients are responsible for ensuring that the planned last
// height of the current revision is somehow encoded in the proof verification process.
// This is to ensure that no premature upgrades occur, since upgrade plans committed to by the counterparty
// may be cancelled or modified before the last planned height.
VerifyUpgradeAndUpdateState(
ctx sdk.Context,
cdc codec.BinaryCodec,
store sdk.KVStore,
newClient ClientState,
newConsState ConsensusState,
proofUpgradeClient,
proofUpgradeConsState []byte,
) (ClientState, ConsensusState, error)
// Utility function that zeroes out any client customizable fields in client state
// Ledger enforced fields are maintained while all custom fields are zero values
// Used to verify upgrades
ZeroCustomFields() ClientState
// State verification functions
VerifyClientState(
store sdk.KVStore,
cdc codec.BinaryCodec,
height Height,
prefix Prefix,
counterpartyClientIdentifier string,
proof []byte,
clientState ClientState,
) error
VerifyClientConsensusState(
store sdk.KVStore,
cdc codec.BinaryCodec,
height Height,
counterpartyClientIdentifier string,
consensusHeight Height,
prefix Prefix,
proof []byte,
consensusState ConsensusState,
) error
VerifyConnectionState(
store sdk.KVStore,
cdc codec.BinaryCodec,
height Height,
prefix Prefix,
proof []byte,
connectionID string,
connectionEnd ConnectionI,
) error
VerifyChannelState(
store sdk.KVStore,
cdc codec.BinaryCodec,
height Height,
prefix Prefix,
proof []byte,
portID,
channelID string,
channel ChannelI,
) error
VerifyPacketCommitment(
ctx sdk.Context,
store sdk.KVStore,
cdc codec.BinaryCodec,
height Height,
delayTimePeriod uint64,
delayBlockPeriod uint64,
prefix Prefix,
proof []byte,
portID,
channelID string,
sequence uint64,
commitmentBytes []byte,
) error
VerifyPacketAcknowledgement(
ctx sdk.Context,
store sdk.KVStore,
cdc codec.BinaryCodec,
height Height,
delayTimePeriod uint64,
delayBlockPeriod uint64,
prefix Prefix,
proof []byte,
portID,
channelID string,
sequence uint64,
acknowledgement []byte,
) error
VerifyPacketReceiptAbsence(
ctx sdk.Context,
store sdk.KVStore,
cdc codec.BinaryCodec,
height Height,
delayTimePeriod uint64,
delayBlockPeriod uint64,
prefix Prefix,
proof []byte,
portID,
channelID string,
sequence uint64,
) error
VerifyNextSequenceRecv(
ctx sdk.Context,
store sdk.KVStore,
cdc codec.BinaryCodec,
height Height,
delayTimePeriod uint64,
delayBlockPeriod uint64,
prefix Prefix,
proof []byte,
portID,
channelID string,
nextSequenceRecv uint64,
) error
}
// ConsensusState is the state of the consensus process
type ConsensusState interface {
proto.Message
ClientType() string // Consensus kind
// GetRoot returns the commitment root of the consensus state,
// which is used for key-value pair verification.
GetRoot() Root
// GetTimestamp returns the timestamp (in nanoseconds) of the consensus state
GetTimestamp() uint64
ValidateBasic() error
}
// Misbehaviour defines counterparty misbehaviour for a specific consensus type
type Misbehaviour interface {
proto.Message
ClientType() string
GetClientID() string
ValidateBasic() error
}
// Header is the consensus state update information
type Header interface {
proto.Message
ClientType() string
GetHeight() Height
ValidateBasic() error
}
// Height is a wrapper interface over clienttypes.Height
// all clients must use the concrete implementation in types
type Height interface {
IsZero() bool
LT(Height) bool
LTE(Height) bool
EQ(Height) bool
GT(Height) bool
GTE(Height) bool
GetRevisionNumber() uint64
GetRevisionHeight() uint64
Increment() Height
Decrement() (Height, bool)
String() string
}
// GenesisMetadata is a wrapper interface over clienttypes.GenesisMetadata
// all clients must use the concrete implementation in types
type GenesisMetadata interface {
// return store key that contains metadata without clientID-prefix
GetKey() []byte
// returns metadata value
GetValue() []byte
}
// String returns the string representation of a client status.
func (s Status) String() string {
return string(s)
}