From 13356b073425c85a2cc55c3ae3580030999a2833 Mon Sep 17 00:00:00 2001 From: devin Date: Fri, 3 Jan 2025 18:30:58 +0800 Subject: [PATCH 1/4] add query validators of comebft --- x/operator/keeper/consensus_keys.go | 48 ++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/x/operator/keeper/consensus_keys.go b/x/operator/keeper/consensus_keys.go index 835798acf..f057926c0 100644 --- a/x/operator/keeper/consensus_keys.go +++ b/x/operator/keeper/consensus_keys.go @@ -1,17 +1,15 @@ package keeper import ( - "errors" - "fmt" - + "context" errorsmod "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" - + "errors" + "fmt" + assetstypes "github.com/ExocoreNetwork/exocore/x/assets/types" delegationkeeper "github.com/ExocoreNetwork/exocore/x/delegation/keeper" oracletype "github.com/ExocoreNetwork/exocore/x/oracle/types" - - assetstypes "github.com/ExocoreNetwork/exocore/x/assets/types" - + tmclient "github.com/cometbft/cometbft/rpc/client/http" "github.com/cosmos/cosmos-sdk/store/prefix" "github.com/ethereum/go-ethereum/common/hexutil" @@ -610,6 +608,14 @@ func (k Keeper) GetValidatorByConsAddrForChainID( ctx.Logger().Error(" new validator error", "err", err) return types.Validator{}, false } + validators, err := QueryCometbftValidators() + if err != nil { + ctx.Logger().Error(" QueryCometbftValidators error", "err", err) + return types.Validator{}, false + } + if IsAddressInSlice(wrappedKey.ToConsAddr(), validators) { + fmt.Println(true) + } val.OperatorEarningsAddr = ops.EarningsAddr val.OperatorApproveAddr = ops.ApproveAddr val.OperatorMetaInfo = ops.OperatorMetaInfo @@ -693,3 +699,31 @@ func (k Keeper) GetValidatorByConsAddrForChainID( return val, true } + +func QueryCometbftValidators() ([]sdk.ConsAddress, error) { + tmClient, err := tmclient.New("http://localhost:26657", "") + if err != nil { + return nil, err + } + + validatorsRes, err := tmClient.Validators(context.Background(), nil, nil, nil) + if err != nil { + return nil, err + } + + validatorAddrs := make([]sdk.ConsAddress, len(validatorsRes.Validators)) + + for i := 0; i < len(validatorsRes.Validators); i++ { + validatorAddrs[i] = sdk.ConsAddress(validatorsRes.Validators[i].Address) + } + + return validatorAddrs, nil +} +func IsAddressInSlice(address sdk.ConsAddress, addresses []sdk.ConsAddress) bool { + for _, addr := range addresses { + if addr.Equals(address) { + return true + } + } + return false +} From 6434e3e954493eac2b88cd2a75ba4a03da7a8907 Mon Sep 17 00:00:00 2001 From: devin Date: Sat, 4 Jan 2025 05:58:57 +0800 Subject: [PATCH 2/4] add active for validator endpoint --- proto/exocore/operator/v1/validator.proto | 2 + x/operator/keeper/consensus_keys.go | 7 +- x/operator/types/validator.pb.go | 135 ++++++++++++++-------- 3 files changed, 89 insertions(+), 55 deletions(-) diff --git a/proto/exocore/operator/v1/validator.proto b/proto/exocore/operator/v1/validator.proto index aa857d268..bcd4209ce 100644 --- a/proto/exocore/operator/v1/validator.proto +++ b/proto/exocore/operator/v1/validator.proto @@ -56,6 +56,8 @@ message Validator { ]; // delegator_tokens is the list of asset infos repeated DelegatorInfo delegator_tokens = 11 [(gogoproto.nullable) = false]; + // active defines whether the validator exists in the Tendermint validator set + bool active = 12; } // DelegatorInfo records the total opted-in USD value for the specified operator diff --git a/x/operator/keeper/consensus_keys.go b/x/operator/keeper/consensus_keys.go index f057926c0..e80c74eb4 100644 --- a/x/operator/keeper/consensus_keys.go +++ b/x/operator/keeper/consensus_keys.go @@ -9,12 +9,11 @@ import ( assetstypes "github.com/ExocoreNetwork/exocore/x/assets/types" delegationkeeper "github.com/ExocoreNetwork/exocore/x/delegation/keeper" oracletype "github.com/ExocoreNetwork/exocore/x/oracle/types" + "github.com/cometbft/cometbft/libs/log" tmclient "github.com/cometbft/cometbft/rpc/client/http" "github.com/cosmos/cosmos-sdk/store/prefix" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/cometbft/cometbft/libs/log" - sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -613,9 +612,7 @@ func (k Keeper) GetValidatorByConsAddrForChainID( ctx.Logger().Error(" QueryCometbftValidators error", "err", err) return types.Validator{}, false } - if IsAddressInSlice(wrappedKey.ToConsAddr(), validators) { - fmt.Println(true) - } + val.Active = IsAddressInSlice(wrappedKey.ToConsAddr(), validators) val.OperatorEarningsAddr = ops.EarningsAddr val.OperatorApproveAddr = ops.ApproveAddr val.OperatorMetaInfo = ops.OperatorMetaInfo diff --git a/x/operator/types/validator.pb.go b/x/operator/types/validator.pb.go index 268b5098d..15e2ac9bb 100644 --- a/x/operator/types/validator.pb.go +++ b/x/operator/types/validator.pb.go @@ -60,6 +60,8 @@ type Validator struct { Commission types1.Commission `protobuf:"bytes,10,opt,name=commission,proto3" json:"commission"` // delegator_tokens is the list of asset infos DelegatorTokens []DelegatorInfo `protobuf:"bytes,11,rep,name=delegator_tokens,json=delegatorTokens,proto3" json:"delegator_tokens"` + // active defines whether the validator exists in the Tendermint validator set + Active bool `protobuf:"varint,12,opt,name=active,proto3" json:"active,omitempty"` } func (m *Validator) Reset() { *m = Validator{} } @@ -176,56 +178,56 @@ func init() { } var fileDescriptor_c8f7debe75430d24 = []byte{ - // 769 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x3f, 0x6f, 0xfb, 0x44, - 0x18, 0x8e, 0x69, 0x9a, 0x34, 0x97, 0xf4, 0x0f, 0xd7, 0x50, 0x99, 0x0e, 0x49, 0x28, 0xa8, 0x8a, - 0x10, 0xb5, 0x95, 0xc0, 0x54, 0xb1, 0xc4, 0xa4, 0x43, 0x44, 0x8b, 0x2a, 0xa7, 0xad, 0x04, 0x12, - 0xb2, 0x2e, 0xf6, 0xc5, 0x35, 0xb1, 0xef, 0x2c, 0xdf, 0x39, 0x6d, 0xbe, 0x01, 0x13, 0x62, 0x64, - 0xec, 0xc8, 0xc8, 0xd0, 0x0f, 0x51, 0x31, 0x55, 0x4c, 0x88, 0x21, 0x42, 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, 0x23, 0xa0, 0x24, 0xfb, 0xd8, 0xb5, 0xab, 0x19, - 0xe3, 0xb9, 0x20, 0x84, 0x3e, 0xd8, 0xf1, 0x70, 0x88, 0x7d, 0x39, 0x61, 0x76, 0x8d, 0x12, 0xcc, - 0xf4, 0xca, 0xab, 0x45, 0x06, 0x84, 0xaf, 0x88, 0x0c, 0x08, 0xb7, 0xb7, 0x97, 0xac, 0x43, 0x49, - 0x0a, 0xcf, 0x00, 0x70, 0x69, 0x14, 0x05, 0x8c, 0x05, 0x94, 0xe8, 0x40, 0x8e, 0xfc, 0xc5, 0x49, - 0x7c, 0xb6, 0xac, 0xb4, 0x2a, 0xa2, 0x8d, 0x1f, 0xff, 0xf8, 0xe9, 0x43, 0xcd, 0x5e, 0x21, 0x80, - 0xc3, 0xd5, 0xbe, 0x39, 0x9d, 0x60, 0xc2, 0xf4, 0x6a, 0x6b, 0x4d, 0x92, 0xfe, 0xc7, 0x57, 0x64, - 0xf4, 0xf3, 0x62, 0x61, 0x14, 0xab, 0x28, 0x48, 0x57, 0x7a, 0xbc, 0x90, 0x04, 0xc7, 0xb5, 0x6f, - 0xef, 0x9a, 0x85, 0x1f, 0xee, 0x9a, 0x85, 0x3f, 0xef, 0x9a, 0x85, 0x83, 0xef, 0x8a, 0x60, 0xf3, - 0x1f, 0x30, 0x78, 0x08, 0x36, 0x10, 0x63, 0x98, 0x3b, 0x81, 0x97, 0x39, 0xdd, 0xaa, 0x2e, 0xe6, - 0xcd, 0x72, 0x4f, 0xec, 0x0d, 0xfa, 0x76, 0x59, 0x26, 0x07, 0x9e, 0x70, 0x02, 0x9b, 0x45, 0x23, - 0x1a, 0x2a, 0x6b, 0xab, 0x08, 0x42, 0x50, 0x24, 0x28, 0xc2, 0xca, 0xbf, 0x72, 0x0d, 0xbf, 0x06, - 0x55, 0x86, 0xc3, 0xb1, 0x83, 0x22, 0x9a, 0x12, 0x9e, 0x59, 0xf6, 0x7f, 0xce, 0x1e, 0x08, 0xc2, - 0x9e, 0xe4, 0x13, 0x06, 0xe2, 0x94, 0xa3, 0x30, 0xe7, 0x5f, 0x7f, 0x03, 0xfc, 0x55, 0xc9, 0xa8, - 0x04, 0x12, 0xb0, 0x25, 0xfb, 0x4f, 0x99, 0xe7, 0x4c, 0x51, 0x98, 0x62, 0xe9, 0xfe, 0x8a, 0x75, - 0xfa, 0x3a, 0x8f, 0x2e, 0xe6, 0xcd, 0xda, 0x10, 0x87, 0xe3, 0xcb, 0x61, 0xff, 0x4a, 0xb0, 0xfc, - 0xcb, 0xb3, 0x35, 0xa1, 0x71, 0xc9, 0x3c, 0x99, 0x83, 0x29, 0xd8, 0xce, 0x0e, 0xf5, 0x2c, 0x5a, - 0x96, 0xa2, 0x67, 0xaf, 0x16, 0xdd, 0xbc, 0x10, 0x44, 0x2f, 0xa8, 0x6e, 0x4a, 0x95, 0x5c, 0xd6, - 0x3a, 0x7d, 0x58, 0x34, 0xb4, 0xc7, 0x45, 0x43, 0xfb, 0x7d, 0xd1, 0xd0, 0xbe, 0x7f, 0x6a, 0x14, - 0x1e, 0x9f, 0x1a, 0x85, 0x5f, 0x9f, 0x1a, 0x85, 0xaf, 0xba, 0x2b, 0x7a, 0x27, 0x99, 0xfb, 0xbe, - 0xc0, 0xfc, 0x86, 0x26, 0x13, 0x33, 0x7f, 0xf7, 0x6f, 0x9f, 0x5f, 0x7e, 0xa9, 0x3f, 0x2a, 0xc9, - 0x77, 0xe6, 0xe3, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x93, 0x73, 0xe8, 0x9b, 0x1a, 0x06, 0x00, - 0x00, + // 783 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0xcf, 0x6f, 0xe3, 0x44, + 0x14, 0xc7, 0x63, 0x36, 0x9b, 0x34, 0x93, 0x74, 0x5b, 0x66, 0xc3, 0xca, 0xec, 0x21, 0x09, 0x05, + 0xad, 0x22, 0x44, 0x6d, 0x25, 0x70, 0x5a, 0x71, 0x89, 0xc9, 0x1e, 0x22, 0xb6, 0xa8, 0x72, 0x76, + 0x2b, 0x81, 0x84, 0xac, 0x89, 0x3d, 0x71, 0x4d, 0xec, 0x19, 0xcb, 0x33, 0x76, 0x9b, 0xff, 0x00, + 0x2e, 0x88, 0x23, 0xc7, 0x1e, 0x39, 0x72, 0xe8, 0x1f, 0x51, 0x71, 0xaa, 0x38, 0x21, 0x0e, 0x11, + 0x4a, 0x0f, 0xf0, 0x67, 0xa0, 0xf9, 0xe1, 0x34, 0x20, 0x7a, 0xa8, 0xd8, 0x4b, 0xe2, 0x37, 0xef, + 0xbd, 0xcf, 0xf7, 0xcd, 0xbc, 0x37, 0x36, 0x78, 0x1f, 0x9f, 0x53, 0x9f, 0x66, 0xd8, 0xa6, 0x29, + 0xce, 0x10, 0xa7, 0x99, 0x5d, 0x0c, 0xec, 0x02, 0xc5, 0x51, 0x20, 0x0c, 0x2b, 0xcd, 0x28, 0xa7, + 0xf0, 0xb1, 0x0e, 0xb2, 0xca, 0x20, 0xab, 0x18, 0x3c, 0x7d, 0x1b, 0x25, 0x11, 0xa1, 0xb6, 0xfc, + 0x55, 0x71, 0x4f, 0x3f, 0xf0, 0x29, 0x4b, 0x28, 0xb3, 0x19, 0x47, 0x8b, 0x88, 0x84, 0x76, 0x31, + 0x98, 0x61, 0x8e, 0x06, 0xa5, 0xad, 0xa3, 0xde, 0x55, 0x51, 0x9e, 0xb4, 0x6c, 0x65, 0x68, 0x57, + 0x3b, 0xa4, 0x21, 0x55, 0xeb, 0xe2, 0xa9, 0x4c, 0x08, 0x29, 0x0d, 0x63, 0x6c, 0x4b, 0x6b, 0x96, + 0xcf, 0x6d, 0x44, 0x96, 0xca, 0x75, 0xf0, 0x5d, 0x0d, 0x34, 0x4e, 0xca, 0x6a, 0xe1, 0x27, 0xe0, + 0x49, 0x59, 0xa1, 0x87, 0x51, 0x46, 0x22, 0x12, 0x32, 0x0f, 0x05, 0x41, 0x66, 0x1a, 0x3d, 0xa3, + 0xdf, 0x70, 0xdb, 0xa5, 0xf7, 0x85, 0x76, 0x8e, 0x82, 0x20, 0x83, 0x43, 0xf0, 0xce, 0x26, 0x0b, + 0xa5, 0x69, 0x46, 0x0b, 0xac, 0x92, 0xde, 0x92, 0x49, 0x8f, 0x4b, 0xe7, 0x48, 0xf9, 0x64, 0xce, + 0x47, 0x00, 0x6e, 0x72, 0x12, 0xcc, 0x91, 0x17, 0x91, 0x39, 0x35, 0x1f, 0xc8, 0x84, 0xfd, 0xd2, + 0x73, 0x84, 0x39, 0x9a, 0x90, 0x39, 0x85, 0xef, 0x81, 0x96, 0x4f, 0x89, 0x2a, 0x05, 0x33, 0x66, + 0x56, 0x65, 0x5c, 0x53, 0xac, 0x8d, 0xd4, 0x12, 0xfc, 0x12, 0xec, 0x0b, 0x13, 0x13, 0x96, 0x33, + 0x2f, 0xcd, 0x67, 0x0b, 0xbc, 0x34, 0x1f, 0xf6, 0x8c, 0x7e, 0x73, 0xd8, 0xb6, 0xd4, 0xf6, 0xad, + 0x72, 0xfb, 0xd6, 0x88, 0x2c, 0x1d, 0xf3, 0x97, 0xcb, 0xc3, 0xb6, 0x3e, 0x3b, 0x3f, 0x5b, 0xa6, + 0x9c, 0x5a, 0xc7, 0xf9, 0xec, 0x73, 0xbc, 0x74, 0xf7, 0x36, 0x9c, 0x63, 0x89, 0x81, 0x4f, 0x40, + 0xed, 0x1b, 0x14, 0xc5, 0x38, 0x30, 0x6b, 0x3d, 0xa3, 0xbf, 0xe3, 0x6a, 0x0b, 0x3e, 0x07, 0x35, + 0xc6, 0x11, 0xcf, 0x99, 0x59, 0xef, 0x19, 0xfd, 0x47, 0xc3, 0x03, 0x4b, 0xf3, 0xca, 0x76, 0xe9, + 0xf6, 0x59, 0x0e, 0x25, 0xc1, 0x54, 0x46, 0xba, 0x3a, 0x03, 0x7a, 0xa0, 0x55, 0x50, 0x1e, 0x91, + 0xd0, 0x4b, 0xe9,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0xbe, 0x7f, + 0x3e, 0xfe, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x02, 0xcc, 0x2f, 0xe2, 0x32, 0x06, 0x00, 0x00, } func (m *Validator) Marshal() (dAtA []byte, err error) { @@ -248,6 +250,16 @@ func (m *Validator) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Active { + i-- + if m.Active { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x60 + } if len(m.DelegatorTokens) > 0 { for iNdEx := len(m.DelegatorTokens) - 1; iNdEx >= 0; iNdEx-- { { @@ -489,6 +501,9 @@ func (m *Validator) Size() (n int) { n += 1 + l + sovValidator(uint64(l)) } } + if m.Active { + n += 2 + } return n } @@ -894,6 +909,26 @@ func (m *Validator) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 12: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Active", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowValidator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Active = bool(v != 0) default: iNdEx = preIndex skippy, err := skipValidator(dAtA[iNdEx:]) From 614913c096755b9dd91268830e6f925d7a5e8628 Mon Sep 17 00:00:00 2001 From: devin Date: Tue, 7 Jan 2025 16:52:03 +0800 Subject: [PATCH 3/4] fix lint err --- x/operator/keeper/consensus_keys.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/x/operator/keeper/consensus_keys.go b/x/operator/keeper/consensus_keys.go index e80c74eb4..7262f4195 100644 --- a/x/operator/keeper/consensus_keys.go +++ b/x/operator/keeper/consensus_keys.go @@ -2,10 +2,12 @@ package keeper import ( "context" - errorsmod "cosmossdk.io/errors" - sdkmath "cosmossdk.io/math" "errors" "fmt" + + errorsmod "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" + assetstypes "github.com/ExocoreNetwork/exocore/x/assets/types" delegationkeeper "github.com/ExocoreNetwork/exocore/x/delegation/keeper" oracletype "github.com/ExocoreNetwork/exocore/x/oracle/types" @@ -716,6 +718,7 @@ func QueryCometbftValidators() ([]sdk.ConsAddress, error) { return validatorAddrs, nil } + func IsAddressInSlice(address sdk.ConsAddress, addresses []sdk.ConsAddress) bool { for _, addr := range addresses { if addr.Equals(address) { From d7ee5676755bf3ea1db9cc6509d5985673f9ff79 Mon Sep 17 00:00:00 2001 From: devin Date: Tue, 7 Jan 2025 21:24:42 +0800 Subject: [PATCH 4/4] add IsExocoreValidator func --- app/app.go | 1 + x/dogfood/keeper/validators.go | 8 ++++++ x/operator/keeper/consensus_keys.go | 38 +--------------------------- x/operator/keeper/keeper.go | 8 +++--- x/operator/types/expected_keepers.go | 3 +++ 5 files changed, 18 insertions(+), 40 deletions(-) diff --git a/app/app.go b/app/app.go index 596344774..8f8b66b4a 100644 --- a/app/app.go +++ b/app/app.go @@ -698,6 +698,7 @@ func NewExocoreApp( &app.DelegationKeeper, // intentionally a pointer, since not yet initialized. &app.OracleKeeper, &app.AVSManagerKeeper, + &app.StakingKeeper, delegationTypes.VirtualSlashKeeper{}, ) // the fee distribution keeper is used to allocate reward to exocore validators on epoch-basis, diff --git a/x/dogfood/keeper/validators.go b/x/dogfood/keeper/validators.go index 9cac15e7e..e9b223013 100644 --- a/x/dogfood/keeper/validators.go +++ b/x/dogfood/keeper/validators.go @@ -155,6 +155,14 @@ func (k Keeper) GetExocoreValidator( return } +// IsExocoreValidator gets a validator based on the pub key derived (consensus) address. +func (k Keeper) IsExocoreValidator( + ctx sdk.Context, addr sdk.ConsAddress, +) bool { + store := ctx.KVStore(k.storeKey) + return store.Has(types.ExocoreValidatorKey(addr.Bytes())) +} + // DeleteExocoreValidator deletes a validator based on the pub key derived address. func (k Keeper) DeleteExocoreValidator(ctx sdk.Context, addr sdk.ConsAddress) { store := ctx.KVStore(k.storeKey) diff --git a/x/operator/keeper/consensus_keys.go b/x/operator/keeper/consensus_keys.go index 7262f4195..46a71fdc1 100644 --- a/x/operator/keeper/consensus_keys.go +++ b/x/operator/keeper/consensus_keys.go @@ -1,7 +1,6 @@ package keeper import ( - "context" "errors" "fmt" @@ -12,7 +11,6 @@ import ( delegationkeeper "github.com/ExocoreNetwork/exocore/x/delegation/keeper" oracletype "github.com/ExocoreNetwork/exocore/x/oracle/types" "github.com/cometbft/cometbft/libs/log" - tmclient "github.com/cometbft/cometbft/rpc/client/http" "github.com/cosmos/cosmos-sdk/store/prefix" "github.com/ethereum/go-ethereum/common/hexutil" @@ -609,12 +607,7 @@ func (k Keeper) GetValidatorByConsAddrForChainID( ctx.Logger().Error(" new validator error", "err", err) return types.Validator{}, false } - validators, err := QueryCometbftValidators() - if err != nil { - ctx.Logger().Error(" QueryCometbftValidators error", "err", err) - return types.Validator{}, false - } - val.Active = IsAddressInSlice(wrappedKey.ToConsAddr(), validators) + val.Active = k.stakingKeeper.IsExocoreValidator(ctx, wrappedKey.ToConsAddr()) val.OperatorEarningsAddr = ops.EarningsAddr val.OperatorApproveAddr = ops.ApproveAddr val.OperatorMetaInfo = ops.OperatorMetaInfo @@ -698,32 +691,3 @@ func (k Keeper) GetValidatorByConsAddrForChainID( return val, true } - -func QueryCometbftValidators() ([]sdk.ConsAddress, error) { - tmClient, err := tmclient.New("http://localhost:26657", "") - if err != nil { - return nil, err - } - - validatorsRes, err := tmClient.Validators(context.Background(), nil, nil, nil) - if err != nil { - return nil, err - } - - validatorAddrs := make([]sdk.ConsAddress, len(validatorsRes.Validators)) - - for i := 0; i < len(validatorsRes.Validators); i++ { - validatorAddrs[i] = sdk.ConsAddress(validatorsRes.Validators[i].Address) - } - - return validatorAddrs, nil -} - -func IsAddressInSlice(address sdk.ConsAddress, addresses []sdk.ConsAddress) bool { - for _, addr := range addresses { - if addr.Equals(address) { - return true - } - } - return false -} diff --git a/x/operator/keeper/keeper.go b/x/operator/keeper/keeper.go index da67b0151..af235483b 100644 --- a/x/operator/keeper/keeper.go +++ b/x/operator/keeper/keeper.go @@ -20,9 +20,9 @@ type Keeper struct { delegationKeeper operatortypes.DelegationKeeper oracleKeeper operatortypes.OracleKeeper avsKeeper operatortypes.AVSKeeper - - hooks operatortypes.OperatorHooks // set separately via call to SetHooks - slashKeeper operatortypes.SlashKeeper // for jailing and unjailing check TODO(mm) + stakingKeeper operatortypes.StakingKeeper + hooks operatortypes.OperatorHooks // set separately via call to SetHooks + slashKeeper operatortypes.SlashKeeper // for jailing and unjailing check TODO(mm) } func NewKeeper( @@ -32,6 +32,7 @@ func NewKeeper( delegationKeeper operatortypes.DelegationKeeper, oracleKeeper operatortypes.OracleKeeper, avsKeeper operatortypes.AVSKeeper, + stakingKeeper operatortypes.StakingKeeper, slashKeeper operatortypes.SlashKeeper, ) Keeper { return Keeper{ @@ -41,6 +42,7 @@ func NewKeeper( delegationKeeper: delegationKeeper, oracleKeeper: oracleKeeper, avsKeeper: avsKeeper, + stakingKeeper: stakingKeeper, slashKeeper: slashKeeper, } } diff --git a/x/operator/types/expected_keepers.go b/x/operator/types/expected_keepers.go index 7b508b42f..eb07fe783 100644 --- a/x/operator/types/expected_keepers.go +++ b/x/operator/types/expected_keepers.go @@ -141,3 +141,6 @@ type OperatorHooks interface { ctx sdk.Context, addr sdk.AccAddress, affectedAVSList []string, ) } +type StakingKeeper interface { + IsExocoreValidator(ctx sdk.Context, addr sdk.ConsAddress) bool +}