Skip to content

Commit

Permalink
fix: remove start_epoch and end_epoch parameters in APIs (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis authored Feb 14, 2023
1 parent 8242bc6 commit a5b42bf
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 347 deletions.
20 changes: 0 additions & 20 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,6 @@ paths:
type: string
format: byte
parameters:
- name: start_epoch
in: query
required: false
type: string
format: uint64
- name: end_epoch
in: query
required: false
type: string
format: uint64
- name: pagination.key
description: |-
key is a value returned in PageResponse.next_key to begin
Expand Down Expand Up @@ -1875,16 +1865,6 @@ paths:
"value": "1.212s"
}
parameters:
- name: start_epoch
in: query
required: false
type: string
format: uint64
- name: end_epoch
in: query
required: false
type: string
format: uint64
- name: pagination.key
description: |-
key is a value returned in PageResponse.next_key to begin
Expand Down
5 changes: 1 addition & 4 deletions proto/babylon/btccheckpoint/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ message QueryBtcCheckpointInfoResponse {

// QueryBtcCheckpointsInfoRequest is request type for the Query/BtcCheckpointsInfo RPC method
message QueryBtcCheckpointsInfoRequest {
uint64 start_epoch = 1;
uint64 end_epoch = 2;

// pagination defines whether to have the pagination in the request
cosmos.base.query.v1beta1.PageRequest pagination = 3;
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// QueryBtcCheckpointsInfoResponse is response type for the Query/BtcCheckpointsInfo RPC method
Expand Down
5 changes: 1 addition & 4 deletions proto/babylon/epoching/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ message QueryEpochInfoResponse {
}

message QueryEpochsInfoRequest {
uint64 start_epoch = 1;
uint64 end_epoch = 2;

// pagination defines whether to have the pagination in the request
cosmos.base.query.v1beta1.PageRequest pagination = 3;
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryEpochsInfoResponse {
Expand Down
13 changes: 0 additions & 13 deletions x/btccheckpoint/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,6 @@ func (k Keeper) BtcCheckpointsInfo(c context.Context, req *types.QueryBtcCheckpo

ctx := sdk.UnwrapSDKContext(c)

// parse start_epoch and end_epoch and forward to the pagination request
if req.EndEpoch > 0 {
// this query uses start_epoch and end_epoch to specify range
if req.StartEpoch > req.EndEpoch {
return nil, fmt.Errorf("StartEpoch (%d) should not be larger than EndEpoch (%d)", req.StartEpoch, req.EndEpoch)
}
req.Pagination = &query.PageRequest{
Key: sdk.Uint64ToBigEndian(req.StartEpoch),
Limit: req.EndEpoch - req.StartEpoch + 1,
Reverse: false,
}
}

store := ctx.KVStore(k.storeKey)
epochDataStore := prefix.NewStore(store, types.EpochDataPrefix)

Expand Down
156 changes: 42 additions & 114 deletions x/btccheckpoint/types/query.pb.go

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

14 changes: 0 additions & 14 deletions x/epoching/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
"context"
"errors"
"fmt"

"cosmossdk.io/math"

Expand Down Expand Up @@ -59,19 +58,6 @@ func (k Keeper) EpochInfo(c context.Context, req *types.QueryEpochInfoRequest) (
func (k Keeper) EpochsInfo(c context.Context, req *types.QueryEpochsInfoRequest) (*types.QueryEpochsInfoResponse, error) {
ctx := sdk.UnwrapSDKContext(c)

// parse start_epoch and end_epoch and forward to the pagination request
if req.EndEpoch > 0 {
// this query uses start_epoch and end_epoch to specify range
if req.StartEpoch > req.EndEpoch {
return nil, fmt.Errorf("StartEpoch (%d) should not be larger than EndEpoch (%d)", req.StartEpoch, req.EndEpoch)
}
req.Pagination = &query.PageRequest{
Key: sdk.Uint64ToBigEndian(req.StartEpoch),
Limit: req.EndEpoch - req.StartEpoch + 1,
Reverse: false,
}
}

epochInfoStore := k.epochInfoStore(ctx)
epochs := []*types.Epoch{}
pageRes, err := query.Paginate(epochInfoStore, req.Pagination, func(key, value []byte) error {
Expand Down
37 changes: 0 additions & 37 deletions x/epoching/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,43 +124,6 @@ func FuzzEpochsInfo(f *testing.F) {
})
}

func FuzzEpochsInfo_QueryParams(f *testing.F) {
datagen.AddRandomSeedsToFuzzer(f, 10)

f.Fuzz(func(t *testing.T, seed int64) {
rand.Seed(seed)
numEpochs := datagen.RandomInt(10) + 2

endEpoch := rand.Uint64()%(numEpochs-1) + 1
startEpoch := rand.Uint64() % endEpoch

helper := testepoching.NewHelper(t)
ctx, keeper, queryClient := helper.Ctx, helper.EpochingKeeper, helper.QueryClient
wctx := sdk.WrapSDKContext(ctx)

// enque the first block of the numEpochs'th epoch
epochInterval := keeper.GetParams(ctx).EpochInterval
for i := uint64(0); i < numEpochs-1; i++ {
for j := uint64(0); j < epochInterval; j++ {
helper.GenAndApplyEmptyBlock()
}
}

// get epoch msgs
req := types.QueryEpochsInfoRequest{
StartEpoch: startEpoch,
EndEpoch: endEpoch,
}
resp, err := queryClient.EpochsInfo(wctx, &req)
require.NoError(t, err)

require.Equal(t, endEpoch-startEpoch+1, uint64(len(resp.Epochs)))
for i, epoch := range resp.Epochs {
require.Equal(t, uint64(i)+startEpoch, epoch.EpochNumber)
}
})
}

// FuzzEpochMsgsQuery fuzzes queryClient.EpochMsgs
// 1. randomly generate msgs and limit in pagination
// 2. check the returned msg was previously enqueued
Expand Down
Loading

0 comments on commit a5b42bf

Please sign in to comment.