Skip to content

Commit

Permalink
feat: consumer throttle state query (#1285)
Browse files Browse the repository at this point in the history
* wip, tests not fixed yet

* rm packet query on provider

* rm unneeded UTs

* rm tests from relay_test

* rm query and more tests

* rm more tests

* builds again and rm debug tests

* lint

* fix handling of slash packet and integration test

* Fix TestMultiConsumerSlashPacketThrottling

* fix two more slashing integration tests

* Update TestSlashRetries, cleanup neededc

* cleaned up TestSlashRetries

* UT for TestOnRecvDowntimeSlashPacket

* cleans

* use helper in throttle test

* lintz

* Revert "rm packet query on provider"

This reverts commit a10a239.

* cmd file too

* fully restore query

* Revert "Merge branch 'main' into shawn/throttle-with-retries-provider-changes"

This reverts commit 73db33b, reversing
changes made to 78a8269.

* make e2e test pass, with todos

* clean

* Revert "Revert "Merge branch 'main' into shawn/throttle-with-retries-provider-changes""

This reverts commit 5bfccc3.

* lint

* Update CHANGELOG.md

* slightly longer buffer

* build(deps): bump actions/checkout from 3 to 4 (#1257)

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps)!: bump github.com/cosmos/ibc-go/v7 from 7.2.0 to 7.3.0 (#1258)

* build(deps): bump github.com/cosmos/ibc-go/v7 from 7.2.0 to 7.3.0

Bumps [github.com/cosmos/ibc-go/v7](https://github.com/cosmos/ibc-go) from 7.2.0 to 7.3.0.
- [Release notes](https://github.com/cosmos/ibc-go/releases)
- [Changelog](https://github.com/cosmos/ibc-go/blob/main/CHANGELOG.md)
- [Commits](cosmos/ibc-go@v7.2.0...v7.3.0)

---
updated-dependencies:
- dependency-name: github.com/cosmos/ibc-go/v7
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* add changelog entries

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: mpoke <[email protected]>

* build(deps): bump github.com/cosmos/cosmos-sdk from 0.47.4 to 0.47.5 (#1259)

* build(deps): bump github.com/cosmos/cosmos-sdk from 0.47.3 to 0.47.5

Bumps [github.com/cosmos/cosmos-sdk](https://github.com/cosmos/cosmos-sdk) from 0.47.3 to 0.47.5.
- [Release notes](https://github.com/cosmos/cosmos-sdk/releases)
- [Changelog](https://github.com/cosmos/cosmos-sdk/blob/main/CHANGELOG.md)
- [Commits](cosmos/cosmos-sdk@v0.47.3...v0.47.5)

---
updated-dependencies:
- dependency-name: github.com/cosmos/cosmos-sdk
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* add changelog entries

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: mpoke <[email protected]>

* chore: Separate semver (#1217)

separate semver

* docs: cleanup changelog (#1260)

fix changelog

* fix!: validate MsgTransfer before calling Transfer() (#1244)

* validate MsgTransfer

* add TestSendRewardsToProvider

* update DefaultConsumerUnbondingPeriod to 14 days

* update changelog

* fix linter

* fix test

* apply review suggestions

* update changelog

* docs: Create adr-012-separate-releasing.md (#1229)

* Create adr-011-separate-releasing.md

* Update docs/docs/adrs/adr-011-separate-releasing.md

Co-authored-by: Philip Offtermatt <[email protected]>

* adr 12 not 11

* correct that we use postfix not prefix

* explanation on example release flow

---------

Co-authored-by: Philip Offtermatt <[email protected]>

* fix: remove addr validation for provider fee pool addr param (#1262)

* fix: remove validation for provider chain address since we cannot validate it properly on consumer

* add changelog entry

* Revert "Merge branch 'main' into shawn/throttle-with-retries-provider-changes"

This reverts commit 6bdfff9, reversing
changes made to d8f5690.

* fmt

* protobuf gen

* impl query resp

* add query assertion to e2e tests

* lint

* add consumer to pending packets name

* add panic for invalid bytes

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: mpoke <[email protected]>
Co-authored-by: Philip Offtermatt <[email protected]>
Co-authored-by: Dmitry Kolupaev <[email protected]>
  • Loading branch information
5 people authored Sep 18, 2023
1 parent 727e731 commit f060f48
Show file tree
Hide file tree
Showing 7 changed files with 617 additions and 47 deletions.
14 changes: 14 additions & 0 deletions proto/interchain_security/ccv/consumer/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ option go_package = "github.com/cosmos/interchain-security/v3/x/ccv/consumer/typ
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "interchain_security/ccv/consumer/v1/consumer.proto";
import "interchain_security/ccv/v1/wire.proto";

service Query {
// ConsumerGenesis queries the genesis state needed to start a consumer chain
Expand All @@ -24,6 +25,11 @@ service Query {
rpc QueryProviderInfo(QueryProviderInfoRequest) returns (QueryProviderInfoResponse) {
option (google.api.http).get = "/interchain_security/ccv/consumer/provider-info";
}

// QueryThrottleState returns on-chain state relevant to throttled consumer packets
rpc QueryThrottleState(QueryThrottleStateRequest) returns (QueryThrottleStateResponse) {
option (google.api.http).get = "/interchain_security/ccv/consumer/throttle_state";
}
}

// NextFeeDistributionEstimate holds information about next fee distribution
Expand Down Expand Up @@ -65,6 +71,14 @@ message QueryProviderInfoResponse {
ChainInfo provider = 2 [ (gogoproto.nullable) = false ];
}

message QueryThrottleStateRequest {}

message QueryThrottleStateResponse {
SlashRecord slash_record = 1 [ (gogoproto.nullable) = true ];
repeated interchain_security.ccv.v1.ConsumerPacketData packet_data_queue = 2 [ (gogoproto.nullable) = false ];
}


message ChainInfo {
string chainID = 1;
string clientID = 2;
Expand Down
33 changes: 31 additions & 2 deletions tests/e2e/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ type ChainState struct {
ConsumerChains *map[chainID]bool
AssignedKeys *map[validatorID]string
ProviderKeys *map[validatorID]string // validatorID: validator provider key
ConsumerChainQueueSizes *map[chainID]uint
GlobalSlashQueueSize *uint
ConsumerPendingPacketQueueSize *uint // Only relevant to consumer chains
RegisteredConsumerRewardDenoms *[]string
}

Expand Down Expand Up @@ -173,6 +172,11 @@ func (tr TestRun) getChainState(chain chainID, modelState ChainState) ChainState
chainState.RegisteredConsumerRewardDenoms = &registeredConsumerRewardDenoms
}

if modelState.ConsumerPendingPacketQueueSize != nil {
pendingPacketQueueSize := tr.getPendingPacketQueueSize(chain)
chainState.ConsumerPendingPacketQueueSize = &pendingPacketQueueSize
}

if *verbose {
log.Println("Done getting chain state:\n" + pretty.Sprint(chainState))
}
Expand Down Expand Up @@ -694,6 +698,27 @@ func (tr TestRun) getRegisteredConsumerRewardDenoms(chain chainID) []string {
return rewardDenoms
}

func (tr TestRun) getPendingPacketQueueSize(chain chainID) uint {
//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
cmd := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[chain].binaryName,

"query", "ccvconsumer", "throttle-state",
`--node`, tr.getQueryNode(chain),
`-o`, `json`,
)
bz, err := cmd.CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}

if !gjson.ValidBytes(bz) {
panic("invalid json response from query ccvconsumer throttle-state: " + string(bz))
}

packetData := gjson.Get(string(bz), "packet_data_queue").Array()
return uint(len(packetData))
}

func (tr TestRun) getValidatorNode(chain chainID, validator validatorID) string {
// for CometMock, validatorNodes are all the same address as the query node (which is CometMocks address)
if tr.useCometmock {
Expand Down Expand Up @@ -742,3 +767,7 @@ func (tr TestRun) curlJsonRPCRequest(method, params, address string) {
verbosity := false
executeCommandWithVerbosity(cmd, "curlJsonRPCRequest", verbosity)
}

func uintPtr(i uint) *uint {
return &i
}
4 changes: 4 additions & 0 deletions tests/e2e/steps_downtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ func stepsThrottledDowntime(consumerName string) []Step {
validatorID("bob"): 500,
validatorID("carol"): 500,
},
ConsumerPendingPacketQueueSize: uintPtr(1), // bob's downtime slash packet is queued
},
},
},
Expand Down Expand Up @@ -321,6 +322,7 @@ func stepsThrottledDowntime(consumerName string) []Step {
validatorID("bob"): 500,
validatorID("carol"): 500,
},
ConsumerPendingPacketQueueSize: uintPtr(0), // slash packet handled ack clears consumer queue
},
},
},
Expand All @@ -344,6 +346,7 @@ func stepsThrottledDowntime(consumerName string) []Step {
validatorID("bob"): 500, // VSC packet jailing bob is not yet relayed to consumer
validatorID("carol"): 500,
},
ConsumerPendingPacketQueueSize: uintPtr(1), // carol's downtime slash packet is queued
},
},
},
Expand All @@ -368,6 +371,7 @@ func stepsThrottledDowntime(consumerName string) []Step {
validatorID("bob"): 0, // VSC packet applying bob jailing is also relayed and recv by consumer
validatorID("carol"): 500,
},
ConsumerPendingPacketQueueSize: uintPtr(1), // slash packet bounced ack keeps carol's downtime slash packet queued
},
},
},
Expand Down
28 changes: 28 additions & 0 deletions x/ccv/consumer/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func NewQueryCmd() *cobra.Command {
cmd.AddCommand(
CmdNextFeeDistribution(),
CmdProviderInfo(),
CmdThrottleState(),
)

return cmd
Expand Down Expand Up @@ -80,3 +81,30 @@ func CmdProviderInfo() *cobra.Command {

return cmd
}

func CmdThrottleState() *cobra.Command {
cmd := &cobra.Command{
Use: "throttle-state",
Short: "Query throttle state",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryThrottleStateRequest{}
res, err := queryClient.QueryThrottleState(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
23 changes: 23 additions & 0 deletions x/ccv/consumer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

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

var _ types.QueryServer = Keeper{} //nolint:golint
Expand Down Expand Up @@ -51,3 +52,25 @@ func (k Keeper) QueryProviderInfo(c context.Context, //nolint:golint

return k.GetProviderInfo(ctx)
}

func (k Keeper) QueryThrottleState(c context.Context,
req *types.QueryThrottleStateRequest,
) (*types.QueryThrottleStateResponse, error) {
ctx := sdk.UnwrapSDKContext(c)

resp := types.QueryThrottleStateResponse{}

slashRecord, found := k.GetSlashRecord(ctx)
if found {
resp.SlashRecord = &slashRecord
} else {
resp.SlashRecord = nil
}

resp.PacketDataQueue = make([]ccvtypes.ConsumerPacketData, 0)
pendingPackets := k.GetAllPendingPacketsWithIdx(ctx)
for _, packet := range pendingPackets {
resp.PacketDataQueue = append(resp.PacketDataQueue, packet.ConsumerPacketData)
}
return &resp, nil
}
Loading

0 comments on commit f060f48

Please sign in to comment.