-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathsteps_sovereign_changeover.go
367 lines (360 loc) · 9.94 KB
/
steps_sovereign_changeover.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
package main
import clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
// this creates new clients on both chains and a connection (connection-0) between them
// connection-0 is used to create a transfer channel between the chains
// the transfer channel is maintained during the changeover process, meaning that
// the consumer chain will be able to send rewards to the provider chain using the old channel
// as opposed to creating a new transfer channel which happens for new consumers
func stepsSovereignTransferChan() []Step {
return []Step{
{
Action: createIbcClientsAction{
ChainA: ChainID("sover"),
ChainB: ChainID("provi"),
},
State: State{},
},
{
// this will create channel-0 connection end on both chain
Action: addIbcChannelAction{
ChainA: ChainID("sover"),
ChainB: ChainID("provi"),
ConnectionA: 0,
PortA: "transfer",
PortB: "transfer",
Order: "unordered",
Version: "ics20-1",
},
State: State{},
},
}
}
// steps to convert sovereign to consumer chain
func stepsChangeoverToConsumer(consumerName string) []Step {
s := []Step{
{
Action: submitConsumerAdditionProposalAction{
PreCCV: true,
Chain: ChainID("provi"),
From: ValidatorID("alice"),
Deposit: 10000001,
ConsumerChain: ChainID(consumerName),
// chain-0 is the transfer channelID that gets created in stepsSovereignTransferChan
// the consumer chain will use this channel to send rewards to the provider chain
// there is no need to create a new channel for rewards distribution
DistributionChannel: "channel-0",
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 111}, // 1 block after upgrade !important
},
State: State{
ChainID("provi"): ChainState{
ValBalances: &map[ValidatorID]uint{
ValidatorID("alice"): 9489999999,
ValidatorID("bob"): 9500000000,
},
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID(consumerName),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 111},
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
},
},
},
},
},
{
Action: voteGovProposalAction{
Chain: ChainID("provi"),
From: []ValidatorID{ValidatorID("alice"), ValidatorID("bob"), ValidatorID("carol")},
Vote: []string{"yes", "yes", "yes"},
PropNumber: 1,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID(consumerName),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 111},
Status: "PROPOSAL_STATUS_PASSED",
},
},
ValBalances: &map[ValidatorID]uint{
ValidatorID("alice"): 9500000000,
ValidatorID("bob"): 9500000000,
},
},
},
},
{
Action: ChangeoverChainAction{
SovereignChain: ChainID(consumerName),
ProviderChain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: 500000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: 500000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 500000000, Allocation: 10000000000},
},
GenesisChanges: ".app_state.ccvconsumer.params.soft_opt_out_threshold = \"0.05\"",
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 500,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
},
ChainID(consumerName): ChainState{
ValPowers: &map[ValidatorID]uint{
// uses val powers from consumer
ValidatorID("alice"): 500,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
},
},
},
{
Action: addIbcConnectionAction{
ChainA: ChainID(consumerName),
ChainB: ChainID("provi"),
ClientA: 1,
ClientB: 1,
},
State: State{},
},
{
Action: addIbcChannelAction{
ChainA: ChainID(consumerName),
ChainB: ChainID("provi"),
ConnectionA: 1,
PortA: "consumer",
PortB: "provider",
Order: "ordered",
},
State: State{},
},
}
return s
}
// start sovereign chain with a single validator so it is easier to manage
// when the chain is converted to a consumer chain the validators from the
// consumer chain will be used
// validatoralice is the only validator on the sovereign chain that is in both
// sovereign validator set and consumer validator set
func stepRunSovereignChain() []Step {
return []Step{
{
Action: StartSovereignChainAction{
Chain: ChainID("sover"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: 500000000, Allocation: 10000000000},
},
},
State: State{
ChainID("sover"): ChainState{
ValBalances: &map[ValidatorID]uint{
ValidatorID("alice"): 9500000000,
},
},
},
},
{
Action: delegateTokensAction{
Chain: ChainID("sover"),
From: ValidatorID("alice"),
To: ValidatorID("alice"),
Amount: 11000000,
},
State: State{
ChainID("sover"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 511,
ValidatorID("bob"): 0, // does not exist on pre-ccv sover
ValidatorID("carol"): 0, // does not exist on pre-ccv sover
},
},
},
},
}
}
// TODO: use args instead of hardcoding
func stepsUpgradeChain() []Step {
return []Step{
{
Action: LegacyUpgradeProposalAction{
ChainID: ChainID("sover"),
UpgradeTitle: "sovereign-changeover",
Proposer: ValidatorID("alice"),
UpgradeHeight: 110,
},
State: State{
ChainID("sover"): ChainState{
Proposals: &map[uint]Proposal{
1: UpgradeProposal{
Title: "sovereign-changeover",
UpgradeHeight: 110,
Type: "/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal",
Deposit: 10000000,
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
},
},
},
},
},
{
Action: voteGovProposalAction{
Chain: ChainID("sover"),
From: []ValidatorID{ValidatorID("alice")},
Vote: []string{"yes"},
PropNumber: 1,
},
State: State{
ChainID("sover"): ChainState{
Proposals: &map[uint]Proposal{
1: UpgradeProposal{
Deposit: 10000000,
UpgradeHeight: 110,
Title: "sovereign-changeover",
Type: "/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal",
Status: "PROPOSAL_STATUS_PASSED",
},
},
},
},
},
{
Action: waitUntilBlockAction{
Chain: ChainID("sover"),
Block: 110,
},
State: State{},
},
}
}
// stepsPostChangeoverDelegate tests basic delegation and resulting validator power changes after changeover
// we cannot use stepsDelegate and stepsUnbond because they make assumptions about which connection to use
// here we need to use connection-1, and in tests with new consumers connection-0 is used because the chain is new (has no IBC states prior to launch)
func stepsPostChangeoverDelegate(consumerName string) []Step {
return []Step{
{
Action: SendTokensAction{
Chain: ChainID(consumerName),
From: ValidatorID("alice"),
To: ValidatorID("bob"),
Amount: 100,
},
State: State{
ChainID(consumerName): ChainState{
// Tx should not go through, ICS channel is not setup until first VSC packet has been relayed to consumer
ValBalances: &map[ValidatorID]uint{
ValidatorID("bob"): 0,
},
},
},
},
{
Action: delegateTokensAction{
Chain: ChainID("provi"),
From: ValidatorID("alice"),
To: ValidatorID("alice"),
Amount: 11000000,
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 511,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
},
ChainID(consumerName): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 500,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
},
},
},
{
Action: relayPacketsAction{
ChainA: ChainID("provi"),
ChainB: ChainID(consumerName),
Port: "provider",
Channel: 1,
},
State: State{
ChainID(consumerName): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 511,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
},
},
},
{
Action: SendTokensAction{
Chain: ChainID(consumerName),
From: ValidatorID("alice"),
To: ValidatorID("bob"),
Amount: 100,
},
State: State{
ChainID(consumerName): ChainState{
// Tx should go through, ICS channel is setup
ValBalances: &map[ValidatorID]uint{
ValidatorID("bob"): 100,
},
},
},
},
{
Action: unbondTokensAction{
Chain: ChainID("provi"),
UnbondFrom: ValidatorID("alice"),
Sender: ValidatorID("alice"),
Amount: 1000000,
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 510,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
},
ChainID(consumerName): ChainState{
ValPowers: &map[ValidatorID]uint{
// Voting power on consumer should not be affected yet
ValidatorID("alice"): 511,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
},
},
},
{
Action: relayPacketsAction{
ChainA: ChainID("provi"),
ChainB: ChainID(consumerName),
Port: "provider",
Channel: 1,
},
State: State{
ChainID(consumerName): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 510,
ValidatorID("bob"): 500,
ValidatorID("carol"): 500,
},
},
},
},
}
}