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(sequencer): query all proposers #1221

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,782 changes: 1,600 additions & 182 deletions docs/static/openapi.yml

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions proto/dymensionxyz/dymension/sequencer/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ service Query {
option (google.api.http).get =
"/dymensionxyz/dymension/sequencer/next_proposer/{rollappId}";
}

// Queries a list of proposers.
rpc Proposers(QueryProposersRequest) returns (QueryProposersResponse) {
option (google.api.http).get =
"/dymensionxyz/dymension/sequencer/proposer";
zale144 marked this conversation as resolved.
Show resolved Hide resolved
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -114,3 +120,14 @@ message QueryGetNextProposerByRollappResponse {
// rotationInProgress is true if the proposer rotation is in progress.
bool rotationInProgress = 2;
}

// Request type for the Proposers RPC method.
message QueryProposersRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// Response type for the Proposers RPC method.
message QueryProposersResponse {
repeated Sequencer proposers = 1 [ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
3 changes: 2 additions & 1 deletion x/sequencer/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
func GetQueryCmd() *cobra.Command {
// Group sequencer queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,
Expand All @@ -26,6 +26,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdShowSequencersByRollapp())
cmd.AddCommand(CmdGetProposerByRollapp())
cmd.AddCommand(CmdGetNextProposerByRollapp())
cmd.AddCommand(CmdGetAllProposers())

return cmd
}
26 changes: 26 additions & 0 deletions x/sequencer/client/cli/query_sequencers_by_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,29 @@ func CmdGetNextProposerByRollapp() *cobra.Command {
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func CmdGetAllProposers() *cobra.Command {
cmd := &cobra.Command{
Use: "list-proposer",
Short: "List all proposers",
RunE: func(cmd *cobra.Command, args []string) error {
params := &types.QueryProposersRequest{}

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

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

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}
34 changes: 33 additions & 1 deletion x/sequencer/keeper/grpc_query_sequencers_by_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import (
"context"
"errors"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
)

func (k Keeper) SequencersByRollapp(c context.Context, req *types.QueryGetSequencersByRollappRequest) (*types.QueryGetSequencersByRollappResponse, error) {
Expand Down Expand Up @@ -77,3 +83,29 @@ func (k Keeper) GetNextProposerByRollapp(c context.Context, req *types.QueryGetN
RotationInProgress: k.IsRotating(ctx, req.RollappId),
}, nil
}

func (k Keeper) Proposers(c context.Context, req *types.QueryProposersRequest) (*types.QueryProposersResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

var proposers []types.Sequencer
ctx := sdk.UnwrapSDKContext(c)

store := ctx.KVStore(k.storeKey)
sequencerStore := prefix.NewStore(store, types.ProposerByRollappKey(""))

pageRes, err := query.Paginate(sequencerStore, req.Pagination, func(key []byte, value []byte) error {
proposer, ok := k.GetSequencer(ctx, string(value))
mtsitrin marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
return errorsmod.Wrap(types.ErrNoProposer, string(value))
}
proposers = append(proposers, proposer)
return nil
})
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &types.QueryProposersResponse{Proposers: proposers, Pagination: pageRes}, nil
}
2 changes: 1 addition & 1 deletion x/sequencer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (a AppModuleBasic) GetTxCmd() *cobra.Command {

// GetQueryCmd returns the capability module's root query command.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd(types.StoreKey)
return cli.GetQueryCmd()
}

// ----------------------------------------------------------------------------
Expand Down
572 changes: 518 additions & 54 deletions x/sequencer/types/query.pb.go

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions x/sequencer/types/query.pb.gw.go

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

Loading