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

[oracle] Add slash window progress query #627

Merged
merged 3 commits into from
Mar 3, 2023
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
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
go.opentelemetry.io/otel/trace v1.9.0
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
google.golang.org/genproto v0.0.0-20230221151758-ace64dc21148
google.golang.org/genproto v0.0.0-20230223222841-637eb2293923
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -94,6 +94,7 @@ require (
github.com/firefart/nonamedreturns v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fzipp/gocyclo v0.5.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-critic/go-critic v0.6.3 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.0 // indirect
Expand Down Expand Up @@ -140,6 +141,7 @@ require (
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ github.com/fullstorydev/grpcurl v1.6.0/go.mod h1:ZQ+ayqbKMJNhzLmbpCiurTVlaK2M/3n
github.com/fzipp/gocyclo v0.5.1 h1:L66amyuYogbxl0j2U+vGqJXusPF2IkduvXLnYD5TFgw=
github.com/fzipp/gocyclo v0.5.1/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
Expand Down Expand Up @@ -595,6 +596,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 h1:gDLXvp5S9izjldquuoAhDzccbskOL6tDC5jMSyx3zxE=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2/go.mod h1:7pdNwVWBBHGiCxa9lAszqCJMbfTISJ7oMftp8+UGV08=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
Expand Down Expand Up @@ -1817,6 +1820,8 @@ google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb/go.mod h1:hAL49I2I
google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo=
google.golang.org/genproto v0.0.0-20230221151758-ace64dc21148 h1:muK+gVBJBfFb4SejshDBlN2/UgxCCOKH9Y34ljqEGOc=
google.golang.org/genproto v0.0.0-20230221151758-ace64dc21148/go.mod h1:3Dl5ZL0q0isWJt+FVcfpQyirqemEuLAK/iFvg1UP1Hw=
google.golang.org/genproto v0.0.0-20230223222841-637eb2293923 h1:znp6mq/drrY+6khTAlJUDNFFcDGV2ENLYKpMq8SyCds=
google.golang.org/genproto v0.0.0-20230223222841-637eb2293923/go.mod h1:3Dl5ZL0q0isWJt+FVcfpQyirqemEuLAK/iFvg1UP1Hw=
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
Expand Down
18 changes: 18 additions & 0 deletions proto/oracle/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ service Query {
option (google.api.http).get = "/sei-protocol/sei-chain/oracle/validators/aggregate_votes";
}

// SlashWindow returns slash window information
rpc SlashWindow(QuerySlashWindowRequest) returns (QuerySlashWindowResponse) {
option (google.api.http).get =
"/sei-protocol/sei-chain/oracle/slash_window";
}

// Params queries all parameters.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/sei-protocol/sei-chain/oracle/params";
Expand Down Expand Up @@ -196,6 +202,18 @@ message QueryAggregateVotesResponse {
repeated AggregateExchangeRateVote aggregate_votes = 1 [(gogoproto.nullable) = false];
}

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

// 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;
}

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

Expand Down
17 changes: 17 additions & 0 deletions x/oracle/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,20 @@ func (q querier) AggregateVotes(c context.Context, req *types.QueryAggregateVote
AggregateVotes: votes,
}, nil
}

func (q querier) SlashWindow(
goCtx context.Context,
req *types.QuerySlashWindowRequest,
) (*types.QuerySlashWindowResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

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

return &types.QuerySlashWindowResponse{
WindowProgress: (uint64(ctx.BlockHeight()) % params.SlashWindow) /
params.VotePeriod,
}, nil
}
17 changes: 17 additions & 0 deletions x/oracle/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ func TestQueryAggregateVotes(t *testing.T) {
require.Equal(t, expectedVotes, res.AggregateVotes)
}

func TestQuerySlashingWindow(t *testing.T) {
input := CreateTestInput(t)
querier := NewQuerier(input.OracleKeeper)

input.Ctx = input.Ctx.WithBlockHeight(12502)
ctx := sdk.WrapSDKContext(input.Ctx)
res, err := querier.SlashWindow(ctx, &types.QuerySlashWindowRequest{})
require.NoError(t, err)
require.Equal(t, 1250, int(res.WindowProgress))

input.Ctx = input.Ctx.WithBlockHeight(300501)
ctx = sdk.WrapSDKContext(input.Ctx)
res, err = querier.SlashWindow(ctx, &types.QuerySlashWindowRequest{})
require.NoError(t, err)
require.Equal(t, 9890, int(res.WindowProgress))
}

func TestQueryVoteTargets(t *testing.T) {
input := CreateTestInput(t)
ctx := sdk.WrapSDKContext(input.Ctx)
Expand Down
Loading