Skip to content

Commit

Permalink
epoching: bugfix of LatestEpochMsgs API (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis authored Sep 14, 2022
1 parent d44d836 commit 1d3386e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
18 changes: 9 additions & 9 deletions proto/babylon/epoching/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,27 @@ service Query {
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
babylon.epoching.v1.Params params = 1 [ (gogoproto.nullable) = false ];
}

// QueryCurrentEpochRequest is request type for the Query/CurrentEpoch RPC method
// QueryCurrentEpochRequest is the request type for the Query/CurrentEpoch RPC method
message QueryCurrentEpochRequest {}

// QueryCurrentEpochResponse is response type for the Query/CurrentEpoch RPC method
// QueryCurrentEpochResponse is the response type for the Query/CurrentEpoch RPC method
message QueryCurrentEpochResponse {
// current_epoch is the current epoch number
uint64 current_epoch = 1;
// epoch_boundary is the height of this epoch's last block
uint64 epoch_boundary = 2;
}

// QueryEpochMsgsRequest is request type for the Query/EpochMsgs RPC method
// QueryEpochMsgsRequest is the request type for the Query/EpochMsgs RPC method
message QueryEpochMsgsRequest {
// epoch_num is the number of epoch of the requested msg queue
uint64 epoch_num = 1;
Expand All @@ -66,16 +66,16 @@ message QueryEpochMsgsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryEpochMsgsResponse is response type for the Query/EpochMsgs RPC method
// QueryEpochMsgsResponse is the response type for the Query/EpochMsgs RPC method
message QueryEpochMsgsResponse {
// msgs is the list of messages queued in the current epoch
repeated babylon.epoching.v1.QueuedMessage msgs = 1;
// pagination defines the pagination in the response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryLatestEpochMsgsRequest is request type for the Query/LatestEpochMsgs RPC method
// it returns epoch msgs within epoch [min(1, end_epoch-epoch_count+1), end_epoch]
// QueryLatestEpochMsgsRequest is the request type for the Query/LatestEpochMsgs RPC method
// it returns epoch msgs within epoch [max(1, end_epoch-epoch_count+1), end_epoch]
message QueryLatestEpochMsgsRequest {
// end_epoch is the number of the last epoch to query
uint64 end_epoch = 1;
Expand All @@ -85,7 +85,7 @@ message QueryLatestEpochMsgsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

// QueryLatestEpochMsgsResponse is response type for the Query/LatestEpochMsgs RPC method
// QueryLatestEpochMsgsResponse is the response type for the Query/LatestEpochMsgs RPC method
message QueryLatestEpochMsgsResponse {
// epoch_msg_map is a list of QueuedMessageList
// each QueuedMessageList has a field identifying the epoch number
Expand Down
13 changes: 6 additions & 7 deletions x/epoching/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,16 @@ func (k Keeper) LatestEpochMsgs(c context.Context, req *types.QueryLatestEpochMs
)
}

// the API will return epoch msgs between [min(1, end_epoch-epoch_count+1), end_epoch].
// NOTE:
// - epoch 0 does not have any queued msg
// - if not specified, endEpoch will be the current epoch
// the API will return epoch msgs between [max(1, end_epoch-epoch_count+1), end_epoch].
// NOTE: epoch 0 does not have any queued msg
endEpoch := req.EndEpoch
// If not specified, endEpoch will be the current epoch
if endEpoch == 0 {
endEpoch = k.GetEpoch(ctx).EpochNumber
}
beginEpoch := endEpoch - req.EpochCount + 1
if beginEpoch <= 1 {
beginEpoch = 1
beginEpoch := uint64(1)
if req.EpochCount < endEpoch { // i.e., 1 < endEpoch - req.EpochCount + 1
beginEpoch = endEpoch - req.EpochCount + 1
}

latestEpochMsgs := []*types.QueuedMessageList{}
Expand Down
18 changes: 9 additions & 9 deletions x/epoching/types/query.pb.go

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

0 comments on commit 1d3386e

Please sign in to comment.