Skip to content

Commit

Permalink
feat(Validator endpoints): Implement exocore validator endpoints (#235)
Browse files Browse the repository at this point in the history
* implement validator endpoint
  • Loading branch information
trestinlsd authored Nov 11, 2024
1 parent b4a331e commit 6518f04
Show file tree
Hide file tree
Showing 13 changed files with 3,108 additions and 225 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,4 @@ replace (
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
//fix cosmos-sdk error
golang.org/x/exp => golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc
)
)
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2435,4 +2435,4 @@ rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
33 changes: 12 additions & 21 deletions proto/exocore/operator/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,18 @@ message GenesisState {
// operator_records refers to a list of operator records. each record
// contains an operator address and a list of chain id +
// cons key combination.
repeated OperatorConsKeyRecord operator_records = 2
[(gogoproto.nullable) = false];
repeated OperatorConsKeyRecord operator_records = 2 [(gogoproto.nullable) = false];
// opt_states is a list of all opted information for the AVS and operators
repeated OptedState opt_states = 3 [(gogoproto.nullable) = false];
repeated OptedState opt_states = 3 [(gogoproto.nullable) = false];
// avs_usd_values is a list of AVS USD value
repeated AVSUSDValue avs_usd_values = 4[
(gogoproto.nullable) = false,
(gogoproto.customname) = "AVSUSDValues"
];
repeated AVSUSDValue avs_usd_values = 4 [(gogoproto.nullable) = false, (gogoproto.customname) = "AVSUSDValues"];
// operator_usd_values is a list of operator USD value
repeated OperatorUSDValue operator_usd_values = 5[
(gogoproto.nullable) = false,
(gogoproto.customname) = "OperatorUSDValues"
];
repeated OperatorUSDValue operator_usd_values = 5
[(gogoproto.nullable) = false, (gogoproto.customname) = "OperatorUSDValues"];
// slash_states is a list of all slashing information
repeated OperatorSlashState slash_states = 6 [(gogoproto.nullable) = false];
// pre_cons_key is a list of all previous consensus public key
repeated PrevConsKey pre_cons_keys = 7 [(gogoproto.nullable) = false];
repeated PrevConsKey pre_cons_keys = 7 [(gogoproto.nullable) = false];
// operator_key_removal is a list of operator with the given address
// is in the process of unbonding their key for the given chainID.
repeated OperatorKeyRemoval operator_key_removals = 8 [(gogoproto.nullable) = false];
Expand All @@ -50,7 +44,7 @@ message OperatorDetail {
// encoded version of sdk.AccAddress.
string operator_address = 1;
// operator_info is the detail information for the above operator
OperatorInfo operator_info = 2 [(gogoproto.nullable) = false] ;
OperatorInfo operator_info = 2 [(gogoproto.nullable) = false];
}

// OptedStates is helper structure to store the opted state for the genesis state.
Expand All @@ -60,16 +54,16 @@ message OptedState {
// which is a combination of the operator address and AVS address.
string key = 1;
// opt_info is the value of undelegation state for the above key
OptedInfo opt_info = 2 [(gogoproto.nullable) = false] ;
OptedInfo opt_info = 2 [(gogoproto.nullable) = false];
}

// AVSUSDValue is helper structure to store the USD value for the genesis state.
// it's corresponding to the kvStore `KeyPrefixUSDValueForAVS`
message AVSUSDValue {
// avs_addr
string avs_addr = 1[(gogoproto.customname) = "AVSAddr"];
string avs_addr = 1 [(gogoproto.customname) = "AVSAddr"];
// value is the USD value for the AVS address
DecValueField value = 2 [(gogoproto.nullable) = false] ;
DecValueField value = 2 [(gogoproto.nullable) = false];
}

// OperatorUSDValue is helper structure to store the USD value for the genesis state.
Expand All @@ -79,10 +73,7 @@ message OperatorUSDValue {
// which is the combination of operator and AVS address.
string key = 1;
// value is the USD value states for the AVS address
OperatorOptedUSDValue opted_usd_value = 2[
(gogoproto.nullable) = false,
(gogoproto.customname) = "OptedUSDValue"
] ;
OperatorOptedUSDValue opted_usd_value = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "OptedUSDValue"];
}

// OperatorSlashState is helper structure to store the slash information for the genesis state.
Expand All @@ -92,7 +83,7 @@ message OperatorSlashState {
// which is the combination of the operator address, AVS address, and slashID.
string key = 1;
// states is the voting power value for the above key
OperatorSlashInfo info = 2 [(gogoproto.nullable) = false] ;
OperatorSlashInfo info = 2 [(gogoproto.nullable) = false];
}

// PrevConsKey is helper structure to store the previous consensus key
Expand Down
107 changes: 74 additions & 33 deletions proto/exocore/operator/v1/query.proto
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
syntax = "proto3";
package exocore.operator.v1;

import "amino/amino.proto";

import "cosmos/base/query/v1beta1/pagination.proto";
import "cosmos/query/v1/query.proto";
import "cosmos_proto/cosmos.proto";

import "exocore/operator/v1/tx.proto";
import "exocore/operator/v1/validator.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";

import "tendermint/crypto/keys.proto";

option go_package = "github.com/ExocoreNetwork/exocore/x/operator/types";

// QueryOperatorInfoReq is the request to obtain the operator information.
message GetOperatorInfoReq {
// operator_addr is the operator address,its type should be a sdk.AccAddress
string operator_addr = 1
[(cosmos_proto.scalar) = "cosmos.AddressString"];
string operator_addr = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// QueryAllOperatorsRequest is the request to obtain all operators.
Expand Down Expand Up @@ -42,21 +47,19 @@ message OperatorAVSAddress {
// QueryOperatorUSDValueRequest is the request to obtain the USD value for operator.
message QueryOperatorUSDValueRequest {
// operator_and_avs is the operator and AVS address
OperatorAVSAddress operator_and_avs = 1 [(gogoproto.embed) = true];;
OperatorAVSAddress operator_and_avs = 1 [(gogoproto.embed) = true];
}

// QueryOperatorUSDValueResponse is the response to obtain the USD value for operator.
message QueryOperatorUSDValueResponse {
// usd_info includes the self and total staking for the operator and AVS
OperatorOptedUSDValue usd_values = 1
[(gogoproto.customname) = "USDValues"];
OperatorOptedUSDValue usd_values = 1 [(gogoproto.customname) = "USDValues"];
}

// QueryAVSUSDValueRequest is the request to obtain the USD value for AVS.
message QueryAVSUSDValueRequest {
// avs_address is the AVS address opted-in by the operator
string avs_address = 1
[(gogoproto.customname) = "AVSAddress"];
string avs_address = 1 [(gogoproto.customname) = "AVSAddress"];
}

// QueryOperatorSlashInfoRequest is the request to obtain the slash information for the specified
Expand All @@ -78,7 +81,7 @@ message OperatorSlashInfoByID {
}

// QueryOperatorSlashInfoResponse is the response for GetOperatorSlashInfoRequest
message QueryOperatorSlashInfoResponse{
message QueryOperatorSlashInfoResponse {
// all_slash_info is a list of the slash information for the specified operator and AVS
repeated OperatorSlashInfoByID all_slash_info = 1;
// pagination related response.
Expand Down Expand Up @@ -185,7 +188,6 @@ message OperatorConsAddrPair {
bool opting_out = 3;
}


// QueryAllOperatorsWithOptInAVSRequest is the request to obtain all opt-in operator addresses
// for a specific avs with pagination.
message QueryAllOperatorsByOptInAVSRequest {
Expand Down Expand Up @@ -236,65 +238,56 @@ service Query {
}

// QueryOperatorConsKeyForChainID queries the consensus public key for the operator
rpc QueryOperatorConsKeyForChainID(QueryOperatorConsKeyRequest) returns (
QueryOperatorConsKeyResponse
) {
rpc QueryOperatorConsKeyForChainID(QueryOperatorConsKeyRequest) returns (QueryOperatorConsKeyResponse) {
option (google.api.http) = {
get: "/exocore/operator/v1/operator_cons_key/{operator_acc_addr}/{chain}"
};
}

// QueryOperatorConsAddressForChainID queries the consensus address for the operator.
rpc QueryOperatorConsAddressForChainID(QueryOperatorConsAddressRequest) returns (
QueryOperatorConsAddressResponse
) {
rpc QueryOperatorConsAddressForChainID(QueryOperatorConsAddressRequest) returns (QueryOperatorConsAddressResponse) {
option (google.api.http) = {
get: "/exocore/operator/v1/operator_cons_addr/{operator_acc_addr}/{chain}"
};
}

// QueryAllOperatorConsKeysByChainID queries all operators and their consensus public keys
// for a specific chain ID
rpc QueryAllOperatorConsKeysByChainID(QueryAllOperatorConsKeysByChainIDRequest) returns (
QueryAllOperatorConsKeysByChainIDResponse
) {
rpc QueryAllOperatorConsKeysByChainID(QueryAllOperatorConsKeysByChainIDRequest)
returns (QueryAllOperatorConsKeysByChainIDResponse) {
option (google.api.http) = {
get: "/exocore/operator/v1/all_operator_cons_keys/{chain}"
};
}

// QueryOperatorUSDValue queries the opted-in USD value for the operator
rpc QueryOperatorUSDValue(QueryOperatorUSDValueRequest) returns(QueryOperatorUSDValueResponse){
option (google.api.http).get =
"/exocore/operator/v1/QueryOperatorUSDValue/{operator_and_avs.operator_addr}/"
"{operator_and_avs.avs_address}";
rpc QueryOperatorUSDValue(QueryOperatorUSDValueRequest) returns (QueryOperatorUSDValueResponse) {
option (google.api.http).get = "/exocore/operator/v1/query_operator_usd_value/{operator_and_avs.operator_addr}/"
"{operator_and_avs.avs_address}";
}

// QueryAVSUSDValue queries the USD value for the AVS
rpc QueryAVSUSDValue(QueryAVSUSDValueRequest) returns(DecValueField){
rpc QueryAVSUSDValue(QueryAVSUSDValueRequest) returns (DecValueField) {
option (google.api.http).get = "/exocore/operator/v1/QueryAVSUSDValue";
}

// QueryOperatorSlashInfo queries the slash information for the specified operator and AVS
rpc QueryOperatorSlashInfo(QueryOperatorSlashInfoRequest) returns(QueryOperatorSlashInfoResponse){
option (google.api.http).get =
"/exocore/operator/v1/QueryOperatorSlashInfo/{operator_and_avs.operator_addr}/"
"{operator_and_avs.avs_address}";
rpc QueryOperatorSlashInfo(QueryOperatorSlashInfoRequest) returns (QueryOperatorSlashInfoResponse) {
option (google.api.http).get = "/exocore/operator/v1/query_operator_slash_info/{operator_and_avs.operator_addr}/"
"{operator_and_avs.avs_address}";
}

// QueryAllOperatorConsAddrsByChainID queries all operators and their consensus addresses
// for a specific chain ID
rpc QueryAllOperatorConsAddrsByChainID(QueryAllOperatorConsAddrsByChainIDRequest) returns (
QueryAllOperatorConsAddrsByChainIDResponse
) {
rpc QueryAllOperatorConsAddrsByChainID(QueryAllOperatorConsAddrsByChainIDRequest)
returns (QueryAllOperatorConsAddrsByChainIDResponse) {
option (google.api.http) = {
get: "/exocore/operator/v1/all_operator_cons_addrs/{chain}"
};
}

// QueryAllOperatorsWithOptInAVS queries operator list by avs.
rpc QueryAllOperatorsWithOptInAVS(QueryAllOperatorsByOptInAVSRequest) returns (
QueryAllOperatorsByOptInAVSResponse) {
rpc QueryAllOperatorsWithOptInAVS(QueryAllOperatorsByOptInAVSRequest) returns (QueryAllOperatorsByOptInAVSResponse) {
option (google.api.http) = {
get: "/exocore/operator/v1/opt/operator_list/{avs}"
};
Expand All @@ -313,4 +306,52 @@ service Query {
get: "/exocore/operator/v1/opt_info/{operator_and_avs.operator_addr}/{operator_and_avs.avs_address}"
};
}
}

// Validators queries all validators that match the given status.
// When called from another module, this query might consume a high amount of
// gas if the pagination field is incorrectly set.
rpc Validators(QueryValidatorsRequest) returns (QueryValidatorsResponse) {
option (cosmos.query.v1.module_query_safe) = true;
option (google.api.http).get = "/exocore/operator/v1/validators/{chain}";
}

// Validator queries validator info for given validator address.
rpc Validator(QueryValidatorRequest) returns (QueryValidatorResponse) {
option (cosmos.query.v1.module_query_safe) = true;
option (google.api.http).get = "/exocore/operator/v1/validator/{validator_acc_addr}/{chain}";
}
}
// QueryValidatorsRequest is request type for Query/Validators RPC method.
message QueryValidatorsRequest {
// chain is the id of the chain served by the operator. here chain_id is not used since the
// Linter complains about capitalization, which can be set with a gogoproto.custom_name but
// that is not compatible with google.api.http.get in the Query service below.
string chain = 1;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
// QueryValidatorsResponse is response type for the Query/Validators RPC method
message QueryValidatorsResponse {
// validators contains all the queried validators.
repeated Validator validators = 1
[(gogoproto.nullable) = false, (amino.dont_omitempty) = true];

// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryValidatorRequest is response type for the Query/Validator RPC method
message QueryValidatorRequest {
// validator_acc_addr defines the validator address to query for.
string validator_acc_addr = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// chain is the id of the chain served by the operator. here chain_id is not used since the
// Linter complains about capitalization, which can be set with a gogoproto.custom_name but
// that is not compatible with google.api.http.get in the Query service below.
string chain = 2;
}

// QueryValidatorResponse is response type for the Query/Validator RPC method
message QueryValidatorResponse {
// validator defines the validator info.
Validator validator = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}
Loading

0 comments on commit 6518f04

Please sign in to comment.