diff --git a/proto/exocore/operator/v1/genesis.proto b/proto/exocore/operator/v1/genesis.proto new file mode 100644 index 000000000..0ed481a71 --- /dev/null +++ b/proto/exocore/operator/v1/genesis.proto @@ -0,0 +1,91 @@ +syntax = "proto3"; +package exocore.operator.v1; + +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; + +import "exocore/operator/v1/tx.proto"; + +option go_package = "github.com/ExocoreNetwork/exocore/x/operator/types"; + +// GenesisState defines the operator module's genesis state. +message GenesisState { + // there are no params for this module. + // operators is a list of the registered operators. + repeated OperatorInfo operators = 1 [(gogoproto.nullable) = false]; + // 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]; + // TODO: add other AVS opt-in information for exporting / importing. + // Although it is not necessary for the bootstrapped genesis, it is + // necessary for chain restarts. +} + +// OperatorConsKeyRecord is a helper structure for the genesis state. Each record +// contains an operator address and a list of chain id + cons key combination. +message OperatorConsKeyRecord { + // operator_address is the address of the operator as the bech32 + // encoded version of sdk.AccAddress. + string operator_address = 1; + // chains is a list of chain id + consensus key combination. + repeated ChainDetails chains = 2 [(gogoproto.nullable) = false]; +} + +// ChainDetails is a helper structure for the genesis state. Each record +// contains a chain id and a consensus key. +message ChainDetails { + // chain_id is the unique identifier of the chain. + string chain_id = 1 [(gogoproto.customname) = "ChainID"]; + // consensus_key is the consensus key of the operator on the chain. + // the length of this key should be exactly 32 bytes, and must be enforced + // outside of protobuf. + string consensus_key = 2; +} + +// all operators in the genesis (during bootstrap) are assumed to have +// opted into validating Exocore. however, we still need to set their opt-in +// data. we can do this by calling k.OptIn(ctx, sdk.AccAddress, ctx.ChainID()) + +// this will then allow us to call +// k.UpdateOptedInAssetsState(ctx, staker, assetID, operator, stakedValue) +// for now, we keep this data in the genesis as the order stored, but +// it would be trivial to alter the order if deemed necessary. +// this relies in GetSpecifiedAssetsPrice, GetStakingAssetInfo, GetAvsSupportedAssets +// the first and third need to be set up and done before this genesis. +// the second is already set up before this genesis. + +// StakerRecord is a helper structure for the genesis state. Each record +// contains a staker address and a list of asset IDs with their operator + +// amount combination. +message StakerRecord { + // staker_id denotes the address + l0id of the staker. + string staker_id = 1 [(gogoproto.customname) = "StakerID"]; + // staker_details is a list of asset ID + operator + amount combination. + repeated StakerDetails staker_details = 2 [(gogoproto.nullable) = false]; +} + +// StakerDetails is a helper structure for the genesis state. Each record +// contains an asset ID and a list of operator + amount combination. +message StakerDetails { + // asset_id is the unique identifier of the asset. + string asset_id = 1 [(gogoproto.customname) = "AssetID"]; + // details is a list of operator + amount combination. + repeated AssetDetails details = 2 [(gogoproto.nullable) = false]; +} + +// AssetDetails is a helper structure for the genesis state. Each record +// contains an operator and an amount. +message AssetDetails { + // operator_address is the address of the operator as the bech32 + // version of sdk.AccAddress. + string operator_address = 1; + // amount is the amount of the asset staked by the staker for this + // asset and operator. + string amount = 2 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; +} \ No newline at end of file diff --git a/x/operator/keeper/consensus_keys.go b/x/operator/keeper/consensus_keys.go index c6fd55434..2dd7420a4 100644 --- a/x/operator/keeper/consensus_keys.go +++ b/x/operator/keeper/consensus_keys.go @@ -24,12 +24,13 @@ func (k *Keeper) Logger(ctx sdk.Context) log.Logger { // and chain id. By doing this, an operator is consenting to be an operator on the given chain. // If a key already exists, it will be overwritten and the change in voting power will flow // through to the validator set. +// TODO: Rationalize with k.OptIn func (k *Keeper) SetOperatorConsKeyForChainID( ctx sdk.Context, opAccAddr sdk.AccAddress, chainID string, // should be tm-ed25519 - consKey tmprotocrypto.PublicKey, + consKey *tmprotocrypto.PublicKey, ) error { // check if we are an operator if !k.IsOperator(ctx, opAccAddr) { @@ -44,6 +45,7 @@ func (k *Keeper) SetOperatorConsKeyForChainID( return assetstypes.ErrUnknownAppChainID } // if opting out, do not allow key replacement + // TODO: merge with the functionality in state_update.go if k.IsOperatorOptingOutFromChainID(ctx, opAccAddr, chainID) { return types.ErrAlreadyOptingOut } @@ -51,16 +53,14 @@ func (k *Keeper) SetOperatorConsKeyForChainID( bz, err := consKey.Marshal() if err != nil { return errorsmod.Wrap( - err, - "SetOperatorConsKeyForChainID: error occurred when marshal public key", + err, "SetOperatorConsKeyForChainID: cannot marshal public key", ) } // convert to address for reverse lookup consAddr, err := types.TMCryptoPublicKeyToConsAddr(consKey) if err != nil { return errorsmod.Wrap( - err, - "SetOperatorConsKeyForChainID: error occurred when convert public key to consensus address", + err, "SetOperatorConsKeyForChainID: cannot convert pub key to consensus address", ) } // check if the key is already in use by another operator @@ -94,24 +94,32 @@ func (k *Keeper) SetOperatorConsKeyForChainID( panic(err) } if !alreadyRecorded { - if err := k.setOperatorPrevConsKeyForChainID(ctx, opAccAddr, chainID, prevKey); err != nil { + if err := k.setOperatorPrevConsKeyForChainID( + ctx, opAccAddr, chainID, prevKey, + ); err != nil { // this should not happen panic(err) } } } - // k.setOperatorConsKeyForChainID(ctx, opAccAddr, chainID, bz) - // return nil - // } + k.setOperatorConsKeyForChainID(ctx, opAccAddr, consAddr, chainID, bz) + if found { + if !alreadyRecorded { + k.Hooks().AfterOperatorKeyReplacement(ctx, opAccAddr, prevKey, consKey, chainID) + } + } else { + k.Hooks().AfterOperatorOptIn(ctx, opAccAddr, chainID, consKey) + } + return nil +} - // // setOperatorConsKeyForChainID is the internal private version. It performs - // // no error checking of the input. - // func (k Keeper) setOperatorConsKeyForChainID( - // ctx sdk.Context, - // opAccAddr sdk.AccAddress, - // chainID string, - // bz []byte, - // ) { +// setOperatorConsKeyForChainID is the internal private version. It performs +// no error checking of the input. The caller must do the error checking +// and then call this function. +func (k Keeper) setOperatorConsKeyForChainID( + ctx sdk.Context, opAccAddr sdk.AccAddress, consAddr sdk.ConsAddress, + chainID string, bz []byte, +) { store := ctx.KVStore(k.storeKey) // forward lookup // given operator address and chain id, find the consensus key, @@ -132,14 +140,6 @@ func (k *Keeper) SetOperatorConsKeyForChainID( // this pruning will be triggered by the app chain module and will not be // recorded here. store.Set(types.KeyForChainIDAndConsKeyToOperator(chainID, consAddr), opAccAddr.Bytes()) - if found { - if !alreadyRecorded { - k.Hooks().AfterOperatorKeyReplacement(ctx, opAccAddr, prevKey, consKey, chainID) - } - } else { - k.Hooks().AfterOperatorOptIn(ctx, opAccAddr, chainID, consKey) - } - return nil } // setOperatorPrevConsKeyForChainID sets the previous (consensus) public key for the given @@ -150,7 +150,7 @@ func (k *Keeper) setOperatorPrevConsKeyForChainID( ctx sdk.Context, opAccAddr sdk.AccAddress, chainID string, - prevKey tmprotocrypto.PublicKey, + prevKey *tmprotocrypto.PublicKey, ) error { bz, err := prevKey.Marshal() if err != nil { @@ -169,7 +169,7 @@ func (k *Keeper) setOperatorPrevConsKeyForChainID( // to 0 in the validator update. func (k *Keeper) GetOperatorPrevConsKeyForChainID( ctx sdk.Context, opAccAddr sdk.AccAddress, chainID string, -) (found bool, key tmprotocrypto.PublicKey, err error) { +) (found bool, key *tmprotocrypto.PublicKey, err error) { // check if we are an operator if !k.IsOperator(ctx, opAccAddr) { err = delegationtypes.ErrOperatorNotExist @@ -184,19 +184,19 @@ func (k *Keeper) GetOperatorPrevConsKeyForChainID( return } -// getOperatorPrevConsKeyForChainID is the internal version of -// GetOperatorPrevConsKeyForChainID. +// getOperatorPrevConsKeyForChainID is the internal version of GetOperatorPrevConsKeyForChainID. // It performs no error checking of the input. func (k *Keeper) getOperatorPrevConsKeyForChainID( ctx sdk.Context, opAccAddr sdk.AccAddress, chainID string, -) (found bool, key tmprotocrypto.PublicKey, err error) { +) (found bool, key *tmprotocrypto.PublicKey, err error) { store := ctx.KVStore(k.storeKey) res := store.Get(types.KeyForOperatorAndChainIDToPrevConsKey(opAccAddr, chainID)) if res == nil { return } + key = &tmprotocrypto.PublicKey{} if err = key.Unmarshal(res); err != nil { return } @@ -210,7 +210,7 @@ func (k *Keeper) GetOperatorConsKeyForChainID( ctx sdk.Context, opAccAddr sdk.AccAddress, chainID string, -) (found bool, key tmprotocrypto.PublicKey, err error) { +) (found bool, key *tmprotocrypto.PublicKey, err error) { // check if we are an operator if !k.IsOperator(ctx, opAccAddr) { err = delegationtypes.ErrOperatorNotExist @@ -232,25 +232,27 @@ func (k *Keeper) getOperatorConsKeyForChainID( ctx sdk.Context, opAccAddr sdk.AccAddress, chainID string, -) (found bool, key tmprotocrypto.PublicKey, err error) { +) (found bool, key *tmprotocrypto.PublicKey, err error) { store := ctx.KVStore(k.storeKey) res := store.Get(types.KeyForOperatorAndChainIDToConsKey(opAccAddr, chainID)) if res == nil { return } + key = &tmprotocrypto.PublicKey{} if err = key.Unmarshal(res); err != nil { return } return true, key, nil } -// GetChainIDsAndKeysForOperator gets the chain ids for which the given operator address has set a +// GetChainIDsAndKeysForOperator gets the chain ids for which the given operator address has set +// a // (consensus) public key. TODO: would it be better to make this a key per operator? // This is intentionally an array of strings because I don't see the utility for the vote power // or the public key here. If we need it, we can add it later. func (k *Keeper) GetChainIDsAndKeysForOperator( ctx sdk.Context, opAccAddr sdk.AccAddress, -) (chainIDs []string, consKeys []tmprotocrypto.PublicKey) { +) (chainIDs []string, consKeys []*tmprotocrypto.PublicKey) { // check if we are an operator if !k.IsOperator(ctx, opAccAddr) { return @@ -268,7 +270,7 @@ func (k *Keeper) GetChainIDsAndKeysForOperator( for ; iterator.Valid(); iterator.Next() { // the key returned is the full key, with the prefix. drop the prefix and the length. chainID := string(iterator.Key()[len(prefix)+8:]) - var key tmprotocrypto.PublicKey + var key *tmprotocrypto.PublicKey if err := key.Unmarshal(iterator.Value()); err != nil { // grave error because we are the ones who stored this information in the first // place @@ -285,7 +287,7 @@ func (k *Keeper) GetChainIDsAndKeysForOperator( // jailed or frozen operators. func (k *Keeper) GetOperatorsForChainID( ctx sdk.Context, chainID string, -) (addrs []sdk.AccAddress, pubKeys []tmprotocrypto.PublicKey) { +) (addrs []sdk.AccAddress, pubKeys []*tmprotocrypto.PublicKey) { if !k.assetsKeeper.AppChainInfoIsExist(ctx, chainID) { return nil, nil } @@ -306,7 +308,7 @@ func (k *Keeper) GetOperatorsForChainID( // so just drop it and convert to sdk.AccAddress addr := iterator.Key()[len(prefix):] res := iterator.Value() - var ret tmprotocrypto.PublicKey + var ret *tmprotocrypto.PublicKey if err := ret.Unmarshal(res); err != nil { // grave error panic(err) @@ -426,6 +428,6 @@ func (k *Keeper) Jail(sdk.Context, sdk.ConsAddress, string) {} func (k *Keeper) GetActiveOperatorsForChainID( sdk.Context, string, -) ([]sdk.AccAddress, []tmprotocrypto.PublicKey) { +) ([]sdk.AccAddress, []*tmprotocrypto.PublicKey) { return nil, nil } diff --git a/x/operator/keeper/genesis.go b/x/operator/keeper/genesis.go new file mode 100644 index 000000000..c30f0e424 --- /dev/null +++ b/x/operator/keeper/genesis.go @@ -0,0 +1,47 @@ +package keeper + +import ( + "github.com/ExocoreNetwork/exocore/x/operator/types" + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) []abci.ValidatorUpdate { + for _, op := range state.Operators { + op := op + if err := k.SetOperatorInfo(ctx, op.EarningsAddr, &op); err != nil { + panic(err) + } + } + for _, record := range state.OperatorRecords { + addr := record.OperatorAddress + // #nosec G703 // already validated + operatorAddr, _ := sdk.AccAddressFromBech32(addr) + bootstrapping := false + for _, detail := range record.Chains { + // opt into the specified chain (TODO: avs address format) + if err := k.OptIn(ctx, operatorAddr, detail.ChainID); err != nil { + panic(err) + } + // #nosec G703 // already validated + key, _ := types.HexStringToPubKey(detail.ConsensusKey) + // then set pub key + if err := k.SetOperatorConsKeyForChainID( + ctx, operatorAddr, detail.ChainID, key, + ); err != nil { + panic(err) + } + bootstrapping = bootstrapping || ctx.ChainID() == detail.ChainID + } + if !bootstrapping { + // TODO: consider removing this check + panic("registered an operator but they aren't bootstrapping the current chain") + } + } + return []abci.ValidatorUpdate{} +} + +func (Keeper) ExportGenesis(sdk.Context) *types.GenesisState { + // TODO + return types.DefaultGenesis() +} diff --git a/x/operator/keeper/grpc_query.go b/x/operator/keeper/grpc_query.go index d86edeb0a..3865c6d36 100644 --- a/x/operator/keeper/grpc_query.go +++ b/x/operator/keeper/grpc_query.go @@ -35,6 +35,6 @@ func (k *Keeper) QueryOperatorConsKeyForChainID( return nil, errors.New("no key assigned") } return &operatortypes.QueryOperatorConsKeyResponse{ - PublicKey: key, + PublicKey: *key, }, nil } diff --git a/x/operator/keeper/msg_server.go b/x/operator/keeper/msg_server.go index fcc018a67..e7ae588b6 100644 --- a/x/operator/keeper/msg_server.go +++ b/x/operator/keeper/msg_server.go @@ -2,9 +2,6 @@ package keeper import ( context "context" - "encoding/base64" - - tmprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" "github.com/ExocoreNetwork/exocore/x/operator/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -34,7 +31,7 @@ func (k *Keeper) OptInToCosmosChain( if err != nil { return nil, err } - key, err := stringToPubKey(req.PublicKey) + key, err := types.StringToPubKey(req.PublicKey) if err != nil { return nil, err } @@ -65,16 +62,3 @@ func (k *Keeper) InitOptOutFromCosmosChain( } return &types.InitOptOutFromCosmosChainResponse{}, nil } - -func stringToPubKey(pubKey string) (key tmprotocrypto.PublicKey, err error) { - pubKeyBytes, err := base64.StdEncoding.DecodeString(pubKey) - if err != nil { - return - } - subscriberTMConsKey := tmprotocrypto.PublicKey{ - Sum: &tmprotocrypto.PublicKey_Ed25519{ - Ed25519: pubKeyBytes, - }, - } - return subscriberTMConsKey, nil -} diff --git a/x/operator/module.go b/x/operator/module.go index cf870c535..29999fbee 100644 --- a/x/operator/module.go +++ b/x/operator/module.go @@ -2,6 +2,8 @@ package operator import ( "context" + "encoding/json" + "fmt" "github.com/ExocoreNetwork/exocore/x/operator/client/cli" "github.com/ExocoreNetwork/exocore/x/operator/keeper" @@ -38,8 +40,13 @@ func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry operatortypes.RegisterInterfaces(registry) } -func (b AppModuleBasic) RegisterGRPCGatewayRoutes(c client.Context, serveMux *runtime.ServeMux) { - if err := operatortypes.RegisterQueryHandlerClient(context.Background(), serveMux, operatortypes.NewQueryClient(c)); err != nil { +func (b AppModuleBasic) RegisterGRPCGatewayRoutes( + c client.Context, + serveMux *runtime.ServeMux, +) { + if err := operatortypes.RegisterQueryHandlerClient( + context.Background(), serveMux, operatortypes.NewQueryClient(c), + ); err != nil { panic(err) } } @@ -92,3 +99,44 @@ func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.V am.keeper.EndBlock(ctx, req) return []abci.ValidatorUpdate{} } + +// DefaultGenesis returns a default GenesisState for the module, marshaled to json.RawMessage. +// The default GenesisState need to be defined by the module developer and is primarily used for +// testing +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(operatortypes.DefaultGenesis()) +} + +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form +func (AppModuleBasic) ValidateGenesis( + cdc codec.JSONCodec, + _ client.TxEncodingConfig, + bz json.RawMessage, +) error { + var genState operatortypes.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf( + "failed to unmarshal %s genesis state: %w", + operatortypes.ModuleName, + err, + ) + } + return genState.Validate() +} + +// InitGenesis performs the module's genesis initialization. +func (am AppModule) InitGenesis( + ctx sdk.Context, + cdc codec.JSONCodec, + gs json.RawMessage, +) []abci.ValidatorUpdate { + var genState operatortypes.GenesisState + cdc.MustUnmarshalJSON(gs, &genState) + return am.keeper.InitGenesis(ctx, genState) +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(genState) +} diff --git a/x/operator/types/consensus_keys.go b/x/operator/types/consensus_keys.go new file mode 100644 index 000000000..534409837 --- /dev/null +++ b/x/operator/types/consensus_keys.go @@ -0,0 +1,81 @@ +package types + +import ( + "encoding/base64" + "encoding/json" + + errorsmod "cosmossdk.io/errors" + + tmprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/ethereum/go-ethereum/common/hexutil" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// HexStringToPubKey converts a 32-byte public key (from the Ethereum side of things), +// which is represented as a 66-byte string (with the 0x prefix) within Golang, +// to a tendermint public key. It is, in effect, a reverse of the command +// `exocored keys consensus-pubkey-to-bytes` +func HexStringToPubKey(key string) (*tmprotocrypto.PublicKey, error) { + if len(key) != 66 { + return nil, errorsmod.Wrapf( + ErrInvalidPubKey, + "expected 66 length string, got %d", + len(key), + ) + } + keyBytes, err := hexutil.Decode(key) + if err != nil { + return nil, errorsmod.Wrapf( + ErrInvalidPubKey, + "failed to decode hex string: %s", + err, + ) + } + return &tmprotocrypto.PublicKey{ + Sum: &tmprotocrypto.PublicKey_Ed25519{ + Ed25519: keyBytes, + }, + }, nil +} + +// StringToPubKey converts a base64-encoded public key to a tendermint public key. +// Typically, this function is fed an input from ParseConsumerKeyFromJSON. +func StringToPubKey(pubKey string) (key *tmprotocrypto.PublicKey, err error) { + pubKeyBytes, err := base64.StdEncoding.DecodeString(pubKey) + if err != nil { + return + } + subscriberTMConsKey := &tmprotocrypto.PublicKey{ + Sum: &tmprotocrypto.PublicKey_Ed25519{ + Ed25519: pubKeyBytes, + }, + } + return subscriberTMConsKey, nil +} + +// ParseConsumerKeyFromJSON parses the consumer key from a JSON string. +// This function replaces deserializing a protobuf any. +func ParseConsumerKeyFromJSON(jsonStr string) (pkType, key string, err error) { + type PubKey struct { + Type string `json:"type"` + Key string `json:"value"` + } + var pubKey PubKey + err = json.Unmarshal([]byte(jsonStr), &pubKey) + if err != nil { + return "", "", err + } + return pubKey.Type, pubKey.Key, nil +} + +// TMCryptoPublicKeyToConsAddr converts a TM public key to an SDK public key +// and returns the associated consensus address +func TMCryptoPublicKeyToConsAddr(k *tmprotocrypto.PublicKey) (sdk.ConsAddress, error) { + sdkK, err := cryptocodec.FromTmProtoPublicKey(*k) + if err != nil { + return nil, err + } + return sdk.GetConsAddress(sdkK), nil +} diff --git a/x/operator/types/errors.go b/x/operator/types/errors.go index d7e4ed12a..1a7c4f60c 100644 --- a/x/operator/types/errors.go +++ b/x/operator/types/errors.go @@ -3,33 +3,72 @@ package types import errorsmod "cosmossdk.io/errors" var ( - ErrNoKeyInTheStore = errorsmod.Register(ModuleName, 0, "there is not the key for in the store") + ErrNoKeyInTheStore = errorsmod.Register( + ModuleName, 0, + "there is not the key for in the store", + ) - ErrCliCmdInputArg = errorsmod.Register(ModuleName, 1, "there is an error in the input client command args") + ErrCliCmdInputArg = errorsmod.Register( + ModuleName, 1, + "there is an error in the input client command args", + ) - ErrSlashInfo = errorsmod.Register(ModuleName, 2, "there is an error in the field of slash info") + ErrSlashInfo = errorsmod.Register( + ModuleName, 2, + "there is an error in the field of slash info", + ) - ErrSlashInfoExist = errorsmod.Register(ModuleName, 3, "the slash info exists") + ErrSlashInfoExist = errorsmod.Register( + ModuleName, 3, + "the slash info exists", + ) - ErrParameterInvalid = errorsmod.Register(ModuleName, 4, "the input parameter is invalid") + ErrParameterInvalid = errorsmod.Register( + ModuleName, 4, + "the input parameter is invalid", + ) - ErrAlreadyOptedIn = errorsmod.Register(ModuleName, 5, "the operator has already opted in the avs") + ErrAlreadyOptedIn = errorsmod.Register( + ModuleName, 5, + "the operator has already opted in the avs", + ) - ErrNotOptedIn = errorsmod.Register(ModuleName, 6, "the operator hasn't opted in the avs") + ErrNotOptedIn = errorsmod.Register( + ModuleName, 6, + "the operator hasn't opted in the avs", + ) - ErrTheValueIsNegative = errorsmod.Register(ModuleName, 7, "the value is negative") + ErrTheValueIsNegative = errorsmod.Register( + ModuleName, 7, + "the value is negative", + ) - ErrSlashContractNotMatch = errorsmod.Register(ModuleName, 8, "the slash contract isn't the slash contract address saved in the opted-in info") + ErrSlashContractNotMatch = errorsmod.Register( + ModuleName, 8, + "the slash contract isn't the slash contract address saved in the opted-in info", + ) - ErrSlashOccurredHeight = errorsmod.Register(ModuleName, 9, "the occurred height of slash event is error") + ErrSlashOccurredHeight = errorsmod.Register( + ModuleName, 9, + "the occurred height of slash event is error", + ) - // add for dogfood ErrConsKeyAlreadyInUse = errorsmod.Register( - ModuleName, - 10, + ModuleName, 10, "consensus key already in use by another operator", ) + ErrAlreadyOptingOut = errorsmod.Register( ModuleName, 11, "operator already opting out", ) + + ErrInvalidPubKey = errorsmod.Register( + ModuleName, 12, + "invalid public key", + ) + + ErrInvalidGenesisData = errorsmod.Register( + ModuleName, 13, + "the genesis data supplied is invalid", + ) ) diff --git a/x/operator/types/expected_keepers.go b/x/operator/types/expected_keepers.go index 5377075f8..3ef6791bf 100644 --- a/x/operator/types/expected_keepers.go +++ b/x/operator/types/expected_keepers.go @@ -14,20 +14,46 @@ var ( ) type AssetsKeeper interface { - GetStakingAssetInfo(ctx sdk.Context, assetID string) (info *assetstype.StakingAssetInfo, err error) - IteratorOperatorAssetState(ctx sdk.Context, f func(operatorAddr, assetID string, state *assetstype.OperatorAssetInfo) error) error + GetStakingAssetInfo( + ctx sdk.Context, assetID string, + ) (info *assetstype.StakingAssetInfo, err error) + IteratorOperatorAssetState( + ctx sdk.Context, + f func(operatorAddr, assetID string, state *assetstype.OperatorAssetInfo) error, + ) error AppChainInfoIsExist(ctx sdk.Context, chainID string) bool - GetOperatorAssetInfos(ctx sdk.Context, operatorAddr sdk.Address, _ map[string]interface{}) (assetsInfo map[string]*assetstype.OperatorAssetInfo, err error) - UpdateStakerAssetState(ctx sdk.Context, stakerID string, assetID string, changeAmount assetstype.StakerSingleAssetChangeInfo) (err error) - UpdateOperatorAssetState(ctx sdk.Context, operatorAddr sdk.Address, assetID string, changeAmount assetstype.OperatorSingleAssetChangeInfo) (err error) + GetOperatorAssetInfos( + ctx sdk.Context, operatorAddr sdk.Address, _ map[string]interface{}, + ) (assetsInfo map[string]*assetstype.OperatorAssetInfo, err error) + UpdateStakerAssetState( + ctx sdk.Context, stakerID string, assetID string, + changeAmount assetstype.StakerSingleAssetChangeInfo, + ) (err error) + UpdateOperatorAssetState( + ctx sdk.Context, operatorAddr sdk.Address, assetID string, + changeAmount assetstype.OperatorSingleAssetChangeInfo, + ) (err error) } type DelegationKeeper interface { - DelegationStateByOperatorAssets(ctx sdk.Context, operatorAddr string, assetsFilter map[string]interface{}) (map[string]map[string]delegationtype.DelegationAmounts, error) - IterateDelegationState(ctx sdk.Context, f func(restakerID, assetID, operatorAddr string, state *delegationtype.DelegationAmounts) error) error - UpdateDelegationState(ctx sdk.Context, stakerID string, assetID string, delegationAmounts map[string]*delegationtype.DelegationAmounts) (err error) - - UpdateStakerDelegationTotalAmount(ctx sdk.Context, stakerID string, assetID string, opAmount sdkmath.Int) error + DelegationStateByOperatorAssets( + ctx sdk.Context, operatorAddr string, assetsFilter map[string]interface{}, + ) (map[string]map[string]delegationtype.DelegationAmounts, error) + IterateDelegationState( + ctx sdk.Context, + f func( + restakerID, assetID, operatorAddr string, + state *delegationtype.DelegationAmounts, + ) error, + ) error + UpdateDelegationState( + ctx sdk.Context, stakerID string, assetID string, + delegationAmounts map[string]*delegationtype.DelegationAmounts, + ) (err error) + UpdateStakerDelegationTotalAmount( + ctx sdk.Context, stakerID string, assetID string, + opAmount sdkmath.Int, + ) error } type PriceChange struct { @@ -39,12 +65,14 @@ type PriceChange struct { // OracleKeeper is the oracle interface expected by operator module // These functions need to be implemented by the oracle module type OracleKeeper interface { - // GetSpecifiedAssetsPrice is a function to retrieve the asset price according to the assetID - // the first return value is price, and the second return value is decimal of the price. + // GetSpecifiedAssetsPrice is a function to retrieve the asset price according to the + // assetID. the first return value is price, and the second return value is decimal of the + // price. GetSpecifiedAssetsPrice(ctx sdk.Context, assetID string) (sdkmath.Int, uint8, error) - // GetPriceChangeAssets the operator module expect a function that can retrieve all information - // about assets price change. Then it can update the USD share state according to the change - // information. This function need to return a map, the key is assetID and the value is PriceChange + // GetPriceChangeAssets the operator module expect a function that can retrieve all + // information about assets price change. Then it can update the USD share state according + // to the change information. This function need to return a map, the key is assetID and the + // value is PriceChange GetPriceChangeAssets(ctx sdk.Context) (map[string]*PriceChange, error) } @@ -81,9 +109,10 @@ func (MockAvs) GetAvsSlashContract(_ sdk.Context, _ string) (string, error) { } type AvsKeeper interface { - // GetAvsSupportedAssets The ctx can be historical or current, depending on the state you wish to retrieve. - // If the caller want to retrieve a historical assets info supported by Avs, it needs to generate a historical - // context through calling `ContextForHistoricalState` implemented in x/assets/types/general.go + // GetAvsSupportedAssets The ctx can be historical or current, depending on the state you + // wish to retrieve. If the caller want to retrieve a historical assets info supported by + // Avs, it needs to generate a historical context through calling + // `ContextForHistoricalState` implemented in x/assets/types/general.go GetAvsSupportedAssets(ctx sdk.Context, avsAddr string) (map[string]interface{}, error) GetAvsSlashContract(ctx sdk.Context, avsAddr string) (string, error) } @@ -97,25 +126,17 @@ type SlashKeeper interface { type OperatorConsentHooks interface { // This hook is called when an operator opts in to a chain. AfterOperatorOptIn( - ctx sdk.Context, - addr sdk.AccAddress, - chainID string, - pubKey tmprotocrypto.PublicKey, + ctx sdk.Context, addr sdk.AccAddress, chainID string, + pubKey *tmprotocrypto.PublicKey, ) // This hook is called when an operator's consensus key is replaced for // a chain. AfterOperatorKeyReplacement( - ctx sdk.Context, - addr sdk.AccAddress, - oldKey tmprotocrypto.PublicKey, - newKey tmprotocrypto.PublicKey, - chainID string, + ctx sdk.Context, addr sdk.AccAddress, oldKey *tmprotocrypto.PublicKey, + newKey *tmprotocrypto.PublicKey, chainID string, ) // This hook is called when an operator opts out of a chain. AfterOperatorOptOutInitiated( - ctx sdk.Context, - addr sdk.AccAddress, - chainID string, - key tmprotocrypto.PublicKey, + ctx sdk.Context, addr sdk.AccAddress, chainID string, key *tmprotocrypto.PublicKey, ) } diff --git a/x/operator/types/genesis.go b/x/operator/types/genesis.go new file mode 100644 index 000000000..8ee9a34ef --- /dev/null +++ b/x/operator/types/genesis.go @@ -0,0 +1,126 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" +) + +func NewGenesisState( + operators []OperatorInfo, + records []OperatorConsKeyRecord, +) *GenesisState { + return &GenesisState{ + Operators: operators, + OperatorRecords: records, + } +} + +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return NewGenesisState([]OperatorInfo{}, []OperatorConsKeyRecord{}) +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + operators := make(map[string]struct{}, len(gs.Operators)) + for _, op := range gs.Operators { + address := op.EarningsAddr + if _, found := operators[address]; found { + return errorsmod.Wrapf( + ErrInvalidGenesisData, + "duplicate operator address %s", address, + ) + } + _, err := sdk.AccAddressFromBech32(address) + if err != nil { + return errorsmod.Wrapf( + ErrInvalidGenesisData, + "invalid operator address %s: %s", address, err, + ) + } + operators[address] = struct{}{} + if op.ClientChainEarningsAddr != nil { + lzIDs := make(map[uint64]struct{}, len(op.ClientChainEarningsAddr.EarningInfoList)) + for _, info := range op.ClientChainEarningsAddr.EarningInfoList { + lzID := info.LzClientChainID + if _, found := lzIDs[lzID]; found { + return errorsmod.Wrapf( + ErrInvalidGenesisData, + "duplicate lz client chain id %d", lzID, + ) + } + lzIDs[lzID] = struct{}{} + // TODO: consider removing this check for non-EVM chains + if !common.IsHexAddress(info.ClientChainEarningAddr) { + return errorsmod.Wrapf( + ErrInvalidGenesisData, + "invalid client chain earning address %s", info.ClientChainEarningAddr, + ) + } + } + } + } + operatorRecords := make(map[string]struct{}, len(gs.OperatorRecords)) + keysByChainID := make(map[string]map[string]struct{}) + for _, record := range gs.OperatorRecords { + addr := record.OperatorAddress + if _, err := sdk.AccAddressFromBech32(addr); err != nil { + return errorsmod.Wrapf( + ErrInvalidGenesisData, + "invalid operator address %s: %s", record.OperatorAddress, err, + ) + } + if _, found := operatorRecords[addr]; found { + return errorsmod.Wrapf( + ErrInvalidGenesisData, + "duplicate operator record for operator %s", addr, + ) + } + operatorRecords[addr] = struct{}{} + if _, opFound := operators[addr]; !opFound { + return errorsmod.Wrapf( + ErrInvalidGenesisData, + "operator record for un-registered operator %s", addr, + ) + } + for _, chain := range record.Chains { + consensusKeyString := chain.ConsensusKey + if _, found := keysByChainID[chain.ChainID]; !found { + keysByChainID[chain.ChainID] = make(map[string]struct{}) + } + if _, err := HexStringToPubKey(consensusKeyString); err != nil { + return errorsmod.Wrapf( + ErrInvalidGenesisData, + "invalid consensus key for operator %s: %s", addr, err, + ) + } + // within a chain id, there should not be duplicate consensus keys + if _, found := keysByChainID[chain.ChainID][consensusKeyString]; found { + return errorsmod.Wrapf( + ErrInvalidGenesisData, + "duplicate consensus key for operator %s on chain %s", addr, chain.ChainID, + ) + } + keysByChainID[chain.ChainID][consensusKeyString] = struct{}{} + } + } + // i do not know that chain id here, so i cannot check whether + // each registered operator has a key defined for the chain id. but i can: + // ensure that there is a consensus key record (of any chain id) for each operator. + // for bootstrapping, this is bound to happen since the operator registration is contingent + // on the operator having a consensus key for the chain id. however, in the future, + // it may be possible for an operator to opt into an AVS which does not have a consensus + // key requirement, so this check could be removed if we set up the Export case. but i + // think it is better to keep it for now. + if len(operators) != len(operatorRecords) { + // operatorRecords is always a subset of operators, since we do not add any operator + // to operatorRecords unless it is in operators. + return errorsmod.Wrapf( + ErrInvalidGenesisData, + "operator addresses in operators and operator records do not match", + ) + } + return nil +} diff --git a/x/operator/types/genesis.pb.go b/x/operator/types/genesis.pb.go new file mode 100644 index 000000000..aa066e84c --- /dev/null +++ b/x/operator/types/genesis.pb.go @@ -0,0 +1,1579 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: exocore/operator/v1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the operator module's genesis state. +type GenesisState struct { + // there are no params for this module. + // operators is a list of the registered operators. + Operators []OperatorInfo `protobuf:"bytes,1,rep,name=operators,proto3" json:"operators"` + // operator_records refers to a list of operator records. each record + // contains an operator address and a list of chain id + + // cons key combination. + OperatorRecords []OperatorConsKeyRecord `protobuf:"bytes,2,rep,name=operator_records,json=operatorRecords,proto3" json:"operator_records"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_bb7040bc6ae6ddee, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetOperators() []OperatorInfo { + if m != nil { + return m.Operators + } + return nil +} + +func (m *GenesisState) GetOperatorRecords() []OperatorConsKeyRecord { + if m != nil { + return m.OperatorRecords + } + return nil +} + +// OperatorConsKeyRecord is a helper structure for the genesis state. Each record +// contains an operator address and a list of chain id + cons key combination. +type OperatorConsKeyRecord struct { + // operator_address is the address of the operator as the bech32 + // encoded version of sdk.AccAddress. + OperatorAddress string `protobuf:"bytes,1,opt,name=operator_address,json=operatorAddress,proto3" json:"operator_address,omitempty"` + // chains is a list of chain id + consensus key combination. + Chains []ChainDetails `protobuf:"bytes,2,rep,name=chains,proto3" json:"chains"` +} + +func (m *OperatorConsKeyRecord) Reset() { *m = OperatorConsKeyRecord{} } +func (m *OperatorConsKeyRecord) String() string { return proto.CompactTextString(m) } +func (*OperatorConsKeyRecord) ProtoMessage() {} +func (*OperatorConsKeyRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_bb7040bc6ae6ddee, []int{1} +} +func (m *OperatorConsKeyRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *OperatorConsKeyRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_OperatorConsKeyRecord.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *OperatorConsKeyRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_OperatorConsKeyRecord.Merge(m, src) +} +func (m *OperatorConsKeyRecord) XXX_Size() int { + return m.Size() +} +func (m *OperatorConsKeyRecord) XXX_DiscardUnknown() { + xxx_messageInfo_OperatorConsKeyRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_OperatorConsKeyRecord proto.InternalMessageInfo + +func (m *OperatorConsKeyRecord) GetOperatorAddress() string { + if m != nil { + return m.OperatorAddress + } + return "" +} + +func (m *OperatorConsKeyRecord) GetChains() []ChainDetails { + if m != nil { + return m.Chains + } + return nil +} + +// ChainDetails is a helper structure for the genesis state. Each record +// contains a chain id and a consensus key. +type ChainDetails struct { + // chain_id is the unique identifier of the chain. + ChainID string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + // consensus_key is the consensus key of the operator on the chain. + // the length of this key should be exactly 32 bytes, and must be enforced + // outside of protobuf. + ConsensusKey string `protobuf:"bytes,2,opt,name=consensus_key,json=consensusKey,proto3" json:"consensus_key,omitempty"` +} + +func (m *ChainDetails) Reset() { *m = ChainDetails{} } +func (m *ChainDetails) String() string { return proto.CompactTextString(m) } +func (*ChainDetails) ProtoMessage() {} +func (*ChainDetails) Descriptor() ([]byte, []int) { + return fileDescriptor_bb7040bc6ae6ddee, []int{2} +} +func (m *ChainDetails) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ChainDetails) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ChainDetails.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ChainDetails) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChainDetails.Merge(m, src) +} +func (m *ChainDetails) XXX_Size() int { + return m.Size() +} +func (m *ChainDetails) XXX_DiscardUnknown() { + xxx_messageInfo_ChainDetails.DiscardUnknown(m) +} + +var xxx_messageInfo_ChainDetails proto.InternalMessageInfo + +func (m *ChainDetails) GetChainID() string { + if m != nil { + return m.ChainID + } + return "" +} + +func (m *ChainDetails) GetConsensusKey() string { + if m != nil { + return m.ConsensusKey + } + return "" +} + +// StakerRecord is a helper structure for the genesis state. Each record +// contains a staker address and a list of asset IDs with their operator + +// amount combination. +type StakerRecord struct { + // staker_id denotes the address + l0id of the staker. + StakerID string `protobuf:"bytes,1,opt,name=staker_id,json=stakerId,proto3" json:"staker_id,omitempty"` + // staker_details is a list of asset ID + operator + amount combination. + StakerDetails []StakerDetails `protobuf:"bytes,2,rep,name=staker_details,json=stakerDetails,proto3" json:"staker_details"` +} + +func (m *StakerRecord) Reset() { *m = StakerRecord{} } +func (m *StakerRecord) String() string { return proto.CompactTextString(m) } +func (*StakerRecord) ProtoMessage() {} +func (*StakerRecord) Descriptor() ([]byte, []int) { + return fileDescriptor_bb7040bc6ae6ddee, []int{3} +} +func (m *StakerRecord) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StakerRecord) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StakerRecord.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *StakerRecord) XXX_Merge(src proto.Message) { + xxx_messageInfo_StakerRecord.Merge(m, src) +} +func (m *StakerRecord) XXX_Size() int { + return m.Size() +} +func (m *StakerRecord) XXX_DiscardUnknown() { + xxx_messageInfo_StakerRecord.DiscardUnknown(m) +} + +var xxx_messageInfo_StakerRecord proto.InternalMessageInfo + +func (m *StakerRecord) GetStakerID() string { + if m != nil { + return m.StakerID + } + return "" +} + +func (m *StakerRecord) GetStakerDetails() []StakerDetails { + if m != nil { + return m.StakerDetails + } + return nil +} + +// StakerDetails is a helper structure for the genesis state. Each record +// contains an asset ID and a list of operator + amount combination. +type StakerDetails struct { + // asset_id is the unique identifier of the asset. + AssetID string `protobuf:"bytes,1,opt,name=asset_id,json=assetId,proto3" json:"asset_id,omitempty"` + // details is a list of operator + amount combination. + Details []AssetDetails `protobuf:"bytes,2,rep,name=details,proto3" json:"details"` +} + +func (m *StakerDetails) Reset() { *m = StakerDetails{} } +func (m *StakerDetails) String() string { return proto.CompactTextString(m) } +func (*StakerDetails) ProtoMessage() {} +func (*StakerDetails) Descriptor() ([]byte, []int) { + return fileDescriptor_bb7040bc6ae6ddee, []int{4} +} +func (m *StakerDetails) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StakerDetails) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StakerDetails.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *StakerDetails) XXX_Merge(src proto.Message) { + xxx_messageInfo_StakerDetails.Merge(m, src) +} +func (m *StakerDetails) XXX_Size() int { + return m.Size() +} +func (m *StakerDetails) XXX_DiscardUnknown() { + xxx_messageInfo_StakerDetails.DiscardUnknown(m) +} + +var xxx_messageInfo_StakerDetails proto.InternalMessageInfo + +func (m *StakerDetails) GetAssetID() string { + if m != nil { + return m.AssetID + } + return "" +} + +func (m *StakerDetails) GetDetails() []AssetDetails { + if m != nil { + return m.Details + } + return nil +} + +// AssetDetails is a helper structure for the genesis state. Each record +// contains an operator and an amount. +type AssetDetails struct { + // operator_address is the address of the operator as the bech32 + // version of sdk.AccAddress. + OperatorAddress string `protobuf:"bytes,1,opt,name=operator_address,json=operatorAddress,proto3" json:"operator_address,omitempty"` + // amount is the amount of the asset staked by the staker for this + // asset and operator. + Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` +} + +func (m *AssetDetails) Reset() { *m = AssetDetails{} } +func (m *AssetDetails) String() string { return proto.CompactTextString(m) } +func (*AssetDetails) ProtoMessage() {} +func (*AssetDetails) Descriptor() ([]byte, []int) { + return fileDescriptor_bb7040bc6ae6ddee, []int{5} +} +func (m *AssetDetails) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AssetDetails) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AssetDetails.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AssetDetails) XXX_Merge(src proto.Message) { + xxx_messageInfo_AssetDetails.Merge(m, src) +} +func (m *AssetDetails) XXX_Size() int { + return m.Size() +} +func (m *AssetDetails) XXX_DiscardUnknown() { + xxx_messageInfo_AssetDetails.DiscardUnknown(m) +} + +var xxx_messageInfo_AssetDetails proto.InternalMessageInfo + +func (m *AssetDetails) GetOperatorAddress() string { + if m != nil { + return m.OperatorAddress + } + return "" +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "exocore.operator.v1.GenesisState") + proto.RegisterType((*OperatorConsKeyRecord)(nil), "exocore.operator.v1.OperatorConsKeyRecord") + proto.RegisterType((*ChainDetails)(nil), "exocore.operator.v1.ChainDetails") + proto.RegisterType((*StakerRecord)(nil), "exocore.operator.v1.StakerRecord") + proto.RegisterType((*StakerDetails)(nil), "exocore.operator.v1.StakerDetails") + proto.RegisterType((*AssetDetails)(nil), "exocore.operator.v1.AssetDetails") +} + +func init() { proto.RegisterFile("exocore/operator/v1/genesis.proto", fileDescriptor_bb7040bc6ae6ddee) } + +var fileDescriptor_bb7040bc6ae6ddee = []byte{ + // 513 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0xcf, 0x6b, 0x13, 0x41, + 0x14, 0xce, 0x56, 0xc9, 0x8f, 0xe9, 0x46, 0x65, 0x54, 0x88, 0x45, 0x36, 0x76, 0x85, 0x52, 0x85, + 0xee, 0xd2, 0x7a, 0x15, 0x24, 0x69, 0x8a, 0x2c, 0x15, 0x0b, 0x5b, 0x4f, 0xf6, 0x10, 0xb6, 0x3b, + 0x63, 0xba, 0xc4, 0xcc, 0x84, 0x79, 0x93, 0x9a, 0x78, 0xf5, 0xe6, 0x45, 0xff, 0x16, 0xf1, 0x8f, + 0xe8, 0xb1, 0x78, 0x12, 0x0f, 0x41, 0x36, 0xff, 0x88, 0xec, 0xcc, 0x6c, 0xb2, 0x91, 0x45, 0xf0, + 0xb4, 0x33, 0xef, 0xfb, 0xde, 0xf7, 0xbe, 0x6f, 0x96, 0x87, 0xb6, 0xe9, 0x94, 0xc7, 0x5c, 0x50, + 0x9f, 0x8f, 0xa9, 0x88, 0x24, 0x17, 0xfe, 0xe5, 0xbe, 0x3f, 0xa0, 0x8c, 0x42, 0x02, 0xde, 0x58, + 0x70, 0xc9, 0xf1, 0x5d, 0x43, 0xf1, 0x72, 0x8a, 0x77, 0xb9, 0xbf, 0xf5, 0x20, 0xe6, 0x30, 0xe2, + 0xd0, 0x57, 0x14, 0x5f, 0x5f, 0x34, 0x7f, 0xeb, 0xde, 0x80, 0x0f, 0xb8, 0xae, 0x67, 0x27, 0x53, + 0x7d, 0x58, 0x36, 0x48, 0x4e, 0x35, 0xea, 0x7e, 0xb3, 0x90, 0xfd, 0x52, 0x4f, 0x3d, 0x95, 0x91, + 0xa4, 0xf8, 0x08, 0x35, 0x72, 0x22, 0xb4, 0xac, 0x47, 0x37, 0x76, 0x37, 0x0f, 0xb6, 0xbd, 0x12, + 0x23, 0xde, 0x89, 0x39, 0x07, 0xec, 0x1d, 0xef, 0xde, 0xbc, 0x9a, 0xb7, 0x2b, 0xe1, 0xaa, 0x13, + 0x9f, 0xa1, 0x3b, 0xf9, 0xa5, 0x2f, 0x68, 0xcc, 0x05, 0x81, 0xd6, 0x86, 0x52, 0x7b, 0xfa, 0x4f, + 0xb5, 0x43, 0xce, 0xe0, 0x98, 0xce, 0x42, 0xd5, 0x62, 0x64, 0x6f, 0xe7, 0x44, 0x5d, 0x05, 0xf7, + 0x93, 0x85, 0xee, 0x97, 0x36, 0xe0, 0x27, 0x85, 0xb1, 0x11, 0x21, 0x82, 0x42, 0x16, 0xc2, 0xda, + 0x6d, 0xac, 0x44, 0x3a, 0xba, 0x8c, 0x5f, 0xa0, 0x6a, 0x7c, 0x11, 0x25, 0x2c, 0xf7, 0x55, 0x9e, + 0xf2, 0x30, 0xa3, 0xf4, 0xa8, 0x8c, 0x92, 0xf7, 0x60, 0xec, 0x98, 0x36, 0xf7, 0x0c, 0xd9, 0x45, + 0x14, 0xef, 0xa0, 0xba, 0x42, 0xfa, 0x09, 0xd1, 0x33, 0xbb, 0x9b, 0xe9, 0xbc, 0x5d, 0x53, 0x9c, + 0xa0, 0x17, 0xd6, 0x14, 0x18, 0x10, 0xfc, 0x18, 0x35, 0x63, 0xce, 0x80, 0x32, 0x98, 0x40, 0x7f, + 0x48, 0x67, 0xad, 0x0d, 0x65, 0xd0, 0x5e, 0x16, 0x8f, 0xe9, 0xcc, 0xfd, 0x6c, 0x21, 0xfb, 0x54, + 0x46, 0x43, 0x2a, 0x96, 0xc9, 0x1a, 0xa0, 0xee, 0x2b, 0x79, 0x3b, 0x9d, 0xb7, 0xeb, 0x9a, 0x14, + 0xf4, 0xc2, 0xba, 0x86, 0x03, 0x82, 0x4f, 0xd0, 0x2d, 0x43, 0x25, 0xda, 0x9a, 0x49, 0xe8, 0x96, + 0x26, 0xd4, 0x02, 0xeb, 0x11, 0x9b, 0x50, 0x2c, 0xba, 0x1f, 0x51, 0x73, 0x8d, 0x95, 0x45, 0x8d, + 0x00, 0xa8, 0xfc, 0x2b, 0x6a, 0x27, 0xab, 0x65, 0x51, 0x15, 0x18, 0x10, 0xdc, 0x41, 0xb5, 0x75, + 0x0b, 0xe5, 0x8f, 0xac, 0xfa, 0xd6, 0x1d, 0xe4, 0x7d, 0xee, 0x17, 0x0b, 0xd9, 0x45, 0xfc, 0x7f, + 0x7e, 0xf1, 0x1b, 0x54, 0x8d, 0x46, 0x7c, 0xc2, 0xa4, 0x7e, 0xe2, 0xee, 0xf3, 0x4c, 0xfa, 0xd7, + 0xbc, 0xbd, 0x33, 0x48, 0xe4, 0xc5, 0xe4, 0xdc, 0x8b, 0xf9, 0xc8, 0x6c, 0x90, 0xf9, 0xec, 0x01, + 0x19, 0xfa, 0x72, 0x36, 0xa6, 0xe0, 0x05, 0x4c, 0xfe, 0xf8, 0xbe, 0x87, 0xcc, 0x82, 0x05, 0x4c, + 0x86, 0x46, 0xab, 0xfb, 0xea, 0x2a, 0x75, 0xac, 0xeb, 0xd4, 0xb1, 0x7e, 0xa7, 0x8e, 0xf5, 0x75, + 0xe1, 0x54, 0xae, 0x17, 0x4e, 0xe5, 0xe7, 0xc2, 0xa9, 0xbc, 0x3d, 0x28, 0xe8, 0x1e, 0xe9, 0x9c, + 0xaf, 0xa9, 0xfc, 0xc0, 0xc5, 0xd0, 0xcf, 0x97, 0x70, 0xba, 0x5a, 0x43, 0x35, 0xe7, 0xbc, 0xaa, + 0xf6, 0xf0, 0xd9, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa9, 0xbb, 0x29, 0x6e, 0x10, 0x04, 0x00, + 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.OperatorRecords) > 0 { + for iNdEx := len(m.OperatorRecords) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.OperatorRecords[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Operators) > 0 { + for iNdEx := len(m.Operators) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Operators[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *OperatorConsKeyRecord) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *OperatorConsKeyRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *OperatorConsKeyRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Chains) > 0 { + for iNdEx := len(m.Chains) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Chains[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.OperatorAddress) > 0 { + i -= len(m.OperatorAddress) + copy(dAtA[i:], m.OperatorAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.OperatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ChainDetails) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ChainDetails) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ChainDetails) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ConsensusKey) > 0 { + i -= len(m.ConsensusKey) + copy(dAtA[i:], m.ConsensusKey) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ConsensusKey))) + i-- + dAtA[i] = 0x12 + } + if len(m.ChainID) > 0 { + i -= len(m.ChainID) + copy(dAtA[i:], m.ChainID) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ChainID))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *StakerRecord) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *StakerRecord) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StakerRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.StakerDetails) > 0 { + for iNdEx := len(m.StakerDetails) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.StakerDetails[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.StakerID) > 0 { + i -= len(m.StakerID) + copy(dAtA[i:], m.StakerID) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.StakerID))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *StakerDetails) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *StakerDetails) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StakerDetails) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Details) > 0 { + for iNdEx := len(m.Details) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Details[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.AssetID) > 0 { + i -= len(m.AssetID) + copy(dAtA[i:], m.AssetID) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.AssetID))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *AssetDetails) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AssetDetails) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AssetDetails) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.OperatorAddress) > 0 { + i -= len(m.OperatorAddress) + copy(dAtA[i:], m.OperatorAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.OperatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Operators) > 0 { + for _, e := range m.Operators { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.OperatorRecords) > 0 { + for _, e := range m.OperatorRecords { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *OperatorConsKeyRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.OperatorAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.Chains) > 0 { + for _, e := range m.Chains { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *ChainDetails) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChainID) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.ConsensusKey) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *StakerRecord) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.StakerID) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.StakerDetails) > 0 { + for _, e := range m.StakerDetails { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *StakerDetails) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.AssetID) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if len(m.Details) > 0 { + for _, e := range m.Details { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *AssetDetails) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.OperatorAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Operators", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Operators = append(m.Operators, OperatorInfo{}) + if err := m.Operators[len(m.Operators)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OperatorRecords", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OperatorRecords = append(m.OperatorRecords, OperatorConsKeyRecord{}) + if err := m.OperatorRecords[len(m.OperatorRecords)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OperatorConsKeyRecord) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: OperatorConsKeyRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OperatorConsKeyRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OperatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OperatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Chains", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Chains = append(m.Chains, ChainDetails{}) + if err := m.Chains[len(m.Chains)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ChainDetails) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ChainDetails: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ChainDetails: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChainID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsensusKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConsensusKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *StakerRecord) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: StakerRecord: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StakerRecord: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StakerID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StakerID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StakerDetails", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.StakerDetails = append(m.StakerDetails, StakerDetails{}) + if err := m.StakerDetails[len(m.StakerDetails)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *StakerDetails) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: StakerDetails: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StakerDetails: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AssetID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AssetID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Details", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Details = append(m.Details, AssetDetails{}) + if err := m.Details[len(m.Details)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AssetDetails) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AssetDetails: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AssetDetails: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OperatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OperatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/operator/types/genesis_test.go b/x/operator/types/genesis_test.go new file mode 100644 index 000000000..7ce643e0d --- /dev/null +++ b/x/operator/types/genesis_test.go @@ -0,0 +1,277 @@ +package types_test + +import ( + "testing" + + utiltx "github.com/ExocoreNetwork/exocore/testutil/tx" + "github.com/ExocoreNetwork/exocore/utils" + "github.com/ExocoreNetwork/exocore/x/operator/types" + "github.com/cometbft/cometbft/crypto/ed25519" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/stretchr/testify/suite" +) + +type GenesisTestSuite struct { + suite.Suite +} + +func (suite *GenesisTestSuite) SetupTest() { +} + +func TestGenesisTestSuite(t *testing.T) { + suite.Run(t, new(GenesisTestSuite)) +} + +func (suite *GenesisTestSuite) TestValidateGenesis() { + key := hexutil.Encode(ed25519.GenPrivKey().PubKey().Bytes()) + accAddress1 := sdk.AccAddress(utiltx.GenerateAddress().Bytes()) + accAddress2 := sdk.AccAddress(utiltx.GenerateAddress().Bytes()) + newGen := &types.GenesisState{} + + testCases := []struct { + name string + genState *types.GenesisState + expPass bool + malleate func(*types.GenesisState) + }{ + { + name: "valid genesis constructor", + genState: newGen, + expPass: true, + }, + { + name: "default", + genState: types.DefaultGenesis(), + expPass: true, + }, + { + name: "invalid genesis state due to non bech32 operator address", + genState: &types.GenesisState{ + Operators: []types.OperatorInfo{ + { + EarningsAddr: "invalid", + }, + }, + }, + expPass: false, + }, + { + name: "invalid genesis state due to duplicate operator address", + genState: &types.GenesisState{ + Operators: []types.OperatorInfo{ + { + EarningsAddr: accAddress1.String(), + }, + { + EarningsAddr: accAddress1.String(), + }, + }, + }, + expPass: false, + }, + { + name: "invalid genesis state due to duplicate lz chain id", + genState: &types.GenesisState{ + Operators: []types.OperatorInfo{ + { + EarningsAddr: accAddress1.String(), + ClientChainEarningsAddr: &types.ClientChainEarningAddrList{ + EarningInfoList: []*types.ClientChainEarningAddrInfo{ + { + LzClientChainID: 1, + ClientChainEarningAddr: utiltx.GenerateAddress().String(), + }, + { + LzClientChainID: 1, + ClientChainEarningAddr: utiltx.GenerateAddress().String(), + }, + }, + }, + }, + }, + }, + expPass: false, + }, + { + name: "invalid genesis state due to invalid client chain earnings address", + genState: &types.GenesisState{ + Operators: []types.OperatorInfo{ + { + EarningsAddr: accAddress1.String(), + ClientChainEarningsAddr: &types.ClientChainEarningAddrList{ + EarningInfoList: []*types.ClientChainEarningAddrInfo{ + { + LzClientChainID: 1, + ClientChainEarningAddr: "invalid", + }, + }, + }, + }, + }, + }, + expPass: false, + }, + { + name: "invalid genesis state due to invalid cons key operator address", + genState: &types.GenesisState{ + Operators: []types.OperatorInfo{ + { + EarningsAddr: accAddress1.String(), + }, + }, + OperatorRecords: []types.OperatorConsKeyRecord{ + { + OperatorAddress: "invalid", + }, + }, + }, + expPass: false, + }, + { + name: "invalid genesis state due to unregistered operator in cons key", + genState: &types.GenesisState{ + Operators: []types.OperatorInfo{ + { + EarningsAddr: accAddress1.String(), + }, + }, + OperatorRecords: []types.OperatorConsKeyRecord{ + { + OperatorAddress: accAddress2.String(), + }, + }, + }, + expPass: false, + }, + { + name: "invalid genesis state due to duplicate operator in cons key", + genState: &types.GenesisState{ + Operators: []types.OperatorInfo{ + { + EarningsAddr: accAddress1.String(), + }, + { + EarningsAddr: accAddress2.String(), + }, + }, + OperatorRecords: []types.OperatorConsKeyRecord{ + { + OperatorAddress: accAddress1.String(), + Chains: []types.ChainDetails{ + { + ChainID: utils.TestnetChainID, + ConsensusKey: key, + }, + }, + }, + { + OperatorAddress: accAddress1.String(), + Chains: []types.ChainDetails{ + { + ChainID: utils.TestnetChainID, + ConsensusKey: hexutil.Encode(ed25519.GenPrivKey().PubKey().Bytes()), + }, + }, + }, + }, + }, + expPass: false, + }, + { + name: "invalid genesis state due to invalid cons key", + genState: &types.GenesisState{ + Operators: []types.OperatorInfo{ + { + EarningsAddr: accAddress1.String(), + }, + }, + OperatorRecords: []types.OperatorConsKeyRecord{ + { + OperatorAddress: accAddress1.String(), + Chains: []types.ChainDetails{ + { + ChainID: utils.TestnetChainID, + ConsensusKey: key + "fake", + }, + }, + }, + }, + }, + expPass: false, + }, + { + name: "invalid genesis state due to duplicate cons key for the same chain id", + genState: &types.GenesisState{ + Operators: []types.OperatorInfo{ + { + EarningsAddr: accAddress1.String(), + }, + { + EarningsAddr: accAddress2.String(), + }, + }, + OperatorRecords: []types.OperatorConsKeyRecord{ + { + OperatorAddress: accAddress1.String(), + Chains: []types.ChainDetails{ + { + ChainID: utils.TestnetChainID, + ConsensusKey: key, + }, + }, + }, + { + OperatorAddress: accAddress2.String(), + Chains: []types.ChainDetails{ + { + ChainID: utils.TestnetChainID, + ConsensusKey: key, + }, + }, + }, + }, + }, + expPass: false, + }, + { + name: "invalid genesis state due to registered operator without key", + genState: &types.GenesisState{ + Operators: []types.OperatorInfo{ + { + EarningsAddr: accAddress1.String(), + }, + { + EarningsAddr: accAddress2.String(), + }, + }, + OperatorRecords: []types.OperatorConsKeyRecord{ + { + OperatorAddress: accAddress1.String(), + Chains: []types.ChainDetails{ + { + ChainID: utils.TestnetChainID, + ConsensusKey: key, + }, + }, + }, + }, + }, + expPass: false, + }, + } + + for _, tc := range testCases { + tc := tc + if tc.malleate != nil { + tc.malleate(tc.genState) + } + err := tc.genState.Validate() + if tc.expPass { + suite.Require().NoError(err, tc.name) + } else { + suite.Require().Error(err, tc.name) + } + // fmt.Println(tc.name, err) + } +} diff --git a/x/operator/types/hooks.go b/x/operator/types/hooks.go index 0c3441ab6..f27d2b411 100644 --- a/x/operator/types/hooks.go +++ b/x/operator/types/hooks.go @@ -17,7 +17,7 @@ func (hooks MultiOperatorConsentHooks) AfterOperatorOptIn( ctx sdk.Context, addr sdk.AccAddress, chainID string, - pubKey tmprotocrypto.PublicKey, + pubKey *tmprotocrypto.PublicKey, ) { for _, hook := range hooks { hook.AfterOperatorOptIn(ctx, addr, chainID, pubKey) @@ -27,8 +27,8 @@ func (hooks MultiOperatorConsentHooks) AfterOperatorOptIn( func (hooks MultiOperatorConsentHooks) AfterOperatorKeyReplacement( ctx sdk.Context, addr sdk.AccAddress, - oldKey tmprotocrypto.PublicKey, - newAddr tmprotocrypto.PublicKey, + oldKey *tmprotocrypto.PublicKey, + newAddr *tmprotocrypto.PublicKey, chainID string, ) { for _, hook := range hooks { @@ -37,7 +37,7 @@ func (hooks MultiOperatorConsentHooks) AfterOperatorKeyReplacement( } func (hooks MultiOperatorConsentHooks) AfterOperatorOptOutInitiated( - ctx sdk.Context, addr sdk.AccAddress, chainID string, key tmprotocrypto.PublicKey, + ctx sdk.Context, addr sdk.AccAddress, chainID string, key *tmprotocrypto.PublicKey, ) { for _, hook := range hooks { hook.AfterOperatorOptOutInitiated(ctx, addr, chainID, key) diff --git a/x/operator/types/app_chain_utils.go b/x/operator/types/utils.go similarity index 57% rename from x/operator/types/app_chain_utils.go rename to x/operator/types/utils.go index d776a976b..6ec7351a9 100644 --- a/x/operator/types/app_chain_utils.go +++ b/x/operator/types/utils.go @@ -1,13 +1,9 @@ package types import ( - tmprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) -// add for dogfood - // AppendMany appends a variable number of byte slices together func AppendMany(byteses ...[]byte) (out []byte) { for _, bytes := range byteses { @@ -29,13 +25,3 @@ func ChainIDWithLenKey(chainID string) []byte { []byte(chainID), ) } - -// TMCryptoPublicKeyToConsAddr converts a TM public key to an SDK public key -// and returns the associated consensus address -func TMCryptoPublicKeyToConsAddr(k tmprotocrypto.PublicKey) (sdk.ConsAddress, error) { - sdkK, err := cryptocodec.FromTmProtoPublicKey(k) - if err != nil { - return nil, err - } - return sdk.GetConsAddress(sdkK), nil -}