forked from cosmos/interchain-security
-
Notifications
You must be signed in to change notification settings - Fork 1
/
steps_compatibility.go
219 lines (211 loc) · 6.78 KB
/
steps_compatibility.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
package main
// Compatibility steps comprise a reduced set of actions suited to perform
// sanity checks across different ICS versions.
import (
gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types"
)
func compstepStartProviderChain() []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 compstepsStartConsumerChain(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},
TopN: 100,
},
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: gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD.String(), // breaking change in SDK: gov.ProposalStatus(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD).String(),
},
},
// not supported across major versions
// ProposedConsumerChains: &[]string{consumerName},
},
},
},
// 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: getDefaultValidators()[ValidatorID("carol")].ConsumerValPubKey,
// 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"): getDefaultValidators()[ValidatorID("carol")].ConsumerValconsAddressOnProvider,
},
ProviderKeys: &map[ValidatorID]string{
ValidatorID("carol"): getDefaultValidators()[ValidatorID("carol")].ValconsAddress,
},
},
},
},
{
// op should fail - key already assigned by another validator
Action: AssignConsumerPubKeyAction{
Chain: ChainID(consumerName),
Validator: ValidatorID("bob"),
// same pub key as carol
ConsumerPubkey: getDefaultValidators()[ValidatorID("carol")].ConsumerValPubKey,
ReconfigureNode: false,
ExpectError: true,
ExpectedError: providertypes.ErrConsumerKeyInUse.Error(),
},
State: State{
ChainID(consumerName): ChainState{
AssignedKeys: &map[ValidatorID]string{
ValidatorID("carol"): getDefaultValidators()[ValidatorID("carol")].ConsumerValconsAddressOnProvider,
ValidatorID("bob"): "",
},
ProviderKeys: &map[ValidatorID]string{
ValidatorID("carol"): getDefaultValidators()[ValidatorID("carol")].ValconsAddress,
},
},
},
},
{
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: gov.ProposalStatus_PROPOSAL_STATUS_PASSED.String(),
},
},
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},
},
},
State: State{
ChainID("provi"): ChainState{
ValBalances: &map[ValidatorID]uint{
ValidatorID("alice"): 9500000000,
ValidatorID("bob"): 9500000000,
ValidatorID("carol"): 9500000000,
},
// not supported
// ProposedConsumerChains: &[]string{},
},
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 compstepsStartChains(consumerNames []string, setupTransferChans bool) []Step {
s := compstepStartProviderChain()
for i, consumerName := range consumerNames {
s = append(s, compstepsStartConsumerChain(consumerName, uint(i+1), uint(i), setupTransferChans)...)
}
return s
}