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: consumer throttle state query #1285

Merged
Merged
Changes from 47 commits
Commits
Show all changes
49 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
c956441
protobuf gen
shaspitz Sep 11, 2023
280e854
impl query resp
shaspitz Sep 11, 2023
688fd8a
add query assertion to e2e tests
shaspitz Sep 12, 2023
000d4a5
Merge branch 'feat/throttle-complete-attempt-2' into shawn/consumer-t…
shaspitz Sep 14, 2023
8d50918
lint
shaspitz Sep 14, 2023
3ea0cf4
add consumer to pending packets name
shaspitz Sep 18, 2023
6e4768e
add panic for invalid bytes
shaspitz Sep 18, 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
14 changes: 14 additions & 0 deletions proto/interchain_security/ccv/consumer/v1/query.proto
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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;
29 changes: 27 additions & 2 deletions tests/e2e/state.go
Original file line number Diff line number Diff line change
@@ -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
PendingPacketQueueSize *uint // Only relevant to consumer chains
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make the name more explicitly mention Consumer chains again?

Suggested change
PendingPacketQueueSize *uint // Only relevant to consumer chains
ConsumerChainsPendingPacketQueueSize *uint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RegisteredConsumerRewardDenoms *[]string
}

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

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

if *verbose {
log.Println("Done getting chain state:\n" + pretty.Sprint(chainState))
}
@@ -694,6 +698,23 @@ 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))
}

packetData := gjson.Get(string(bz), "packet_data_queue").Array()
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add validation logic here? I'd be worried this could break in "interesting" ways.

From the gjson documentation on the Get function https://godocs.io/github.com/tidwall/gjson#Get:
"This function expects that the json is well-formed, and does not validate. Invalid json will not panic, but it may return back unexpected results. If you are consuming JSON from an unpredictable source then you may want to use the Valid function first. "

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup seems reasonable to panic when valid returns false for the json 👍 6e4768e

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 {
@@ -742,3 +763,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
@@ -293,6 +293,7 @@ func stepsThrottledDowntime(consumerName string) []Step {
validatorID("bob"): 500,
validatorID("carol"): 500,
},
PendingPacketQueueSize: uintPtr(1), // bob's downtime slash packet is queued
},
},
},
@@ -321,6 +322,7 @@ func stepsThrottledDowntime(consumerName string) []Step {
validatorID("bob"): 500,
validatorID("carol"): 500,
},
PendingPacketQueueSize: uintPtr(0), // slash packet handled ack clears consumer queue
},
},
},
@@ -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,
},
PendingPacketQueueSize: uintPtr(1), // carol's downtime slash packet is queued
},
},
},
@@ -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,
},
PendingPacketQueueSize: uintPtr(1), // slash packet bounced ack keeps carol's downtime slash packet queued
},
},
},
28 changes: 28 additions & 0 deletions x/ccv/consumer/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ func NewQueryCmd() *cobra.Command {
cmd.AddCommand(
CmdNextFeeDistribution(),
CmdProviderInfo(),
CmdThrottleState(),
)

return cmd
@@ -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
@@ -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
@@ -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
Loading