Skip to content

Commit

Permalink
implement the interfaces expected by dogfood
Browse files Browse the repository at this point in the history
  • Loading branch information
TimmyExogenous committed Mar 25, 2024
1 parent 658364d commit 1df2ddf
Show file tree
Hide file tree
Showing 11 changed files with 642 additions and 366 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ proto-download-deps:
git remote add origin "https://github.com/cosmos/cosmos-sdk.git" && \
git config core.sparseCheckout true && \
printf "proto\nthird_party\n" > .git/info/sparse-checkout && \
git pull origin main && \
git pull origin release/v0.47.x && \
rm -f ./proto/buf.* && \
mv ./proto/* ..
rm -rf "$(THIRD_PARTY_DIR)/cosmos_tmp"
Expand All @@ -441,7 +441,7 @@ proto-download-deps:
git remote add origin "https://github.com/cosmos/ibc-go.git" && \
git config core.sparseCheckout true && \
printf "proto\n" > .git/info/sparse-checkout && \
git pull origin main && \
git pull origin release/v7.2.x && \
rm -f ./proto/buf.* && \
mv ./proto/* ..
rm -rf "$(THIRD_PARTY_DIR)/ibc_tmp"
Expand All @@ -452,7 +452,8 @@ proto-download-deps:
git remote add origin "https://github.com/cosmos/cosmos-proto.git" && \
git config core.sparseCheckout true && \
printf "proto\n" > .git/info/sparse-checkout && \
git pull origin main && \
git fetch origin tags/v1.0.0-beta.3 && \
git checkout -b my_branch FETCH_HEAD && \
rm -f ./proto/buf.* && \
mv ./proto/* ..
rm -rf "$(THIRD_PARTY_DIR)/cosmos_proto_tmp"
Expand Down
11 changes: 11 additions & 0 deletions proto/exocore/operator/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exocore.operator.v1;

import "amino/amino.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos/staking/v1beta1/staking.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

Expand Down Expand Up @@ -45,6 +46,14 @@ message OperatorInfo {
string operator_meta_info = 3;
// client_chain_earning_addr_list is the client chain earning address list.
ClientChainEarningAddrList client_chain_earnings_addr = 4;
// commission defines the commission parameters.
cosmos.staking.v1beta1.Commission commission = 5 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
// min_self_delegation is the validator's self declared minimum self delegation.
string min_self_delegation = 6 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

// OptedInfo is the opted information about operator
Expand All @@ -55,6 +64,8 @@ message OptedInfo {
uint64 opted_in_height = 2;
// opted_out_height is the exocore block height at which the operator opted out
uint64 opted_out_height = 3;
// jailed defined whether the operator has been jailed from bonded status or not.
bool jailed = 4;
}

// OptedInAssetState is the state of opted-in asset
Expand Down
22 changes: 4 additions & 18 deletions x/dogfood/keeper/impl_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,8 @@ func (k Keeper) ValidatorByConsAddr(
ctx sdk.Context,
addr sdk.ConsAddress,
) stakingtypes.ValidatorI {
found, accAddr := k.operatorKeeper.GetOperatorAddressForChainIDAndConsAddr(
ctx, ctx.ChainID(), addr,
)
if !found {
// replicate the behavior of the SDK's staking module; do not panic.
return nil
}
return stakingtypes.Validator{
Jailed: k.operatorKeeper.IsOperatorJailedForChainID(ctx, accAddr, ctx.ChainID()),
Jailed: k.operatorKeeper.IsOperatorJailedForChainID(ctx, addr, ctx.ChainID()),
}
}

Expand Down Expand Up @@ -123,8 +116,8 @@ func (k Keeper) Jail(ctx sdk.Context, addr sdk.ConsAddress) {
// The function is called by the slashing module only when it receives a request from the
// operator to do so. TODO(mm): We need to use the SDK's slashing module to allow for downtime
// slashing but somehow we need to prevent its Unjail function from being called by anyone.
func (k Keeper) Unjail(sdk.Context, sdk.ConsAddress) {
panic("unimplemented on this keeper")
func (k Keeper) Unjail(ctx sdk.Context, addr sdk.ConsAddress) {
k.operatorKeeper.Unjail(ctx, addr, ctx.ChainID())
}

// Delegation is an implementation of the staking interface expected by the SDK's slashing
Expand Down Expand Up @@ -154,14 +147,7 @@ func (k Keeper) GetAllValidators(sdk.Context) (validators []stakingtypes.Validat
// slashing module. It is called by the slashing module to record validator signatures
// for downtime tracking. We delegate the call to the operator keeper.
func (k Keeper) IsValidatorJailed(ctx sdk.Context, addr sdk.ConsAddress) bool {
found, accAddr := k.operatorKeeper.GetOperatorAddressForChainIDAndConsAddr(
ctx, ctx.ChainID(), addr,
)
if !found {
// replicate the behavior of the SDK's staking module
return false
}
return k.operatorKeeper.IsOperatorJailedForChainID(ctx, accAddr, ctx.ChainID())
return k.operatorKeeper.IsOperatorJailedForChainID(ctx, addr, ctx.ChainID())
}

// ApplyAndReturnValidatorSetUpdates is an implementation of the staking interface expected
Expand Down
5 changes: 3 additions & 2 deletions x/dogfood/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ type OperatorKeeper interface {
GetOperatorAddressForChainIDAndConsAddr(
sdk.Context, string, sdk.ConsAddress,
) (bool, sdk.AccAddress)
IsOperatorJailedForChainID(sdk.Context, sdk.AccAddress, string) bool
IsOperatorJailedForChainID(sdk.Context, sdk.ConsAddress, string) bool
Jail(sdk.Context, sdk.ConsAddress, string)
Unjail(sdk.Context, sdk.ConsAddress, string)
// GetActiveOperatorsForChainID should return a list of operators and their public keys.
// These operators should not be in the process of opting our, and should not be jailed
// These operators should not be in the process of opting out, and should not be jailed
// whether permanently or temporarily.
GetActiveOperatorsForChainID(
sdk.Context, string,
Expand Down
26 changes: 18 additions & 8 deletions x/operator/keeper/consensus_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,24 @@ func (k *Keeper) CompleteOperatorOptOutFromChainID(
store.Delete(types.KeyForOperatorOptOutFromChainID(opAccAddr, chainID))
}

// IsOperatorJailedForChainID add for dogfood
func (k *Keeper) IsOperatorJailedForChainID(sdk.Context, sdk.AccAddress, string) bool {
return false
}
func (k *Keeper) Jail(sdk.Context, sdk.ConsAddress, string) {}

func (k *Keeper) GetActiveOperatorsForChainID(
sdk.Context, string,
ctx sdk.Context, chainID string,
) ([]sdk.AccAddress, []tmprotocrypto.PublicKey) {
return nil, nil
operatorsAddr, pks := k.GetOperatorsForChainID(ctx, chainID)
avsAddr, err := k.avsKeeper.GetAvsAddrByChainID(ctx, chainID)
if err != nil {
k.Logger(ctx).Error(err.Error(), chainID)
return nil, nil
}

activeOperator := make([]sdk.AccAddress, 0)
activePks := make([]tmprotocrypto.PublicKey, 0)
// check if the operator is active
for i, operator := range operatorsAddr {
if k.IsActive(ctx, operator.String(), avsAddr) {
activeOperator = append(activeOperator, operator)
activePks = append(activePks, pks[i])
}
}
return activeOperator, activePks
}
39 changes: 38 additions & 1 deletion x/operator/keeper/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,30 @@ func (k *Keeper) IsOperator(ctx sdk.Context, addr sdk.AccAddress) bool {
return store.Has(addr)
}

func (k *Keeper) UpdateOptedInfo(ctx sdk.Context, operatorAddr, avsAddr string, info *operatortypes.OptedInfo) error {
func (k *Keeper) HandleOptedInfo(ctx sdk.Context, operatorAddr, avsAddr string, handleFunc func(info *operatortypes.OptedInfo)) error {
opAccAddr, err := sdk.AccAddressFromBech32(operatorAddr)
if err != nil {
return errorsmod.Wrap(err, "HandleOptedInfo: error occurred when parse acc address from Bech32")
}
store := prefix.NewStore(ctx.KVStore(k.storeKey), operatortypes.KeyPrefixOperatorOptedAVSInfo)
infoKey := assetstype.GetJoinedStoreKey(operatorAddr, avsAddr)
ifExist := store.Has(infoKey)
if !ifExist {
return errorsmod.Wrap(operatortypes.ErrNoKeyInTheStore, fmt.Sprintf("HandleOptedInfo: key is %suite", opAccAddr))
}
// get info from the store
value := store.Get(infoKey)
info := &operatortypes.OptedInfo{}
k.cdc.MustUnmarshal(value, info)
// call the handleFunc
handleFunc(info)
// restore the info after handling
bz := k.cdc.MustMarshal(info)
store.Set(infoKey, bz)
return nil
}

func (k *Keeper) SetOptedInfo(ctx sdk.Context, operatorAddr, avsAddr string, info *operatortypes.OptedInfo) error {
store := prefix.NewStore(ctx.KVStore(k.storeKey), operatortypes.KeyPrefixOperatorOptedAVSInfo)

// check operator address validation
Expand Down Expand Up @@ -99,6 +122,20 @@ func (k *Keeper) IsOptedIn(ctx sdk.Context, operatorAddr, avsAddr string) bool {
return true
}

func (k *Keeper) IsActive(ctx sdk.Context, operatorAddr, avsAddr string) bool {
optedInfo, err := k.GetOptedInfo(ctx, operatorAddr, avsAddr)
if err != nil {
return false
}
if optedInfo.OptedOutHeight != operatortypes.DefaultOptedOutHeight {
return false
}
if optedInfo.Jailed {
return false
}
return true
}

func (k *Keeper) GetOptedInAVSForOperator(ctx sdk.Context, operatorAddr string) ([]string, error) {
// get all opted-in info
store := prefix.NewStore(ctx.KVStore(k.storeKey), operatortypes.KeyPrefixOperatorOptedAVSInfo)
Expand Down
4 changes: 4 additions & 0 deletions x/operator/keeper/operator_info_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package keeper_test

import (
"cosmossdk.io/math"
"github.com/ExocoreNetwork/exocore/x/assets/types"
operatortype "github.com/ExocoreNetwork/exocore/x/operator/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

func (suite *OperatorTestSuite) TestOperatorInfo() {
Expand All @@ -15,6 +17,8 @@ func (suite *OperatorTestSuite) TestOperatorInfo() {
{101, "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984"},
},
},
Commission: stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec()),
MinSelfDelegation: math.NewInt(0),
}
err := suite.App.OperatorKeeper.SetOperatorInfo(suite.Ctx, suite.AccAddress.String(), info)
suite.NoError(err)
Expand Down
Loading

0 comments on commit 1df2ddf

Please sign in to comment.