Skip to content

Commit

Permalink
fix the rest o the shit
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed Sep 20, 2023
1 parent 01b001f commit cb21ebd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
6 changes: 3 additions & 3 deletions tests/integration/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *CCVTestSuite) TestRelayAndApplyDowntimePacket() {
valsetUpdateIdN := providerKeeper.GetValidatorSetUpdateId(s.providerCtx())

// receive the slash packet on the provider chain. RecvPacket() calls the provider endblocker twice
packet := s.newPacketFromConsumer(slashPacket.GetBytes(), sequence, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp)
packet := s.newPacketFromConsumer(slashPacket.GetData(), sequence, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp)
err = s.path.EndpointB.RecvPacket(packet)
s.Require().NoError(err)

Expand Down Expand Up @@ -202,8 +202,8 @@ func (s *CCVTestSuite) TestRelayAndApplyDoubleSignPacket() {
timeoutHeight = clienttypes.Height{}
timeoutTimestamp = uint64(s.getFirstBundle().GetCtx().BlockTime().Add(ccv.DefaultCCVTimeoutPeriod).UnixNano())
)
slashPacket := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmVal, stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN)
packet := sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, slashPacket.GetBytes())
slashPacket := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmVal, stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN, 1)
packet := sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, slashPacket.GetData())

// Advance a few more blocks to make sure any voting power changes would be reflected
s.providerChain.NextBlock()
Expand Down
54 changes: 32 additions & 22 deletions tests/integration/throttle.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
icstestingutils "github.com/cosmos/interchain-security/v3/testutil/ibc_testing"
"github.com/cosmos/interchain-security/v3/x/ccv/provider"
providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"
ccv "github.com/cosmos/interchain-security/v3/x/ccv/types"

Check failure on line 16 in tests/integration/throttle.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "github.com/cosmos/interchain-security/v3/x/ccv/types" is being imported more than once (stylecheck)

Check failure on line 16 in tests/integration/throttle.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "github.com/cosmos/interchain-security/v3/x/ccv/types" is being imported more than once (stylecheck)
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"

Check failure on line 17 in tests/integration/throttle.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "github.com/cosmos/interchain-security/v3/x/ccv/types" (stylecheck)

Check failure on line 17 in tests/integration/throttle.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "github.com/cosmos/interchain-security/v3/x/ccv/types" (stylecheck)
)

const fullSlashMeterString = "1.0"
Expand Down Expand Up @@ -66,8 +68,8 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() {
// Send a slash packet from consumer to provider
s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[0])
tmVal := s.providerChain.Vals.Validators[0]
slashPacket := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmVal, stakingtypes.Infraction_INFRACTION_DOWNTIME)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, slashPacket.GetBytes())
slashPacket := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmVal, stakingtypes.Infraction_INFRACTION_DOWNTIME, 1)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, slashPacket.GetData())

// Assert validator 0 is jailed and has no power
vals = providerStakingKeeper.GetAllValidators(s.providerCtx())
Expand All @@ -85,8 +87,8 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() {
// Now send a second slash packet from consumer to provider for a different validator.
s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[2])
tmVal = s.providerChain.Vals.Validators[2]
slashPacket = s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmVal, stakingtypes.Infraction_INFRACTION_DOWNTIME)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, slashPacket.GetBytes())
slashPacket = s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmVal, stakingtypes.Infraction_INFRACTION_DOWNTIME, 2)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, slashPacket.GetData())

// Require that slash packet has not been handled, a bounce result would have
// been returned, but the IBC helper throws out acks.
Expand Down Expand Up @@ -141,9 +143,9 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() {

// Assert validator 2 is jailed once slash packet is retried.
tmVal2 := s.providerChain.Vals.Validators[2]
packet = s.constructSlashPacketFromConsumer(s.getFirstBundle(),
packet := s.constructSlashPacketFromConsumer(s.getFirstBundle(),
*tmVal2, stakingtypes.Infraction_INFRACTION_DOWNTIME, 3) // make sure to use a new seq num
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, packet)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, packet.GetData())

stakingVal2 := s.mustGetStakingValFromTmVal(*tmVal2)
s.Require().True(stakingVal2.IsJailed())
Expand All @@ -163,6 +165,11 @@ func (s *CCVTestSuite) TestMultiConsumerSlashPacketThrottling() {
s.SetupAllCCVChannels()
s.setupValidatorPowers()

var (
timeoutHeight = clienttypes.Height{}
timeoutTimestamp = uint64(s.getFirstBundle().GetCtx().BlockTime().Add(ccv.DefaultCCVTimeoutPeriod).UnixNano())
)

providerStakingKeeper := s.providerApp.GetTestStakingKeeper()

// Choose 3 consumer bundles. It doesn't matter which ones.
Expand Down Expand Up @@ -194,7 +201,7 @@ func (s *CCVTestSuite) TestMultiConsumerSlashPacketThrottling() {
stakingtypes.Infraction_INFRACTION_DOWNTIME,
1, // all consumers use 1 seq num
)
sendOnConsumerRecvOnProvider(s, bundle.Path, timeoutHeight, timeoutTimestamp, slashPacket.GetBytes())
sendOnConsumerRecvOnProvider(s, bundle.Path, timeoutHeight, timeoutTimestamp, slashPacket.GetData())

idx++
}
Expand Down Expand Up @@ -222,7 +229,7 @@ func (s *CCVTestSuite) TestMultiConsumerSlashPacketThrottling() {
stakingtypes.Infraction_INFRACTION_DOWNTIME,
2, // seq number is incremented since last try
)
sendOnConsumerRecvOnProvider(s, bundle.Path, packet)
sendOnConsumerRecvOnProvider(s, bundle.Path, timeoutHeight, timeoutTimestamp, packet.GetData())

// retry from consumer with idx 2
bundle = senderBundles[2]
Expand All @@ -232,7 +239,7 @@ func (s *CCVTestSuite) TestMultiConsumerSlashPacketThrottling() {
stakingtypes.Infraction_INFRACTION_DOWNTIME,
2, // seq number is incremented since last try
)
sendOnConsumerRecvOnProvider(s, bundle.Path, packet)
sendOnConsumerRecvOnProvider(s, bundle.Path, timeoutHeight, timeoutTimestamp, packet.GetData())

// Call NextBlocks to update staking module val powers
s.providerChain.NextBlock()
Expand All @@ -253,7 +260,7 @@ func (s *CCVTestSuite) TestMultiConsumerSlashPacketThrottling() {
stakingtypes.Infraction_INFRACTION_DOWNTIME,
3, // seq number is incremented since last try
)
sendOnConsumerRecvOnProvider(s, bundle.Path, packet)
sendOnConsumerRecvOnProvider(s, bundle.Path, timeoutHeight, timeoutTimestamp, packet.GetData())

// Call NextBlocks to update staking module val powers
s.providerChain.NextBlock()
Expand Down Expand Up @@ -311,8 +318,8 @@ func (s *CCVTestSuite) TestPacketSpam() {
infractionType = stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN
}
valToJail := s.providerChain.Vals.Validators[ibcSeqNum%3]
slashPacket := s.constructSlashPacketFromConsumer(firstBundle, *valToJail, infractionType)
packetsData = append(packetsData, slashPacket.GetBytes())
slashPacket := s.constructSlashPacketFromConsumer(firstBundle, *valToJail, infractionType, ibcSeqNum)
packetsData = append(packetsData, slashPacket.GetData())
}

// Recv 500 packets from consumer to provider in same block
Expand Down Expand Up @@ -368,8 +375,8 @@ func (s *CCVTestSuite) TestDoubleSignDoesNotAffectThrottling() {
// Increment ibc seq num for each packet (starting at 1)
ibcSeqNum++
valToJail := s.providerChain.Vals.Validators[ibcSeqNum%3]
slashPacket := s.constructSlashPacketFromConsumer(firstBundle, *valToJail, stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN)
packetsData = append(packetsData, slashPacket.GetBytes())
slashPacket := s.constructSlashPacketFromConsumer(firstBundle, *valToJail, stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN, ibcSeqNum)
packetsData = append(packetsData, slashPacket.GetData())
}

// Recv 500 packets from consumer to provider in same block
Expand Down Expand Up @@ -452,12 +459,12 @@ func (s *CCVTestSuite) TestSlashingSmallValidators() {
tmval1 := s.providerChain.Vals.Validators[1]
tmval2 := s.providerChain.Vals.Validators[2]
tmval3 := s.providerChain.Vals.Validators[3]
slashPacket1 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval1, stakingtypes.Infraction_INFRACTION_DOWNTIME)
slashPacket2 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval2, stakingtypes.Infraction_INFRACTION_DOWNTIME)
slashPacket3 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval3, stakingtypes.Infraction_INFRACTION_DOWNTIME)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, slashPacket1.GetBytes())
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, slashPacket2.GetBytes())
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, slashPacket3.GetBytes())
slashPacket1 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval1, stakingtypes.Infraction_INFRACTION_DOWNTIME, 1)
slashPacket2 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval2, stakingtypes.Infraction_INFRACTION_DOWNTIME, 2)
slashPacket3 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval3, stakingtypes.Infraction_INFRACTION_DOWNTIME, 3)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, slashPacket1.GetData())
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, slashPacket2.GetData())
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp, slashPacket3.GetData())

// Default slash meter replenish fraction is 0.05, so all sent packets should be handled immediately.
vals = providerStakingKeeper.GetAllValidators(s.providerCtx())
Expand Down Expand Up @@ -524,17 +531,20 @@ func (s CCVTestSuite) TestSlashAllValidators() { //nolint:govet // this is a tes

// Instantiate a slash packet for each validator,
// these first 4 packets should jail 100% of the total power.
ibcSeqNum := uint64(1)
for _, val := range s.providerChain.Vals.Validators {
s.setDefaultValSigningInfo(*val)
packetsData = append(packetsData, s.constructSlashPacketFromConsumer(
s.getFirstBundle(), *val, stakingtypes.Infraction_INFRACTION_DOWNTIME).GetBytes())
s.getFirstBundle(), *val, stakingtypes.Infraction_INFRACTION_DOWNTIME, ibcSeqNum).GetData())
ibcSeqNum++
}

// add 5 more slash packets for each validator, that will be handled in the same block.
for _, val := range s.providerChain.Vals.Validators {
for i := 0; i < 5; i++ {
packetsData = append(packetsData, s.constructSlashPacketFromConsumer(
s.getFirstBundle(), *val, stakingtypes.Infraction_INFRACTION_DOWNTIME).GetBytes())
s.getFirstBundle(), *val, stakingtypes.Infraction_INFRACTION_DOWNTIME, ibcSeqNum).GetData())
ibcSeqNum++
}
}

Expand Down

0 comments on commit cb21ebd

Please sign in to comment.