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] add the new slash implementation and some missed RPC and CLI #61

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
37 changes: 37 additions & 0 deletions proto/exocore/delegation/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exocore.delegation.v1;

import "cosmos/query/v1/query.proto";
import "cosmos_proto/cosmos.proto";
import "exocore/delegation/v1/tx.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";

Expand Down Expand Up @@ -69,6 +70,28 @@ message SingleDelegationInfoReq {
string asset_id = 3 [(gogoproto.customname) = "AssetID"];
}

// UndelegationsReq is the request to obtain all delegations
// by staker id and asset id.
message UndelegationsReq {
// staker_id is the staker id.
string staker_id = 1 [(gogoproto.customname) = "StakerID"];
// asset_id is the asset id.
string asset_id = 2 [(gogoproto.customname) = "AssetID"];
}

// UndelegationsReq is the request to obtain all undelegations waiting to be completed
// by height.
message WaitCompleteUndelegationsReq {
bwhour marked this conversation as resolved.
Show resolved Hide resolved
// block_height is the block height to query.
uint64 block_height = 1;
}

// UndelegationRecordList is the response to query undelegations.
message UndelegationRecordList {
// UndelegationRecord is the returned undelegations
repeated UndelegationRecord undelegations = 1;
}

// Query is the service API for the delegation module.
service Query {
// DelegationInfo queries the delegation information for {stakerID, assetID}.
Expand All @@ -82,5 +105,19 @@ service Query {
option (cosmos.query.v1.module_query_safe) = true;
option (google.api.http).get = "/exocore/delegation/v1/QuerySingleDelegationInfo";
}

// QueryUndelegations queries all undelegations for
// {staker, asset}.
rpc QueryUndelegations(UndelegationsReq) returns (UndelegationRecordList) {
option (cosmos.query.v1.module_query_safe) = true;
option (google.api.http).get = "/exocore/delegation/v1/QueryUndelegations";
}

// QueryWaitCompleteUndelegations queries all undelegations waiting to be completed by
// {height}.
rpc QueryWaitCompleteUndelegations(WaitCompleteUndelegationsReq) returns (UndelegationRecordList) {
option (cosmos.query.v1.module_query_safe) = true;
option (google.api.http).get = "/exocore/delegation/v1/QueryWaitCompleteUndelegations";
}
}

57 changes: 54 additions & 3 deletions proto/exocore/operator/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,42 @@ message GetOperatorInfoReq {
[(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// QueryOperatorUSDValueRequest is the request to obtain the USD value for operator.
message QueryOperatorUSDValueRequest {
// operator_addr is the operator address,its type should be a sdk.AccAddress
bwhour marked this conversation as resolved.
Show resolved Hide resolved
string operator_addr = 1
[(cosmos_proto.scalar) = "cosmos.AddressString"];
// avs_address is the AVS address opted-in by the operator
string avs_address = 2
[(gogoproto.customname) = "AVSAddress"];
}

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

// QueryOperatorSlashInfoRequest is the request to obtain the slash information for the specified
// operator and AVS
message QueryOperatorSlashInfoRequest {
// operator_addr is the operator address,its type should be a sdk.AccAddress
string operator_addr = 1
[(cosmos_proto.scalar) = "cosmos.AddressString"];
// avs_address is the AVS address opted-in by the operator
string avs_address = 2
[(gogoproto.customname) = "AVSAddress"];
}

// QueryOperatorSlashInfoResponse is the response for GetOperatorSlashInfoRequest
message QueryOperatorSlashInfoResponse{
// AllSlashInfo the key is slashID, the value is the specified slash information
// It's okay to use a map here, because it won't be used to store state, only in
// the response to an RPC call
map<string, OperatorSlashInfo> all_slash_info = 1;
}

// QueryOperatorConsKeyRequest is the request to obtain the consensus public key of the operator
message QueryOperatorConsKeyRequest {
// addr is the ACC address of operator
Expand All @@ -27,21 +63,36 @@ message QueryOperatorConsKeyRequest {
// QueryOperatorConsKeyResponse is the response for QueryOperatorConsKeyRequest
message QueryOperatorConsKeyResponse {
// public_key is the consensus public key of the operator
tendermint.crypto.PublicKey public_key = 1 [ (gogoproto.nullable) = false ];
tendermint.crypto.PublicKey public_key = 1 [(gogoproto.nullable) = false];
}

// Query defines the gRPC querier service.
service Query {
// OperatorInfo queries the operator information.
rpc GetOperatorInfo(GetOperatorInfoReq) returns(OperatorInfo){
option (google.api.http).get = "/exocore/delegation/v1/GetOperatorInfo";
option (google.api.http).get = "/exocore/operator/v1/GetOperatorInfo";
}

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

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

// QueryAVSUSDValue queries the USD value for the AVS
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";
}
}

62 changes: 56 additions & 6 deletions proto/exocore/operator/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,56 @@
SLASH_TYPE_NO_INSTANTANEOUS_SLASH = 2;
}

// SlashFromUndelegation records the slash detail from the undelegation
message SlashFromUndelegation {
// staker_id is the staker id.
string staker_id = 1 [(gogoproto.customname) = "StakerID"];
// asset_id is the asset id.
string asset_id = 2 [(gogoproto.customname) = "AssetID"];
// amount is the slashed amount from the undelegation.
string amount = 3
[
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
// SlashFromAssetsPool records the slash detail from the operator assets pool
message SlashFromAssetsPool {
// asset_id is the asset id.
string asset_id = 1 [(gogoproto.customname) = "AssetID"];
// amount is the slashed amount from the assets pool.
string amount = 2
[
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}


// SlashAssetsInfo is the slashed assets information
leonz789 marked this conversation as resolved.
Show resolved Hide resolved
message SlashExecutionInfo {
// slash_proportion is the new calculated proportion when execute the slash
string slash_proportion = 1
[
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// slash_value is the usd value of all slashed assets
string slash_value = 2
[
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// SlashUndelegations records all slash info related to the undelegation
repeated SlashFromUndelegation slash_undelegations = 3;
// SlashFromAssetsPool records all slash info related to the assets pool
repeated SlashFromAssetsPool slash_assets_pool = 4;
}

// OperatorSlashInfo is the slash info of operator
message OperatorSlashInfo {
// slash_contract is the address of slash contract
Expand All @@ -100,19 +150,19 @@
int64 submitted_height = 2;
// event_height is the exocore block height at which the slash event occurs
int64 event_height = 3;
// processed_height is the exocore block height at which the slash event is processed
int64 processed_height = 4;
// is_vetoed is a flag to indicate if this slash is vetoed
bool is_vetoed = 5;
bool is_vetoed = 4;

Check failure on line 154 in proto/exocore/operator/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "4" with name "is_vetoed" on message "OperatorSlashInfo" changed option "json_name" from "processedHeight" to "isVetoed".

Check failure on line 154 in proto/exocore/operator/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "4" on message "OperatorSlashInfo" changed type from "int64" to "bool".

Check failure on line 154 in proto/exocore/operator/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "4" on message "OperatorSlashInfo" changed name from "processed_height" to "is_vetoed".
TimmyExogenous marked this conversation as resolved.
Show resolved Hide resolved
// slash_proportion is the proportion of assets that need to be slashed
string slash_proportion = 6
string slash_proportion = 5

Check failure on line 156 in proto/exocore/operator/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "5" with name "slash_proportion" on message "OperatorSlashInfo" changed option "json_name" from "isVetoed" to "slashProportion".

Check failure on line 156 in proto/exocore/operator/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "5" on message "OperatorSlashInfo" changed type from "bool" to "string".

Check failure on line 156 in proto/exocore/operator/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "5" on message "OperatorSlashInfo" changed name from "is_vetoed" to "slash_proportion".
leonz789 marked this conversation as resolved.
Show resolved Hide resolved
[
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// type indicates the slash type.
SlashType slash_type = 7;
// slash_type indicates the slash type of specified AVS.
uint32 slash_type = 6;

Check failure on line 163 in proto/exocore/operator/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "6" with name "slash_type" on message "OperatorSlashInfo" changed option "json_name" from "slashProportion" to "slashType".

Check failure on line 163 in proto/exocore/operator/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "6" on message "OperatorSlashInfo" changed type from "string" to "uint32".

Check failure on line 163 in proto/exocore/operator/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "6" on message "OperatorSlashInfo" changed name from "slash_proportion" to "slash_type".
// SlashExecutionInfo stores the slashed execution information
SlashExecutionInfo execution_info = 7;

Check failure on line 165 in proto/exocore/operator/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "7" with name "execution_info" on message "OperatorSlashInfo" changed option "json_name" from "slashType" to "executionInfo".
}

// RegisterOperatorReq is the request to register a new operator.
Expand Down
9 changes: 7 additions & 2 deletions x/assets/keeper/operator_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (k Keeper) GetOperatorAssetInfos(ctx sdk.Context, operatorAddr sdk.Address,
ret[assetID] = state
return nil
}
err = k.IteratorAssetsForOperator(ctx, operatorAddr.String(), assetsFilter, opFunc)
err = k.IteratorAssetsForOperator(ctx, false, operatorAddr.String(), assetsFilter, opFunc)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -96,7 +96,7 @@ func (k Keeper) UpdateOperatorAssetState(ctx sdk.Context, operatorAddr sdk.Addre
// IteratorAssetsForOperator iterates all assets for the specified operator
// if `assetsFilter` is nil, the `opFunc` will handle all assets, it equals to an iterator without filter
// if `assetsFilter` isn't nil, the `opFunc` will only handle the assets that is in the filter map.
func (k Keeper) IteratorAssetsForOperator(ctx sdk.Context, operator string, assetsFilter map[string]interface{}, opFunc func(assetID string, state *assetstype.OperatorAssetInfo) error) error {
func (k Keeper) IteratorAssetsForOperator(ctx sdk.Context, isUpdate bool, operator string, assetsFilter map[string]interface{}, opFunc func(assetID string, state *assetstype.OperatorAssetInfo) error) error {
store := prefix.NewStore(ctx.KVStore(k.storeKey), assetstype.KeyPrefixOperatorAssetInfos)
iterator := sdk.KVStorePrefixIterator(store, []byte(operator))
defer iterator.Close()
Expand All @@ -116,6 +116,11 @@ func (k Keeper) IteratorAssetsForOperator(ctx sdk.Context, operator string, asse
if err != nil {
return err
}
if isUpdate {
TimmyExogenous marked this conversation as resolved.
Show resolved Hide resolved
// store the updated state
bz := k.cdc.MustMarshal(&amounts)
store.Set(iterator.Key(), bz)
}
}
return nil
}
Loading
Loading