forked from cosmos/interchain-security
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsteps_inactive_vals.go
973 lines (960 loc) · 31 KB
/
steps_inactive_vals.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
package main
import (
gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
)
// stepsInactiveValidatorsOnConsumer tests situations where validators that are *not* in the active set on the
// provider chain validate on the consumer chain.
// The provider chain is set to have at most *2* validators active in consensus, and there are 3 validators in total.
// high-level, this test does:
// - start the provider chain
// - start a consumer chain
// - check that non-consensus validators do not get slashed for downtime on the provider; and that they don't get rewards
// - check that active validators *do* get slashed for downtime on the provider, and don't get rewards while they are down
// - check that non-consensus validators *do* get jailed for consumer downtime on the provider
// - check that non-consensus validators *become* consensus validators when they have enough power
func stepsInactiveProviderValidators() []Step {
s := concatSteps(
[]Step{
{
Action: StartChainAction{
Chain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: 100000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: 200000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 300000000, Allocation: 10000000000},
},
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0, // max consensus validators is 2, so alice should not be in power
ValidatorID("bob"): 200,
ValidatorID("carol"): 300,
},
StakedTokens: &map[ValidatorID]uint{
ValidatorID("alice"): 100000000,
ValidatorID("bob"): 200000000,
ValidatorID("carol"): 300000000,
},
Rewards: &Rewards{
Denom: "stake", // check for rewards in the provider denom
IsIncrementalReward: true, // we need to get incremental rewards
// if we would look at total rewards, alice would trivially also get rewards,
// because she gets rewards in the first block due to being in the genesis
IsRewarded: map[ValidatorID]bool{
ValidatorID("alice"): false,
ValidatorID("bob"): true,
ValidatorID("carol"): true,
},
},
},
},
},
},
setupOptInChain(),
[]Step{
// check that active-but-not-consensus validators do not get slashed for downtime
{
// alices provider node goes offline
Action: DowntimeSlashAction{
Chain: ChainID("provi"),
Validator: ValidatorID("alice"),
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0, // still 0 consensus power
ValidatorID("bob"): 200,
ValidatorID("carol"): 300,
},
StakedTokens: &map[ValidatorID]uint{
ValidatorID("alice"): 100000000, // but alice does not get jailed or slashed
ValidatorID("bob"): 200000000,
ValidatorID("carol"): 300000000,
},
},
},
},
// give carol more power so that she has enough power to validate if bob goes down
{
Action: DelegateTokensAction{
Chain: ChainID("provi"),
From: ValidatorID("carol"),
To: ValidatorID("carol"),
Amount: 700000000, // carol needs to have more than 2/3rds of power(alice) + power(carol) + power(bob) to run both chains alone, so we stake some more to her
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0,
ValidatorID("bob"): 200,
ValidatorID("carol"): 1000,
},
StakedTokens: &map[ValidatorID]uint{
ValidatorID("alice"): 100000000,
ValidatorID("bob"): 200000000,
ValidatorID("carol"): 1000000000,
},
// check that bob and carol get rewards, but alice does not
Rewards: &Rewards{
Denom: "stake", // check for rewards in the provider denom
IsIncrementalReward: true, // check rewards since block 1
IsRewarded: map[ValidatorID]bool{
ValidatorID("alice"): false,
ValidatorID("bob"): true,
ValidatorID("carol"): true,
},
},
},
},
},
// bob goes offline
{
Action: DowntimeSlashAction{
Chain: ChainID("provi"),
Validator: ValidatorID("bob"),
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 100, // alice gets into the active set
ValidatorID("bob"): 0, // bob is jailed
ValidatorID("carol"): 1000,
},
StakedTokens: &map[ValidatorID]uint{
ValidatorID("alice"): 100000000,
ValidatorID("bob"): 198000000, // 1% slash
ValidatorID("carol"): 1000000000,
},
},
},
},
{
// relay packets so that the consumer gets up to date with the provider
Action: RelayPacketsAction{
ChainA: ChainID("provi"),
ChainB: ChainID("consu"),
Port: "provider",
Channel: 0,
},
State: State{
ChainID("provi"): ChainState{
Rewards: &Rewards{
Denom: "stake", // check for rewards in the provider denom
IsIncrementalReward: true, // check rewards for currently produced blocks only
IsRewarded: map[ValidatorID]bool{
ValidatorID("alice"): true, // alice is participating right now, so gets rewards
ValidatorID("bob"): false, // bob does not get rewards since he is not participating in consensus
ValidatorID("carol"): true,
},
},
},
ChainID("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 100,
ValidatorID("bob"): 0,
ValidatorID("carol"): 1000,
},
},
},
},
// unjail bob
{
Action: UnjailValidatorAction{
Provider: ChainID("provi"),
Validator: ValidatorID("bob"),
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0, // alice is back out because only 2 validators can be active in consensus
ValidatorID("bob"): 198, // bob was slashed 1%
ValidatorID("carol"): 1000,
},
// check that between two blocks now, alice does not get rewarded with the native denom
Rewards: &Rewards{
Denom: "stake", // check for rewards in the provider denom
IsIncrementalReward: true, // check rewards for currently produced blocks only
IsRewarded: map[ValidatorID]bool{
ValidatorID("alice"): false,
ValidatorID("bob"): true,
ValidatorID("carol"): true,
},
},
},
// bob is still at 0 power on the consumer chain
ChainID("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 100,
ValidatorID("bob"): 0,
ValidatorID("carol"): 1000,
},
},
},
},
// relay packets so that the consumer gets up to date with the provider
{
Action: RelayPacketsAction{
ChainA: ChainID("provi"),
ChainB: ChainID("consu"),
Port: "provider",
Channel: 0,
},
State: State{
ChainID("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 100,
ValidatorID("bob"): 198,
ValidatorID("carol"): 1000,
},
},
},
},
// alice goes offline on the consumer chain
{
Action: DowntimeSlashAction{
Chain: ChainID("consu"),
Validator: ValidatorID("alice"),
},
State: State{
ChainID("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 100, // power not affected yet
ValidatorID("bob"): 198,
ValidatorID("carol"): 1000,
},
},
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0, // alice is not consensus-active anyways, since we allow two vals at maximum
ValidatorID("bob"): 198,
ValidatorID("carol"): 1000,
},
},
},
},
// relay the packets so that the provider chain knows about alice's downtime
{
Action: RelayPacketsAction{
ChainA: ChainID("consu"),
ChainB: ChainID("provi"),
Port: "consumer",
Channel: 0,
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0, // alice is still not in the active set, and should now be jailed too.
// we cannot test directly whether alice is jailed, but we will test this below
ValidatorID("bob"): 198,
ValidatorID("carol"): 1000,
},
},
},
},
// we need to double-check that alice is actually jailed, so we get bob jailed, too, which usually would mean alice gets into power
{
Action: DowntimeSlashAction{
Chain: ChainID("provi"),
Validator: ValidatorID("bob"),
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0, // alice is jailed
ValidatorID("bob"): 0, // bob is jailed
ValidatorID("carol"): 1000,
},
},
},
},
// relay the packets so that the consumer chain is in sync again
{
Action: RelayPacketsAction{
ChainA: ChainID("provi"),
ChainB: ChainID("consu"),
Port: "provider",
Channel: 0,
},
State: State{
ChainID("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0, // alice is jailed
ValidatorID("bob"): 0, // bob is jailed
ValidatorID("carol"): 1000,
},
},
},
},
// unjail alice
{
Action: UnjailValidatorAction{
Provider: ChainID("provi"),
Validator: ValidatorID("alice"),
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
// alice was not slashed because consumer downtime just jails without slashing tokens
ValidatorID("alice"): 100, // alice is back as an active consensus validator.
ValidatorID("bob"): 0, // bob is still jailed
ValidatorID("carol"): 1000,
},
},
},
},
// unjail bob
{
Action: UnjailValidatorAction{
Provider: ChainID("provi"),
Validator: ValidatorID("bob"),
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0, // alice is back out because only 2 validators can be active in consensus
ValidatorID("bob"): 196, // bob is back as an active consensus validator and lost 2 more power due to the second downtime
ValidatorID("carol"): 1000,
},
},
},
},
// relay the packets so that the consumer chain is in sync again
{
Action: RelayPacketsAction{
ChainA: ChainID("provi"),
ChainB: ChainID("consu"),
Port: "provider",
Channel: 0,
},
State: State{
ChainID("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 100, // both alice and bob are validating the consumer
ValidatorID("bob"): 196,
ValidatorID("carol"): 1000,
},
},
},
},
},
)
return s
}
// Precondition: The provider chain is running.
// Postcondition: A consumer chain with Top N = 0 is running, including an up-and-running IBC connection to the provider.
// "alice", "bob", "carol" have opted in and are validating.
func setupOptInChain() []Step {
return concatSteps([]Step{
{
Action: SubmitConsumerAdditionProposalAction{
Chain: ChainID("provi"),
From: ValidatorID("alice"),
Deposit: 10000001,
ConsumerChain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
TopN: 0,
AllowInactiveVals: true,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD.String(),
},
},
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {},
ValidatorID("bob"): {},
ValidatorID("carol"): {},
},
},
},
},
},
stepsOptInValidators("alice", "bob", "carol"),
[]Step{
{
Action: VoteGovProposalAction{
Chain: ChainID("provi"),
From: []ValidatorID{ValidatorID("alice"), ValidatorID("bob")},
Vote: []string{"yes", "yes"},
PropNumber: 1,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: gov.ProposalStatus_PROPOSAL_STATUS_PASSED.String(),
},
},
},
},
},
{
// we start all the validators but only "alice" and "bob" have opted in and hence
// only "alice" and "bob" are validating blocks
Action: StartConsumerChainAction{
ConsumerChain: ChainID("consu"),
ProviderChain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: 100000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: 200000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 300000000, 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("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 100,
ValidatorID("bob"): 200,
ValidatorID("carol"): 300,
},
},
},
},
{
Action: AddIbcConnectionAction{
ChainA: ChainID("consu"),
ChainB: ChainID("provi"),
ClientA: 0,
ClientB: 0,
},
State: State{},
},
{
Action: AddIbcChannelAction{
ChainA: ChainID("consu"),
ChainB: ChainID("provi"),
ConnectionA: 0,
PortA: "consumer",
PortB: "provider",
Order: "ordered",
},
State: State{},
},
},
)
}
func stepsOptInValidators(validators ...ValidatorID) []Step {
s := make([]Step, 0)
for _, val := range validators {
// Οpt in all validators
s = append(s, Step{
Action: OptInAction{
Chain: ChainID("consu"),
Validator: val,
},
State: State{
ChainID("provi"): ChainState{},
},
},
)
}
return s
}
// stepsInactiveProviderValidatorsGovernance validates that inactive validators
// are not included in the calculation of the quorum for governance proposals.
// It checks that when the quorum is met *among active validators*,
// the proposal can pass, even though the quorum would not be met if inactive validators
// would be counted.
func stepsInactiveProviderValidatorsGovernance() []Step {
s := concatSteps(
[]Step{
{
Action: StartChainAction{
Chain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: 290000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: 290000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 300000000, Allocation: 10000000000},
},
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0, // max consensus validators is 1, so alice and bob should not be in power
ValidatorID("bob"): 0,
ValidatorID("carol"): 300,
},
StakedTokens: &map[ValidatorID]uint{
ValidatorID("alice"): 290000000,
ValidatorID("bob"): 290000000,
ValidatorID("carol"): 300000000,
},
},
},
},
},
[]Step{
// create a governance proposal
{
Action: SubmitConsumerAdditionProposalAction{
Chain: ChainID("provi"),
From: ValidatorID("alice"),
Deposit: 10000001,
ConsumerChain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
TopN: 51,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD.String(),
},
},
},
},
},
// vote for it with carol
{
Action: VoteGovProposalAction{
Chain: ChainID("provi"),
From: []ValidatorID{ValidatorID("carol")},
Vote: []string{"yes"},
PropNumber: 1,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
// the proposal should have passed because carol voted for it.
// carol alone is enough to pass the quorum, because stake of the other validators is not counted
Status: gov.ProposalStatus_PROPOSAL_STATUS_PASSED.String(),
},
},
},
},
},
},
)
return s
}
// stepsInactiveProviderValidatorsGovernanceBasecase is a sanity check to go along with
// stepsInactiveProviderValidatorsGovernance. It tests that with all validators being active,
// the proposal does not pass if it does not meet the quorum among validators.
func stepsInactiveProviderValidatorsGovernanceBasecase() []Step {
s := concatSteps(
[]Step{
{
Action: StartChainAction{
Chain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: 290000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: 290000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 300000000, Allocation: 10000000000},
},
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 290,
ValidatorID("bob"): 290,
ValidatorID("carol"): 300,
},
StakedTokens: &map[ValidatorID]uint{
ValidatorID("alice"): 290000000,
ValidatorID("bob"): 290000000,
ValidatorID("carol"): 300000000,
},
},
},
},
},
[]Step{
// create a governance proposal
{
Action: SubmitConsumerAdditionProposalAction{
Chain: ChainID("provi"),
From: ValidatorID("alice"),
Deposit: 10000001,
ConsumerChain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
TopN: 51,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD.String(),
},
},
},
},
},
// vote for it with carol
{
Action: VoteGovProposalAction{
Chain: ChainID("provi"),
From: []ValidatorID{ValidatorID("carol")},
Vote: []string{"yes"},
PropNumber: 1,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
// the proposal should *not* have passed because only carol voted for it,
// and carol is not enough to pass the quorum
Status: gov.ProposalStatus_PROPOSAL_STATUS_REJECTED.String(),
},
},
},
},
},
},
)
return s
}
// stepsMinStake validates that a validator with less stake than the specified minStake parameter
// cannot validate the consumer chain.
func stepsMinStake() []Step {
return concatSteps(
[]Step{
{
Action: StartChainAction{
Chain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: 290000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: 290000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 300000000, Allocation: 10000000000},
},
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 290,
ValidatorID("bob"): 290,
ValidatorID("carol"): 300,
},
StakedTokens: &map[ValidatorID]uint{
ValidatorID("alice"): 290000000,
ValidatorID("bob"): 290000000,
ValidatorID("carol"): 300000000,
},
},
},
},
// create a governance proposal
{
Action: SubmitConsumerAdditionProposalAction{
Chain: ChainID("provi"),
From: ValidatorID("alice"),
Deposit: 10000001,
ConsumerChain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
TopN: 0,
MinStake: 300000000,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD.String(),
},
},
},
},
},
},
stepsOptInValidators("alice", "bob", "carol"),
[]Step{
{
Action: VoteGovProposalAction{
Chain: ChainID("provi"),
From: []ValidatorID{ValidatorID("alice"), ValidatorID("bob")},
Vote: []string{"yes", "yes"},
PropNumber: 1,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: gov.ProposalStatus_PROPOSAL_STATUS_PASSED.String(),
},
},
},
},
},
{
// we start all the validators, but due to the min stake, only carol can validate
Action: StartConsumerChainAction{
ConsumerChain: ChainID("consu"),
ProviderChain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: 100000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: 200000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 300000000, 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("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0,
ValidatorID("bob"): 0,
ValidatorID("carol"): 300, // due to min stake of 300000000, only carol can validate
},
},
},
},
},
)
}
// This test case validates that inactive validators are not included when computing
// the top N.
func stepsInactiveValsWithTopN() []Step {
return []Step{
{
Action: StartChainAction{
Chain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: 100000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: 200000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 300000000, Allocation: 10000000000},
},
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0, // max consensus validators is 2, so alice should not be in power
ValidatorID("bob"): 200,
ValidatorID("carol"): 300,
},
StakedTokens: &map[ValidatorID]uint{
ValidatorID("alice"): 100000000,
ValidatorID("bob"): 200000000,
ValidatorID("carol"): 300000000,
},
Rewards: &Rewards{
Denom: "stake", // check for rewards in the provider denom
IsIncrementalReward: true, // we need to get incremental rewards
// if we would look at total rewards, alice would trivially also get rewards,
// because she gets rewards in the first block due to being in the genesis
IsRewarded: map[ValidatorID]bool{
ValidatorID("alice"): false,
ValidatorID("bob"): true,
ValidatorID("carol"): true,
},
},
},
},
},
{
Action: SubmitConsumerAdditionProposalAction{
Chain: ChainID("provi"),
From: ValidatorID("alice"),
Deposit: 10000001,
ConsumerChain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
TopN: 51,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD.String(),
},
},
},
},
},
{
Action: VoteGovProposalAction{
Chain: ChainID("provi"),
From: []ValidatorID{ValidatorID("alice"), ValidatorID("bob")},
Vote: []string{"yes", "yes"},
PropNumber: 1,
},
State: State{
ChainID("provi"): ChainState{
Proposals: &map[uint]Proposal{
1: ConsumerAdditionProposal{
Deposit: 10000001,
Chain: ChainID("consu"),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: gov.ProposalStatus_PROPOSAL_STATUS_PASSED.String(),
},
},
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {},
ValidatorID("bob"): {}, // bob doesn't have to validate because he is not in the top N
ValidatorID("carol"): {"consu"},
},
},
},
},
{
Action: StartConsumerChainAction{
ConsumerChain: ChainID("consu"),
ProviderChain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: 100000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: 200000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 300000000, 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("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0, // alice and bob are not in the top N, so aren't in the validator set
ValidatorID("bob"): 0,
ValidatorID("carol"): 300,
},
},
},
},
}
}
// stepsInactiveValsMint tests the minting of tokens with inactive validators
// It checks that inactive validators are not counted when computing whether the
// inflation rate should go up or down.
func stepsInactiveValsMint() []Step {
// total supply is 30000000000, bonded goal ratio makes it so we want 30000000 tokens bonded
return []Step{
{
Action: StartChainAction{
Chain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: 27000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: 28000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 29000000, Allocation: 10000000000},
},
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0,
ValidatorID("bob"): 0,
ValidatorID("carol"): 29, // other validators are not in power since only 1 can be active
},
InflationRateChange: intPtr(1), // inflation rate goes up because less than the goal is bonded, since only carol is active
},
},
},
{
Action: DelegateTokensAction{
Chain: ChainID("provi"),
From: ValidatorID("carol"),
To: ValidatorID("carol"),
Amount: 50000000,
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 0,
ValidatorID("bob"): 0,
ValidatorID("carol"): 79,
},
InflationRateChange: intPtr(-1), // inflation rate goes down now, because carol has more bonded than the goal
},
},
},
}
}
// stepsMintBasecase tests the minting of tokens without inactive validators.
// This is done as a sanity check to complement stepsInactiveValsMint.
func stepsMintBasecase() []Step {
// total supply is 30000000000, bonded goal ratio makes it so we want 30000000 tokens bonded
return []Step{
{
Action: StartChainAction{
Chain: ChainID("provi"),
Validators: []StartChainValidator{
{Id: ValidatorID("alice"), Stake: 27000000, Allocation: 10000000000},
{Id: ValidatorID("bob"), Stake: 28000000, Allocation: 10000000000},
{Id: ValidatorID("carol"), Stake: 29000000, Allocation: 10000000000},
},
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 27,
ValidatorID("bob"): 28,
ValidatorID("carol"): 29,
},
InflationRateChange: intPtr(-1), // inflation rate goes down because more than the goal is bonded
},
},
},
{
Action: DelegateTokensAction{
Chain: ChainID("provi"),
From: ValidatorID("carol"),
To: ValidatorID("carol"),
Amount: 50000000,
},
State: State{
ChainID("provi"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 27,
ValidatorID("bob"): 28,
ValidatorID("carol"): 79,
},
InflationRateChange: intPtr(-1), // inflation rate *still* goes down
},
},
},
}
}