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(delayedack): Add type filter for delayedack query #860

Merged
merged 7 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

- (delayedack) [#850](https://github.com/dymensionxyz/dymension/issues/850) Add type filter for delayedack
- (rollapp) [#829](https://github.com/dymensionxyz/dymension/issues/829) Refactor rollapp cli to be more useful
- (delayedack) [#728](https://github.com/dymensionxyz/dymension/issues/728) Create eibc order on err ack from rollapp
- (delayedack) [#672](https://github.com/dymensionxyz/dymension/issues/672) Delayedack invariant for finalized and reverted packets
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/osmosis-labs/osmosis/v15 v15.2.1
github.com/osmosis-labs/osmosis/v15 v15.2.0
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
Expand Down
3 changes: 2 additions & 1 deletion proto/dymension/common/rollapp_packet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ message RollappPacket {
ON_RECV = 0;
ON_ACK = 1;
ON_TIMEOUT = 2;
}
UNDEFINED = -1;
}
Type type = 7;
// stores the result of onAck, onTimeout or onRecv/writeAck
string error = 8;
Expand Down
3 changes: 0 additions & 3 deletions proto/dymension/common/status.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ package dymensionxyz.dymension.common;

import "gogoproto/gogo.proto";


option go_package = "github.com/dymensionxyz/dymension/v3/x/common/types";


enum Status {
PENDING = 0;
FINALIZED = 1;
REVERTED = 3;
}

6 changes: 2 additions & 4 deletions proto/dymension/delayedack/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ service Query {
rpc GetPackets(QueryRollappPacketsRequest) returns (QueryRollappPacketListResponse) {
option (google.api.http).get = "/dymensionxyz/dymension/delayedack/packets/{rollappId}/{status}";
}


}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand All @@ -34,11 +32,11 @@ message QueryParamsResponse {
Params params = 1 [(gogoproto.nullable) = false];
}


message QueryRollappPacketsRequest {
string rollappId = 1;
common.Status status = 2;
cosmos.base.query.v1beta1.PageRequest pagination = 3;
common.RollappPacket.Type type = 3;
cosmos.base.query.v1beta1.PageRequest pagination = 4;
}

message QueryRollappPacketListResponse {
Expand Down
2 changes: 1 addition & 1 deletion x/common/types/packet_uid.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package types

import fmt "fmt"
import "fmt"

// PacketUID is a unique identifier for an Rollapp IBC packet on the hub
type PacketUID struct {
Expand Down
67 changes: 36 additions & 31 deletions x/common/types/rollapp_packet.pb.go

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

114 changes: 89 additions & 25 deletions x/delayedack/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"

commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
"github.com/dymensionxyz/dymension/v3/x/delayedack/types"
)
Expand All @@ -29,6 +30,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdGetPacketsByRollapp())
cmd.AddCommand(CmdGetPacketsByStatus())
cmd.AddCommand(CmdGetPacketsByType())

return cmd
}
Expand Down Expand Up @@ -57,22 +59,15 @@ func CmdQueryParams() *cobra.Command {
return cmd
}

// Define the map
var statusMap = map[string]commontypes.Status{
"PENDING": commontypes.Status_PENDING,
"FINALIZED": commontypes.Status_FINALIZED,
"REVERTED": commontypes.Status_REVERTED,
}

func CmdGetPacketsByRollapp() *cobra.Command {
cmd := &cobra.Command{
Use: "packets-by-rollapp rollapp-id [status]",
Short: "get packets by rollapp-id",
Long: `get packets by rollapp-id. Can filter by status (pending/finalized/reverted)
Use: "packets-by-rollapp rollapp-id [status] [type]",
Short: "Get packets by rollapp-id",
Long: `Get packets by rollapp-id. Can filter by status (pending/finalized/reverted) and by type (recv/ack/timeout)
Example:
packets rollapp1 PENDING
packets rollapp1
packets PENDING`,
packets rollapp1 PENDING
packets rollapp1 PENDING RECV`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
Expand All @@ -83,21 +78,34 @@ func CmdGetPacketsByRollapp() *cobra.Command {

req := &types.QueryRollappPacketsRequest{
RollappId: rollappId,
Status: commontypes.Status_PENDING, // get pending packets by default
Status: commontypes.Status_PENDING, // get pending packets by default
Type: commontypes.RollappPacket_UNDEFINED, // must specify, as '0' is a valid type
}

if len(args) > 1 {
// Use the map to convert a string to an enum
statusStr := strings.ToUpper(args[1])
status, ok := statusMap[statusStr]
status, ok := commontypes.Status_value[statusStr]
if !ok {
// Handle error: statusStr is not a valid commontypes.Status
return fmt.Errorf("invalid status: %s", statusStr)
}
req.Status = status
req.Status = commontypes.Status(status)
}

if len(args) > 2 {
typeStr := strings.ToUpper(args[2])
Copy link
Contributor

@trinitys7 trinitys7 Apr 24, 2024

Choose a reason for hiding this comment

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

As I understand in the code, in order to filter by type, we need to filter it by status first. We should make the code separate between status and type. Let do them same as this, check if the first argument start with ON_ ... . If yes then it should be filtered by type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in packets-by-rollapp the status and type are optional filters. In packets-by-status the type is optional. But you still have packets-by-type so you can use that to filter by type alone, granted the status will be PENDING by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I mean is like, when you assert like that, the filter must always be status first, and then after that it can be type. So it's kinda annoying if I want to filter just by type

if !strings.HasPrefix(typeStr, "ON_") {
typeStr = "ON_" + typeStr
}
dtype, ok := commontypes.RollappPacket_Type_value[typeStr]
if !ok {
// Handle error: typeStr is not a valid commontypes.Type
return fmt.Errorf("invalid type: %s", typeStr)
}
req.Type = commontypes.RollappPacket_Type(dtype)
}

res, err := queryClient.GetPackets(context.Background(), req)
res, err := queryClient.GetPackets(cmd.Context(), req)
if err != nil {
return err
}
Expand All @@ -113,28 +121,84 @@ func CmdGetPacketsByRollapp() *cobra.Command {

func CmdGetPacketsByStatus() *cobra.Command {
cmd := &cobra.Command{
Use: "packets-by-status status",
Short: "get packets by status",
Long: `get packets by status. Can filter by status (pending/finalized/reverted)
Use: "packets-by-status status [type]",
Short: "Get packets by status",
Long: `Get packets by status (pending/finalized/reverted). Can filter by type (recv/ack/timeout)
Example:
packets-by-status pending
packets-by-status finalized`,
Args: cobra.ExactArgs(1),
packets-by-status finalized recv`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)

statusStr := strings.ToUpper(args[0])
status, ok := statusMap[statusStr]
status, ok := commontypes.Status_value[statusStr]
if !ok {
return fmt.Errorf("invalid status: %s", statusStr)
}

req := &types.QueryRollappPacketsRequest{
Status: status,
Status: commontypes.Status(status),
Type: commontypes.RollappPacket_UNDEFINED, // must specify, as '0' is a valid type
}

if len(args) > 1 {
typeStr := strings.ToUpper(args[1])
if !strings.HasPrefix(typeStr, "ON_") {
typeStr = "ON_" + typeStr
}
dtype, ok := commontypes.RollappPacket_Type_value[typeStr]
if !ok {
return fmt.Errorf("invalid type: %s", typeStr)
}
req.Type = commontypes.RollappPacket_Type(dtype)
}

res, err := queryClient.GetPackets(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func CmdGetPacketsByType() *cobra.Command {
cmd := &cobra.Command{
Use: "packets-by-type type",
Short: "Get pending packets by type",
Long: `Get pending packets by type. Can filter by type (recv/ack/timeout)
Example:
packets-by-type on_recv
packets-by-type on_timeout`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)

typeStr := strings.ToUpper(args[0])

if !strings.HasPrefix(typeStr, "ON_") {
typeStr = "ON_" + typeStr
}

dtype, ok := commontypes.RollappPacket_Type_value[typeStr]
if !ok {
return fmt.Errorf("invalid type: %s", typeStr)
}

req := &types.QueryRollappPacketsRequest{
Type: commontypes.RollappPacket_Type(dtype),
Status: commontypes.Status_PENDING, // get pending packets by default
}

res, err := queryClient.GetPackets(context.Background(), req)
res, err := queryClient.GetPackets(cmd.Context(), req)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions x/delayedack/eibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"

"github.com/dymensionxyz/dymension/v3/utils"
commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
"github.com/dymensionxyz/dymension/v3/x/delayedack/types"
Expand Down
1 change: 1 addition & 0 deletions x/delayedack/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types"
"github.com/cosmos/ibc-go/v6/modules/core/exported"

commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
"github.com/dymensionxyz/dymension/v3/x/delayedack/keeper"
"github.com/dymensionxyz/dymension/v3/x/delayedack/types"
Expand Down
3 changes: 2 additions & 1 deletion x/delayedack/keeper/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types"

commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
"github.com/dymensionxyz/dymension/v3/x/delayedack/types"

osmoutils "github.com/osmosis-labs/osmosis/v15/osmoutils"
"github.com/osmosis-labs/osmosis/v15/osmoutils"
"github.com/tendermint/tendermint/libs/log"
)

Expand Down
1 change: 1 addition & 0 deletions x/delayedack/keeper/fraud.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types"

commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
)

Expand Down
Loading
Loading