-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(genesis export): genesis exporting for avs,distribution modules (#…
…209) * impl genesis exporting for avs,distribution * fix dogfood initgenesis duplicate registration of avs * add UT for exportGenesis * fix validatorAddr in initGenesis of distribution module * fix test err
- Loading branch information
1 parent
a361c1d
commit b4a331e
Showing
23 changed files
with
3,499 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 an optional parameter to specify the chain_id of the AVS, if any | ||
string chain_id = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,104 @@ | ||
package keeper | ||
|
||
import ( | ||
"strings" | ||
|
||
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 { | ||
avs.AvsAddress = strings.ToLower(avs.AvsAddress) | ||
avs.TaskAddr = strings.ToLower(avs.TaskAddr) | ||
avs.RewardAddr = strings.ToLower(avs.RewardAddr) | ||
avs.SlashAddr = strings.ToLower(avs.SlashAddr) | ||
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 { | ||
elem.TaskContractAddress = strings.ToLower(elem.TaskContractAddress) | ||
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 { | ||
elem.TaskAddr = strings.ToLower(elem.TaskAddr) | ||
k.SetTaskID(ctx, common.HexToAddress(elem.TaskAddr), elem.TaskId) | ||
} | ||
// Set all the task result infos | ||
for _, elem := range state.TaskResultInfos { | ||
elem.TaskContractAddress = strings.ToLower(elem.TaskContractAddress) | ||
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 { | ||
elem.AvsAddress = strings.ToLower(elem.AvsAddress) | ||
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 | ||
} |
Oops, something went wrong.