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(blocktime): Implement query for SynchronyParams (backport #2686) #2687

Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LCDClient } from "@osmonauts/lcd";
import { QueryDowntimeParamsRequest, QueryDowntimeParamsResponseSDKType, QueryAllDowntimeInfoRequest, QueryAllDowntimeInfoResponseSDKType } from "./query";
import { QueryDowntimeParamsRequest, QueryDowntimeParamsResponseSDKType, QueryAllDowntimeInfoRequest, QueryAllDowntimeInfoResponseSDKType, QuerySynchronyParamsRequest, QuerySynchronyParamsResponseSDKType } from "./query";
export class LCDQueryClient {
req: LCDClient;

Expand All @@ -11,6 +11,7 @@ export class LCDQueryClient {
this.req = requestClient;
this.downtimeParams = this.downtimeParams.bind(this);
this.allDowntimeInfo = this.allDowntimeInfo.bind(this);
this.synchronyParams = this.synchronyParams.bind(this);
}
/* Queries the DowntimeParams. */

Expand All @@ -26,5 +27,12 @@ export class LCDQueryClient {
const endpoint = `dydxprotocol/v4/blocktime/all_downtime_info`;
return await this.req.get<QueryAllDowntimeInfoResponseSDKType>(endpoint);
}
/* Queries the SynchronyParams. */


async synchronyParams(_params: QuerySynchronyParamsRequest = {}): Promise<QuerySynchronyParamsResponseSDKType> {
const endpoint = `dydxprotocol/v4/blocktime/synchrony_params`;
return await this.req.get<QuerySynchronyParamsResponseSDKType>(endpoint);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Rpc } from "../../helpers";
import * as _m0 from "protobufjs/minimal";
import { QueryClient, createProtobufRpcClient } from "@cosmjs/stargate";
import { QueryDowntimeParamsRequest, QueryDowntimeParamsResponse, QueryPreviousBlockInfoRequest, QueryPreviousBlockInfoResponse, QueryAllDowntimeInfoRequest, QueryAllDowntimeInfoResponse } from "./query";
import { QueryDowntimeParamsRequest, QueryDowntimeParamsResponse, QueryPreviousBlockInfoRequest, QueryPreviousBlockInfoResponse, QueryAllDowntimeInfoRequest, QueryAllDowntimeInfoResponse, QuerySynchronyParamsRequest, QuerySynchronyParamsResponse } from "./query";
/** Query defines the gRPC querier service. */

export interface Query {
Expand All @@ -13,6 +13,9 @@ export interface Query {
/** Queries all recorded downtime info. */

allDowntimeInfo(request?: QueryAllDowntimeInfoRequest): Promise<QueryAllDowntimeInfoResponse>;
/** Queries the SynchronyParams. */

synchronyParams(request?: QuerySynchronyParamsRequest): Promise<QuerySynchronyParamsResponse>;
}
export class QueryClientImpl implements Query {
private readonly rpc: Rpc;
Expand All @@ -22,6 +25,7 @@ export class QueryClientImpl implements Query {
this.downtimeParams = this.downtimeParams.bind(this);
this.previousBlockInfo = this.previousBlockInfo.bind(this);
this.allDowntimeInfo = this.allDowntimeInfo.bind(this);
this.synchronyParams = this.synchronyParams.bind(this);
}

downtimeParams(request: QueryDowntimeParamsRequest = {}): Promise<QueryDowntimeParamsResponse> {
Expand All @@ -42,6 +46,12 @@ export class QueryClientImpl implements Query {
return promise.then(data => QueryAllDowntimeInfoResponse.decode(new _m0.Reader(data)));
}

synchronyParams(request: QuerySynchronyParamsRequest = {}): Promise<QuerySynchronyParamsResponse> {
const data = QuerySynchronyParamsRequest.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.blocktime.Query", "SynchronyParams", data);
return promise.then(data => QuerySynchronyParamsResponse.decode(new _m0.Reader(data)));
}

}
export const createRpcQueryExtension = (base: QueryClient) => {
const rpc = createProtobufRpcClient(base);
Expand All @@ -57,6 +67,10 @@ export const createRpcQueryExtension = (base: QueryClient) => {

allDowntimeInfo(request?: QueryAllDowntimeInfoRequest): Promise<QueryAllDowntimeInfoResponse> {
return queryService.allDowntimeInfo(request);
},

synchronyParams(request?: QuerySynchronyParamsRequest): Promise<QuerySynchronyParamsResponse> {
return queryService.synchronyParams(request);
}

};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import { DowntimeParams, DowntimeParamsSDKType } from "./params";
import { SynchronyParams, SynchronyParamsSDKType, DowntimeParams, DowntimeParamsSDKType } from "./params";
import { BlockInfo, BlockInfoSDKType, AllDowntimeInfo, AllDowntimeInfoSDKType } from "./blocktime";
import * as _m0 from "protobufjs/minimal";
import { DeepPartial } from "../../helpers";
/** QuerySynchronyParamsRequest is a request type for the SynchronyParams */

export interface QuerySynchronyParamsRequest {}
/** QuerySynchronyParamsRequest is a request type for the SynchronyParams */

export interface QuerySynchronyParamsRequestSDKType {}
/** QuerySynchronyParamsResponse is a response type for the SynchronyParams */

export interface QuerySynchronyParamsResponse {
params?: SynchronyParams;
}
/** QuerySynchronyParamsResponse is a response type for the SynchronyParams */

export interface QuerySynchronyParamsResponseSDKType {
params?: SynchronyParamsSDKType;
}
/**
* QueryDowntimeParamsRequest is a request type for the DowntimeParams
* RPC method.
Expand Down Expand Up @@ -103,6 +119,85 @@ export interface QueryAllDowntimeInfoResponseSDKType {
info?: AllDowntimeInfoSDKType;
}

function createBaseQuerySynchronyParamsRequest(): QuerySynchronyParamsRequest {
return {};
}

export const QuerySynchronyParamsRequest = {
encode(_: QuerySynchronyParamsRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): QuerySynchronyParamsRequest {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseQuerySynchronyParamsRequest();

while (reader.pos < end) {
const tag = reader.uint32();

switch (tag >>> 3) {
default:
reader.skipType(tag & 7);
break;
}
}

return message;
},

fromPartial(_: DeepPartial<QuerySynchronyParamsRequest>): QuerySynchronyParamsRequest {
const message = createBaseQuerySynchronyParamsRequest();
return message;
}

};

function createBaseQuerySynchronyParamsResponse(): QuerySynchronyParamsResponse {
return {
params: undefined
};
}

export const QuerySynchronyParamsResponse = {
encode(message: QuerySynchronyParamsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.params !== undefined) {
SynchronyParams.encode(message.params, writer.uint32(10).fork()).ldelim();
}

return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): QuerySynchronyParamsResponse {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseQuerySynchronyParamsResponse();

while (reader.pos < end) {
const tag = reader.uint32();

switch (tag >>> 3) {
case 1:
message.params = SynchronyParams.decode(reader, reader.uint32());
break;

default:
reader.skipType(tag & 7);
break;
}
}

return message;
},

fromPartial(object: DeepPartial<QuerySynchronyParamsResponse>): QuerySynchronyParamsResponse {
const message = createBaseQuerySynchronyParamsResponse();
message.params = object.params !== undefined && object.params !== null ? SynchronyParams.fromPartial(object.params) : undefined;
return message;
}

};

function createBaseQueryDowntimeParamsRequest(): QueryDowntimeParamsRequest {
return {};
}
Expand Down
15 changes: 15 additions & 0 deletions proto/dydxprotocol/blocktime/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ service Query {
option (google.api.http).get =
"/dydxprotocol/v4/blocktime/all_downtime_info";
}

// Queries the SynchronyParams.
rpc SynchronyParams(QuerySynchronyParamsRequest)
returns (QuerySynchronyParamsResponse) {
option (google.api.http).get =
"/dydxprotocol/v4/blocktime/synchrony_params";
}
}

// QuerySynchronyParamsRequest is a request type for the SynchronyParams
message QuerySynchronyParamsRequest {}

// QuerySynchronyParamsResponse is a response type for the SynchronyParams
message QuerySynchronyParamsResponse {
SynchronyParams params = 1 [ (gogoproto.nullable) = false ];
}

// QueryDowntimeParamsRequest is a request type for the DowntimeParams
Expand Down
39 changes: 38 additions & 1 deletion protocol/mocks/QueryClient.go

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

24 changes: 24 additions & 0 deletions protocol/x/blocktime/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdQueryDowntimeParams())
cmd.AddCommand(CmdQueryAllDowntimeInfo())
cmd.AddCommand(CmdQueryPreviousBlockInfo())
cmd.AddCommand(CmdQuerySynchronyParams())

return cmd
}
Expand Down Expand Up @@ -96,3 +97,26 @@ func CmdQueryPreviousBlockInfo() *cobra.Command {

return cmd
}

func CmdQuerySynchronyParams() *cobra.Command {
cmd := &cobra.Command{
Use: "sychrony-params",
Short: "get synchrony params",
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.SynchronyParams(
context.Background(),
&types.QuerySynchronyParamsRequest{},
)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
18 changes: 18 additions & 0 deletions protocol/x/blocktime/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ import (

var _ types.QueryServer = Keeper{}

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

ctx := lib.UnwrapSDKContext(c, types.ModuleName)
params := k.GetSynchronyParams(ctx)
return &types.QuerySynchronyParamsResponse{
Params: params,
}, nil
}

func (k Keeper) DowntimeParams(
c context.Context,
req *types.QueryDowntimeParamsRequest,
Expand Down
35 changes: 35 additions & 0 deletions protocol/x/blocktime/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,41 @@ import (
"github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types"
)

func TestSynchronyParams(t *testing.T) {
tApp := testapp.NewTestAppBuilder(t).Build()
ctx := tApp.InitChain()
k := tApp.App.BlockTimeKeeper

for name, tc := range map[string]struct {
req *types.QuerySynchronyParamsRequest
res *types.QuerySynchronyParamsResponse
err error
}{
"Default": {
req: &types.QuerySynchronyParamsRequest{},
res: &types.QuerySynchronyParamsResponse{
Params: types.DefaultSynchronyParams(),
},
err: nil,
},
"Nil": {
req: nil,
res: nil,
err: status.Error(codes.InvalidArgument, "invalid request"),
},
} {
t.Run(name, func(t *testing.T) {
res, err := k.SynchronyParams(ctx, tc.req)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
require.NoError(t, err)
require.Equal(t, tc.res, res)
}
})
}
}

func TestDowntimeParams(t *testing.T) {
tApp := testapp.NewTestAppBuilder(t).Build()
ctx := tApp.InitChain()
Expand Down
Loading
Loading