Skip to content

Commit

Permalink
feat: add oracle miss counters and ibc inflows grpc api (#2352)
Browse files Browse the repository at this point in the history
* adding miss counters grpc api

* added cli queries

* ++

* removed all-inflows and added quota expires grpc req

* address the review comments
  • Loading branch information
gsk967 authored Dec 12, 2023
1 parent 095aff9 commit 75b0a6c
Show file tree
Hide file tree
Showing 9 changed files with 1,938 additions and 176 deletions.
29 changes: 29 additions & 0 deletions proto/umee/oracle/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,35 @@ service Query {
option (google.api.http).get =
"/umee/oracle/v1/denoms/exg_rates_timestamp";
}

// MissCounters returns oracle missing votes count of validators.
rpc MissCounters(QueryMissCounters)
returns (QueryMissCountersResponse) {
option (google.api.http).get =
"/umee/oracle/v1/miss_counters";
}
}

// QueryMissCounters is the request type for the Query/MissCounters RPC
// method.
message QueryMissCounters {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
string validator = 1;
}

// QueryMissCountersResponse is response type for the Query/MissCounters RPC method.
message QueryMissCountersResponse {
repeated PriceMissCounter miss_counters = 1 [
(gogoproto.nullable) = false
];
}

// PriceMissCounter is the validator's oracle price votes missing count.
message PriceMissCounter {
string validator = 1;
// miss_counter defines the oracle miss counter of a validator
uint64 miss_counter = 2;
}

// QueryExgRatesWithTimestamp is the request type for the Query/ExchangeRatesWithTimestamp RPC
Expand Down
43 changes: 43 additions & 0 deletions proto/umee/uibc/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "google/api/annotations.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "umee/uibc/v1/quota.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/umee-network/umee/v6/x/uibc";
Expand All @@ -28,6 +29,48 @@ service Query {
rpc AllOutflows(QueryAllOutflows) returns (QueryAllOutflowsResponse) {
option (google.api.http).get = "/umee/uibc/v1/all_outflows";
}

// Inflows returns registered IBC denoms inflows in the current quota period.
// If denom is not specified, returns sum of all registered inflows.
rpc Inflows(QueryInflows) returns (QueryInflowsResponse) {
option (google.api.http).get = "/umee/uibc/v1/inflows";
}

// QuotaExpires returns when current ibc quota will end.
rpc QuotaExpires(QueryQuotaExpires) returns (QueryQuotaExpiresResponse) {
option (google.api.http).get = "/umee/uibc/v1/quota_expires";
}
}

// QueryAllInflows defines request type for query the inflow quota of registered denoms.
message QueryQuotaExpires {}

// QueryAllInflowsResponse defines response type of Query/AllInflows
message QueryQuotaExpiresResponse {
google.protobuf.Timestamp end_time = 4 [
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true,
(gogoproto.jsontag) = "end_time,omitempty",
(gogoproto.moretags) = "yaml:\"end_time\""
];
}

// QueryInflows defines request type for query the inflow quota of denoms
message QueryInflows {
string denom = 1;
}

// QueryInflowsResponse defines response type of Query/Inflows
message QueryInflowsResponse {
string sum = 1 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
repeated cosmos.base.v1beta1.DecCoin inflows = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.DecCoin",
(gogoproto.nullable) = false
];
}

// QueryParams defines the request structure for the Params gRPC service
Expand Down
31 changes: 31 additions & 0 deletions x/oracle/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,34 @@ func (q querier) ExgRatesWithTimestamp(

return &types.QueryExgRatesWithTimestampResponse{ExgRates: exgRates}, nil
}

// MissCounters implements types.QueryServer.
func (q querier) MissCounters(goCtx context.Context, req *types.QueryMissCounters) (*types.QueryMissCountersResponse,
error) {
ctx := sdk.UnwrapSDKContext(goCtx)

var pfMissCounts []types.PriceMissCounter
if len(req.Validator) != 0 {
valAddr, err := sdk.ValAddressFromBech32(req.Validator)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
missCounter := q.GetMissCounter(ctx, valAddr)
pfMissCounts = append(pfMissCounts, types.PriceMissCounter{
Validator: req.Validator,
MissCounter: missCounter,
})
} else {
q.IterateMissCounters(ctx, func(val sdk.ValAddress, u uint64) bool {
pfMissCounts = append(pfMissCounts, types.PriceMissCounter{
Validator: val.String(),
MissCounter: u,
})
return false
})
}

return &types.QueryMissCountersResponse{
MissCounters: pfMissCounts,
}, nil
}
Loading

0 comments on commit 75b0a6c

Please sign in to comment.