From e4552d9ae8653fbc77e30fad2b32df3b16d7c179 Mon Sep 17 00:00:00 2001 From: trestin Date: Tue, 5 Nov 2024 14:58:58 +0800 Subject: [PATCH] impl genesis exporting for avs,distribution --- precompiles/avs/tx.go | 2 +- proto/exocore/avs/v1/genesis.proto | 61 + .../exocore/feedistribution/v1/genesis.proto | 58 + x/avs/keeper/avs.go | 18 + x/avs/keeper/genesis.go | 89 +- x/avs/keeper/keeper.go | 166 ++ x/avs/keeper/msg_server.go | 2 +- .../keeper/multi_operator_submit_task_test.go | 4 +- x/avs/keeper/submit_task_test.go | 4 +- x/avs/keeper/task.go | 300 ++-- x/avs/module.go | 5 +- x/avs/types/genesis.go | 152 +- x/avs/types/genesis.pb.go | 1145 +++++++++++++- x/avs/types/genesis_test.go | 79 +- x/feedistribution/keeper/genesis.go | 55 + x/feedistribution/keeper/keeper.go | 111 ++ x/feedistribution/types/genesis.pb.go | 1371 ++++++++++++++++- x/operator/keeper/operator.go | 6 +- 18 files changed, 3350 insertions(+), 278 deletions(-) create mode 100644 proto/exocore/avs/v1/genesis.proto diff --git a/precompiles/avs/tx.go b/precompiles/avs/tx.go index 4929fed78..94eb5ead4 100644 --- a/precompiles/avs/tx.go +++ b/precompiles/avs/tx.go @@ -399,7 +399,7 @@ func (p Precompile) OperatorSubmitTask( BlsSignature: resultParams.BlsSignature, Phase: phaseEnum, } - err := p.avsKeeper.SetTaskResultInfo(ctx, resultParams.CallerAddress.String(), result) + err := p.avsKeeper.SubmitTaskResult(ctx, resultParams.CallerAddress.String(), result) if err != nil { return nil, err } diff --git a/proto/exocore/avs/v1/genesis.proto b/proto/exocore/avs/v1/genesis.proto new file mode 100644 index 000000000..3ef374944 --- /dev/null +++ b/proto/exocore/avs/v1/genesis.proto @@ -0,0 +1,61 @@ +syntax = "proto3"; +package exocore.avs.v1; + +import "exocore/avs/v1/tx.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/ExocoreNetwork/exocore/x/avs/types"; + +// GenesisState defines the avs module's state. It needs to encompass +// all of the state that is required to start the chain from the genesis +// or in the event of a restart. +message GenesisState { + // avs_infos is the list of registered avs infos, + // that are supported at chain genesis (or restart). + repeated AVSInfo avs_infos = 1 [(gogoproto.nullable) = false]; + // task_infos is the tasks issued by avs owner, indexed by + // task address and task id + // that are supported at chain genesis (or restart). + repeated TaskInfo task_infos = 2 [(gogoproto.nullable) = false]; + // bls_pub_keys is the list of operator pubKey info, indexed by operator address + // The struct is the `BlsPubKeyInfo` + // which contains blsPubKey, operator address. + repeated BlsPubKeyInfo bls_pub_keys = 3 [(gogoproto.nullable) = false]; + + // task_result_infos is the task result informations, indexed + // by the operator address ,task address and the task id. The struct is the `TaskResultInfo` + repeated TaskResultInfo task_result_infos = 4 [(gogoproto.nullable) = false]; + // challenge_infos is the task challenge informations, indexed + // by the operator address ,task address and the task id. The struct is the `ChallengeInfo` + repeated ChallengeInfo challenge_infos = 5 [(gogoproto.nullable) = false]; + // task_nums is the task id, indexed + // by the task address. The struct is the `TaskID` + repeated TaskID task_nums = 6 [(gogoproto.nullable) = false]; + // chain_id_infos is the dogfood chain id informations, indexed + // by the avs address. The struct is the `ChainIDInfo` + repeated ChainIDInfo chain_id_infos = 7 [(gogoproto.nullable) = false]; + +} + +// TaskID is helper structure to store the task id information for the genesis state. +message TaskID { + // task_addr is the address of task as a hex string + string task_addr = 1; + // id of task. + uint64 task_id = 2; +} +// ChallengeInfo is helper structure to store the task challenge information for the genesis state. +message ChallengeInfo { + // key is used for storing the ChallengeInfos, + // which is a combination of the operator address ,task address and task id. + string key = 1; + // challenge_addr is the address of the challenger + string challenge_addr = 2; +} +// ChainIDInfo is helper structure to store the dogfood ChainID information for the genesis state. +message ChainIDInfo { + // avs_address is the address of avs as a hex string. + string avs_address = 1; + // chain_id is a dogfood parameter + string chain_id = 2; +} \ No newline at end of file diff --git a/proto/exocore/feedistribution/v1/genesis.proto b/proto/exocore/feedistribution/v1/genesis.proto index 5cb1ab6ee..27238528b 100644 --- a/proto/exocore/feedistribution/v1/genesis.proto +++ b/proto/exocore/feedistribution/v1/genesis.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package exocore.feedistribution.v1; import "amino/amino.proto"; +import "exocore/feedistribution/v1/distribution.proto"; import "exocore/feedistribution/v1/params.proto"; import "gogoproto/gogo.proto"; @@ -14,4 +15,61 @@ message GenesisState { (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; + // fee_pool is the global fee pool for distribution. + // It holds decimal coins. Once whole those coins can be burned or distributed to the community pool. + FeePool fee_pool = 2 [(gogoproto.nullable) = false]; + // validator_accumulated_commissions represents accumulated commission + // for a validator kept as a running counter, can be withdrawn at any time. + repeated ValidatorAccumulatedCommissions validator_accumulated_commissions = 3 [(gogoproto.nullable) = false]; + // validator_current_rewards_list represents current rewards and current + // period for a validator kept as a running counter and incremented + // each block as long as the validator's tokens remain constant. + repeated ValidatorCurrentRewardsList validator_current_rewards_list = 4 [(gogoproto.nullable) = false]; + + // validator_outstanding_rewards_list represents outstanding (un-withdrawn) rewards + // for a validator inexpensive to track, allows simple sanity checks. + repeated ValidatorOutstandingRewardsList validator_outstanding_rewards_list = 5 [(gogoproto.nullable) = false]; + // staker_outstanding_rewards_list represents outstanding (un-withdrawn) rewards + // for a staker inexpensive to track, allows simple sanity checks. + repeated StakerOutstandingRewardsList staker_outstanding_rewards_list = 6 [(gogoproto.nullable) = false]; + +} + +// ValidatorAccumulatedCommissions is helper structure to store +// the validator accumulated commissions for the genesis state. +message ValidatorAccumulatedCommissions { + // val_addr is the address of validator + string val_addr = 1; + + // ValidatorAccumulatedCommission represents accumulated commission + // for a validator kept as a running counter, can be withdrawn at any time. + ValidatorAccumulatedCommission commission = 2; } +// ValidatorCurrentRewardsList is helper structure to store the validator current rewards for the genesis state. +message ValidatorCurrentRewardsList { + // val_addr is the address of validator + string val_addr = 1; + + // ValidatorCurrentRewards represents current rewards and current + // period for a validator kept as a running counter and incremented + // each block as long as the validator's tokens remain constant. + ValidatorCurrentRewards current_rewards = 2; +} +// TaskID is helper structure to store the validator outstanding rewards for the genesis state. +message ValidatorOutstandingRewardsList { + // val_addr is the address of validator + string val_addr = 1; + + // ValidatorOutstandingRewards represents outstanding (un-withdrawn) rewards + // for a validator inexpensive to track, allows simple sanity checks. + ValidatorOutstandingRewards outstanding_rewards = 2; +} +// StakerOutstandingRewardsList is helper structure to store the staker outstanding rewards for the genesis state. +message StakerOutstandingRewardsList { + // val_addr is the address of validator + string val_addr = 1; + + // StakerOutstandingRewards represents outstanding (un-withdrawn) rewards + // for a staker inexpensive to track, allows simple sanity checks. + StakerOutstandingRewards staker_outstanding_rewards = 2; +} \ No newline at end of file diff --git a/x/avs/keeper/avs.go b/x/avs/keeper/avs.go index 8f91b53a1..93f86038c 100644 --- a/x/avs/keeper/avs.go +++ b/x/avs/keeper/avs.go @@ -194,3 +194,21 @@ func (k Keeper) GetChainIDByAVSAddr(ctx sdk.Context, avsAddr string) (string, bo } return string(bz), true } + +func (k *Keeper) GetAllChainIDInfos(ctx sdk.Context) ([]types.ChainIDInfo, error) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixAVSAddressToChainID) + iterator := sdk.KVStorePrefixIterator(store, nil) + defer iterator.Close() + + ret := make([]types.ChainIDInfo, 0) + for ; iterator.Valid(); iterator.Next() { + avsAddr := strings.ToLower(common.BytesToAddress(iterator.Key()).Hex()) + chainID := string(iterator.Value()) + + ret = append(ret, types.ChainIDInfo{ + AvsAddress: avsAddr, + ChainId: chainID, + }) + } + return ret, nil +} diff --git a/x/avs/keeper/genesis.go b/x/avs/keeper/genesis.go index b5c41c397..b6fa92ecf 100644 --- a/x/avs/keeper/genesis.go +++ b/x/avs/keeper/genesis.go @@ -1,25 +1,94 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" "github.com/ExocoreNetwork/exocore/x/avs/types" - abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" ) // InitGenesis initializes the module's state from a provided genesis state. // Since this action typically occurs on chain starts, this function is allowed to panic. -func (k Keeper) InitGenesis( - ctx sdk.Context, - _ types.GenesisState, -) []abci.ValidatorUpdate { +func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { // Store a lookup from codeHash to code. Since these are static parameters, // such a lookup is stored at genesis and never updated. k.evmKeeper.SetCode(ctx, types.ChainIDCodeHash.Bytes(), types.ChainIDCode) - return []abci.ValidatorUpdate{} + // Set all the avs infos + for _, avs := range state.AvsInfos { + err := k.SetAVSInfo(ctx, &avs) //nolint:gosec + if err != nil { + panic(errorsmod.Wrap(err, "failed to set all avs info")) + } + } + // Set all the task infos + for _, elem := range state.TaskInfos { + err := k.SetTaskInfo(ctx, &elem) //nolint:gosec + if err != nil { + panic(errorsmod.Wrap(err, "failed to set all task info")) + } + } + // Set all the bls infos + for _, elem := range state.BlsPubKeys { + err := k.SetOperatorPubKey(ctx, &elem) //nolint:gosec + if err != nil { + panic(errorsmod.Wrap(err, "failed to set all bls info")) + } + } + // Set all the taskNum infos + for _, elem := range state.TaskNums { + k.SetTaskID(ctx, common.HexToAddress(elem.TaskAddr), elem.TaskId) + } + // Set all the task result infos + for _, elem := range state.TaskResultInfos { + k.SetTaskResultInfo(ctx, &elem) //nolint:gosec + } + // Set all the task challenge infos + err := k.SetAllTaskChallengedInfo(ctx, state.ChallengeInfos) + if err != nil { + panic(errorsmod.Wrap(err, "failed to set all challenge info")) + } + // Set all the chainID infos + for _, elem := range state.ChainIdInfos { + k.SetAVSAddrToChainID(ctx, common.HexToAddress(elem.AvsAddress), elem.ChainId) + } } -// ExportGenesis returns the module's exported genesis -func (Keeper) ExportGenesis(sdk.Context) *types.GenesisState { - // TODO - return types.DefaultGenesis() +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + res := types.GenesisState{} + var err error + res.AvsInfos, err = k.GetAllAVSInfos(ctx) + if err != nil { + panic(errorsmod.Wrap(err, "failed to get all avs infos")) + } + res.TaskInfos, err = k.GetAllTaskInfos(ctx) + if err != nil { + panic(errorsmod.Wrap(err, "failed to get all task infos").Error()) + } + + res.BlsPubKeys, err = k.GetAllBlsPubKeys(ctx) + if err != nil { + panic(errorsmod.Wrap(err, "failed to get all bls key info").Error()) + } + + res.TaskNums, err = k.GetAllTaskNums(ctx) + if err != nil { + panic(errorsmod.Wrap(err, "failed to get all TaskNums").Error()) + } + + res.TaskResultInfos, err = k.GetAllTaskResultInfos(ctx) + if err != nil { + panic(errorsmod.Wrap(err, "failed to get all TaskResultInfos").Error()) + } + + res.ChallengeInfos, err = k.GetAllChallengeInfos(ctx) + if err != nil { + panic(errorsmod.Wrap(err, "failed to get all ChallengeInfos").Error()) + } + + res.ChainIdInfos, err = k.GetAllChainIDInfos(ctx) + if err != nil { + panic(errorsmod.Wrap(err, "failed to get all ChainIdInfos").Error()) + } + + return &res } diff --git a/x/avs/keeper/keeper.go b/x/avs/keeper/keeper.go index 80286befa..4c7d2e88c 100644 --- a/x/avs/keeper/keeper.go +++ b/x/avs/keeper/keeper.go @@ -1,12 +1,15 @@ package keeper import ( + "bytes" "encoding/hex" "fmt" "slices" "strconv" "strings" + "github.com/ethereum/go-ethereum/crypto" + "github.com/prysmaticlabs/prysm/v4/crypto/bls" "github.com/prysmaticlabs/prysm/v4/crypto/bls/blst" @@ -440,3 +443,166 @@ func (k Keeper) RaiseAndResolveChallenge(ctx sdk.Context, params *types.Challeng return k.SetTaskChallengedInfo(ctx, params.TaskID, params.OperatorAddress.String(), params.CallerAddress.String(), params.TaskContractAddress) } + +func (k *Keeper) GetAllAVSInfos(ctx sdk.Context) ([]types.AVSInfo, error) { + var ret []types.AVSInfo + k.IterateAVSInfo(ctx, func(_ int64, avsInfo types.AVSInfo) bool { + ret = append(ret, avsInfo) + return false + }) + return ret, nil +} + +func (k Keeper) SubmitTaskResult(ctx sdk.Context, addr string, info *types.TaskResultInfo) error { + // the operator's `addr` must match the from address. + if addr != info.OperatorAddress { + return errorsmod.Wrap( + types.ErrInvalidAddr, + "SetTaskResultInfo:from address is not equal to the operator address", + ) + } + opAccAddr, _ := sdk.AccAddressFromBech32(info.OperatorAddress) + // check operator + if !k.operatorKeeper.IsOperator(ctx, opAccAddr) { + return errorsmod.Wrap( + delegationtypes.ErrOperatorNotExist, + fmt.Sprintf("SetTaskResultInfo:invalid operator address:%s", opAccAddr), + ) + } + // check operator bls pubkey + keyInfo, err := k.GetOperatorPubKey(ctx, info.OperatorAddress) + if err != nil || keyInfo.PubKey == nil { + return errorsmod.Wrap( + types.ErrPubKeyIsNotExists, + fmt.Sprintf("SetTaskResultInfo:get operator address:%s", opAccAddr), + ) + } + pubKey, err := blst.PublicKeyFromBytes(keyInfo.PubKey) + if err != nil || pubKey == nil { + return errorsmod.Wrap( + types.ErrParsePubKey, + fmt.Sprintf("SetTaskResultInfo:get operator address:%s", opAccAddr), + ) + } + // check task contract + task, err := k.GetTaskInfo(ctx, strconv.FormatUint(info.TaskId, 10), info.TaskContractAddress) + if err != nil || task.TaskContractAddress == "" { + return errorsmod.Wrap( + types.ErrTaskIsNotExists, + fmt.Sprintf("SetTaskResultInfo: task info not found: %s (Task ID: %d)", + info.TaskContractAddress, info.TaskId), + ) + } + + // check prescribed period + // If submitted in the first phase, in order to avoid plagiarism by other operators, + // TaskResponse and TaskResponseHash must be null values + // At the same time, it must be submitted within the response deadline in the first phase + avsInfo := k.GetAVSInfoByTaskAddress(ctx, info.TaskContractAddress) + if avsInfo.AvsAddress == "" { + return errorsmod.Wrap(types.ErrUnregisterNonExistent, fmt.Sprintf("the taskaddr is :%s", info.TaskContractAddress)) + } + epoch, found := k.epochsKeeper.GetEpochInfo(ctx, avsInfo.EpochIdentifier) + if !found { + return errorsmod.Wrap(types.ErrEpochNotFound, fmt.Sprintf("epoch info not found %s", + avsInfo.EpochIdentifier)) + } + + switch info.Phase { + case types.PhasePrepare: + if k.IsExistTaskResultInfo(ctx, info.OperatorAddress, info.TaskContractAddress, info.TaskId) { + return errorsmod.Wrap( + types.ErrResAlreadyExists, + fmt.Sprintf("SetTaskResultInfo: task result is already exists, "+ + "OperatorAddress: %s (TaskContractAddress: %s),(Task ID: %d)", + info.OperatorAddress, info.TaskContractAddress, info.TaskId), + ) + } + // check parameters + if info.BlsSignature == nil { + return errorsmod.Wrap( + types.ErrParamNotEmptyError, + fmt.Sprintf("SetTaskResultInfo: invalid param BlsSignature is not be null (BlsSignature: %s)", info.BlsSignature), + ) + } + if info.TaskResponseHash != "" || info.TaskResponse != nil { + return errorsmod.Wrap( + types.ErrParamNotEmptyError, + fmt.Sprintf("SetTaskResultInfo: invalid param TaskResponseHash: %s (TaskResponse: %d)", + info.TaskResponseHash, info.TaskResponse), + ) + } + // check epoch,The first phase submission must be within the response window period + // #nosec G115 + if epoch.CurrentEpoch > int64(task.StartingEpoch)+int64(task.TaskResponsePeriod) { + return errorsmod.Wrap( + types.ErrSubmitTooLateError, + fmt.Sprintf("SetTaskResultInfo:submit too late, CurrentEpoch:%d", epoch.CurrentEpoch), + ) + } + k.SetTaskResultInfo(ctx, info) + return nil + + case types.PhaseDoCommit: + // check task response + if info.TaskResponse == nil { + return errorsmod.Wrap( + types.ErrNotNull, + fmt.Sprintf("SetTaskResultInfo: invalid param (TaskResponse: %d)", + info.TaskResponse), + ) + } + // check parameters + res, err := k.GetTaskResultInfo(ctx, info.OperatorAddress, info.TaskContractAddress, info.TaskId) + if err != nil || !bytes.Equal(res.BlsSignature, info.BlsSignature) { + return errorsmod.Wrap( + types.ErrInconsistentParams, + fmt.Sprintf("SetTaskResultInfo: invalid param OperatorAddress: %s ,(TaskContractAddress: %s)"+ + ",(TaskId: %d),(BlsSignature: %s)", + info.OperatorAddress, info.TaskContractAddress, info.TaskId, info.BlsSignature), + ) + } + // check epoch,The second phase submission must be within the statistical window period + // #nosec G115 + if epoch.CurrentEpoch <= int64(task.StartingEpoch)+int64(task.TaskResponsePeriod) { + return errorsmod.Wrap( + types.ErrSubmitTooSoonError, + fmt.Sprintf("SetTaskResultInfo:the TaskResponse period has not started , CurrentEpoch:%d", epoch.CurrentEpoch), + ) + } + if epoch.CurrentEpoch > int64(task.StartingEpoch)+int64(task.TaskResponsePeriod)+int64(task.TaskStatisticalPeriod) { + return errorsmod.Wrap( + types.ErrSubmitTooLateError, + fmt.Sprintf("SetTaskResultInfo:submit too late, CurrentEpoch:%d", epoch.CurrentEpoch), + ) + } + + // calculate hash by original task + taskResponseDigest := crypto.Keccak256Hash(info.TaskResponse) + info.TaskResponseHash = taskResponseDigest.String() + // check taskID + resp, err := types.UnmarshalTaskResponse(info.TaskResponse) + if err != nil || info.TaskId != resp.TaskID { + return errorsmod.Wrap( + types.ErrInconsistentParams, + fmt.Sprintf("SetTaskResultInfo: invalid TaskId param value:%s", info.TaskResponse), + ) + } + // check bls sig + flag, err := blst.VerifySignature(info.BlsSignature, taskResponseDigest, pubKey) + if !flag || err != nil { + return errorsmod.Wrap( + types.ErrSigVerifyError, + fmt.Sprintf("SetTaskResultInfo: invalid task address: %s (Task ID: %d)", info.TaskContractAddress, info.TaskId), + ) + } + + k.SetTaskResultInfo(ctx, info) + return nil + default: + return errorsmod.Wrap( + types.ErrParamError, + fmt.Sprintf("SetTaskResultInfo: invalid param value:%d", info.Phase), + ) + } +} diff --git a/x/avs/keeper/msg_server.go b/x/avs/keeper/msg_server.go index bf0811448..fa46d2985 100644 --- a/x/avs/keeper/msg_server.go +++ b/x/avs/keeper/msg_server.go @@ -20,7 +20,7 @@ var _ types.MsgServer = &MsgServerImpl{} func (m MsgServerImpl) SubmitTaskResult(goCtx context.Context, req *types.SubmitTaskResultReq) (*types.SubmitTaskResultResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - if err := m.keeper.SetTaskResultInfo(ctx, req.FromAddress, req.Info); err != nil { + if err := m.keeper.SubmitTaskResult(ctx, req.FromAddress, req.Info); err != nil { return nil, err } return &types.SubmitTaskResultResponse{}, nil diff --git a/x/avs/keeper/multi_operator_submit_task_test.go b/x/avs/keeper/multi_operator_submit_task_test.go index 9c17628a6..3c17c9086 100644 --- a/x/avs/keeper/multi_operator_submit_task_test.go +++ b/x/avs/keeper/multi_operator_submit_task_test.go @@ -203,7 +203,7 @@ func (suite *AVSTestSuite) TestSubmitTask_OnlyPhaseOne_Mul() { BlsSignature: sig.Marshal(), Phase: avstypes.Phase(avstypes.PhasePrepare), } - err := suite.App.AVSManagerKeeper.SetTaskResultInfo(suite.Ctx, operatorAddress, info) + err := suite.App.AVSManagerKeeper.SubmitTaskResult(suite.Ctx, operatorAddress, info) suite.Require().NoError(err) } } @@ -231,7 +231,7 @@ func (suite *AVSTestSuite) TestSubmitTask_OnlyPhaseTwo_Mul() { BlsSignature: sig.Marshal(), Phase: avstypes.Phase(avstypes.PhaseDoCommit), } - err = suite.App.AVSManagerKeeper.SetTaskResultInfo(suite.Ctx, operatorAddress, info) + err = suite.App.AVSManagerKeeper.SubmitTaskResult(suite.Ctx, operatorAddress, info) suite.NoError(err) } } diff --git a/x/avs/keeper/submit_task_test.go b/x/avs/keeper/submit_task_test.go index 1302b7e06..7abda46b9 100644 --- a/x/avs/keeper/submit_task_test.go +++ b/x/avs/keeper/submit_task_test.go @@ -190,7 +190,7 @@ func (suite *AVSTestSuite) TestSubmitTask_OnlyPhaseOne() { BlsSignature: sig.Marshal(), Phase: avstypes.Phase(avstypes.PhasePrepare), } - err = suite.App.AVSManagerKeeper.SetTaskResultInfo(suite.Ctx, suite.operatorAddr.String(), info) + err = suite.App.AVSManagerKeeper.SubmitTaskResult(suite.Ctx, suite.operatorAddr.String(), info) suite.NoError(err) } @@ -219,6 +219,6 @@ func (suite *AVSTestSuite) TestSubmitTask_OnlyPhaseTwo() { BlsSignature: sig.Marshal(), Phase: avstypes.Phase(avstypes.PhaseDoCommit), } - err = suite.App.AVSManagerKeeper.SetTaskResultInfo(suite.Ctx, suite.operatorAddr.String(), info) + err = suite.App.AVSManagerKeeper.SubmitTaskResult(suite.Ctx, suite.operatorAddr.String(), info) suite.NoError(err) } diff --git a/x/avs/keeper/task.go b/x/avs/keeper/task.go index 3dd890c6d..6fd31b26b 100644 --- a/x/avs/keeper/task.go +++ b/x/avs/keeper/task.go @@ -1,23 +1,18 @@ package keeper import ( - "bytes" "fmt" "sort" "strconv" "strings" - "github.com/ethereum/go-ethereum/crypto" - errorsmod "cosmossdk.io/errors" assetstype "github.com/ExocoreNetwork/exocore/x/assets/types" "github.com/ExocoreNetwork/exocore/x/avs/types" - delegationtypes "github.com/ExocoreNetwork/exocore/x/delegation/types" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" - "github.com/prysmaticlabs/prysm/v4/crypto/bls/blst" ) func (k Keeper) SetTaskInfo(ctx sdk.Context, task *types.TaskInfo) (err error) { @@ -48,6 +43,15 @@ func (k *Keeper) GetTaskInfo(ctx sdk.Context, taskID, taskContractAddress string return &ret, nil } +func (k Keeper) GetAllTaskInfos(ctx sdk.Context) ([]types.TaskInfo, error) { + var taskInfos []types.TaskInfo + k.IterateTaskAVSInfo(ctx, func(_ int64, taskInfo types.TaskInfo) bool { + taskInfos = append(taskInfos, taskInfo) + return false + }) + return taskInfos, nil +} + func (k *Keeper) IsExistTask(ctx sdk.Context, taskID, taskContractAddress string) bool { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixAVSTaskInfo) infoKey := assetstype.GetJoinedStoreKey(strings.ToLower(taskContractAddress), taskID) @@ -84,6 +88,34 @@ func (k *Keeper) GetOperatorPubKey(ctx sdk.Context, addr string) (pub *types.Bls return &ret, nil } +func (k *Keeper) GetAllBlsPubKeys(ctx sdk.Context) ([]types.BlsPubKeyInfo, error) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixOperatePub) + // Count items first for optimal slice allocation + iterator := sdk.KVStorePrefixIterator(store, nil) + // Pre-allocate the slice for better performance by counting items first. + count := 0 + for ; iterator.Valid(); iterator.Next() { + count++ + } + iterator.Close() + + // Reset iterator + iterator = sdk.KVStorePrefixIterator(store, nil) + defer iterator.Close() + + pubKeys := make([]types.BlsPubKeyInfo, 0, count) + for ; iterator.Valid(); iterator.Next() { + var pubKey types.BlsPubKeyInfo + err := k.cdc.Unmarshal(iterator.Value(), &pubKey) + if err != nil { + return nil, errorsmod.Wrap(err, "GetAllBlsPubKeys: failed to unmarshal pubkey") + } + pubKeys = append(pubKeys, pubKey) + } + + return pubKeys, nil +} + func (k *Keeper) IsExistPubKey(ctx sdk.Context, addr string) bool { opAccAddr, _ := sdk.AccAddressFromBech32(addr) store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixOperatePub) @@ -112,6 +144,14 @@ func (k Keeper) IterateTaskAVSInfo(ctx sdk.Context, fn func(index int64, taskInf } } +func (k Keeper) SetTaskID(ctx sdk.Context, taskAddr common.Address, id uint64) { + if taskAddr == (common.Address{}) { + panic("invalid task address") + } + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixLatestTaskNum) + store.Set(taskAddr.Bytes(), sdk.Uint64ToBigEndian(id)) +} + // GetTaskID Increase the task ID by 1 each time. func (k Keeper) GetTaskID(ctx sdk.Context, taskAddr common.Address) uint64 { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixLatestTaskNum) @@ -127,169 +167,38 @@ func (k Keeper) GetTaskID(ctx sdk.Context, taskAddr common.Address) uint64 { return id } -// SetTaskResultInfo is used to store the operator's sign task information. -func (k *Keeper) SetTaskResultInfo( - ctx sdk.Context, addr string, info *types.TaskResultInfo, -) (err error) { - // the operator's `addr` must match the from address. - if addr != info.OperatorAddress { - return errorsmod.Wrap( - types.ErrInvalidAddr, - "SetTaskResultInfo:from address is not equal to the operator address", - ) - } - opAccAddr, _ := sdk.AccAddressFromBech32(info.OperatorAddress) - // check operator - if !k.operatorKeeper.IsOperator(ctx, opAccAddr) { - return errorsmod.Wrap( - delegationtypes.ErrOperatorNotExist, - fmt.Sprintf("SetTaskResultInfo:invalid operator address:%s", opAccAddr), - ) - } - // check operator bls pubkey - keyInfo, err := k.GetOperatorPubKey(ctx, info.OperatorAddress) - if err != nil || keyInfo.PubKey == nil { - return errorsmod.Wrap( - types.ErrPubKeyIsNotExists, - fmt.Sprintf("SetTaskResultInfo:get operator address:%s", opAccAddr), - ) - } - pubKey, err := blst.PublicKeyFromBytes(keyInfo.PubKey) - if err != nil || pubKey == nil { - return errorsmod.Wrap( - types.ErrParsePubKey, - fmt.Sprintf("SetTaskResultInfo:get operator address:%s", opAccAddr), - ) - } - // check task contract - task, err := k.GetTaskInfo(ctx, strconv.FormatUint(info.TaskId, 10), info.TaskContractAddress) - if err != nil || task.TaskContractAddress == "" { - return errorsmod.Wrap( - types.ErrTaskIsNotExists, - fmt.Sprintf("SetTaskResultInfo: task info not found: %s (Task ID: %d)", - info.TaskContractAddress, info.TaskId), - ) +// GetAllTaskNums returns a map containing all task addresses and their corresponding task IDs. +func (k *Keeper) GetAllTaskNums(ctx sdk.Context) ([]types.TaskID, error) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixLatestTaskNum) + iterator := sdk.KVStorePrefixIterator(store, nil) + defer iterator.Close() + ret := make([]types.TaskID, 0) + for ; iterator.Valid(); iterator.Next() { + taskAddr := strings.ToLower(common.BytesToAddress(iterator.Key()).Hex()) + id := sdk.BigEndianToUint64(iterator.Value()) + ret = append(ret, types.TaskID{ + TaskAddr: taskAddr, + TaskId: id, + }) } + return ret, nil +} - // check prescribed period - // If submitted in the first phase, in order to avoid plagiarism by other operators, - // TaskResponse and TaskResponseHash must be null values - // At the same time, it must be submitted within the response deadline in the first phase - avsInfo := k.GetAVSInfoByTaskAddress(ctx, info.TaskContractAddress) - if avsInfo.AvsAddress == "" { - return errorsmod.Wrap(types.ErrUnregisterNonExistent, fmt.Sprintf("the taskaddr is :%s", info.TaskContractAddress)) - } - epoch, found := k.epochsKeeper.GetEpochInfo(ctx, avsInfo.EpochIdentifier) - if !found { - return errorsmod.Wrap(types.ErrEpochNotFound, fmt.Sprintf("epoch info not found %s", - avsInfo.EpochIdentifier)) +// SetTaskResultInfo is used to store the operator's sign task information. +func (k *Keeper) SetTaskResultInfo( + ctx sdk.Context, info *types.TaskResultInfo, +) { + if _, err := sdk.AccAddressFromBech32(info.OperatorAddress); err != nil { + panic(fmt.Sprintf("invalid operator address: %s", info.OperatorAddress)) } - - switch info.Phase { - case types.PhasePrepare: - if k.IsExistTaskResultInfo(ctx, info.OperatorAddress, info.TaskContractAddress, info.TaskId) { - return errorsmod.Wrap( - types.ErrResAlreadyExists, - fmt.Sprintf("SetTaskResultInfo: task result is already exists, "+ - "OperatorAddress: %s (TaskContractAddress: %s),(Task ID: %d)", - info.OperatorAddress, info.TaskContractAddress, info.TaskId), - ) - } - // check parameters - if info.BlsSignature == nil { - return errorsmod.Wrap( - types.ErrParamNotEmptyError, - fmt.Sprintf("SetTaskResultInfo: invalid param BlsSignature is not be null (BlsSignature: %s)", info.BlsSignature), - ) - } - if info.TaskResponseHash != "" || info.TaskResponse != nil { - return errorsmod.Wrap( - types.ErrParamNotEmptyError, - fmt.Sprintf("SetTaskResultInfo: invalid param TaskResponseHash: %s (TaskResponse: %d)", - info.TaskResponseHash, info.TaskResponse), - ) - } - // check epoch,The first phase submission must be within the response window period - // #nosec G115 - if epoch.CurrentEpoch > int64(task.StartingEpoch)+int64(task.TaskResponsePeriod) { - return errorsmod.Wrap( - types.ErrSubmitTooLateError, - fmt.Sprintf("SetTaskResultInfo:submit too late, CurrentEpoch:%d", epoch.CurrentEpoch), - ) - } - infoKey := assetstype.GetJoinedStoreKey(strings.ToLower(info.OperatorAddress), strings.ToLower(info.TaskContractAddress), - strconv.FormatUint(info.TaskId, 10)) - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixTaskResult) - bz := k.cdc.MustMarshal(info) - store.Set(infoKey, bz) - return nil - - case types.PhaseDoCommit: - // check task response - if info.TaskResponse == nil { - return errorsmod.Wrap( - types.ErrNotNull, - fmt.Sprintf("SetTaskResultInfo: invalid param (TaskResponse: %d)", - info.TaskResponse), - ) - } - // check parameters - res, err := k.GetTaskResultInfo(ctx, info.OperatorAddress, info.TaskContractAddress, info.TaskId) - if err != nil || !bytes.Equal(res.BlsSignature, info.BlsSignature) { - return errorsmod.Wrap( - types.ErrInconsistentParams, - fmt.Sprintf("SetTaskResultInfo: invalid param OperatorAddress: %s ,(TaskContractAddress: %s)"+ - ",(TaskId: %d),(BlsSignature: %s)", - info.OperatorAddress, info.TaskContractAddress, info.TaskId, info.BlsSignature), - ) - } - // check epoch,The second phase submission must be within the statistical window period - // #nosec G115 - if epoch.CurrentEpoch <= int64(task.StartingEpoch)+int64(task.TaskResponsePeriod) { - return errorsmod.Wrap( - types.ErrSubmitTooSoonError, - fmt.Sprintf("SetTaskResultInfo:the TaskResponse period has not started , CurrentEpoch:%d", epoch.CurrentEpoch), - ) - } - if epoch.CurrentEpoch > int64(task.StartingEpoch)+int64(task.TaskResponsePeriod)+int64(task.TaskStatisticalPeriod) { - return errorsmod.Wrap( - types.ErrSubmitTooLateError, - fmt.Sprintf("SetTaskResultInfo:submit too late, CurrentEpoch:%d", epoch.CurrentEpoch), - ) - } - - // calculate hash by original task - taskResponseDigest := crypto.Keccak256Hash(info.TaskResponse) - info.TaskResponseHash = taskResponseDigest.String() - // check taskID - resp, err := types.UnmarshalTaskResponse(info.TaskResponse) - if err != nil || info.TaskId != resp.TaskID { - return errorsmod.Wrap( - types.ErrInconsistentParams, - fmt.Sprintf("SetTaskResultInfo: invalid TaskId param value:%s", info.TaskResponse), - ) - } - // check bls sig - flag, err := blst.VerifySignature(info.BlsSignature, taskResponseDigest, pubKey) - if !flag || err != nil { - return errorsmod.Wrap( - types.ErrSigVerifyError, - fmt.Sprintf("SetTaskResultInfo: invalid task address: %s (Task ID: %d)", info.TaskContractAddress, info.TaskId), - ) - } - - infoKey := assetstype.GetJoinedStoreKey(strings.ToLower(info.OperatorAddress), strings.ToLower(info.TaskContractAddress), strconv.FormatUint(info.TaskId, 10)) - - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixTaskResult) - bz := k.cdc.MustMarshal(info) - store.Set(infoKey, bz) - return nil - default: - return errorsmod.Wrap( - types.ErrParamError, - fmt.Sprintf("SetTaskResultInfo: invalid param value:%d", info.Phase), - ) + if !common.IsHexAddress(info.TaskContractAddress) { + panic(fmt.Sprintf("invalid task contract address: %s", info.TaskContractAddress)) } + infoKey := assetstype.GetJoinedStoreKey(info.OperatorAddress, strings.ToLower(info.TaskContractAddress), + strconv.FormatUint(info.TaskId, 10)) + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixTaskResult) + bz := k.cdc.MustMarshal(info) + store.Set(infoKey, bz) } func (k *Keeper) IsExistTaskResultInfo(ctx sdk.Context, operatorAddress, taskContractAddress string, taskID uint64) bool { @@ -398,3 +307,66 @@ func (k *Keeper) GetTaskChallengedInfo(ctx sdk.Context, operatorAddress, taskCon return common.Bytes2Hex(value), nil } + +// GetAllTaskResultInfos returns a slice containing all task result information. +func (k *Keeper) GetAllTaskResultInfos(ctx sdk.Context) ([]types.TaskResultInfo, error) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixTaskResult) + iterator := sdk.KVStorePrefixIterator(store, nil) + defer iterator.Close() + + ret := make([]types.TaskResultInfo, 0) + for ; iterator.Valid(); iterator.Next() { + task := types.TaskResultInfo{} + err := k.cdc.Unmarshal(iterator.Value(), &task) + if err != nil { + return nil, errorsmod.Wrap(err, "GetAllTaskResultInfos: failed to unmarshal task result info") + } + ret = append(ret, task) + } + return ret, nil +} + +func (k *Keeper) SetAllTaskChallengedInfo(ctx sdk.Context, states []types.ChallengeInfo) error { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixTaskChallengeResult) + for i := range states { + state := states[i] + bz, err := sdk.AccAddressFromBech32(state.ChallengeAddr) + if err != nil { + return err + } + store.Set([]byte(state.Key), bz) + } + return nil +} + +func (k *Keeper) GetAllChallengeInfos(ctx sdk.Context) ([]types.ChallengeInfo, error) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixTaskChallengeResult) + iterator := sdk.KVStorePrefixIterator(store, nil) + defer iterator.Close() + + // Count items first for optimal slice allocation + count := 0 + for ; iterator.Valid(); iterator.Next() { + count++ + } + iterator.Close() + + // Reset iterator + iterator = sdk.KVStorePrefixIterator(store, nil) + defer iterator.Close() + + ret := make([]types.ChallengeInfo, 0, count) + for ; iterator.Valid(); iterator.Next() { + key := string(iterator.Key()) + challengeAddr := sdk.AccAddress(iterator.Value()) + if len(challengeAddr) == 0 { + return nil, errorsmod.Wrap(types.ErrInvalidAddr, "invalid challenge address") + } + + ret = append(ret, types.ChallengeInfo{ + Key: key, + ChallengeAddr: challengeAddr.String(), + }) + } + return ret, nil +} diff --git a/x/avs/module.go b/x/avs/module.go index 05aeeb72d..aaf2c4ad2 100644 --- a/x/avs/module.go +++ b/x/avs/module.go @@ -117,6 +117,7 @@ func (am AppModule) GenerateGenesisState(_ *module.SimulationState) { } // InitGenesis performs the module's genesis initialization. It returns no validator updates. + func (am AppModule) InitGenesis( ctx sdk.Context, cdc codec.JSONCodec, @@ -126,7 +127,9 @@ func (am AppModule) InitGenesis( // Initialize global index to index in genesis state cdc.MustUnmarshalJSON(gs, &genState) - return am.keeper.InitGenesis(ctx, genState) + am.keeper.InitGenesis(ctx, genState) + + return []abci.ValidatorUpdate{} } // ExportGenesis returns the module's exported genesis state as raw JSON bytes. diff --git a/x/avs/types/genesis.go b/x/avs/types/genesis.go index 1cd6086b0..a7ffd0ebe 100644 --- a/x/avs/types/genesis.go +++ b/x/avs/types/genesis.go @@ -1,21 +1,163 @@ package types +import ( + "fmt" + "strconv" + "strings" + + assetstype "github.com/ExocoreNetwork/exocore/x/assets/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" +) + // this line is used by starport scaffolding # genesis/types/import // DefaultIndex is the default global index const DefaultIndex uint64 = 1 -// DefaultGenesis returns the default genesis state -func DefaultGenesis() *GenesisState { +func NewGenesisState( + avsInfos []AVSInfo, + taskInfos []TaskInfo, + blsPubKeys []BlsPubKeyInfo, + taskResultInfos []TaskResultInfo, + challengeInfos []ChallengeInfo, + taskNums []TaskID, + chainIDInfos []ChainIDInfo, +) *GenesisState { + // Ensure slices are never nil + if avsInfos == nil { + avsInfos = []AVSInfo{} + } + if taskInfos == nil { + taskInfos = []TaskInfo{} + } + if blsPubKeys == nil { + blsPubKeys = []BlsPubKeyInfo{} + } + if taskResultInfos == nil { + taskResultInfos = []TaskResultInfo{} + } + if challengeInfos == nil { + challengeInfos = []ChallengeInfo{} + } + if taskNums == nil { + taskNums = []TaskID{} + } + if chainIDInfos == nil { + chainIDInfos = []ChainIDInfo{} + } return &GenesisState{ - Params: DefaultParams(), + AvsInfos: avsInfos, + TaskInfos: taskInfos, + BlsPubKeys: blsPubKeys, + TaskResultInfos: taskResultInfos, + ChallengeInfos: challengeInfos, + TaskNums: taskNums, + ChainIdInfos: chainIDInfos, } } +// DefaultGenesis returns the default genesis state +func DefaultGenesis() *GenesisState { + return NewGenesisState(nil, nil, nil, nil, nil, nil, nil) +} + // Validate performs basic genesis state validation returning an error upon any // failure. func (gs GenesisState) Validate() error { - // this line is used by starport scaffolding # genesis/types/validate + // Check for duplicated avs address + avsAddresses := make(map[string]bool) + for _, info := range gs.AvsInfos { + if !common.IsHexAddress(info.AvsAddress) { + return fmt.Errorf("invalid AVS address: %s", info.AvsAddress) + } + if avsAddresses[info.AvsAddress] { + return fmt.Errorf("duplicate AVS address: %s", info.AvsAddress) + } + avsAddresses[info.AvsAddress] = true + } + + // Check for duplicated task address + taskInfoMap := make(map[string]bool) + for _, info := range gs.TaskInfos { + if !common.IsHexAddress(info.TaskContractAddress) { + return fmt.Errorf("invalid hex address: %s", info.TaskContractAddress) + } + if taskInfoMap[info.TaskContractAddress] { + return fmt.Errorf("duplicate task address: %s", info.TaskContractAddress) + } + taskInfoMap[info.TaskContractAddress] = true + } + + // Check for duplicated taskID + taskNumMap := make(map[string]bool) + for _, taskNum := range gs.TaskNums { + if !common.IsHexAddress(taskNum.TaskAddr) { + return fmt.Errorf("invalid hex address: %s", taskNum.TaskAddr) + } + taskNumKey := assetstype.GetJoinedStoreKey(strings.ToLower(taskNum.TaskAddr), + strconv.FormatUint(taskNum.TaskId, 10)) + if taskNumMap[string(taskNumKey)] { + return fmt.Errorf("duplicate task ID %v ", taskNum) + } + taskNumMap[string(taskNumKey)] = true + } + + // Check for duplicated pubKey + pubKeyMap := make(map[string]bool) + for _, key := range gs.BlsPubKeys { + _, err := sdk.AccAddressFromBech32(key.Operator) + if err != nil { + return fmt.Errorf("invalid operatorAddress address: %s", key.Operator) + } + if key.PubKey == nil { + return fmt.Errorf("pubKey is nil: %v", key) + } + if pubKeyMap[string(key.PubKey)] { + return fmt.Errorf("duplicate pubKey %v", key) + } + pubKeyMap[string(key.PubKey)] = true + } - return gs.Params.Validate() + // Check for duplicated task result + taskResultMap := make(map[string]bool) + for _, result := range gs.TaskResultInfos { + + if !common.IsHexAddress(result.TaskContractAddress) { + return fmt.Errorf("invalid hex address: %s", result.TaskContractAddress) + } + _, err := sdk.AccAddressFromBech32(result.OperatorAddress) + if err != nil { + return fmt.Errorf("invalid operatorAddress address: %s", result.OperatorAddress) + } + resultKey := assetstype.GetJoinedStoreKey(result.OperatorAddress, strings.ToLower(result.TaskContractAddress), + strconv.FormatUint(result.TaskId, 10)) + + if taskResultMap[string(resultKey)] { + return fmt.Errorf("duplicate Task Result %v", result) + } + taskResultMap[string(resultKey)] = true + } + + // Check for duplicated challenge + challengeMap := make(map[string]bool) + for _, result := range gs.ChallengeInfos { + if challengeMap[result.Key] { + return fmt.Errorf("duplicate challenge %v", result) + } + challengeMap[result.Key] = true + } + + // Check for duplicated chainId Info + chainIDMap := make(map[string]bool) + for _, result := range gs.ChainIdInfos { + if !common.IsHexAddress(result.AvsAddress) { + return fmt.Errorf("invalid hex address: %s", result.AvsAddress) + } + if chainIDMap[result.AvsAddress] { + return fmt.Errorf("duplicate chainId %v", result) + } + chainIDMap[result.AvsAddress] = true + } + return nil } diff --git a/x/avs/types/genesis.pb.go b/x/avs/types/genesis.pb.go index 1742a7a05..82e4e9f77 100644 --- a/x/avs/types/genesis.pb.go +++ b/x/avs/types/genesis.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: exocore/avs/genesis.proto +// source: exocore/avs/v1/genesis.proto package types @@ -23,16 +23,40 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// GenesisState defines the avs module's genesis state. +// GenesisState defines the avs module's state. It needs to encompass +// all of the state that is required to start the chain from the genesis +// or in the event of a restart. type GenesisState struct { - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + // avs_infos is the list of registered avs infos, + // that are supported at chain genesis (or restart). + AvsInfos []AVSInfo `protobuf:"bytes,1,rep,name=avs_infos,json=avsInfos,proto3" json:"avs_infos"` + // task_infos is the tasks issued by avs owner, indexed by + // task address and task id + // that are supported at chain genesis (or restart). + TaskInfos []TaskInfo `protobuf:"bytes,2,rep,name=task_infos,json=taskInfos,proto3" json:"task_infos"` + // bls_pub_keys is the list of operator pubKey info, indexed by operator address + // The struct is the `BlsPubKeyInfo` + // which contains blsPubKey, operator address. + BlsPubKeys []BlsPubKeyInfo `protobuf:"bytes,3,rep,name=bls_pub_keys,json=blsPubKeys,proto3" json:"bls_pub_keys"` + // task_result_infos is the task result informations, indexed + // by the operator address ,task address and the task id. The struct is the `TaskResultInfo` + TaskResultInfos []TaskResultInfo `protobuf:"bytes,4,rep,name=task_result_infos,json=taskResultInfos,proto3" json:"task_result_infos"` + // challenge_infos is the task challenge informations, indexed + // by the operator address ,task address and the task id. The struct is the `ChallengeInfo` + ChallengeInfos []ChallengeInfo `protobuf:"bytes,5,rep,name=challenge_infos,json=challengeInfos,proto3" json:"challenge_infos"` + // task_nums is the task id, indexed + // by the task address. The struct is the `TaskID` + TaskNums []TaskID `protobuf:"bytes,6,rep,name=task_nums,json=taskNums,proto3" json:"task_nums"` + // chain_id_infos is the dogfood chain id informations, indexed + // by the avs address. The struct is the `ChainIDInfo` + ChainIdInfos []ChainIDInfo `protobuf:"bytes,7,rep,name=chain_id_infos,json=chainIdInfos,proto3" json:"chain_id_infos"` } 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_6f7a9069172c0bef, []int{0} + return fileDescriptor_cc32a0542b70c3d1, []int{0} } func (m *GenesisState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -61,33 +85,263 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -func (m *GenesisState) GetParams() Params { +func (m *GenesisState) GetAvsInfos() []AVSInfo { if m != nil { - return m.Params + return m.AvsInfos } - return Params{} + return nil +} + +func (m *GenesisState) GetTaskInfos() []TaskInfo { + if m != nil { + return m.TaskInfos + } + return nil +} + +func (m *GenesisState) GetBlsPubKeys() []BlsPubKeyInfo { + if m != nil { + return m.BlsPubKeys + } + return nil +} + +func (m *GenesisState) GetTaskResultInfos() []TaskResultInfo { + if m != nil { + return m.TaskResultInfos + } + return nil +} + +func (m *GenesisState) GetChallengeInfos() []ChallengeInfo { + if m != nil { + return m.ChallengeInfos + } + return nil +} + +func (m *GenesisState) GetTaskNums() []TaskID { + if m != nil { + return m.TaskNums + } + return nil +} + +func (m *GenesisState) GetChainIdInfos() []ChainIDInfo { + if m != nil { + return m.ChainIdInfos + } + return nil +} + +// TaskID is helper structure to store the task id information for the genesis state. +type TaskID struct { + // task_addr is the address of task as a hex string + TaskAddr string `protobuf:"bytes,1,opt,name=task_addr,json=taskAddr,proto3" json:"task_addr,omitempty"` + // id of task. + TaskId uint64 `protobuf:"varint,2,opt,name=task_id,json=taskId,proto3" json:"task_id,omitempty"` +} + +func (m *TaskID) Reset() { *m = TaskID{} } +func (m *TaskID) String() string { return proto.CompactTextString(m) } +func (*TaskID) ProtoMessage() {} +func (*TaskID) Descriptor() ([]byte, []int) { + return fileDescriptor_cc32a0542b70c3d1, []int{1} +} +func (m *TaskID) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TaskID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TaskID.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 *TaskID) XXX_Merge(src proto.Message) { + xxx_messageInfo_TaskID.Merge(m, src) +} +func (m *TaskID) XXX_Size() int { + return m.Size() +} +func (m *TaskID) XXX_DiscardUnknown() { + xxx_messageInfo_TaskID.DiscardUnknown(m) +} + +var xxx_messageInfo_TaskID proto.InternalMessageInfo + +func (m *TaskID) GetTaskAddr() string { + if m != nil { + return m.TaskAddr + } + return "" +} + +func (m *TaskID) GetTaskId() uint64 { + if m != nil { + return m.TaskId + } + return 0 +} + +// ChallengeInfo is helper structure to store the task challenge information for the genesis state. +type ChallengeInfo struct { + // key is used for storing the ChallengeInfos, + // which is a combination of the operator address ,task address and task id. + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // challenge_addr is the address of the challenger + ChallengeAddr string `protobuf:"bytes,2,opt,name=challenge_addr,json=challengeAddr,proto3" json:"challenge_addr,omitempty"` +} + +func (m *ChallengeInfo) Reset() { *m = ChallengeInfo{} } +func (m *ChallengeInfo) String() string { return proto.CompactTextString(m) } +func (*ChallengeInfo) ProtoMessage() {} +func (*ChallengeInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_cc32a0542b70c3d1, []int{2} +} +func (m *ChallengeInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ChallengeInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ChallengeInfo.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 *ChallengeInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChallengeInfo.Merge(m, src) +} +func (m *ChallengeInfo) XXX_Size() int { + return m.Size() +} +func (m *ChallengeInfo) XXX_DiscardUnknown() { + xxx_messageInfo_ChallengeInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_ChallengeInfo proto.InternalMessageInfo + +func (m *ChallengeInfo) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *ChallengeInfo) GetChallengeAddr() string { + if m != nil { + return m.ChallengeAddr + } + return "" +} + +// ChainIDInfo is helper structure to store the dogfood ChainID information for the genesis state. +type ChainIDInfo struct { + // avs_address is the address of avs as a hex string. + AvsAddress string `protobuf:"bytes,1,opt,name=avs_address,json=avsAddress,proto3" json:"avs_address,omitempty"` + // chain_id is a dogfood parameter + ChainId string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` +} + +func (m *ChainIDInfo) Reset() { *m = ChainIDInfo{} } +func (m *ChainIDInfo) String() string { return proto.CompactTextString(m) } +func (*ChainIDInfo) ProtoMessage() {} +func (*ChainIDInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_cc32a0542b70c3d1, []int{3} +} +func (m *ChainIDInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ChainIDInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ChainIDInfo.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 *ChainIDInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_ChainIDInfo.Merge(m, src) +} +func (m *ChainIDInfo) XXX_Size() int { + return m.Size() +} +func (m *ChainIDInfo) XXX_DiscardUnknown() { + xxx_messageInfo_ChainIDInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_ChainIDInfo proto.InternalMessageInfo + +func (m *ChainIDInfo) GetAvsAddress() string { + if m != nil { + return m.AvsAddress + } + return "" +} + +func (m *ChainIDInfo) GetChainId() string { + if m != nil { + return m.ChainId + } + return "" } func init() { - proto.RegisterType((*GenesisState)(nil), "exocore.avs.GenesisState") + proto.RegisterType((*GenesisState)(nil), "exocore.avs.v1.GenesisState") + proto.RegisterType((*TaskID)(nil), "exocore.avs.v1.TaskID") + proto.RegisterType((*ChallengeInfo)(nil), "exocore.avs.v1.ChallengeInfo") + proto.RegisterType((*ChainIDInfo)(nil), "exocore.avs.v1.ChainIDInfo") } -func init() { proto.RegisterFile("exocore/avs/genesis.proto", fileDescriptor_6f7a9069172c0bef) } +func init() { proto.RegisterFile("exocore/avs/v1/genesis.proto", fileDescriptor_cc32a0542b70c3d1) } -var fileDescriptor_6f7a9069172c0bef = []byte{ - // 192 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4c, 0xad, 0xc8, 0x4f, - 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0x2c, 0x2b, 0xd6, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, - 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x86, 0x4a, 0xe9, 0x25, 0x96, 0x15, 0x4b, 0x89, 0xa4, - 0xe7, 0xa7, 0xe7, 0x83, 0xc5, 0xf5, 0x41, 0x2c, 0x88, 0x12, 0x29, 0x09, 0x64, 0xdd, 0x05, 0x89, - 0x45, 0x89, 0xb9, 0x50, 0xcd, 0x4a, 0x8e, 0x5c, 0x3c, 0xee, 0x10, 0xd3, 0x82, 0x4b, 0x12, 0x4b, - 0x52, 0x85, 0x0c, 0xb9, 0xd8, 0x20, 0xf2, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0xdc, 0x46, 0xc2, 0x7a, - 0x48, 0xa6, 0xeb, 0x05, 0x80, 0xa5, 0x9c, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, 0x2a, 0x74, - 0x72, 0x3f, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, - 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xdd, 0xf4, 0xcc, 0x92, - 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x57, 0x88, 0x31, 0x7e, 0xa9, 0x25, 0xe5, 0xf9, - 0x45, 0xd9, 0xfa, 0x30, 0x07, 0x55, 0x80, 0x9d, 0x54, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, - 0x76, 0x92, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x79, 0xb0, 0x7f, 0x59, 0xec, 0x00, 0x00, 0x00, +var fileDescriptor_cc32a0542b70c3d1 = []byte{ + // 492 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x93, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0x86, 0xe3, 0x26, 0x24, 0xcd, 0x24, 0x6d, 0x61, 0x85, 0x88, 0x69, 0xc1, 0x8d, 0x22, 0x21, + 0xe5, 0x82, 0xad, 0xc2, 0x09, 0x24, 0x90, 0x12, 0x5a, 0x85, 0x08, 0x54, 0x55, 0x29, 0xe2, 0xc0, + 0xc5, 0x5a, 0xc7, 0x5b, 0xd7, 0xb2, 0xe3, 0x8d, 0x3c, 0x6b, 0x93, 0xbc, 0x05, 0x8f, 0xd5, 0x63, + 0x8f, 0x9c, 0x10, 0x4a, 0x5e, 0x81, 0x07, 0x40, 0x5e, 0xaf, 0xc1, 0x89, 0x72, 0x5b, 0xcf, 0xce, + 0xff, 0xcd, 0x3f, 0xb3, 0x1e, 0x78, 0xc6, 0x16, 0x7c, 0xca, 0x63, 0x66, 0xd1, 0x14, 0xad, 0xf4, + 0xcc, 0xf2, 0x58, 0xc4, 0xd0, 0x47, 0x73, 0x1e, 0x73, 0xc1, 0xc9, 0xa1, 0xba, 0x35, 0x69, 0x8a, + 0x66, 0x7a, 0x76, 0xdc, 0xd9, 0xca, 0x16, 0x8b, 0x3c, 0xf1, 0xf8, 0xb1, 0xc7, 0x3d, 0x2e, 0x8f, + 0x56, 0x76, 0xca, 0xa3, 0xbd, 0x3f, 0x55, 0x68, 0x8f, 0x72, 0xe0, 0xb5, 0xa0, 0x82, 0x91, 0xb7, + 0xd0, 0xa4, 0x29, 0xda, 0x7e, 0x74, 0xc3, 0x51, 0xd7, 0xba, 0xd5, 0x7e, 0xeb, 0x55, 0xc7, 0xdc, + 0xac, 0x61, 0x0e, 0xbe, 0x5e, 0x8f, 0xa3, 0x1b, 0x3e, 0xac, 0xdd, 0xfd, 0x3a, 0xad, 0x4c, 0xf6, + 0x69, 0x8a, 0xd9, 0x27, 0x92, 0x77, 0x00, 0x82, 0x62, 0xa0, 0xc4, 0x7b, 0x52, 0xac, 0x6f, 0x8b, + 0xbf, 0x50, 0x0c, 0x4a, 0xea, 0xa6, 0x50, 0xdf, 0x48, 0x2e, 0xa0, 0xed, 0x84, 0x68, 0xcf, 0x13, + 0xc7, 0x0e, 0xd8, 0x12, 0xf5, 0xaa, 0x04, 0x3c, 0xdf, 0x06, 0x0c, 0x43, 0xbc, 0x4a, 0x9c, 0x4f, + 0x6c, 0x59, 0xa2, 0x80, 0x53, 0x04, 0x91, 0x5c, 0xc1, 0x23, 0xe9, 0x22, 0x66, 0x98, 0x84, 0x42, + 0x99, 0xa9, 0x49, 0x96, 0xb1, 0xcb, 0xcc, 0x44, 0xe6, 0x95, 0x60, 0x47, 0x62, 0x23, 0x8a, 0xe4, + 0x33, 0x1c, 0x4d, 0x6f, 0x69, 0x18, 0xb2, 0xc8, 0x63, 0x8a, 0xf7, 0x60, 0xb7, 0xb7, 0x0f, 0x45, + 0x5a, 0x09, 0x77, 0x38, 0x2d, 0x07, 0x91, 0xbc, 0x01, 0xd9, 0xb3, 0x1d, 0x25, 0x33, 0xd4, 0xeb, + 0x92, 0xf3, 0x64, 0xe7, 0x90, 0xce, 0x8b, 0x01, 0x67, 0xe9, 0x97, 0xc9, 0x0c, 0xc9, 0x08, 0x32, + 0x98, 0x1f, 0xd9, 0xbe, 0xab, 0x7c, 0x34, 0xa4, 0xfe, 0x64, 0x87, 0x0f, 0x3f, 0x1a, 0x9f, 0x97, + 0x5c, 0xb4, 0xa5, 0x70, 0xec, 0x4a, 0x0f, 0xbd, 0xf7, 0x50, 0xcf, 0x4b, 0x90, 0x13, 0xe5, 0x86, + 0xba, 0x6e, 0xac, 0x6b, 0x5d, 0xad, 0xdf, 0xcc, 0xeb, 0x0d, 0x5c, 0x37, 0x26, 0x1d, 0x68, 0xe4, + 0x0f, 0xea, 0xea, 0x7b, 0x5d, 0xad, 0x5f, 0x9b, 0xd4, 0xe5, 0x6b, 0xb9, 0xbd, 0x8f, 0x70, 0xb0, + 0xd1, 0x2a, 0x79, 0x08, 0xd5, 0x80, 0x2d, 0x15, 0x20, 0x3b, 0x92, 0x17, 0xf0, 0xbf, 0xf1, 0x9c, + 0xbe, 0x27, 0x2f, 0x0f, 0xfe, 0x45, 0xb3, 0x12, 0xbd, 0x31, 0xb4, 0x4a, 0x66, 0xc9, 0x29, 0xb4, + 0xb2, 0xdf, 0x2f, 0xcb, 0x67, 0x88, 0x8a, 0x07, 0x34, 0xc5, 0x41, 0x1e, 0x21, 0x4f, 0x61, 0xbf, + 0x18, 0x81, 0x02, 0x36, 0x54, 0x67, 0xc3, 0xd1, 0xdd, 0xca, 0xd0, 0xee, 0x57, 0x86, 0xf6, 0x7b, + 0x65, 0x68, 0x3f, 0xd6, 0x46, 0xe5, 0x7e, 0x6d, 0x54, 0x7e, 0xae, 0x8d, 0xca, 0xb7, 0x97, 0x9e, + 0x2f, 0x6e, 0x13, 0xc7, 0x9c, 0xf2, 0x99, 0x75, 0x91, 0x4f, 0xea, 0x92, 0x89, 0xef, 0x3c, 0x0e, + 0xac, 0x62, 0x5d, 0x16, 0x72, 0x61, 0xc4, 0x72, 0xce, 0xd0, 0xa9, 0xcb, 0xdd, 0x78, 0xfd, 0x37, + 0x00, 0x00, 0xff, 0xff, 0xbe, 0x6d, 0x44, 0xb9, 0x7a, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -110,16 +364,213 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.ChainIdInfos) > 0 { + for iNdEx := len(m.ChainIdInfos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ChainIdInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } + } + if len(m.TaskNums) > 0 { + for iNdEx := len(m.TaskNums) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TaskNums[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } + if len(m.ChallengeInfos) > 0 { + for iNdEx := len(m.ChallengeInfos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ChallengeInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + if len(m.TaskResultInfos) > 0 { + for iNdEx := len(m.TaskResultInfos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TaskResultInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.BlsPubKeys) > 0 { + for iNdEx := len(m.BlsPubKeys) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.BlsPubKeys[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.TaskInfos) > 0 { + for iNdEx := len(m.TaskInfos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.TaskInfos[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.AvsInfos) > 0 { + for iNdEx := len(m.AvsInfos) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.AvsInfos[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *TaskID) 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 *TaskID) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TaskID) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.TaskId != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.TaskId)) + i-- + dAtA[i] = 0x10 + } + if len(m.TaskAddr) > 0 { + i -= len(m.TaskAddr) + copy(dAtA[i:], m.TaskAddr) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.TaskAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ChallengeInfo) 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 *ChallengeInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ChallengeInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChallengeAddr) > 0 { + i -= len(m.ChallengeAddr) + copy(dAtA[i:], m.ChallengeAddr) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ChallengeAddr))) + i-- + dAtA[i] = 0x12 + } + if len(m.Key) > 0 { + i -= len(m.Key) + copy(dAtA[i:], m.Key) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Key))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ChainIDInfo) 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 *ChainIDInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ChainIDInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + 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] = 0x12 + } + if len(m.AvsAddress) > 0 { + i -= len(m.AvsAddress) + copy(dAtA[i:], m.AvsAddress) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.AvsAddress))) + i-- + dAtA[i] = 0xa + } return len(dAtA) - i, nil } @@ -140,8 +591,98 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l - l = m.Params.Size() - n += 1 + l + sovGenesis(uint64(l)) + if len(m.AvsInfos) > 0 { + for _, e := range m.AvsInfos { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.TaskInfos) > 0 { + for _, e := range m.TaskInfos { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.BlsPubKeys) > 0 { + for _, e := range m.BlsPubKeys { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.TaskResultInfos) > 0 { + for _, e := range m.TaskResultInfos { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ChallengeInfos) > 0 { + for _, e := range m.ChallengeInfos { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.TaskNums) > 0 { + for _, e := range m.TaskNums { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ChainIdInfos) > 0 { + for _, e := range m.ChainIdInfos { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *TaskID) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.TaskAddr) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.TaskId != 0 { + n += 1 + sovGenesis(uint64(m.TaskId)) + } + return n +} + +func (m *ChallengeInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Key) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.ChallengeAddr) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *ChainIDInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.AvsAddress) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.ChainId) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } return n } @@ -182,7 +723,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field AvsInfos", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -209,10 +750,544 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.AvsInfos = append(m.AvsInfos, AVSInfo{}) + if err := m.AvsInfos[len(m.AvsInfos)-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 TaskInfos", 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.TaskInfos = append(m.TaskInfos, TaskInfo{}) + if err := m.TaskInfos[len(m.TaskInfos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlsPubKeys", 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.BlsPubKeys = append(m.BlsPubKeys, BlsPubKeyInfo{}) + if err := m.BlsPubKeys[len(m.BlsPubKeys)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TaskResultInfos", 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.TaskResultInfos = append(m.TaskResultInfos, TaskResultInfo{}) + if err := m.TaskResultInfos[len(m.TaskResultInfos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChallengeInfos", 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.ChallengeInfos = append(m.ChallengeInfos, ChallengeInfo{}) + if err := m.ChallengeInfos[len(m.ChallengeInfos)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TaskNums", 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.TaskNums = append(m.TaskNums, TaskID{}) + if err := m.TaskNums[len(m.TaskNums)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChainIdInfos", 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.ChainIdInfos = append(m.ChainIdInfos, ChainIDInfo{}) + if err := m.ChainIdInfos[len(m.ChainIdInfos)-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 *TaskID) 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: TaskID: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TaskID: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TaskAddr", 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.TaskAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TaskId", wireType) + } + m.TaskId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TaskId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 *ChallengeInfo) 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: ChallengeInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ChallengeInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Key", 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.Key = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChallengeAddr", 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.ChallengeAddr = 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 *ChainIDInfo) 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: ChainIDInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ChainIDInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AvsAddress", 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.AvsAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + 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 default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/avs/types/genesis_test.go b/x/avs/types/genesis_test.go index 85e46907a..1ed3450b5 100644 --- a/x/avs/types/genesis_test.go +++ b/x/avs/types/genesis_test.go @@ -19,14 +19,83 @@ func TestGenesisState_Validate(t *testing.T) { valid: true, }, { - desc: "valid genesis state", + desc: "valid genesis state", genState: &types.GenesisState{ - - // this line is used by starport scaffolding # types/genesis/validField - }, + AvsInfos: []types.AVSInfo{ + {AvsAddress: "0x1234567890abcdef1234567890abcdef12345678"}, + {AvsAddress: "0x9876543210fedcba9876543210fedcba98765432"}, + }}, valid: true, }, - // this line is used by starport scaffolding # types/genesis/testcase + { + desc: "duplicated avs", + genState: &types.GenesisState{ + AvsInfos: []types.AVSInfo{ + {AvsAddress: "0x9876543210fedcba9876543210fedcba98765432"}, + {AvsAddress: "0x9876543210fedcba9876543210fedcba98765432"}, + }}, + valid: false, + }, + { + desc: "invalid genesis state due hex address", + genState: &types.GenesisState{ + AvsInfos: []types.AVSInfo{ + {AvsAddress: ""}, + }}, + valid: false, + }, + { + desc: "duplicated task", + genState: &types.GenesisState{ + TaskInfos: []types.TaskInfo{ + {TaskContractAddress: "0x9876543210fedcba9876543210fedcba98765432"}, + {TaskContractAddress: "0x9876543210fedcba9876543210fedcba98765432"}, + }}, + valid: false, + }, + { + desc: "duplicated task num", + genState: &types.GenesisState{ + TaskNums: []types.TaskID{ + {TaskAddr: "0x9876543210fedcba9876543210fedcba98765432", TaskId: 1}, + {TaskAddr: "0x9876543210fedcba9876543210fedcba98765432", TaskId: 1}, + }}, + valid: false, + }, + { + desc: "invalid operator address", + genState: &types.GenesisState{ + TaskResultInfos: []types.TaskResultInfo{ + {OperatorAddress: "0x9876543210fedcba9876543210fedcba98765432", TaskId: 1, TaskContractAddress: "0x9876543210fedcba9876543210fedcba98765432"}, + }}, + valid: false, + }, + { + desc: "duplicated task result", + genState: &types.GenesisState{ + TaskResultInfos: []types.TaskResultInfo{ + {OperatorAddress: "0x9876543210fedcba9876543210fedcba98765432", TaskId: 1, TaskContractAddress: "0x9876543210fedcba9876543210fedcba98765432"}, + {OperatorAddress: "0x9876543210fedcba9876543210fedcba98765432", TaskId: 1, TaskContractAddress: "0x9876543210fedcba9876543210fedcba98765432"}, + }}, + valid: false, + }, + { + desc: "invalid task result with different task IDs", + genState: &types.GenesisState{ + TaskResultInfos: []types.TaskResultInfo{ + {OperatorAddress: "0x9876543210fedcba9876543210fedcba98765432", TaskId: 1, TaskContractAddress: "0x9876543210fedcba9876543210fedcba98765432"}, + {OperatorAddress: "0x9876543210fedcba9876543210fedcba98765432", TaskId: 2, TaskContractAddress: "0x9876543210fedcba9876543210fedcba98765432"}, + }}, + valid: false, + }, + { + desc: "invalid BLS public key info with invalid operator address", + genState: &types.GenesisState{ + BlsPubKeys: []types.BlsPubKeyInfo{ + {Operator: "0x9876543210fedcba9876543210fedcba98765432", PubKey: nil}, + }}, + valid: false, + }, } for _, tc := range tests { t.Run(tc.desc, func(t *testing.T) { diff --git a/x/feedistribution/keeper/genesis.go b/x/feedistribution/keeper/genesis.go index a59693795..746744c94 100644 --- a/x/feedistribution/keeper/genesis.go +++ b/x/feedistribution/keeper/genesis.go @@ -1,6 +1,7 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" "github.com/ExocoreNetwork/exocore/x/feedistribution/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -15,11 +16,65 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { // is not running. it means that the genesis file is malformed. panic("not found the epoch info") } + + // Set fee pool + k.SetFeePool(ctx, &genState.FeePool) + + // Set all the validatorAccumulatedCommission + for _, elem := range genState.ValidatorAccumulatedCommissions { + k.SetValidatorAccumulatedCommission(ctx, sdk.ValAddress(elem.ValAddr), *elem.Commission) + } + + // Set all the validatorCurrentRewards + for _, elem := range genState.ValidatorCurrentRewardsList { + k.SetValidatorCurrentRewards(ctx, sdk.ValAddress(elem.ValAddr), *elem.CurrentRewards) + } + + // Set all the validatorOutstandingRewards + for _, elem := range genState.ValidatorOutstandingRewardsList { + k.SetValidatorOutstandingRewards(ctx, sdk.ValAddress(elem.ValAddr), *elem.OutstandingRewards) + } + + // Set all the stakerRewards + for _, elem := range genState.StakerOutstandingRewardsList { + k.SetStakerRewards(ctx, elem.ValAddr, *elem.StakerOutstandingRewards) + } } // ExportGenesis returns the module's exported genesis func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { genesis := types.DefaultGenesis() genesis.Params = k.GetParams(ctx) + feelPool := k.GetFeePool(ctx) + genesis.FeePool = *feelPool + validatorData, err := k.GetAllValidatorData(ctx) + if err != nil { + panic(errorsmod.Wrap(err, "Error getting validator data").Error()) + } + + if accumulatedCommissions, ok := validatorData["ValidatorAccumulatedCommissions"].([]types.ValidatorAccumulatedCommissions); ok { + genesis.ValidatorAccumulatedCommissions = accumulatedCommissions + } else { + panic("Failed to assert ValidatorAccumulatedCommissions type") + } + + if currentRewardsList, ok := validatorData["ValidatorCurrentRewardsList"].([]types.ValidatorCurrentRewardsList); ok { + genesis.ValidatorCurrentRewardsList = currentRewardsList + } else { + panic("Failed to assert ValidatorCurrentRewardsList type") + } + + if outstandingRewardsList, ok := validatorData["ValidatorOutstandingRewardsList"].([]types.ValidatorOutstandingRewardsList); ok { + genesis.ValidatorOutstandingRewardsList = outstandingRewardsList + } else { + panic("Failed to assert ValidatorOutstandingRewardsList type") + } + + if stakerRewardsList, ok := validatorData["StakerOutstandingRewardsList"].([]types.StakerOutstandingRewardsList); ok { + genesis.StakerOutstandingRewardsList = stakerRewardsList + } else { + panic("Failed to assert StakerOutstandingRewardsList type") + } + return genesis } diff --git a/x/feedistribution/keeper/keeper.go b/x/feedistribution/keeper/keeper.go index 60510d4a5..765ac17a9 100644 --- a/x/feedistribution/keeper/keeper.go +++ b/x/feedistribution/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "bytes" "fmt" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -108,6 +109,116 @@ func (k Keeper) GetValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAd return } +// GetAllValidatorData returns a slice containing all accumulated commissions for validators. +func (k Keeper) GetAllValidatorData(ctx sdk.Context) (map[string]interface{}, error) { + store := ctx.KVStore(k.storeKey) + iterator := store.Iterator(nil, nil) + defer iterator.Close() + + commissions := make([]types.ValidatorAccumulatedCommissions, 0) + currentList := make([]types.ValidatorCurrentRewardsList, 0) + outList := make([]types.ValidatorOutstandingRewardsList, 0) + stakerList := make([]types.StakerOutstandingRewardsList, 0) + + for ; iterator.Valid(); iterator.Next() { + key := iterator.Key() + value := iterator.Value() + + switch { + case bytes.HasPrefix(key, types.GetValidatorAccumulatedCommissionKey(sdk.ValAddress{})): + if err := k.processValidatorAccumulatedCommission(key, value, &commissions); err != nil { + return nil, err + } + case bytes.HasPrefix(key, types.GetValidatorCurrentRewardsKey(sdk.ValAddress{})): + if err := k.processValidatorCurrentRewards(key, value, ¤tList); err != nil { + return nil, err + } + case bytes.HasPrefix(key, types.GetValidatorOutstandingRewardsKey(sdk.ValAddress{})): + if err := k.processValidatorOutstandingRewards(key, value, &outList); err != nil { + return nil, err + } + case bytes.HasPrefix(key, types.GetStakerOutstandingRewardsKey("")): + if err := k.processStakerOutstandingRewards(key, value, &stakerList); err != nil { + return nil, err + } + default: + continue + } + } + + validatorData := map[string]interface{}{ + "ValidatorAccumulatedCommissions": commissions, + "ValidatorCurrentRewardsList": currentList, + "ValidatorOutstandingRewardsList": outList, + "StakerOutstandingRewardsList": stakerList, + } + + return validatorData, nil +} + +// processValidatorAccumulatedCommission unmarshals a validator accumulated commission from a store value +func (k Keeper) processValidatorAccumulatedCommission(key, value []byte, commissions *[]types.ValidatorAccumulatedCommissions) error { + var commission types.ValidatorAccumulatedCommission + if err := k.cdc.Unmarshal(value, &commission); err != nil { + return err + } + valAddrKey := bytes.TrimPrefix(key, types.GetValidatorAccumulatedCommissionKey(sdk.ValAddress{})) + valAddr := sdk.ValAddress(valAddrKey[1:]) + *commissions = append(*commissions, types.ValidatorAccumulatedCommissions{ + ValAddr: sdk.AccAddress(valAddr).String(), + Commission: &commission, + }) + return nil +} + +// processValidatorCurrentRewards unmarshals a validator current rewards from a store value +func (k Keeper) processValidatorCurrentRewards(key, value []byte, currentList *[]types.ValidatorCurrentRewardsList) error { + var rewards types.ValidatorCurrentRewards + if err := k.cdc.Unmarshal(value, &rewards); err != nil { + return err + } + valAddrKey := bytes.TrimPrefix(key, types.GetValidatorCurrentRewardsKey(sdk.ValAddress{})) + valAddr := sdk.ValAddress(valAddrKey[1:]) + *currentList = append(*currentList, types.ValidatorCurrentRewardsList{ + ValAddr: sdk.AccAddress(valAddr).String(), + CurrentRewards: &rewards, + }) + return nil +} + +// processValidatorOutstandingRewards unmarshals a validator outstanding rewards from a store value +func (k Keeper) processValidatorOutstandingRewards(key, value []byte, outList *[]types.ValidatorOutstandingRewardsList) error { + var outstandingRewards types.ValidatorOutstandingRewards + if err := k.cdc.Unmarshal(value, &outstandingRewards); err != nil { + return err + } + valAddrKey := bytes.TrimPrefix(key, types.GetValidatorOutstandingRewardsKey(sdk.ValAddress{})) + valAddr := sdk.ValAddress(valAddrKey[1:]) + if len(valAddr) == 0 { + return fmt.Errorf("failed to parse validator address from valAddrKey") + } + *outList = append(*outList, types.ValidatorOutstandingRewardsList{ + ValAddr: sdk.AccAddress(valAddr).String(), + OutstandingRewards: &outstandingRewards, + }) + return nil +} + +// processStakerOutstandingRewards unmarshals a staker outstanding rewards from a store value +func (k Keeper) processStakerOutstandingRewards(key, value []byte, stakerList *[]types.StakerOutstandingRewardsList) error { + var stakerRewards types.StakerOutstandingRewards + if err := k.cdc.Unmarshal(value, &stakerRewards); err != nil { + return err + } + prefix := types.GetStakerOutstandingRewardsKey("") + valAddr := bytes.TrimPrefix(key, prefix) + *stakerList = append(*stakerList, types.StakerOutstandingRewardsList{ + ValAddr: string(valAddr[1:]), + StakerOutstandingRewards: &stakerRewards, + }) + return nil +} + // set accumulated commission for a validator func (k Keeper) SetValidatorAccumulatedCommission(ctx sdk.Context, val sdk.ValAddress, commission types.ValidatorAccumulatedCommission) { var bz []byte diff --git a/x/feedistribution/types/genesis.pb.go b/x/feedistribution/types/genesis.pb.go index 6deaacd81..a0e1c7614 100644 --- a/x/feedistribution/types/genesis.pb.go +++ b/x/feedistribution/types/genesis.pb.go @@ -28,6 +28,22 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type GenesisState struct { // params defines all the parameters of the module. Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + // fee_pool is the global fee pool for distribution. + // It holds decimal coins. Once whole those coins can be burned or distributed to the community pool. + FeePool FeePool `protobuf:"bytes,2,opt,name=fee_pool,json=feePool,proto3" json:"fee_pool"` + // validator_accumulated_commissions represents accumulated commission + // for a validator kept as a running counter, can be withdrawn at any time. + ValidatorAccumulatedCommissions []ValidatorAccumulatedCommissions `protobuf:"bytes,3,rep,name=validator_accumulated_commissions,json=validatorAccumulatedCommissions,proto3" json:"validator_accumulated_commissions"` + // validator_current_rewards_list represents current rewards and current + // period for a validator kept as a running counter and incremented + // each block as long as the validator's tokens remain constant. + ValidatorCurrentRewardsList []ValidatorCurrentRewardsList `protobuf:"bytes,4,rep,name=validator_current_rewards_list,json=validatorCurrentRewardsList,proto3" json:"validator_current_rewards_list"` + // validator_outstanding_rewards_list represents outstanding (un-withdrawn) rewards + // for a validator inexpensive to track, allows simple sanity checks. + ValidatorOutstandingRewardsList []ValidatorOutstandingRewardsList `protobuf:"bytes,5,rep,name=validator_outstanding_rewards_list,json=validatorOutstandingRewardsList,proto3" json:"validator_outstanding_rewards_list"` + // staker_outstanding_rewards_list represents outstanding (un-withdrawn) rewards + // for a staker inexpensive to track, allows simple sanity checks. + StakerOutstandingRewardsList []StakerOutstandingRewardsList `protobuf:"bytes,6,rep,name=staker_outstanding_rewards_list,json=stakerOutstandingRewardsList,proto3" json:"staker_outstanding_rewards_list"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -70,8 +86,273 @@ func (m *GenesisState) GetParams() Params { return Params{} } +func (m *GenesisState) GetFeePool() FeePool { + if m != nil { + return m.FeePool + } + return FeePool{} +} + +func (m *GenesisState) GetValidatorAccumulatedCommissions() []ValidatorAccumulatedCommissions { + if m != nil { + return m.ValidatorAccumulatedCommissions + } + return nil +} + +func (m *GenesisState) GetValidatorCurrentRewardsList() []ValidatorCurrentRewardsList { + if m != nil { + return m.ValidatorCurrentRewardsList + } + return nil +} + +func (m *GenesisState) GetValidatorOutstandingRewardsList() []ValidatorOutstandingRewardsList { + if m != nil { + return m.ValidatorOutstandingRewardsList + } + return nil +} + +func (m *GenesisState) GetStakerOutstandingRewardsList() []StakerOutstandingRewardsList { + if m != nil { + return m.StakerOutstandingRewardsList + } + return nil +} + +// ValidatorAccumulatedCommissions is helper structure to store +// the validator accumulated commissions for the genesis state. +type ValidatorAccumulatedCommissions struct { + // val_addr is the address of validator + ValAddr string `protobuf:"bytes,1,opt,name=val_addr,json=valAddr,proto3" json:"val_addr,omitempty"` + // ValidatorAccumulatedCommission represents accumulated commission + // for a validator kept as a running counter, can be withdrawn at any time. + Commission *ValidatorAccumulatedCommission `protobuf:"bytes,2,opt,name=commission,proto3" json:"commission,omitempty"` +} + +func (m *ValidatorAccumulatedCommissions) Reset() { *m = ValidatorAccumulatedCommissions{} } +func (m *ValidatorAccumulatedCommissions) String() string { return proto.CompactTextString(m) } +func (*ValidatorAccumulatedCommissions) ProtoMessage() {} +func (*ValidatorAccumulatedCommissions) Descriptor() ([]byte, []int) { + return fileDescriptor_ee00a1c72b4ca316, []int{1} +} +func (m *ValidatorAccumulatedCommissions) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorAccumulatedCommissions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorAccumulatedCommissions.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 *ValidatorAccumulatedCommissions) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorAccumulatedCommissions.Merge(m, src) +} +func (m *ValidatorAccumulatedCommissions) XXX_Size() int { + return m.Size() +} +func (m *ValidatorAccumulatedCommissions) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorAccumulatedCommissions.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorAccumulatedCommissions proto.InternalMessageInfo + +func (m *ValidatorAccumulatedCommissions) GetValAddr() string { + if m != nil { + return m.ValAddr + } + return "" +} + +func (m *ValidatorAccumulatedCommissions) GetCommission() *ValidatorAccumulatedCommission { + if m != nil { + return m.Commission + } + return nil +} + +// ValidatorCurrentRewardsList is helper structure to store the validator current rewards for the genesis state. +type ValidatorCurrentRewardsList struct { + // val_addr is the address of validator + ValAddr string `protobuf:"bytes,1,opt,name=val_addr,json=valAddr,proto3" json:"val_addr,omitempty"` + // ValidatorCurrentRewards represents current rewards and current + // period for a validator kept as a running counter and incremented + // each block as long as the validator's tokens remain constant. + CurrentRewards *ValidatorCurrentRewards `protobuf:"bytes,2,opt,name=current_rewards,json=currentRewards,proto3" json:"current_rewards,omitempty"` +} + +func (m *ValidatorCurrentRewardsList) Reset() { *m = ValidatorCurrentRewardsList{} } +func (m *ValidatorCurrentRewardsList) String() string { return proto.CompactTextString(m) } +func (*ValidatorCurrentRewardsList) ProtoMessage() {} +func (*ValidatorCurrentRewardsList) Descriptor() ([]byte, []int) { + return fileDescriptor_ee00a1c72b4ca316, []int{2} +} +func (m *ValidatorCurrentRewardsList) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorCurrentRewardsList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorCurrentRewardsList.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 *ValidatorCurrentRewardsList) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorCurrentRewardsList.Merge(m, src) +} +func (m *ValidatorCurrentRewardsList) XXX_Size() int { + return m.Size() +} +func (m *ValidatorCurrentRewardsList) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorCurrentRewardsList.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorCurrentRewardsList proto.InternalMessageInfo + +func (m *ValidatorCurrentRewardsList) GetValAddr() string { + if m != nil { + return m.ValAddr + } + return "" +} + +func (m *ValidatorCurrentRewardsList) GetCurrentRewards() *ValidatorCurrentRewards { + if m != nil { + return m.CurrentRewards + } + return nil +} + +// TaskID is helper structure to store the validator outstanding rewards for the genesis state. +type ValidatorOutstandingRewardsList struct { + // val_addr is the address of validator + ValAddr string `protobuf:"bytes,1,opt,name=val_addr,json=valAddr,proto3" json:"val_addr,omitempty"` + // ValidatorOutstandingRewards represents outstanding (un-withdrawn) rewards + // for a validator inexpensive to track, allows simple sanity checks. + OutstandingRewards *ValidatorOutstandingRewards `protobuf:"bytes,2,opt,name=outstanding_rewards,json=outstandingRewards,proto3" json:"outstanding_rewards,omitempty"` +} + +func (m *ValidatorOutstandingRewardsList) Reset() { *m = ValidatorOutstandingRewardsList{} } +func (m *ValidatorOutstandingRewardsList) String() string { return proto.CompactTextString(m) } +func (*ValidatorOutstandingRewardsList) ProtoMessage() {} +func (*ValidatorOutstandingRewardsList) Descriptor() ([]byte, []int) { + return fileDescriptor_ee00a1c72b4ca316, []int{3} +} +func (m *ValidatorOutstandingRewardsList) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorOutstandingRewardsList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorOutstandingRewardsList.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 *ValidatorOutstandingRewardsList) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorOutstandingRewardsList.Merge(m, src) +} +func (m *ValidatorOutstandingRewardsList) XXX_Size() int { + return m.Size() +} +func (m *ValidatorOutstandingRewardsList) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorOutstandingRewardsList.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorOutstandingRewardsList proto.InternalMessageInfo + +func (m *ValidatorOutstandingRewardsList) GetValAddr() string { + if m != nil { + return m.ValAddr + } + return "" +} + +func (m *ValidatorOutstandingRewardsList) GetOutstandingRewards() *ValidatorOutstandingRewards { + if m != nil { + return m.OutstandingRewards + } + return nil +} + +// StakerOutstandingRewardsList is helper structure to store the staker outstanding rewards for the genesis state. +type StakerOutstandingRewardsList struct { + // val_addr is the address of validator + ValAddr string `protobuf:"bytes,1,opt,name=val_addr,json=valAddr,proto3" json:"val_addr,omitempty"` + // StakerOutstandingRewards represents outstanding (un-withdrawn) rewards + // for a staker inexpensive to track, allows simple sanity checks. + StakerOutstandingRewards *StakerOutstandingRewards `protobuf:"bytes,2,opt,name=staker_outstanding_rewards,json=stakerOutstandingRewards,proto3" json:"staker_outstanding_rewards,omitempty"` +} + +func (m *StakerOutstandingRewardsList) Reset() { *m = StakerOutstandingRewardsList{} } +func (m *StakerOutstandingRewardsList) String() string { return proto.CompactTextString(m) } +func (*StakerOutstandingRewardsList) ProtoMessage() {} +func (*StakerOutstandingRewardsList) Descriptor() ([]byte, []int) { + return fileDescriptor_ee00a1c72b4ca316, []int{4} +} +func (m *StakerOutstandingRewardsList) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StakerOutstandingRewardsList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StakerOutstandingRewardsList.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 *StakerOutstandingRewardsList) XXX_Merge(src proto.Message) { + xxx_messageInfo_StakerOutstandingRewardsList.Merge(m, src) +} +func (m *StakerOutstandingRewardsList) XXX_Size() int { + return m.Size() +} +func (m *StakerOutstandingRewardsList) XXX_DiscardUnknown() { + xxx_messageInfo_StakerOutstandingRewardsList.DiscardUnknown(m) +} + +var xxx_messageInfo_StakerOutstandingRewardsList proto.InternalMessageInfo + +func (m *StakerOutstandingRewardsList) GetValAddr() string { + if m != nil { + return m.ValAddr + } + return "" +} + +func (m *StakerOutstandingRewardsList) GetStakerOutstandingRewards() *StakerOutstandingRewards { + if m != nil { + return m.StakerOutstandingRewards + } + return nil +} + func init() { proto.RegisterType((*GenesisState)(nil), "exocore.feedistribution.v1.GenesisState") + proto.RegisterType((*ValidatorAccumulatedCommissions)(nil), "exocore.feedistribution.v1.ValidatorAccumulatedCommissions") + proto.RegisterType((*ValidatorCurrentRewardsList)(nil), "exocore.feedistribution.v1.ValidatorCurrentRewardsList") + proto.RegisterType((*ValidatorOutstandingRewardsList)(nil), "exocore.feedistribution.v1.ValidatorOutstandingRewardsList") + proto.RegisterType((*StakerOutstandingRewardsList)(nil), "exocore.feedistribution.v1.StakerOutstandingRewardsList") } func init() { @@ -79,22 +360,43 @@ func init() { } var fileDescriptor_ee00a1c72b4ca316 = []byte{ - // 227 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x48, 0xad, 0xc8, 0x4f, - 0xce, 0x2f, 0x4a, 0xd5, 0x4f, 0x4b, 0x4d, 0x4d, 0xc9, 0x2c, 0x2e, 0x29, 0xca, 0x4c, 0x2a, 0x2d, - 0xc9, 0xcc, 0xcf, 0xd3, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, - 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x82, 0xaa, 0xd4, 0x43, 0x53, 0xa9, 0x57, 0x66, 0x28, 0x25, - 0x98, 0x98, 0x9b, 0x99, 0x97, 0xaf, 0x0f, 0x26, 0x21, 0xca, 0xa5, 0xd4, 0xf1, 0x18, 0x5c, 0x90, - 0x58, 0x94, 0x98, 0x0b, 0x35, 0x57, 0x4a, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0xcc, 0xd4, 0x07, 0xb1, - 0x20, 0xa2, 0x4a, 0xa1, 0x5c, 0x3c, 0xee, 0x10, 0xeb, 0x83, 0x4b, 0x12, 0x4b, 0x52, 0x85, 0x5c, - 0xb9, 0xd8, 0x20, 0xba, 0x24, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0x94, 0xf4, 0x70, 0x3b, 0x47, - 0x2f, 0x00, 0xac, 0xd2, 0x89, 0xf3, 0xc4, 0x3d, 0x79, 0x86, 0x15, 0xcf, 0x37, 0x68, 0x31, 0x06, - 0x41, 0x35, 0x3b, 0x05, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, - 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x65, - 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0xbe, 0x2b, 0xc4, 0x68, 0xbf, 0xd4, - 0x92, 0xf2, 0xfc, 0xa2, 0x6c, 0x7d, 0x98, 0x4f, 0x2a, 0x30, 0xfc, 0x52, 0x52, 0x59, 0x90, 0x5a, - 0x9c, 0xc4, 0x06, 0x76, 0xb2, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x9a, 0x7b, 0xe3, 0xe2, 0x4c, - 0x01, 0x00, 0x00, + // 561 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x6b, 0xd4, 0x40, + 0x18, 0xc6, 0x77, 0x6c, 0xbb, 0x6d, 0xa7, 0xa2, 0x38, 0x7a, 0x58, 0xb7, 0x25, 0x5b, 0xe3, 0xc1, + 0x45, 0x30, 0xa1, 0xad, 0x50, 0xff, 0x9c, 0xba, 0xb5, 0x7a, 0x11, 0x2d, 0x59, 0xf0, 0x50, 0x84, + 0x30, 0x9b, 0xcc, 0x6e, 0x87, 0x26, 0x79, 0x97, 0x99, 0x49, 0x5a, 0xaf, 0x82, 0x47, 0xc5, 0x93, + 0xf8, 0x09, 0xc4, 0x8b, 0xe0, 0xc7, 0xa8, 0xb7, 0x1e, 0x3d, 0x89, 0xec, 0x1e, 0xfc, 0x1a, 0xd2, + 0x24, 0x25, 0xdd, 0x6e, 0x33, 0xda, 0xbd, 0x84, 0xcc, 0xf0, 0xbc, 0xcf, 0xfc, 0x78, 0xdf, 0x87, + 0x17, 0x37, 0xd9, 0x01, 0x78, 0x20, 0x98, 0xdd, 0x65, 0xcc, 0xe7, 0x52, 0x09, 0xde, 0x89, 0x15, + 0x87, 0xc8, 0x4e, 0x56, 0xec, 0x1e, 0x8b, 0x98, 0xe4, 0xd2, 0xea, 0x0b, 0x50, 0x40, 0xea, 0xb9, + 0xd2, 0x3a, 0xa3, 0xb4, 0x92, 0x95, 0xfa, 0x35, 0x1a, 0xf2, 0x08, 0xec, 0xf4, 0x9b, 0xc9, 0xeb, + 0xf7, 0x34, 0xc6, 0x23, 0xe5, 0x99, 0xfc, 0x8e, 0x46, 0xde, 0xa7, 0x82, 0x86, 0x39, 0x46, 0xfd, + 0x46, 0x0f, 0x7a, 0x90, 0xfe, 0xda, 0xc7, 0x7f, 0xd9, 0xad, 0xf9, 0x63, 0x06, 0x5f, 0x7e, 0x96, + 0xe1, 0xb6, 0x15, 0x55, 0x8c, 0x6c, 0xe1, 0x6a, 0x56, 0x56, 0x43, 0xcb, 0xa8, 0xb9, 0xb0, 0x6a, + 0x5a, 0xe5, 0xf8, 0xd6, 0x76, 0xaa, 0x6c, 0xcd, 0x1f, 0xfe, 0x6a, 0x54, 0xbe, 0xfe, 0xf9, 0x7e, + 0x17, 0x39, 0x79, 0x31, 0x79, 0x82, 0xe7, 0xba, 0x8c, 0xb9, 0x7d, 0x80, 0xa0, 0x76, 0x29, 0x35, + 0xba, 0xad, 0x33, 0x7a, 0xca, 0xd8, 0x36, 0x40, 0xd0, 0x9a, 0x3e, 0x76, 0x72, 0x66, 0xbb, 0xd9, + 0x91, 0xbc, 0x47, 0xf8, 0x56, 0x42, 0x03, 0xee, 0x53, 0x05, 0xc2, 0xa5, 0x9e, 0x17, 0x87, 0x71, + 0x40, 0x15, 0xf3, 0x5d, 0x0f, 0xc2, 0x90, 0x4b, 0xc9, 0x21, 0x92, 0xb5, 0xa9, 0xe5, 0xa9, 0xe6, + 0xc2, 0xea, 0x63, 0x9d, 0xff, 0xab, 0x13, 0x93, 0x8d, 0xc2, 0x63, 0xb3, 0xb0, 0xc8, 0xdf, 0x6d, + 0x24, 0x7a, 0x19, 0x79, 0x8b, 0xb0, 0x51, 0xf0, 0x78, 0xb1, 0x10, 0x2c, 0x52, 0xae, 0x60, 0xfb, + 0x54, 0xf8, 0xd2, 0x0d, 0xb8, 0x54, 0xb5, 0xe9, 0x14, 0x66, 0xfd, 0xbf, 0x60, 0x36, 0x33, 0x03, + 0x27, 0xab, 0x7f, 0xce, 0xa5, 0xca, 0x41, 0x16, 0x93, 0x72, 0x09, 0xf9, 0x80, 0xb0, 0x59, 0x40, + 0x40, 0xac, 0xa4, 0xa2, 0x91, 0xcf, 0xa3, 0xde, 0x28, 0xc8, 0xcc, 0x05, 0xba, 0xf2, 0xb2, 0x30, + 0x19, 0x87, 0x29, 0xba, 0x72, 0xbe, 0x8c, 0xbc, 0x43, 0xb8, 0x21, 0x15, 0xdd, 0x63, 0x1a, 0x9a, + 0x6a, 0x4a, 0xf3, 0x40, 0x47, 0xd3, 0x4e, 0x2d, 0xb4, 0x28, 0x4b, 0x52, 0xa3, 0x31, 0x3f, 0x23, + 0xdc, 0xf8, 0xc7, 0xa0, 0xc9, 0x4d, 0x3c, 0x97, 0xd0, 0xc0, 0xa5, 0xbe, 0x2f, 0xd2, 0x80, 0xcf, + 0x3b, 0xb3, 0x09, 0x0d, 0x36, 0x7c, 0x5f, 0x90, 0x1d, 0x8c, 0x8b, 0x54, 0xe5, 0xa1, 0x7d, 0x34, + 0x79, 0xa8, 0x9c, 0x53, 0x6e, 0xe6, 0x27, 0x84, 0x17, 0x35, 0x63, 0xd7, 0x61, 0xbd, 0xc6, 0x57, + 0xcf, 0x04, 0x2d, 0x67, 0x5b, 0x9b, 0x20, 0x63, 0xce, 0x15, 0x6f, 0xe4, 0x6c, 0x7e, 0x39, 0xdd, + 0xb3, 0x92, 0xf9, 0x6a, 0xe0, 0x76, 0xf1, 0xf5, 0x73, 0x46, 0x9e, 0x03, 0xae, 0x4f, 0x98, 0x3d, + 0x87, 0xc0, 0xd8, 0x9d, 0xf9, 0x0d, 0xe1, 0x25, 0x5d, 0x42, 0x74, 0x94, 0x02, 0xd7, 0xcb, 0xf3, + 0x99, 0xc3, 0xde, 0x9f, 0x24, 0x9a, 0x4e, 0xad, 0x2c, 0x90, 0xad, 0xf6, 0xe1, 0xc0, 0x40, 0x47, + 0x03, 0x03, 0xfd, 0x1e, 0x18, 0xe8, 0xe3, 0xd0, 0xa8, 0x1c, 0x0d, 0x8d, 0xca, 0xcf, 0xa1, 0x51, + 0xd9, 0x79, 0xd8, 0xe3, 0x6a, 0x37, 0xee, 0x58, 0x1e, 0x84, 0xf6, 0x56, 0xf6, 0xe6, 0x0b, 0xa6, + 0xf6, 0x41, 0xec, 0xd9, 0x27, 0xbb, 0xfc, 0x60, 0x6c, 0x9b, 0xab, 0x37, 0x7d, 0x26, 0x3b, 0xd5, + 0x74, 0x69, 0xaf, 0xfd, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xdb, 0x55, 0x7e, 0x2d, 0x7d, 0x06, 0x00, + 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -117,48 +419,982 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.StakerOutstandingRewardsList) > 0 { + for iNdEx := len(m.StakerOutstandingRewardsList) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.StakerOutstandingRewardsList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } + if len(m.ValidatorOutstandingRewardsList) > 0 { + for iNdEx := len(m.ValidatorOutstandingRewardsList) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ValidatorOutstandingRewardsList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } + if len(m.ValidatorCurrentRewardsList) > 0 { + for iNdEx := len(m.ValidatorCurrentRewardsList) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ValidatorCurrentRewardsList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.ValidatorAccumulatedCommissions) > 0 { + for iNdEx := len(m.ValidatorAccumulatedCommissions) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ValidatorAccumulatedCommissions[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + { + size, err := m.FeePool.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 { size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *ValidatorAccumulatedCommissions) 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 *ValidatorAccumulatedCommissions) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorAccumulatedCommissions) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Commission != nil { + { + size, err := m.Commission.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.ValAddr) > 0 { + i -= len(m.ValAddr) + copy(dAtA[i:], m.ValAddr) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ValAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ValidatorCurrentRewardsList) 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 *ValidatorCurrentRewardsList) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorCurrentRewardsList) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.CurrentRewards != nil { + { + size, err := m.CurrentRewards.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.ValAddr) > 0 { + i -= len(m.ValAddr) + copy(dAtA[i:], m.ValAddr) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ValAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ValidatorOutstandingRewardsList) 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 *ValidatorOutstandingRewardsList) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorOutstandingRewardsList) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.OutstandingRewards != nil { + { + size, err := m.OutstandingRewards.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.ValAddr) > 0 { + i -= len(m.ValAddr) + copy(dAtA[i:], m.ValAddr) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ValAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *StakerOutstandingRewardsList) 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 *StakerOutstandingRewardsList) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StakerOutstandingRewardsList) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.StakerOutstandingRewards != nil { + { + size, err := m.StakerOutstandingRewards.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.ValAddr) > 0 { + i -= len(m.ValAddr) + copy(dAtA[i:], m.ValAddr) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.ValAddr))) + 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 + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = m.FeePool.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.ValidatorAccumulatedCommissions) > 0 { + for _, e := range m.ValidatorAccumulatedCommissions { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ValidatorCurrentRewardsList) > 0 { + for _, e := range m.ValidatorCurrentRewardsList { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.ValidatorOutstandingRewardsList) > 0 { + for _, e := range m.ValidatorOutstandingRewardsList { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.StakerOutstandingRewardsList) > 0 { + for _, e := range m.StakerOutstandingRewardsList { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *ValidatorAccumulatedCommissions) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValAddr) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.Commission != nil { + l = m.Commission.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *ValidatorCurrentRewardsList) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValAddr) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.CurrentRewards != nil { + l = m.CurrentRewards.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *ValidatorOutstandingRewardsList) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValAddr) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.OutstandingRewards != nil { + l = m.OutstandingRewards.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + return n +} + +func (m *StakerOutstandingRewardsList) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValAddr) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + if m.StakerOutstandingRewards != nil { + l = m.StakerOutstandingRewards.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 Params", 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 + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeePool", 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 + } + if err := m.FeePool.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAccumulatedCommissions", 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.ValidatorAccumulatedCommissions = append(m.ValidatorAccumulatedCommissions, ValidatorAccumulatedCommissions{}) + if err := m.ValidatorAccumulatedCommissions[len(m.ValidatorAccumulatedCommissions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorCurrentRewardsList", 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.ValidatorCurrentRewardsList = append(m.ValidatorCurrentRewardsList, ValidatorCurrentRewardsList{}) + if err := m.ValidatorCurrentRewardsList[len(m.ValidatorCurrentRewardsList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorOutstandingRewardsList", 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.ValidatorOutstandingRewardsList = append(m.ValidatorOutstandingRewardsList, ValidatorOutstandingRewardsList{}) + if err := m.ValidatorOutstandingRewardsList[len(m.ValidatorOutstandingRewardsList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StakerOutstandingRewardsList", 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.StakerOutstandingRewardsList = append(m.StakerOutstandingRewardsList, StakerOutstandingRewardsList{}) + if err := m.StakerOutstandingRewardsList[len(m.StakerOutstandingRewardsList)-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 *ValidatorAccumulatedCommissions) 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: ValidatorAccumulatedCommissions: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorAccumulatedCommissions: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValAddr", 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.ValAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Commission", 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 + } + if m.Commission == nil { + m.Commission = &ValidatorAccumulatedCommission{} + } + if err := m.Commission.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 *ValidatorCurrentRewardsList) 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: ValidatorCurrentRewardsList: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorCurrentRewardsList: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValAddr", 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.ValAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentRewards", 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 + } + if m.CurrentRewards == nil { + m.CurrentRewards = &ValidatorCurrentRewards{} + } + if err := m.CurrentRewards.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 + } } - 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++ + if iNdEx > l { + return io.ErrUnexpectedEOF } - dAtA[offset] = uint8(v) - return base + return nil } -func (m *GenesisState) Size() (n int) { - if m == nil { - return 0 +func (m *ValidatorOutstandingRewardsList) 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: ValidatorOutstandingRewardsList: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorOutstandingRewardsList: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValAddr", 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.ValAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OutstandingRewards", 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 + } + if m.OutstandingRewards == nil { + m.OutstandingRewards = &ValidatorOutstandingRewards{} + } + if err := m.OutstandingRewards.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 + } } - var l int - _ = l - l = m.Params.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)))) + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil } -func (m *GenesisState) Unmarshal(dAtA []byte) error { +func (m *StakerOutstandingRewardsList) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -181,15 +1417,47 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + return fmt.Errorf("proto: StakerOutstandingRewardsList: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: StakerOutstandingRewardsList: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ValAddr", 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.ValAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StakerOutstandingRewards", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -216,7 +1484,10 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if m.StakerOutstandingRewards == nil { + m.StakerOutstandingRewards = &StakerOutstandingRewards{} + } + if err := m.StakerOutstandingRewards.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/operator/keeper/operator.go b/x/operator/keeper/operator.go index 72f292ddc..3e8f65196 100644 --- a/x/operator/keeper/operator.go +++ b/x/operator/keeper/operator.go @@ -192,7 +192,9 @@ func (k *Keeper) GetOptedInAVSForOperator(ctx sdk.Context, operatorAddr string) if err != nil { return nil, err } - avsList = append(avsList, keys[1]) + if k.IsOptedIn(ctx, keys[0], keys[1]) { + avsList = append(avsList, keys[1]) + } } return avsList, nil } @@ -236,7 +238,7 @@ func (k *Keeper) GetOptedInOperatorListByAVS(ctx sdk.Context, avsAddr string) ([ if err != nil { return nil, err } - if strings.ToLower(avsAddr) == keys[1] { + if strings.ToLower(avsAddr) == keys[1] && k.IsOptedIn(ctx, keys[0], keys[1]) { operatorList = append(operatorList, keys[0]) } }