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(oracle): add query & cli for slashing window progress #1147

Merged
merged 7 commits into from
Jul 21, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

- [1147](https://github.com/umee-network/umee/pull/1147) Add SlashWindow oracle query.
- [913](https://github.com/umee-network/umee/pull/913) Add LendEnabled, BorrowEnabled, and Blacklist to Token struct.
- [913](https://github.com/umee-network/umee/pull/913) Changed update registry gov proposal to add and update tokens, but never delete them.
- [918](https://github.com/umee-network/umee/pull/918) Add MarketSummary query to CLI.
Expand Down
18 changes: 18 additions & 0 deletions proto/umee/oracle/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ service Query {
"/umee/oracle/v1/validators/{validator_addr}/miss";
}

// SlashWindow returns slash window information
rpc SlashWindow(QuerySlashWindow) returns (QuerySlashWindowResponse) {
option (google.api.http).get =
"/umee/oracle/v1/slash_window";
}

// AggregatePrevote returns an aggregate prevote of a validator
rpc AggregatePrevote(QueryAggregatePrevote)
returns (QueryAggregatePrevoteResponse) {
Expand Down Expand Up @@ -140,6 +146,18 @@ message QueryMissCounterResponse {
uint64 miss_counter = 1;
}

// QuerySlashWindow is the request type for the
// Query/SlashWindow RPC method.
message QuerySlashWindow {}

// QuerySlashWindowResponse is response type for the
// Query/SlashWindow RPC method.
message QuerySlashWindowResponse {
// window_progress defines the number of voting periods
// since the last slashing event would have taken place.
uint64 window_progress = 1;
}

// QueryAggregatePrevote is the request type for the
// Query/AggregatePrevote RPC method.
message QueryAggregatePrevote {
Expand Down
26 changes: 26 additions & 0 deletions x/oracle/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
GetCmdQueryExchangeRate(),
GetCmdQueryFeederDelegation(),
GetCmdQueryMissCounter(),
GetCmdQuerySlashWindow(),
)

return cmd
Expand Down Expand Up @@ -297,3 +298,28 @@ func GetCmdQueryMissCounter() *cobra.Command {
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

// GetCmdQuerySlashWindow implements the slash window query command.
func GetCmdQuerySlashWindow() *cobra.Command {
cmd := &cobra.Command{
Use: "slash-window",
Short: "Query the current slash window progress",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.SlashWindow(context.Background(), &types.QuerySlashWindow{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}
25 changes: 25 additions & 0 deletions x/oracle/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,31 @@ func (q querier) MissCounter(
}, nil
}

// SlashWindow queries the current slash window progress of the oracle.
func (q querier) SlashWindow(
goCtx context.Context,
req *types.QuerySlashWindow,
) (*types.QuerySlashWindowResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)
params := q.GetParams(ctx)

slashWindow := params.SlashWindow
votePeriod := params.VotePeriod
currentBlock := uint64(ctx.BlockHeight())
votePeriodsPerSlashWindow := slashWindow / votePeriod

currentSlashWindow := currentBlock / votePeriodsPerSlashWindow
blocksIntoSlashWindow := currentBlock - (currentSlashWindow * slashWindow)

return &types.QuerySlashWindowResponse{
WindowProgress: blocksIntoSlashWindow / votePeriod,
}, nil
}

// AggregatePrevote queries an aggregate prevote of a validator.
func (q querier) AggregatePrevote(
goCtx context.Context,
Expand Down
6 changes: 6 additions & 0 deletions x/oracle/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func (s *IntegrationTestSuite) TestQuerier_MissCounter() {
s.Require().Equal(res.MissCounter, missCounter)
}

func (s *IntegrationTestSuite) TestQuerier_SlashWindow() {
res, err := s.queryClient.SlashWindow(s.ctx.Context(), &types.QuerySlashWindow{})
s.Require().NoError(err)
s.Require().Equal(uint64(1), res.WindowProgress)
}

func (s *IntegrationTestSuite) TestQuerier_AggregatePrevote() {
prevote := types.AggregateExchangeRatePrevote{
Hash: "hash",
Expand Down
Loading