-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathsteps_start_chains.go
305 lines (298 loc) · 9.93 KB
/
steps_start_chains.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
package main
import (
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
)
func stepStartProviderChain() []Step {
return []Step{
{
Action: StartChainAction{
Chain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("bob"), Stake: 500000000, Allocation: 10000000000},
{Id: ValidatorID("alice"), Stake: 500000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 500000000, Allocation: 10000000000},
},
},
State: State{
ChainID("provi"): ChainState{
ValBalances: &map[ValidatorID]uint{
ValidatorID("alice"): 9500000000,
ValidatorID("bob"): 9500000000,
ValidatorID("carol"): 9500000000,
},
},
},
},
}
}
func stepsStartConsumerChain(consumerName string, proposalIndex, chainIndex uint, setupTransferChans bool) []Step {
s := []Step{
{
Action: submitConsumerAdditionProposalAction{
Chain: ChainID("provi"),
From: ValidatorID("alice"),
Deposit: 10000001,
ConsumerChain: ChainID(consumerName),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
},
State: State{
ChainID("provi"): ChainState{
ValBalances: &map[ValidatorID]uint{
ValidatorID("alice"): 9489999999,
ValidatorID("bob"): 9500000000,
},
Proposals: &map[uint]Proposal{
proposalIndex: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID(consumerName),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
},
},
},
},
},
// add a consumer key before the chain starts
// the key will be present in consumer genesis initial_val_set
{
Action: assignConsumerPubKeyAction{
Chain: ChainID(consumerName),
Validator: ValidatorID("carol"),
ConsumerPubkey: `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="}`,
// consumer chain has not started
// we don't need to reconfigure the node
// since it will start with consumer key
ReconfigureNode: false,
},
State: State{
ChainID(consumerName): ChainState{
AssignedKeys: &map[ValidatorID]string{
ValidatorID("carol"): "cosmosvalcons1kswr5sq599365kcjmhgufevfps9njf43e4lwdk",
},
ProviderKeys: &map[ValidatorID]string{
ValidatorID("carol"): "cosmosvalcons1ezyrq65s3gshhx5585w6mpusq3xsj3ayzf4uv6",
},
},
},
},
{
// op should fail - key already assigned by the same validator
Action: assignConsumerPubKeyAction{
Chain: ChainID(consumerName),
Validator: ValidatorID("carol"),
ConsumerPubkey: `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="}`,
ReconfigureNode: false,
ExpectError: true,
ExpectedError: "a validator has assigned the consumer key already: consumer key is already in use by a validator",
},
State: State{},
},
{
// op should fail - key already assigned by another validator
Action: assignConsumerPubKeyAction{
Chain: ChainID(consumerName),
Validator: ValidatorID("bob"),
// same pub key as carol
ConsumerPubkey: `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="}`,
ReconfigureNode: false,
ExpectError: true,
ExpectedError: "a validator has assigned the consumer key already: consumer key is already in use by a validator",
},
State: State{
ChainID(consumerName): ChainState{
AssignedKeys: &map[ValidatorID]string{
ValidatorID("carol"): "cosmosvalcons1kswr5sq599365kcjmhgufevfps9njf43e4lwdk",
ValidatorID("bob"): "",
},
ProviderKeys: &map[ValidatorID]string{
ValidatorID("carol"): "cosmosvalcons1ezyrq65s3gshhx5585w6mpusq3xsj3ayzf4uv6",
},
},
},
},
{
Action: voteGovProposalAction{
Chain: ChainID("provi"),
From: []ValidatorID{ValidatorID("alice"), ValidatorID("bob"), ValidatorID("carol")},
Vote: []string{"yes", "yes", "yes"},
PropNumber: proposalIndex,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
proposalIndex: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID(consumerName),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: "PROPOSAL_STATUS_PASSED",
},
},
ValBalances: &map[ValidatorID]uint{
ValidatorID("alice"): 9500000000,
ValidatorID("bob"): 9500000000,
},
},
},
},
{
Action: startConsumerChainAction{
ConsumerChain: ChainID(consumerName),
ProviderChain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("bob"), Stake: 500000000, Allocation: 10000000000},
{Id: ValidatorID("alice"), Stake: 500000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 500000000, Allocation: 10000000000},
},
// For consumers that're launching with the provider being on an earlier version
// of ICS before the soft opt-out threshold was introduced, we need to set the
// soft opt-out threshold to 0.05 in the consumer genesis to ensure that the
// consumer binary doesn't panic. Sdk requires that all params are set to valid
// values from the genesis file.
GenesisChanges: ".app_state.ccvconsumer.params.soft_opt_out_threshold = \"0.05\"",
},
State: State{
ChainID("provi"): ChainState{
ValBalances: &map[ValidatorID]uint{
ValidatorID("alice"): 9500000000,
ValidatorID("bob"): 9500000000,
ValidatorID("carol"): 9500000000,
},
},
ChainID(consumerName): ChainState{
ValBalances: &map[ValidatorID]uint{
ValidatorID("alice"): 10000000000,
ValidatorID("bob"): 10000000000,
ValidatorID("carol"): 10000000000,
},
},
},
},
{
Action: addIbcConnectionAction{
ChainA: ChainID(consumerName),
ChainB: ChainID("provi"),
ClientA: 0,
ClientB: chainIndex,
},
State: State{},
},
{
Action: addIbcChannelAction{
ChainA: ChainID(consumerName),
ChainB: ChainID("provi"),
ConnectionA: 0,
PortA: "consumer", // TODO: check port mapping
PortB: "provider",
Order: "ordered",
},
State: State{},
},
}
// currently only used in democracy tests
if setupTransferChans {
s = append(s, Step{
Action: transferChannelCompleteAction{
ChainA: ChainID(consumerName),
ChainB: ChainID("provi"),
ConnectionA: 0,
PortA: "transfer",
PortB: "transfer",
Order: "unordered",
ChannelA: 1,
ChannelB: 1,
},
State: State{},
})
}
return s
}
// starts provider and consumer chains specified in consumerNames
// setupTransferChans will establish a channel for fee transfers between consumer and provider
func stepsStartChains(consumerNames []string, setupTransferChans bool) []Step {
s := stepStartProviderChain()
for i, consumerName := range consumerNames {
s = append(s, stepsStartConsumerChain(consumerName, uint(i+1), uint(i), setupTransferChans)...)
}
return s
}
func stepsAssignConsumerKeyOnStartedChain(consumerName, validator string) []Step {
return []Step{
{
Action: assignConsumerPubKeyAction{
Chain: ChainID(consumerName),
Validator: ValidatorID("bob"),
// reconfigure the node -> validator was using provider key
// until this point -> key matches config.consumerValPubKey for "bob"
ConsumerPubkey: `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"QlG+iYe6AyYpvY1z9RNJKCVlH14Q/qSz4EjGdGCru3o="}`,
ReconfigureNode: true,
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
// this happens after some delegations
// so that the chain does not halt if 1/3 of power is offline
ValidatorID("alice"): 511,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
},
ChainID(consumerName): ChainState{
ValPowers: &map[ValidatorID]uint{
// this happens after some delegations
// so that the chain does not halt if 1/3 of power is offline
ValidatorID("alice"): 511,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
AssignedKeys: &map[ValidatorID]string{
ValidatorID("bob"): "cosmosvalcons1uuec3cjxajv5te08p220usrjhkfhg9wyvqn0tm",
ValidatorID("carol"): "cosmosvalcons1kswr5sq599365kcjmhgufevfps9njf43e4lwdk",
},
ProviderKeys: &map[ValidatorID]string{
ValidatorID("bob"): "cosmosvalcons1nx7n5uh0ztxsynn4sje6eyq2ud6rc6klc96w39",
ValidatorID("carol"): "cosmosvalcons1ezyrq65s3gshhx5585w6mpusq3xsj3ayzf4uv6",
},
},
},
},
{
Action: relayPacketsAction{
ChainA: ChainID("provi"),
ChainB: ChainID(consumerName),
Port: "provider",
Channel: 0,
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
// this happens after some delegations
// so that the chain does not halt if 1/3 of power is offline
ValidatorID("alice"): 511,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
},
ChainID(consumerName): ChainState{
ValPowers: &map[ValidatorID]uint{
// this happens after some delegations
// so that the chain does not halt if 1/3 of power is offline
ValidatorID("alice"): 511,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
AssignedKeys: &map[ValidatorID]string{
ValidatorID("bob"): "cosmosvalcons1uuec3cjxajv5te08p220usrjhkfhg9wyvqn0tm",
ValidatorID("carol"): "cosmosvalcons1kswr5sq599365kcjmhgufevfps9njf43e4lwdk",
},
ProviderKeys: &map[ValidatorID]string{
ValidatorID("bob"): "cosmosvalcons1nx7n5uh0ztxsynn4sje6eyq2ud6rc6klc96w39",
ValidatorID("carol"): "cosmosvalcons1ezyrq65s3gshhx5585w6mpusq3xsj3ayzf4uv6",
},
},
},
},
}
}