Skip to content

Commit

Permalink
fully restore query
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed Aug 24, 2023
1 parent db8dc1b commit 78a8269
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 70 deletions.
3 changes: 1 addition & 2 deletions proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ service Query {
"/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
// [DEPRECATED] Returns an empty set.
rpc QueryThrottledConsumerPacketData(QueryThrottledConsumerPacketDataRequest)
returns (QueryThrottledConsumerPacketDataResponse) {
option (google.api.http).get =
Expand Down
5 changes: 2 additions & 3 deletions x/ccv/provider/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,9 @@ $ %s query provider throttle-state
func CmdThrottledConsumerPacketData() *cobra.Command {
cmd := &cobra.Command{
Use: "throttled-consumer-packet-data [chainid]",
Short: "Query pending VSCMatured and slash packet data for a consumer chainId",
Short: "[DEPRECIATED] Returns an empty set.",
Long: strings.TrimSpace(
fmt.Sprintf(`Returns the current pending VSCMatured and slash packet data instances for a consumer chainId.
Queue is ordered by ibc sequence number.
fmt.Sprintf(`[DEPRECIATED] Returns an empty set.
Example:
$ %s query provider throttled-consumer-packet-data foochain
`,
Expand Down
62 changes: 1 addition & 61 deletions x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"context"
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -150,24 +149,6 @@ func (k Keeper) QueryThrottleState(goCtx context.Context, req *types.QueryThrott
candidate := k.GetSlashMeterReplenishTimeCandidate(ctx) // always UTC
packets := []*types.ThrottledSlashPacket{}

// iterate global slash entries from all consumer chains
// and fetch corresponding SlashPacketData from the per-chain throttled packet data queue
allGlobalEntries := k.GetAllGlobalSlashEntries(ctx)

for _, entry := range allGlobalEntries {
// Obtain slash packet data instance for the given global entry
slashData, found := k.getSlashPacketData(ctx, entry.ConsumerChainID, entry.IbcSeqNum)
if !found {
// silently skip over invalid data
continue
}

packets = append(packets, &types.ThrottledSlashPacket{
GlobalEntry: entry,
Data: slashData,
})
}

return &types.QueryThrottleStateResponse{
SlashMeter: meter.Int64(),
SlashMeterAllowance: allowance.Int64(),
Expand All @@ -191,55 +172,14 @@ func (k Keeper) QueryThrottledConsumerPacketData(goCtx context.Context, req *typ
}

packetDataInstances := []types.ThrottledPacketDataWrapper{}
_, _, rawOrderedData, _ := k.GetAllThrottledPacketData(ctx, req.ChainId)

for _, raw := range rawOrderedData {
switch data := raw.(type) {
case ccvtypes.SlashPacketData:
w := &types.ThrottledPacketDataWrapper_SlashPacket{SlashPacket: &data}
packetDataInstances = append(packetDataInstances, types.ThrottledPacketDataWrapper{
Data: w,
})
case ccvtypes.VSCMaturedPacketData:
w := &types.ThrottledPacketDataWrapper_VscMaturedPacket{VscMaturedPacket: &data}
packetDataInstances = append(packetDataInstances, types.ThrottledPacketDataWrapper{
Data: w,
})
default:
k.Logger(ctx).Error(fmt.Sprintf("unexpected packet data type: %T", data))
}
}

return &types.QueryThrottledConsumerPacketDataResponse{
ChainId: req.ChainId,
Size_: k.GetThrottledPacketDataSize(ctx, req.ChainId),
Size_: 0,
PacketDataInstances: packetDataInstances,
}, nil
}

// getSlashPacketData fetches a slash packet data from the store using consumerChainId and ibcSeqNum (direct access)
// If the returned bytes do not unmarshal to SlashPacketData, the data is considered not found.
func (k Keeper) getSlashPacketData(ctx sdk.Context, consumerChainID string, ibcSeqNum uint64) (ccvtypes.SlashPacketData, bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ThrottledPacketDataKey(consumerChainID, ibcSeqNum))
if len(bz) == 0 {
return ccvtypes.SlashPacketData{}, false
}

if bz[0] != slashPacketData {
return ccvtypes.SlashPacketData{}, false
}

packet := ccvtypes.SlashPacketData{}
err := packet.Unmarshal(bz[1:])
if err != nil {
// If the data cannot be unmarshaled, it is considered not found
return ccvtypes.SlashPacketData{}, false
}

return packet, true
}

func (k Keeper) QueryRegisteredConsumerRewardDenoms(goCtx context.Context, req *types.QueryRegisteredConsumerRewardDenomsRequest) (*types.QueryRegisteredConsumerRewardDenomsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
Expand Down
6 changes: 2 additions & 4 deletions x/ccv/provider/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 78a8269

Please sign in to comment.