diff --git a/x/emissions/keeper/queryserver/query_server_inferences.go b/x/emissions/keeper/queryserver/query_server_inferences.go index c0eaf0a00..a01aa8ae0 100644 --- a/x/emissions/keeper/queryserver/query_server_inferences.go +++ b/x/emissions/keeper/queryserver/query_server_inferences.go @@ -98,6 +98,32 @@ func (qs queryServer) GetNetworkInferencesAtBlock(ctx context.Context, req *emis return &emissionstypes.GetNetworkInferencesAtBlockResponse{NetworkInferences: result.NetworkInferences}, nil } +// An outlier resistant version of GetNetworkInferencesAtBlock +// TODO implement +func (qs queryServer) GetNetworkInferencesAtBlockOutlierResistant(ctx context.Context, req *emissionstypes.GetNetworkInferencesAtBlockOutlierResistantRequest) (_ *emissionstypes.GetNetworkInferencesAtBlockOutlierResistantResponse, err error) { + defer metrics.RecordMetrics("GetNetworkInferencesAtBlockOutlierResistant", time.Now(), &err) + + topic, err := qs.k.GetTopic(ctx, req.TopicId) + if err != nil { + return nil, status.Errorf(codes.NotFound, "topic %v not found", req.TopicId) + } + if topic.EpochLastEnded == 0 { + return nil, status.Errorf(codes.NotFound, "network inference not available for topic %v", req.TopicId) + } + + result, err := synth.GetNetworkInferences( + sdk.UnwrapSDKContext(ctx), + qs.k, + req.TopicId, + &req.BlockHeightLastInference, + ) + if err != nil { + return nil, err + } + + return &emissionstypes.GetNetworkInferencesAtBlockResponse{NetworkInferences: result.NetworkInferences}, nil +} + // Return full set of inferences in I_i from the chain, as well as weights and forecast implied inferences func (qs queryServer) GetLatestNetworkInferences(ctx context.Context, req *emissionstypes.GetLatestNetworkInferencesRequest) (_ *emissionstypes.GetLatestNetworkInferencesResponse, err error) { defer metrics.RecordMetrics("GetLatestNetworkInferences", time.Now(), &err) diff --git a/x/emissions/module/autocli.go b/x/emissions/module/autocli.go index e6d28305f..97fde51e3 100644 --- a/x/emissions/module/autocli.go +++ b/x/emissions/module/autocli.go @@ -572,6 +572,15 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { {ProtoField: "block_height_last_inference"}, }, }, + { + RpcMethod: "GetNetworkInferencesAtBlockOutlierResistant", + Use: "network-inferences-at-block-outlier-resistant [topic_id] [block_height_last_inference]", + Short: "Get the Network Inferences for a topic at a block height where the last inference was made", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "topic_id"}, + {ProtoField: "block_height_last_inference"}, + }, + }, { RpcMethod: "GetLatestNetworkInferences", Use: "latest-network-inferences [topic_id]", diff --git a/x/emissions/proto/emissions/v6/query.proto b/x/emissions/proto/emissions/v6/query.proto index e0981b018..a139bb149 100644 --- a/x/emissions/proto/emissions/v6/query.proto +++ b/x/emissions/proto/emissions/v6/query.proto @@ -146,6 +146,12 @@ service QueryService { option (google.api.http).get = "/emissions/v6/network_inferences/{topic_id}/last_inference/{block_height_last_inference}"; } + rpc GetNetworkInferencesAtBlockOutlierResistant(GetNetworkInferencesAtBlockOutlierResistantRequest) returns (GetNetworkInferencesAtBlockOutlierResistantResponse) { + option (cosmos.query.v1.module_query_safe) = true; + option (google.api.http).get = + "/emissions/v6/network_inferences_outlier_resistant/{topic_id}/last_inference/{block_height_last_inference}"; + } + rpc GetLatestNetworkInferences(GetLatestNetworkInferencesRequest) returns (GetLatestNetworkInferencesResponse) { option (cosmos.query.v1.module_query_safe) = true; option (google.api.http).get = "/emissions/v6/latest_network_inferences/{topic_id}"; @@ -897,6 +903,11 @@ message GetNetworkInferencesAtBlockRequest { int64 block_height_last_inference = 2; } +message GetNetworkInferencesAtBlockOutlierResistantRequest { + uint64 topic_id = 1; + int64 block_height_last_inference = 2; +} + message GetLatestNetworkInferencesRequest { uint64 topic_id = 1; } @@ -971,6 +982,10 @@ message GetNetworkInferencesAtBlockResponse { emissions.v3.ValueBundle network_inferences = 1; } +message GetNetworkInferencesAtBlockOutlierResistantResponse { + emissions.v3.ValueBundle network_inferences = 1; +} + message GetLatestNetworkInferencesResponse { reserved 4; reserved "forecast_implied_inferences";