Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Goc december more e2e #582

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 82 additions & 52 deletions tests/e2e/throttle.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,87 @@ func (s *CCVTestSuite) TestMultiConsumerSlashPacketThrottling() {
s.Require().Empty(providerKeeper.GetAllPendingSlashPacketEntries(s.providerCtx()))
}

func (s *CCVTestSuite) TestStressTestThrottling() {

// Setup ccv channels to all consumers
s.SetupAllCCVChannels()

// Setup validator powers to be 25%, 25%, 25%, 25%
s.setupValidatorPowers()

// Keep default params, initialize slash meter
providerKeeper := s.providerApp.GetProviderKeeper()
providerKeeper.InitializeSlashMeter(s.providerCtx())

// The packets to be recv in a single block, ordered as they will be recv.
packets := []channeltypes.Packet{}

// Track and increment ibc seq num for each packet, since these need to be unique.
ibcSeqNum := uint64(1)

firstBundle := s.getFirstBundle()

// Slash first 3 but not 4th validator
s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[0])
s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[1])
s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[2])

for i := 0; i < 900; i++ {
// Set infraction type based on even/odd index.
var infractionType stakingtypes.InfractionType
if i%2 == 0 {
infractionType = stakingtypes.Downtime
} else {
infractionType = stakingtypes.DoubleSign
}
valToJail := s.providerChain.Vals.Validators[i%3]
packets = append(packets, s.constructSlashPacketFromConsumer(
firstBundle, *valToJail, infractionType, ibcSeqNum))
ibcSeqNum++
}

// Send 900 slash packets from consumer to provider in same block,
for _, packet := range packets {
slashPacketData := ccvtypes.SlashPacketData{}
ccvtypes.ModuleCdc.MustUnmarshalJSON(packet.GetData(), &slashPacketData)
providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, slashPacketData)
}

// Confirm that global queue has 3 entries. This is not the desired behavior,
// but the expected behavior for this branch.
s.Require().Equal(3, len(providerKeeper.GetAllPendingSlashPacketEntries(s.providerCtx())))

// Confirm that chain specific queue has 900 packet data entries
s.Require().Equal(uint64(900), providerKeeper.GetPendingPacketDataSize(s.providerCtx(), firstBundle.Chain.ChainID))

// Execute end block
s.providerChain.NextBlock()

// Only one packet should have been handled, and the rest should stay queued. (BAD! But expected)
s.Require().Equal(2, len(providerKeeper.GetAllPendingSlashPacketEntries(s.providerCtx())))
s.Require().Equal(uint64(899), providerKeeper.GetPendingPacketDataSize(s.providerCtx(), firstBundle.Chain.ChainID))

// Replenish slash meter, and execute end block to handle another global entry
s.replenishSlashMeterTillPositive()
s.providerChain.NextBlock()
s.Require().Equal(1, len(providerKeeper.GetAllPendingSlashPacketEntries(s.providerCtx())))
s.Require().Equal(uint64(898), providerKeeper.GetPendingPacketDataSize(s.providerCtx(), firstBundle.Chain.ChainID))

// Replenish slash meter, and execute end block to handle another global entry
s.replenishSlashMeterTillPositive()
s.providerChain.NextBlock()
s.Require().Equal(0, len(providerKeeper.GetAllPendingSlashPacketEntries(s.providerCtx())))
s.Require().Equal(uint64(897), providerKeeper.GetPendingPacketDataSize(s.providerCtx(), firstBundle.Chain.ChainID))

// Call HandlePacketDataForChain 897 times, to handle all remaining packets.
// Hacky shiz for debugging and trying to reproduce the hang.
for i := 0; i < 897; i++ {
providerKeeper.HandlePacketDataForChain(s.providerCtx(), firstBundle.Chain.ChainID,
providerKeeper.HandleSlashPacket, providerKeeper.HandleVSCMaturedPacket)
}
s.Require().Equal(uint64(0), providerKeeper.GetPendingPacketDataSize(s.providerCtx(), firstBundle.Chain.ChainID))
}

// TestSlashingSmallValidators tests that multiple slash packets from validators with small
// power can be handled by the provider chain in a non-throttled manner.
func (s *CCVTestSuite) TestSlashingSmallValidators() {
Expand Down Expand Up @@ -341,57 +422,6 @@ func (s *CCVTestSuite) TestSlashMeterAllowanceChanges() {

}

// TestSlashSameValidator tests the edge case that that the total slashed validator power
// queued up for a single block exceeds the slash meter allowance,
// but some of the slash packets are for the same validator, and should all be handled.
func (s *CCVTestSuite) TestSlashSameValidator() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not relevant without cherry picking #560 into this branch


s.SetupAllCCVChannels()

// Setup 4 validators with 25% of the total power each.
s.setupValidatorPowers()

providerKeeper := s.providerApp.GetProviderKeeper()

// Set replenish fraction to 1.0 so that all sent packets should handled immediately (no throttling)
params := providerKeeper.GetParams(s.providerCtx())
params.SlashMeterReplenishFraction = "1.0"
providerKeeper.SetParams(s.providerCtx(), params)
providerKeeper.InitializeSlashMeter(s.providerCtx())

// Send a downtime and double-sign slash packet for 3/4 validators
// This will have a total slashing power of 150% total power.
tmval1 := s.providerChain.Vals.Validators[1]
tmval2 := s.providerChain.Vals.Validators[2]
tmval3 := s.providerChain.Vals.Validators[3]
s.setDefaultValSigningInfo(*tmval1)
s.setDefaultValSigningInfo(*tmval2)
s.setDefaultValSigningInfo(*tmval3)

packets := []channeltypes.Packet{
s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval1, stakingtypes.Downtime, 1),
s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval2, stakingtypes.Downtime, 2),
s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval3, stakingtypes.Downtime, 3),
s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval1, stakingtypes.DoubleSign, 4),
s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval2, stakingtypes.DoubleSign, 5),
s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval3, stakingtypes.DoubleSign, 6),
}

// Recv and queue all slash packets.
for _, packet := range packets {
providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, ccvtypes.MustUnmarshalJsonBzToSlashPacketData(packet.GetData()))
}

// We should have 6 pending slash packet entries queued.
s.Require().Len(providerKeeper.GetAllPendingSlashPacketEntries(s.providerCtx()), 6)

// Call next block to process all pending slash packets in end blocker.
s.providerChain.NextBlock()

// All slash packets should have been handled immediately, even though they totaled to 150% of total power.
s.Require().Len(providerKeeper.GetAllPendingSlashPacketEntries(s.providerCtx()), 0)
}

func (s *CCVTestSuite) confirmValidatorJailed(tmVal tmtypes.Validator) {
sdkVal, found := s.providerApp.GetE2eStakingKeeper().GetValidator(
s.providerCtx(), sdktypes.ValAddress(tmVal.Address))
Expand All @@ -415,7 +445,7 @@ func (s *CCVTestSuite) confirmValidatorNotJailed(tmVal tmtypes.Validator, expect
func (s *CCVTestSuite) replenishSlashMeterTillPositive() {
providerKeeper := s.providerApp.GetProviderKeeper()
idx := 0
for providerKeeper.GetSlashMeter(s.providerCtx()).IsNegative() {
for !providerKeeper.GetSlashMeter(s.providerCtx()).IsPositive() {
if idx > 100 {
panic("replenishTillPositive: failed to replenish slash meter")
}
Expand Down
8 changes: 4 additions & 4 deletions testutil/e2e/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ func TestMultiConsumerSlashPacketThrottling(t *testing.T) {
runCCVTestByName(t, "TestMultiConsumerSlashPacketThrottling")
}

func TestStressTestThrottling(t *testing.T) {
runCCVTestByName(t, "TestStressTestThrottling")
}

func TestSlashingSmallValidators(t *testing.T) {
runCCVTestByName(t, "TestSlashingSmallValidators")
}
Expand All @@ -168,10 +172,6 @@ func TestSlashMeterAllowanceChanges(t *testing.T) {
runCCVTestByName(t, "TestSlashMeterAllowanceChanges")
}

func TestSlashSameValidator(t *testing.T) {
runCCVTestByName(t, "TestSlashSameValidator")
}

//
// Unbonding tests
//
Expand Down