Skip to content

Commit

Permalink
CNS-787: fix downtime query
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Dec 31, 2023
1 parent b6285d3 commit fc175ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions x/downtime/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func CmdQueryParams() *cobra.Command {

func CmdQueryDowntime() *cobra.Command {
cmd := &cobra.Command{
Use: "downtime [epoch_start_block]",
Use: "downtime [block]",
Short: "Query downtime",
Long: "Query downtime between blocks, if only start is provided then will query for downtime at the given block, if end is provided then it will query the full range",
Long: "Query downtime between blocks, if only start is provided then will query for downtime at the given epoch (the epoch of the block)",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
start, err := strconv.ParseUint(args[0], 10, 64)
Expand Down
1 change: 1 addition & 0 deletions x/downtime/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type EpochStorageKeeper interface {
IsEpochStart(ctx sdk.Context) bool
GetEpochStart(ctx sdk.Context) (epochStartBlock uint64)
GetDeletedEpochs(ctx sdk.Context) []uint64
GetEpochStartForBlock(ctx sdk.Context, block uint64) (epochStart uint64, blockInEpoch uint64, err error)
}

func NewKeeper(cdc codec.BinaryCodec, sk storetypes.StoreKey, ps paramtypes.Subspace, esk EpochStorageKeeper) Keeper {
Expand Down
7 changes: 6 additions & 1 deletion x/downtime/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ func (q queryServer) QueryParams(ctx context.Context, request *v1.QueryParamsReq
}

func (q queryServer) QueryDowntime(ctx context.Context, request *v1.QueryDowntimeRequest) (*v1.QueryDowntimeResponse, error) {
dt, _ := q.k.GetDowntime(sdk.UnwrapSDKContext(ctx), request.EpochStartBlock)
_ctx := sdk.UnwrapSDKContext(ctx)
epochStart, _, err := q.k.epochStorageKeeper.GetEpochStartForBlock(_ctx, request.EpochStartBlock)
if err != nil {
return nil, err
}
dt, _ := q.k.GetDowntime(sdk.UnwrapSDKContext(ctx), epochStart)
return &v1.QueryDowntimeResponse{CumulativeDowntimeDuration: dt}, nil
}

Expand Down

0 comments on commit fc175ce

Please sign in to comment.