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
Show file tree
Hide file tree
Changes from 17 commits
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
8 changes: 0 additions & 8 deletions proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import "interchain_security/ccv/consumer/v1/genesis.proto";
import "interchain_security/ccv/provider/v1/provider.proto";

service Query {

Check failure on line 13 in proto/interchain_security/ccv/provider/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present RPC "QueryThrottledConsumerPacketData" on service "Query" was deleted.
// ConsumerGenesis queries the genesis state needed to start a consumer chain
// whose proposal has been accepted
rpc QueryConsumerGenesis(QueryConsumerGenesisRequest)
Expand Down Expand Up @@ -65,14 +65,6 @@
"/interchain_security/ccv/provider/throttle_state";
}

// QueryThrottledConsumerPacketData returns a list of pending packet data
// instances (slash packet and vsc matured) for a single consumer chain
rpc QueryThrottledConsumerPacketData(QueryThrottledConsumerPacketDataRequest)
returns (QueryThrottledConsumerPacketDataResponse) {
option (google.api.http).get =
"/interchain_security/ccv/provider/pending_consumer_packets";
}

// QueryRegisteredConsumerRewardDenoms returns a list of consumer reward
// denoms that are registered
rpc QueryRegisteredConsumerRewardDenoms(
Expand Down
47 changes: 36 additions & 11 deletions tests/integration/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package integration

import (
"bytes"
"fmt"
"time"

Expand Down Expand Up @@ -414,37 +415,46 @@
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
// VSC Matured packet data to be sent from consumer to provider
func (s *CCVTestSuite) constructVSCMaturedPacketFromConsumer(bundle icstestingutils.ConsumerBundle,

Check failure on line 457 in tests/integration/common.go

View workflow job for this annotation

GitHub Actions / lint

func `(*CCVTestSuite).constructVSCMaturedPacketFromConsumer` is unused (unused)
ibcSeqNum uint64,
) channeltypes.Packet {
valsetUpdateId := bundle.GetKeeper().GetHeightValsetUpdateID(
Expand Down Expand Up @@ -615,3 +625,18 @@
}
s.Require().Equal(int64(4000), stakingKeeper.GetLastTotalPower(s.providerCtx()).Int64())
}

// mustGetStakingValFromTmVal returns the staking validator from the current state of the staking keeper,
// corresponding to a given tendermint validator. Note this func will fail the test if the validator is not found.
func (s *CCVTestSuite) mustGetStakingValFromTmVal(tmVal tmtypes.Validator) (stakingVal stakingtypes.Validator) {
vals := s.providerApp.GetTestStakingKeeper().GetAllValidators(s.providerCtx())
for i, val := range vals {
consAddr, err := val.GetConsAddr()
s.Require().NoError(err)
if bytes.Equal(consAddr.Bytes(), tmVal.Address.Bytes()) {
stakingVal = vals[i]
}
}
s.Require().NotZero(stakingVal)
return stakingVal
}
38 changes: 15 additions & 23 deletions tests/integration/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ func (s *CCVTestSuite) TestRelayAndApplyDowntimePacket() {
firstConsumerKeeper.SetOutstandingDowntime(s.consumerCtx(), consumerConsAddr.ToSdkConsAddr())

// Note: RecvPacket advances two blocks. Let's say the provider is currently at height N.
// The received slash packet will be queued during N, and handled by the ccv module during
// the endblocker of N. The staking module will then register a validator update from that
// packet during the endblocker of N+1 (note that staking endblocker runs before ccv endblocker,
// hence why the VSC is registered on N+1). Then the ccv module sends VSC packets to each consumer
// during the endblocker of N+1. The new validator set will be committed to in block N+2,
// and will be in effect for the provider during block N+3.
// The received slash packet will be handled during N. The staking module will then register
// a validator update from that packet during the endblocker of N. Then the ccv module sends
// VSC packets to each consumer during the endblocker of N (note ccv endblocker runs after staking).
// The new validator set will be committed to in block N+1, and will be in effect
// for the provider during block N+2.

valsetUpdateIdN := providerKeeper.GetValidatorSetUpdateId(s.providerCtx())

Expand All @@ -91,8 +90,8 @@ func (s *CCVTestSuite) TestRelayAndApplyDowntimePacket() {

// We've now advanced two blocks.

// VSC packets should have been sent from provider during block N+1 to each consumer
expectedSentValsetUpdateId := valsetUpdateIdN + 1
// VSC packets should have been sent from provider during block N to each consumer
expectedSentValsetUpdateId := valsetUpdateIdN
for _, bundle := range s.consumerBundles {
_, found := providerKeeper.GetVscSendTimestamp(s.providerCtx(),
bundle.Chain.ChainID, expectedSentValsetUpdateId)
Expand All @@ -104,10 +103,7 @@ func (s *CCVTestSuite) TestRelayAndApplyDowntimePacket() {
s.Require().Equal(valsetUpdateIdN+2,
providerKeeper.GetValidatorSetUpdateId(s.providerCtx()))

// Call next block so provider is now on block N + 3 mentioned above
s.providerChain.NextBlock()

// check that the validator was removed from the provider validator set by N + 3
// check that the validator was removed from the provider validator set by N + 2
s.Require().Len(s.providerChain.Vals.Validators, validatorsPerChain-1)

for _, bundle := range s.consumerBundles {
Expand Down Expand Up @@ -151,9 +147,10 @@ func (s *CCVTestSuite) TestRelayAndApplyDowntimePacket() {
pFlag := firstConsumerKeeper.OutstandingDowntime(s.consumerCtx(), consumerConsAddr.ToSdkConsAddr())
s.Require().False(pFlag)

// check that slashing packet gets acknowledged successfully
ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)})
err = s.path.EndpointA.AcknowledgePacket(packet, ack.Acknowledgement())
// Check that first consumer can recv ack from provider.
// Provider has returned SlashPacketHandledResult.
ack := channeltypes.NewResultAcknowledgement(ccv.SlashPacketHandledResult)
err = s.getFirstBundle().Path.EndpointA.AcknowledgePacket(packet, ack.Acknowledgement())
s.Require().NoError(err)
}

Expand Down Expand Up @@ -234,8 +231,9 @@ func (s *CCVTestSuite) TestRelayAndApplyDoubleSignPacket() {
// check that validator was NOT tombstoned on provider
s.Require().False(valSignInfo.Tombstoned)

// check that slashing packet gets acknowledged successfully
ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)})
// check that slashing packet gets acknowledged successfully,
// provider returns V1Result acks for double sign packets
ack := channeltypes.NewResultAcknowledgement(ccv.V1Result)
err = s.path.EndpointA.AcknowledgePacket(packet, ack.Acknowledgement())
s.Require().NoError(err)
}
Expand Down Expand Up @@ -426,16 +424,10 @@ func (suite *CCVTestSuite) TestOnRecvSlashPacketErrors() {
errAck = providerKeeper.OnRecvSlashPacket(ctx, packet, *slashingPkt)
suite.Require().False(errAck.Success())

// Expect nothing was queued
suite.Require().Equal(0, len(providerKeeper.GetAllGlobalSlashEntries(ctx)))
suite.Require().Equal(uint64(0), (providerKeeper.GetThrottledPacketDataSize(ctx, consumerChainID)))

// expect to queue entries for the slash request
slashingPkt.Infraction = stakingtypes.Infraction_INFRACTION_DOWNTIME
ack = providerKeeper.OnRecvSlashPacket(ctx, packet, *slashingPkt)
suite.Require().True(ack.Success())
suite.Require().Equal(1, len(providerKeeper.GetAllGlobalSlashEntries(ctx)))
suite.Require().Equal(uint64(1), (providerKeeper.GetThrottledPacketDataSize(ctx, consumerChainID)))
}

// TestValidatorDowntime tests if a slash packet is sent
Expand Down
48 changes: 0 additions & 48 deletions tests/integration/stop_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

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

Expand Down Expand Up @@ -80,33 +79,6 @@ func (s *CCVTestSuite) TestStopConsumerChain() {
return nil
},
},
{
func(suite *CCVTestSuite) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any test or test case that was removed, is a test that is only relevant to provider queuing logic which is removed in this PR

// Queue slash and vsc packet data for consumer 0, these queue entries will be removed
firstBundle := s.getFirstBundle()
globalEntry := types.NewGlobalSlashEntry(s.providerCtx().BlockTime(), firstBundle.Chain.ChainID, 7, types.ProviderConsAddress{Address: []byte{}})
providerKeeper.QueueGlobalSlashEntry(s.providerCtx(), globalEntry)
err := providerKeeper.QueueThrottledSlashPacketData(s.providerCtx(), firstBundle.Chain.ChainID, 1,
ccv.SlashPacketData{ValsetUpdateId: 1})
suite.Require().NoError(err)
err = providerKeeper.QueueThrottledVSCMaturedPacketData(s.providerCtx(),
firstBundle.Chain.ChainID, 2, ccv.VSCMaturedPacketData{ValsetUpdateId: 2})
suite.Require().NoError(err)

// Queue slash and vsc packet data for consumer 1, these queue entries will be not be removed
secondBundle := s.getBundleByIdx(1)
globalEntry = types.NewGlobalSlashEntry(s.providerCtx().BlockTime(), secondBundle.Chain.ChainID, 7, types.ProviderConsAddress{Address: []byte{}})
providerKeeper.QueueGlobalSlashEntry(s.providerCtx(), globalEntry)
err = providerKeeper.QueueThrottledSlashPacketData(s.providerCtx(), secondBundle.Chain.ChainID, 1,
ccv.SlashPacketData{ValsetUpdateId: 1})
suite.Require().NoError(err)
err = providerKeeper.QueueThrottledVSCMaturedPacketData(s.providerCtx(),
secondBundle.Chain.ChainID, 2, ccv.VSCMaturedPacketData{ValsetUpdateId: 2})
suite.Require().NoError(err)

return nil
},
},
}

for _, so := range setupOperations {
Expand All @@ -120,15 +92,6 @@ func (s *CCVTestSuite) TestStopConsumerChain() {

// check all states are removed and the unbonding operation released
s.checkConsumerChainIsRemoved(firstBundle.Chain.ChainID, true)

// check entries related to second consumer chain are not removed
s.Require().Len(providerKeeper.GetAllGlobalSlashEntries(s.providerCtx()), 1)

secondBundle := s.getBundleByIdx(1)
slashData, vscMaturedData, _, _ := providerKeeper.GetAllThrottledPacketData(
s.providerCtx(), secondBundle.Chain.ChainID)
s.Require().Len(slashData, 1)
s.Require().Len(vscMaturedData, 1)
}

// TODO Simon: implement OnChanCloseConfirm in IBC-GO testing to close the consumer chain's channel end
Expand Down Expand Up @@ -199,15 +162,4 @@ func (s *CCVTestSuite) checkConsumerChainIsRemoved(chainID string, checkChannel
s.Require().Nil(providerKeeper.GetSlashAcks(s.providerCtx(), chainID))
s.Require().Zero(providerKeeper.GetInitChainHeight(s.providerCtx(), chainID))
s.Require().Empty(providerKeeper.GetPendingVSCPackets(s.providerCtx(), chainID))

// No remaining global entries for this consumer
allGlobalEntries := providerKeeper.GetAllGlobalSlashEntries(s.providerCtx())
for _, entry := range allGlobalEntries {
s.Require().NotEqual(chainID, entry.ConsumerChainID)
}

// No remaining per-chain entries for this consumer
slashData, vscMaturedData, _, _ := providerKeeper.GetAllThrottledPacketData(s.providerCtx(), chainID)
s.Require().Empty(slashData)
s.Require().Empty(vscMaturedData)
}
Loading
Loading