@@ -12,6 +12,8 @@ import (
12
12
tmtypes "github.com/tendermint/tendermint/types"
13
13
)
14
14
15
+ const fullSlashMeterString = "1.0"
16
+
15
17
// TestBasicSlashPacketThrottling tests slash packet throttling with a single consumer,
16
18
// two slash packets, and no VSC matured packets. The most basic scenario.
17
19
func (s * CCVTestSuite ) TestBasicSlashPacketThrottling () {
@@ -651,7 +653,7 @@ func (s *CCVTestSuite) TestSlashSameValidator() {
651
653
652
654
// Set replenish fraction to 1.0 so that all sent packets should handled immediately (no throttling)
653
655
params := providerKeeper .GetParams (s .providerCtx ())
654
- params .SlashMeterReplenishFraction = "1.0"
656
+ params .SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter
655
657
providerKeeper .SetParams (s .providerCtx (), params )
656
658
providerKeeper .InitializeSlashMeter (s .providerCtx ())
657
659
@@ -706,7 +708,7 @@ func (s CCVTestSuite) TestSlashAllValidators() { //nolint:govet // this is a tes
706
708
707
709
// Set replenish fraction to 1.0 so that all sent packets should be handled immediately (no throttling)
708
710
params := providerKeeper .GetParams (s .providerCtx ())
709
- params .SlashMeterReplenishFraction = "1.0"
711
+ params .SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter
710
712
providerKeeper .SetParams (s .providerCtx (), params )
711
713
providerKeeper .InitializeSlashMeter (s .providerCtx ())
712
714
@@ -779,7 +781,7 @@ func (s *CCVTestSuite) TestLeadingVSCMaturedAreDequeued() {
779
781
780
782
// Queue up 50 slash packets for each consumer
781
783
for _ , bundle := range s .consumerBundles {
782
- for i := 0 ; i < 50 ; i ++ {
784
+ for i := 50 ; i < 100 ; i ++ {
783
785
ibcSeqNum := uint64 (i )
784
786
packet := s .constructSlashPacketFromConsumer (* bundle ,
785
787
* s .providerChain .Vals .Validators [0 ], stakingtypes .Downtime , ibcSeqNum )
@@ -792,7 +794,7 @@ func (s *CCVTestSuite) TestLeadingVSCMaturedAreDequeued() {
792
794
793
795
// Queue up another 50 vsc matured packets for each consumer
794
796
for _ , bundle := range s .consumerBundles {
795
- for i := 0 ; i < 50 ; i ++ {
797
+ for i := 100 ; i < 150 ; i ++ {
796
798
ibcSeqNum := uint64 (i )
797
799
packet := s .constructVSCMaturedPacketFromConsumer (* bundle , ibcSeqNum )
798
800
packetData := ccvtypes.ConsumerPacketData {}
@@ -818,6 +820,10 @@ func (s *CCVTestSuite) TestLeadingVSCMaturedAreDequeued() {
818
820
providerKeeper .SetSlashMeterReplenishTimeCandidate (s .providerCtx ())
819
821
820
822
// Execute end blocker to dequeue only the leading vsc matured packets.
823
+ // Note we must call the end blocker three times, since only 100 vsc matured packets can be handled
824
+ // each block, and we have 5*50=250 total.
825
+ s .providerChain .NextBlock ()
826
+ s .providerChain .NextBlock ()
821
827
s .providerChain .NextBlock ()
822
828
823
829
// Confirm queue size is 100 for each consumer-specific queue (50 leading vsc matured are dequeued).
@@ -827,9 +833,80 @@ func (s *CCVTestSuite) TestLeadingVSCMaturedAreDequeued() {
827
833
}
828
834
829
835
// No slash packets handled, global slash queue is same size as last block.
836
+ globalEntries = providerKeeper .GetAllGlobalSlashEntries (s .providerCtx ())
837
+ s .Require ().Equal (len (globalEntries ), 50 * 5 )
838
+
839
+ // No slash packets handled even if we call end blocker a couple more times.
840
+ s .providerChain .NextBlock ()
841
+ s .providerChain .NextBlock ()
842
+ globalEntries = providerKeeper .GetAllGlobalSlashEntries (s .providerCtx ())
830
843
s .Require ().Equal (len (globalEntries ), 50 * 5 )
831
844
}
832
845
846
+ // TestVscMaturedHandledPerBlockLimit tests that only 100 vsc matured packets are handled per block,
847
+ // specifically from HandleThrottleQueues().
848
+ //
849
+ // Note the vsc matured per block limit is also tested in, TestLeadingVSCMaturedAreDequeued,
850
+ // specifically in the context of HandleLeadingVSCMaturedPackets().
851
+ func (s * CCVTestSuite ) TestVscMaturedHandledPerBlockLimit () {
852
+ s .SetupAllCCVChannels ()
853
+ providerKeeper := s .providerApp .GetProviderKeeper ()
854
+
855
+ // Set replenish fraction to 1.0 so that all sent packets should be handled immediately (no jail throttling)
856
+ params := providerKeeper .GetParams (s .providerCtx ())
857
+ params .SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter
858
+ providerKeeper .SetParams (s .providerCtx (), params )
859
+ providerKeeper .InitializeSlashMeter (s .providerCtx ())
860
+
861
+ // Queue up 100 vsc matured packets for each consumer
862
+ for _ , bundle := range s .consumerBundles {
863
+ for i := 0 ; i < 100 ; i ++ {
864
+ ibcSeqNum := uint64 (i )
865
+ packet := s .constructVSCMaturedPacketFromConsumer (* bundle , ibcSeqNum )
866
+ packetData := ccvtypes.ConsumerPacketData {}
867
+ ccvtypes .ModuleCdc .MustUnmarshalJSON (packet .GetData (), & packetData )
868
+ providerKeeper .OnRecvVSCMaturedPacket (s .providerCtx (),
869
+ packet , * packetData .GetVscMaturedPacketData ())
870
+ }
871
+ }
872
+
873
+ // Queue up 50 slash packets for each consumer, with new IBC sequence numbers
874
+ for _ , bundle := range s .consumerBundles {
875
+ for i := 100 ; i < 150 ; i ++ {
876
+ ibcSeqNum := uint64 (i )
877
+ packet := s .constructSlashPacketFromConsumer (* bundle ,
878
+ * s .providerChain .Vals .Validators [0 ], stakingtypes .Downtime , ibcSeqNum )
879
+ packetData := ccvtypes.ConsumerPacketData {}
880
+ ccvtypes .ModuleCdc .MustUnmarshalJSON (packet .GetData (), & packetData )
881
+ providerKeeper .OnRecvSlashPacket (s .providerCtx (),
882
+ packet , * packetData .GetSlashPacketData ())
883
+ }
884
+ }
885
+
886
+ // Confirm queue size is 150 for each consumer-specific queue.
887
+ for _ , bundle := range s .consumerBundles {
888
+ s .Require ().Equal (uint64 (150 ),
889
+ providerKeeper .GetThrottledPacketDataSize (s .providerCtx (), bundle .Chain .ChainID ))
890
+ }
891
+ // Confirm global queue size is 50 * 5 (50 slash packets for each of 5 consumers)
892
+ globalEntries := providerKeeper .GetAllGlobalSlashEntries (s .providerCtx ())
893
+ s .Require ().Equal (len (globalEntries ), 50 * 5 )
894
+
895
+ // Note even though there is no jail throttling active, slash packets will not be handled until
896
+ // all of the leading vsc matured packets are handled first. This should take 5 blocks.
897
+ for i := 0 ; i < 5 ; i ++ {
898
+ s .providerChain .NextBlock ()
899
+ s .Require ().Len (providerKeeper .GetAllGlobalSlashEntries (s .providerCtx ()), 250 ) // global entries remain same size
900
+ }
901
+
902
+ // Set signing info for val to be jailed, preventing panic
903
+ s .setDefaultValSigningInfo (* s .providerChain .Vals .Validators [0 ])
904
+
905
+ // Now we execute one more block and all 250 of the slash packets should be handled.
906
+ s .providerChain .NextBlock ()
907
+ s .Require ().Empty (providerKeeper .GetAllGlobalSlashEntries (s .providerCtx ())) // empty global entries = all slash packets handled
908
+ }
909
+
833
910
func (s * CCVTestSuite ) confirmValidatorJailed (tmVal tmtypes.Validator , checkPower bool ) {
834
911
sdkVal , found := s .providerApp .GetTestStakingKeeper ().GetValidator (
835
912
s .providerCtx (), sdk .ValAddress (tmVal .Address ))
0 commit comments