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

feat!: throttle with retries provider changes #1230

Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7691bf5
wip, tests not fixed yet
shaspitz Jun 20, 2023
a10a239
rm packet query on provider
shaspitz Aug 22, 2023
8a557b3
rm unneeded UTs
shaspitz Aug 22, 2023
196ce38
rm tests from relay_test
shaspitz Aug 22, 2023
0f27c31
rm query and more tests
shaspitz Aug 22, 2023
cf09f5f
rm more tests
shaspitz Aug 22, 2023
87ad0f4
Merge branch 'main' into shawn/throttle-with-retries-provider-changes
shaspitz Aug 22, 2023
7e6264f
builds again and rm debug tests
shaspitz Aug 22, 2023
5e4b845
lint
shaspitz Aug 22, 2023
8350956
fix handling of slash packet and integration test
shaspitz Aug 22, 2023
6d20dd1
Fix TestMultiConsumerSlashPacketThrottling
shaspitz Aug 23, 2023
461878c
fix two more slashing integration tests
shaspitz Aug 23, 2023
56242a6
Update TestSlashRetries, cleanup neededc
shaspitz Aug 23, 2023
1d963fa
cleaned up TestSlashRetries
shaspitz Aug 23, 2023
e8acd9e
UT for TestOnRecvDowntimeSlashPacket
shaspitz Aug 23, 2023
8ed33f3
cleans
shaspitz Aug 24, 2023
ecac6a4
use helper in throttle test
shaspitz Aug 24, 2023
f6d4650
lintz
shaspitz Aug 24, 2023
956e595
Revert "rm packet query on provider"
shaspitz Aug 24, 2023
db8dc1b
cmd file too
shaspitz Aug 24, 2023
78a8269
fully restore query
shaspitz Aug 24, 2023
73db33b
Merge branch 'main' into shawn/throttle-with-retries-provider-changes
shaspitz Aug 24, 2023
5bfccc3
Revert "Merge branch 'main' into shawn/throttle-with-retries-provider…
shaspitz Aug 24, 2023
5196394
make e2e test pass, with todos
shaspitz Aug 25, 2023
37e0e93
clean
shaspitz Aug 25, 2023
b1cb354
Revert "Revert "Merge branch 'main' into shawn/throttle-with-retries-…
shaspitz Aug 25, 2023
599854a
lint
shaspitz Aug 25, 2023
8945156
Update CHANGELOG.md
shaspitz Aug 25, 2023
0544fd3
slightly longer buffer
shaspitz Aug 25, 2023
d8f5690
merge main
shaspitz Aug 25, 2023
f91cb70
build(deps): bump actions/checkout from 3 to 4 (#1257)
dependabot[bot] Sep 5, 2023
aca8362
build(deps)!: bump github.com/cosmos/ibc-go/v7 from 7.2.0 to 7.3.0 (#…
dependabot[bot] Sep 5, 2023
66adc8a
build(deps): bump github.com/cosmos/cosmos-sdk from 0.47.4 to 0.47.5 …
dependabot[bot] Sep 5, 2023
cc9064d
chore: Separate semver (#1217)
shaspitz Sep 5, 2023
6da7fef
docs: cleanup changelog (#1260)
mpoke Sep 5, 2023
840d290
fix!: validate MsgTransfer before calling Transfer() (#1244)
mpoke Sep 5, 2023
8ec7bc5
docs: Create adr-012-separate-releasing.md (#1229)
shaspitz Sep 5, 2023
b152c03
fix: remove addr validation for provider fee pool addr param (#1262)
NeverHappened Sep 6, 2023
6bdfff9
Merge branch 'main' into shawn/throttle-with-retries-provider-changes
shaspitz Sep 6, 2023
3b27006
Revert "Merge branch 'main' into shawn/throttle-with-retries-provider…
shaspitz Sep 6, 2023
afa32f4
Merge branch 'feat/throttle-complete-attempt-2' into shawn/throttle-w…
shaspitz Sep 6, 2023
6ee88e2
fmt
shaspitz Sep 6, 2023
1ed2f56
Update steps_downtime.go
shaspitz Sep 14, 2023
fcf0b92
Update tests/e2e/steps_downtime.go
shaspitz Sep 14, 2023
53c02ea
waittime instead of sleep
shaspitz Sep 14, 2023
e9d745d
Update x/ccv/provider/client/cli/query.go
shaspitz Sep 14, 2023
b685958
Update x/ccv/provider/client/cli/query.go
shaspitz Sep 14, 2023
1ceddcb
rm throttled packets from query
shaspitz Sep 14, 2023
e228953
rm provider query
shaspitz Sep 14, 2023
7d3dd64
whoopsies forgot to rm some boilerplate
shaspitz Sep 14, 2023
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
Prev Previous commit
Next Next commit
Update TestSlashRetries, cleanup neededc
shaspitz committed Aug 23, 2023
commit 56242a66a08aceeeccacaf36cd8b3223ddbadc70
31 changes: 20 additions & 11 deletions tests/integration/common.go
Original file line number Diff line number Diff line change
@@ -414,32 +414,41 @@ func (suite *CCVTestSuite) commitConsumerPacket(ctx sdk.Context, packetData ccv.
func (s *CCVTestSuite) constructSlashPacketFromConsumer(bundle icstestingutils.ConsumerBundle,
tmVal tmtypes.Validator, infractionType stakingtypes.Infraction, ibcSeqNum uint64,
) channeltypes.Packet {
packet, _ := s.constructSlashPacketFromConsumerWithData(bundle, tmVal, infractionType, ibcSeqNum)
return packet
}

func (s *CCVTestSuite) constructSlashPacketFromConsumerWithData(bundle icstestingutils.ConsumerBundle,
tmVal tmtypes.Validator, infractionType stakingtypes.Infraction, ibcSeqNum uint64,
) (channeltypes.Packet, ccv.SlashPacketData) {
valsetUpdateId := bundle.GetKeeper().GetHeightValsetUpdateID(
bundle.GetCtx(), uint64(bundle.GetCtx().BlockHeight()))

data := ccv.ConsumerPacketData{
spdData := ccv.SlashPacketData{
Validator: abci.Validator{
Address: tmVal.Address,
Power: tmVal.VotingPower,
},
ValsetUpdateId: valsetUpdateId,
Infraction: infractionType,
}

cpdData := ccv.ConsumerPacketData{
Type: ccv.SlashPacket,
Data: &ccv.ConsumerPacketData_SlashPacketData{
SlashPacketData: &ccv.SlashPacketData{
Validator: abci.Validator{
Address: tmVal.Address,
Power: tmVal.VotingPower,
},
ValsetUpdateId: valsetUpdateId,
Infraction: infractionType,
},
SlashPacketData: &spdData,
},
}

return channeltypes.NewPacket(data.GetBytes(),
return channeltypes.NewPacket(cpdData.GetBytes(),
ibcSeqNum,
ccv.ConsumerPortID, // Src port
bundle.Path.EndpointA.ChannelID, // Src channel
ccv.ProviderPortID, // Dst port
bundle.Path.EndpointB.ChannelID, // Dst channel
clienttypes.Height{},
uint64(bundle.GetCtx().BlockTime().Add(ccv.DefaultCCVTimeoutPeriod).UnixNano()),
)
), spdData
}

// constructVSCMaturedPacketFromConsumer constructs an IBC packet embedding
189 changes: 144 additions & 45 deletions tests/integration/throttle_retry.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package integration

import (
"bytes"
"time"

channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"

stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

provider "github.com/cosmos/interchain-security/v3/x/ccv/provider"
providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"
)

// TestSlashRetries tests the throttling v2 retry logic.
// TestSlashRetries tests the throttling v2 retry logic at an integration level.
//
// TODO: This test will need updating once provider changes are made.
// TODO: can prob make some helpers to make this test more readable and succinct. Matching vals for example
func (s *CCVTestSuite) TestSlashRetries() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test has been adjusted to validate the full throttling v2 logic (provider/consumer both having v2 throttling), previously it just tested that a consumer running the v2 throttling protocol is compatible with a provider running the v1 throttling protocol

s.SetupAllCCVChannels()
s.SendEmptyVSCPacket() // Establish ccv channel
s.setupValidatorPowers()

//
// Provider setup
//
providerKeeper := s.providerApp.GetProviderKeeper()
providerModule := provider.NewAppModule(&providerKeeper, s.providerApp.GetSubspace(providertypes.ModuleName))
// Initialize slash meter
providerKeeper.InitializeSlashMeter(s.providerCtx())
// Assert that we start out with no jailings
@@ -31,12 +32,15 @@ func (s *CCVTestSuite) TestSlashRetries() {
s.Require().False(val.IsJailed())
}
// Setup signing info for jailings
s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[1])
tmval1 := s.providerChain.Vals.Validators[1]
tmval2 := s.providerChain.Vals.Validators[2]
s.setDefaultValSigningInfo(*tmval1)
s.setDefaultValSigningInfo(*tmval2)

//
// Consumer setup
//
consumerKeeper := s.consumerApp.GetConsumerKeeper()
consumerKeeper := s.getFirstBundle().App.GetConsumerKeeper()
// Assert no slash record exists
_, found := consumerKeeper.GetSlashRecord(s.consumerCtx())
s.Require().False(found)
@@ -46,98 +50,193 @@ func (s *CCVTestSuite) TestSlashRetries() {
//

// Construct a mock slash packet from consumer
tmval1 := s.providerChain.Vals.Validators[1]
packet1 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval1, stakingtypes.Infraction_INFRACTION_DOWNTIME, 1)
packet1, data := s.constructSlashPacketFromConsumerWithData(s.getFirstBundle(), *tmval1, stakingtypes.Infraction_INFRACTION_DOWNTIME, 1)

// Mock the sending of the packet on consumer
// Append packet to be sent by consumer
consumerKeeper.AppendPendingPacket(s.consumerCtx(), ccvtypes.SlashPacket,
&ccvtypes.ConsumerPacketData_SlashPacketData{
SlashPacketData: &ccvtypes.SlashPacketData{},
SlashPacketData: &data,
},
)
consumerKeeper.UpdateSlashRecordOnSend(s.consumerCtx())

sendTime := s.consumerCtx().BlockTime()

// Advance block on consumer to send pending packet
s.getFirstBundle().Chain.NextBlock()

// Confirm packet was sent via state that's updated on send
slashRecord, found := consumerKeeper.GetSlashRecord(s.consumerCtx())
s.Require().True(found)
s.Require().True(slashRecord.WaitingOnReply)
s.Require().NotZero(slashRecord.SendTime)
s.Require().Equal(sendTime, slashRecord.SendTime)
s.Require().Len(consumerKeeper.GetPendingPackets(s.consumerCtx()), 1)

// Recv packet on provider and assert ack. Provider should return v1 result.
ack := providerModule.OnRecvPacket(s.providerCtx(), packet1, nil)
expectedv1Ack := channeltypes.NewResultAcknowledgement([]byte(ccvtypes.V1Result))
s.Require().Equal(expectedv1Ack.Acknowledgement(), ack.Acknowledgement())
// Packet sending blocked until provider returns slash packet handled ack
s.Require().False(consumerKeeper.PacketSendingPermitted(s.consumerCtx()))

// Recv packet on provider.
relayAllCommittedPackets(s, s.consumerChain, s.path, ccvtypes.ConsumerPortID, s.path.EndpointA.ChannelID, 1)

// Couple blocks pass on provider for provider staking keeper to process jailing
s.providerChain.NextBlock()
s.providerChain.NextBlock()

// Default slash meter replenish fraction is 0.05, so packet should be handled on provider.
vals = s.providerApp.GetTestStakingKeeper().GetAllValidators(s.providerCtx())
s.Require().True(vals[1].IsJailed())

// Match val from staking keeper to tmval1
var stakingVal1 stakingtypes.Validator
for i, val := range vals {
consAddr, err := val.GetConsAddr()
s.Require().NoError(err)
if bytes.Equal(consAddr.Bytes(), tmval1.Address.Bytes()) {
stakingVal1 = vals[i]
}
}
// Require stakingVal1 is found
s.Require().NotZero(stakingVal1)

s.Require().True(stakingVal1.IsJailed())
s.Require().Equal(int64(0),
s.providerApp.GetTestStakingKeeper().GetLastValidatorPower(s.providerCtx(), vals[1].GetOperator()))
s.providerApp.GetTestStakingKeeper().GetLastValidatorPower(s.providerCtx(), stakingVal1.GetOperator()))

// Now slash meter should be negative on provider
s.Require().True(s.providerApp.GetProviderKeeper().GetSlashMeter(s.providerCtx()).IsNegative())

// Apply ack back on consumer
ackForConsumer := expectedv1Ack
err := consumerKeeper.OnAcknowledgementPacket(s.consumerCtx(), packet1, ackForConsumer)
expectedAck := channeltypes.NewResultAcknowledgement([]byte(ccvtypes.SlashPacketHandledResult))
err := s.getFirstBundle().Path.EndpointA.AcknowledgePacket(packet1, expectedAck.Acknowledgement())
s.Require().NoError(err)

// Slash record should have been deleted, head of pending packets should have been popped
// Since provider has handled the packet
// Slash record should have been deleted, head of pending packets should have been popped,
// since provider has handled the packet.
_, found = consumerKeeper.GetSlashRecord(s.consumerCtx())
s.Require().False(found)
s.Require().Empty(consumerKeeper.GetPendingPackets(s.consumerCtx()))

// Packet sending should now be unblocked
s.Require().True(consumerKeeper.PacketSendingPermitted(s.consumerCtx()))

// pass two blocks on provider and consumer for good measure
s.providerChain.NextBlock()
s.providerChain.NextBlock()
s.consumerChain.NextBlock()
s.consumerChain.NextBlock()

// Construct and mock the sending of a second packet on consumer
tmval2 := s.providerChain.Vals.Validators[2]
packet2 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval2, stakingtypes.Infraction_INFRACTION_DOWNTIME, 1)

// Have consumer queue a new slash packet for a different validator.
packet2, data := s.constructSlashPacketFromConsumerWithData(
s.getFirstBundle(), *tmval2, stakingtypes.Infraction_INFRACTION_DOWNTIME, 1)
consumerKeeper.AppendPendingPacket(s.consumerCtx(), ccvtypes.SlashPacket,
&ccvtypes.ConsumerPacketData_SlashPacketData{
SlashPacketData: &ccvtypes.SlashPacketData{},
SlashPacketData: &data,
},
)
consumerKeeper.UpdateSlashRecordOnSend(s.consumerCtx())

// Advance block on consumer to send pending packet
sendTime = s.consumerCtx().BlockTime()
s.getFirstBundle().Chain.NextBlock()

// Confirm packet was sent via state that's updated on send
slashRecord, found = consumerKeeper.GetSlashRecord(s.consumerCtx())
s.Require().True(found)
s.Require().True(slashRecord.WaitingOnReply)
s.Require().NotZero(slashRecord.SendTime)
s.Require().Equal(sendTime, slashRecord.SendTime)
s.Require().Len(consumerKeeper.GetPendingPackets(s.consumerCtx()), 1)

// Recv 2nd slash packet on provider for different validator.
// Provider should return the same v1 result ack even tho the packet was queued.
ack = providerModule.OnRecvPacket(s.providerCtx(), packet2, nil)
expectedv1Ack = channeltypes.NewResultAcknowledgement([]byte(ccvtypes.V1Result))
s.Require().Equal(expectedv1Ack.Acknowledgement(), ack.Acknowledgement())
// Packet sending blocked until provider returns slash packet handled ack
s.Require().False(consumerKeeper.PacketSendingPermitted(s.consumerCtx()))

// Recv 2nd packet on provider.
relayAllCommittedPackets(s, s.consumerChain, s.path, ccvtypes.ConsumerPortID, s.path.EndpointA.ChannelID, 1)

// Couple blocks pass on provider for staking keeper to process jailings
s.providerChain.NextBlock()
s.providerChain.NextBlock()

s.Fail("need to update with provider changes")
vals = s.providerApp.GetTestStakingKeeper().GetAllValidators(s.providerCtx())

// Match val from staking keeper to tmval2
var stakingVal2 stakingtypes.Validator
for i, val := range vals {
consAddr, err := val.GetConsAddr()
s.Require().NoError(err)
if bytes.Equal(consAddr.Bytes(), tmval2.Address.Bytes()) {
stakingVal2 = vals[i]
}
}
// Require stakingVal2 is found
s.Require().NotZero(stakingVal2)

// Val shouldn't be jailed on provider. Slash packet was queued
s.Require().False(vals[2].IsJailed())
// Val 2 shouldn't be jailed on provider. Slash packet should have been bounced.
s.Require().False(stakingVal2.IsJailed())
s.Require().Equal(int64(1000),
providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), vals[2].GetOperator()))
providerStakingKeeper.GetLastValidatorPower(s.providerCtx(), stakingVal2.GetOperator()))

// Apply ack on consumer
ackForConsumer = expectedv1Ack
err = consumerKeeper.OnAcknowledgementPacket(s.consumerCtx(), packet2, ackForConsumer)
expectedAck = channeltypes.NewResultAcknowledgement([]byte(ccvtypes.SlashPacketBouncedResult))
err = s.getFirstBundle().Path.EndpointA.AcknowledgePacket(packet2, expectedAck.Acknowledgement())
s.Require().NoError(err)

// TODO: when provider changes are made, slashRecord.WaitingOnReply should have been updated to false on consumer. Slash Packet will still be in consumer's pending packets queue.
// Now consumer should have updated it's slash record on receipt of bounce ack
slashRecord, found = consumerKeeper.GetSlashRecord(s.consumerCtx())
s.Require().True(found)
s.Require().False(slashRecord.WaitingOnReply)
// Packet still at head of queue
s.Require().Len(consumerKeeper.GetPendingPackets(s.consumerCtx()), 1)

// Slash record should have been deleted, head of pending packets should have been popped
// Since provider has handled the packet
_, found = consumerKeeper.GetSlashRecord(s.consumerCtx())
s.Require().False(found)
s.Require().Empty(consumerKeeper.GetPendingPackets(s.consumerCtx()))
// Packet sending should still be blocked, WaitingOnReply is false,
// but retry delay hasn't passed yet.
s.Require().False(consumerKeeper.PacketSendingPermitted(s.consumerCtx()))

// IBC testing framework doesn't have a way to advance time,
// so we manually mutate send time in the slash record to be in the past.
slashRecord.SendTime = slashRecord.SendTime.Add(-time.Hour - time.Minute)
consumerKeeper.SetSlashRecord(s.consumerCtx(), slashRecord)

s.Require().True(consumerKeeper.PacketSendingPermitted(s.consumerCtx()))

// Set slash meter on provider to positive value,
// now allowing handling of the slash packet
providerKeeper.InitializeSlashMeter(s.providerCtx())

// Advance block on consumer, now consumer should retry the sending of the slash packet.
sendTime = s.consumerCtx().BlockTime()
s.getFirstBundle().Chain.NextBlock()

// Confirm packet was sent via state that's updated on send
slashRecord, found = consumerKeeper.GetSlashRecord(s.consumerCtx())
s.Require().True(found)
s.Require().True(slashRecord.WaitingOnReply)
s.Require().NotZero(slashRecord.SendTime)
s.Require().Equal(sendTime, slashRecord.SendTime)
s.Require().Len(consumerKeeper.GetPendingPackets(s.consumerCtx()), 1)

// Recv retried packet on provider.
relayAllCommittedPackets(s, s.consumerChain, s.path, ccvtypes.ConsumerPortID, s.path.EndpointA.ChannelID, 1)

// Couple blocks pass on provider for provider staking keeper to process jailing
s.providerChain.NextBlock()
s.providerChain.NextBlock()

vals = s.providerApp.GetTestStakingKeeper().GetAllValidators(s.providerCtx())

// Match val from staking keeper to tmval2
stakingVal2 = stakingtypes.Validator{}
for i, val := range vals {
consAddr, err := val.GetConsAddr()
s.Require().NoError(err)
if bytes.Equal(consAddr.Bytes(), tmval2.Address.Bytes()) {
stakingVal2 = vals[i]
}
}
// Require stakingVal2 is found
s.Require().NotZero(stakingVal2)

// Provider should have now jailed val[2]
vals = s.providerApp.GetTestStakingKeeper().GetAllValidators(s.providerCtx())
s.Require().True(stakingVal2.IsJailed())
s.Require().Equal(int64(0),
s.providerApp.GetTestStakingKeeper().GetLastValidatorPower(s.providerCtx(), stakingVal2.GetOperator()))
}
2 changes: 2 additions & 0 deletions x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
@@ -265,6 +265,8 @@ func (k Keeper) EndBlockCIS(ctx sdk.Context) {

// OnRecvSlashPacket delivers a received slash packet, validates it and
// then queues the slash packet as pending if valid.
//
// TODO: Add UTs for returned acks
func (k Keeper) OnRecvSlashPacket(ctx sdk.Context, packet channeltypes.Packet, data ccv.SlashPacketData) exported.Acknowledgement {
// check that the channel is established, panic if not
chainID, found := k.GetChannelToChain(ctx, packet.DestinationChannel)