Skip to content

Commit

Permalink
feat(sequencer): query all proposers (#1221)
Browse files Browse the repository at this point in the history
zale144 authored Sep 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 0f876b3 commit e670723
Showing 8 changed files with 3,136 additions and 1,097 deletions.
3,486 changes: 2,452 additions & 1,034 deletions docs/static/openapi.yml

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions proto/dymensionxyz/dymension/sequencer/query.proto
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ service Query {
// Queries a list of Sequencer items.
rpc Sequencers(QuerySequencersRequest) returns (QuerySequencersResponse) {
option (google.api.http).get =
"/dymensionxyz/dymension/sequencer/sequencer";
"/dymensionxyz/dymension/sequencer/sequencers";
}

// Queries a SequencersByRollapp by rollappId.
@@ -39,15 +39,15 @@ service Query {
// Queries a SequencersByRollappByStatus
rpc SequencersByRollappByStatus(QueryGetSequencersByRollappByStatusRequest)
returns (QueryGetSequencersByRollappByStatusResponse) {
option (google.api.http).get = "/dymensionxyz/dymension/sequencer/"
"sequencers_by_rollapp/{rollappId}/{status}";
option (google.api.http).get =
"/dymensionxyz/dymension/sequencer/sequencers_by_rollapp/{rollappId}/{status}";
}

// Queries the current proposer by rollappId.
rpc GetProposerByRollapp(QueryGetProposerByRollappRequest)
returns (QueryGetProposerByRollappResponse) {
option (google.api.http).get =
"/dymensionxyz/dymension/sequencer/proposer/{rollappId}";
"/dymensionxyz/dymension/sequencer/proposers/{rollappId}";
}

// Queries the next proposer by rollappId.
@@ -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/proposers";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
@@ -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
@@ -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,
@@ -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
@@ -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
}
32 changes: 31 additions & 1 deletion x/sequencer/keeper/grpc_query_sequencers_by_rollapp.go
Original file line number Diff line number Diff line change
@@ -4,9 +4,14 @@ import (
"context"
"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) {
@@ -77,3 +82,28 @@ 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))
if ok {
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
@@ -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()
}

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

Large diffs are not rendered by default.

87 changes: 85 additions & 2 deletions x/sequencer/types/query.pb.gw.go

0 comments on commit e670723

Please sign in to comment.