-
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.
Merge pull request #27 from MaxMustermann2/feat/genesis-operator
feat(operator): load genesis state
- Loading branch information
Showing
16 changed files
with
2,379 additions
and
123 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,91 @@ | ||
syntax = "proto3"; | ||
package exocore.operator.v1; | ||
|
||
import "cosmos_proto/cosmos.proto"; | ||
import "gogoproto/gogo.proto"; | ||
|
||
import "exocore/operator/v1/tx.proto"; | ||
|
||
option go_package = "github.com/ExocoreNetwork/exocore/x/operator/types"; | ||
|
||
// GenesisState defines the operator module's genesis state. | ||
message GenesisState { | ||
// there are no params for this module. | ||
// operators is a list of the registered operators. | ||
repeated OperatorInfo operators = 1 [(gogoproto.nullable) = false]; | ||
// operator_records refers to a list of operator records. each record | ||
// contains an operator address and a list of chain id + | ||
// cons key combination. | ||
repeated OperatorConsKeyRecord operator_records = 2 | ||
[(gogoproto.nullable) = false]; | ||
// TODO: add other AVS opt-in information for exporting / importing. | ||
// Although it is not necessary for the bootstrapped genesis, it is | ||
// necessary for chain restarts. | ||
} | ||
|
||
// OperatorConsKeyRecord is a helper structure for the genesis state. Each record | ||
// contains an operator address and a list of chain id + cons key combination. | ||
message OperatorConsKeyRecord { | ||
// operator_address is the address of the operator as the bech32 | ||
// encoded version of sdk.AccAddress. | ||
string operator_address = 1; | ||
// chains is a list of chain id + consensus key combination. | ||
repeated ChainDetails chains = 2 [(gogoproto.nullable) = false]; | ||
} | ||
|
||
// ChainDetails is a helper structure for the genesis state. Each record | ||
// contains a chain id and a consensus key. | ||
message ChainDetails { | ||
// chain_id is the unique identifier of the chain. | ||
string chain_id = 1 [(gogoproto.customname) = "ChainID"]; | ||
// consensus_key is the consensus key of the operator on the chain. | ||
// the length of this key should be exactly 32 bytes, and must be enforced | ||
// outside of protobuf. | ||
string consensus_key = 2; | ||
} | ||
|
||
// all operators in the genesis (during bootstrap) are assumed to have | ||
// opted into validating Exocore. however, we still need to set their opt-in | ||
// data. we can do this by calling k.OptIn(ctx, sdk.AccAddress, ctx.ChainID()) | ||
|
||
// this will then allow us to call | ||
// k.UpdateOptedInAssetsState(ctx, staker, assetID, operator, stakedValue) | ||
// for now, we keep this data in the genesis as the order stored, but | ||
// it would be trivial to alter the order if deemed necessary. | ||
// this relies in GetSpecifiedAssetsPrice, GetStakingAssetInfo, GetAvsSupportedAssets | ||
// the first and third need to be set up and done before this genesis. | ||
// the second is already set up before this genesis. | ||
|
||
// StakerRecord is a helper structure for the genesis state. Each record | ||
// contains a staker address and a list of asset IDs with their operator + | ||
// amount combination. | ||
message StakerRecord { | ||
// staker_id denotes the address + l0id of the staker. | ||
string staker_id = 1 [(gogoproto.customname) = "StakerID"]; | ||
// staker_details is a list of asset ID + operator + amount combination. | ||
repeated StakerDetails staker_details = 2 [(gogoproto.nullable) = false]; | ||
} | ||
|
||
// StakerDetails is a helper structure for the genesis state. Each record | ||
// contains an asset ID and a list of operator + amount combination. | ||
message StakerDetails { | ||
// asset_id is the unique identifier of the asset. | ||
string asset_id = 1 [(gogoproto.customname) = "AssetID"]; | ||
// details is a list of operator + amount combination. | ||
repeated AssetDetails details = 2 [(gogoproto.nullable) = false]; | ||
} | ||
|
||
// AssetDetails is a helper structure for the genesis state. Each record | ||
// contains an operator and an amount. | ||
message AssetDetails { | ||
// operator_address is the address of the operator as the bech32 | ||
// version of sdk.AccAddress. | ||
string operator_address = 1; | ||
// amount is the amount of the asset staked by the staker for this | ||
// asset and operator. | ||
string amount = 2 [ | ||
(cosmos_proto.scalar) = "cosmos.Int", | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.nullable) = false | ||
]; | ||
} |
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,47 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/ExocoreNetwork/exocore/x/operator/types" | ||
abci "github.com/cometbft/cometbft/abci/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) []abci.ValidatorUpdate { | ||
for i := range state.Operators { | ||
op := state.Operators[i] // avoid implicit memory aliasing | ||
if err := k.SetOperatorInfo(ctx, op.EarningsAddr, &op); err != nil { | ||
panic(err) | ||
} | ||
} | ||
for _, record := range state.OperatorRecords { | ||
addr := record.OperatorAddress | ||
// #nosec G703 // already validated | ||
operatorAddr, _ := sdk.AccAddressFromBech32(addr) | ||
for _, detail := range record.Chains { | ||
chainID := detail.ChainID | ||
// validate that the chain exists | ||
// TODO: move this to the avs keeper when it is merged. | ||
if !k.assetsKeeper.AppChainInfoIsExist(ctx, chainID) { | ||
panic("chain info not found") | ||
} | ||
// opt into the specified chain (TODO: avs address format) | ||
if err := k.OptIn(ctx, operatorAddr, chainID); err != nil { | ||
panic(err) | ||
} | ||
// #nosec G703 // already validated | ||
key, _ := types.HexStringToPubKey(detail.ConsensusKey) | ||
// then set pub key | ||
if err := k.setOperatorConsKeyForChainID( | ||
ctx, operatorAddr, chainID, key, true, | ||
); err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
return []abci.ValidatorUpdate{} | ||
} | ||
|
||
func (Keeper) ExportGenesis(sdk.Context) *types.GenesisState { | ||
// TODO | ||
return types.DefaultGenesis() | ||
} |
Oops, something went wrong.