Skip to content

Commit

Permalink
fix test/lint err
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd committed Nov 1, 2024
1 parent 7b8b7ad commit 8d1059b
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 14 deletions.
4 changes: 2 additions & 2 deletions x/avs/keeper/avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ func (k *Keeper) GetAllChainIDInfos(ctx sdk.Context) ([]types.ChainIDInfo, error
ret := make([]types.ChainIDInfo, 0)
for ; iterator.Valid(); iterator.Next() {
avsAddr := strings.ToLower(common.BytesToAddress(iterator.Key()).Hex())
chainID := iterator.Value()
chainID := string(iterator.Value())

ret = append(ret, types.ChainIDInfo{
AvsAddress: avsAddr,
ChainId: string(chainID),
ChainId: chainID,
})
}
return ret, nil
Expand Down
5 changes: 4 additions & 1 deletion x/avs/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
// 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, 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)
// Set all the avs infos
for _, avs := range state.AvsInfos {
err := k.SetAVSInfo(ctx, &avs) //nolint:gosec
Expand Down Expand Up @@ -37,7 +40,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {
}
// Set all the task result infos
for _, elem := range state.TaskResultInfos {
k.SetTaskResultInfo(ctx, &elem)
k.SetTaskResultInfo(ctx, &elem) //nolint:gosec
}
// Set all the task challenge infos
err := k.SetAllTaskChallengedInfo(ctx, state.ChallengeInfos)
Expand Down
3 changes: 2 additions & 1 deletion x/avs/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bytes"
"encoding/hex"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
"slices"
"strconv"

"github.com/ethereum/go-ethereum/crypto"

"github.com/prysmaticlabs/prysm/v4/crypto/bls"
"github.com/prysmaticlabs/prysm/v4/crypto/bls/blst"

Expand Down
8 changes: 7 additions & 1 deletion x/avs/keeper/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ func (k *Keeper) GetAllTaskNums(ctx sdk.Context) ([]types.TaskID, error) {
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))
}
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)
Expand All @@ -204,7 +210,7 @@ func (k *Keeper) GetTaskResultInfo(ctx sdk.Context, operatorAddress, taskContrac
return nil, types.ErrInvalidAddr
}
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixTaskResult)
infoKey := assetstype.GetJoinedStoreKey(operatorAddress, taskContractAddress,
infoKey := assetstype.GetJoinedStoreKey(operatorAddress, strings.ToLower(taskContractAddress),
strconv.FormatUint(taskID, 10))
value := store.Get(infoKey)
if value == nil {
Expand Down
49 changes: 48 additions & 1 deletion x/avs/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ func NewGenesisState(
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{
AvsInfos: avsInfos,
TaskInfos: taskInfos,
Expand All @@ -33,7 +55,32 @@ func DefaultGenesis() *GenesisState {
// 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
// Helper to check for duplicates in a slice
// seenAddresses := make(map[string]bool)
//
//// Validate AVS infos
// for _, info := range gs.AvsInfos {
// if err := sdk.ValidateAccAddress(info.Address); err != nil {
// return fmt.Errorf("invalid AVS address: %w", err)
// }
// if seenAddresses[info.Address] {
// return fmt.Errorf("duplicate AVS address: %s", info.Address)
// }
// seenAddresses[info.Address] = true
//}
//
// // Validate task IDs correspond to task infos
// taskInfoMap := make(map[string]bool)
// for _, info := range gs.TaskInfos {
// taskInfoMap[info.ID] = true
//}
// for _, taskNum := range gs.TaskNums {
// if !taskInfoMap[taskNum] {
// return fmt.Errorf("task ID %s referenced but not found in task infos", taskNum)
// }
//}

// Add more validation as needed...

return nil
}
33 changes: 25 additions & 8 deletions x/feedistribution/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,36 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)

feelPool := k.GetFeePool(ctx)

genesis.FeePool = *feelPool
var err error

validatorData, err := k.GetAllValidatorData(ctx)
if err != nil {
panic(errorsmod.Wrap(err, "Error getting validator data").Error())
}
genesis.ValidatorAccumulatedCommissions = validatorData["ValidatorAccumulatedCommissions"].([]types.ValidatorAccumulatedCommissions)
genesis.ValidatorCurrentRewardsList = validatorData["ValidatorCurrentRewardsList"].([]types.ValidatorCurrentRewardsList)
genesis.ValidatorOutstandingRewardsList = validatorData["ValidatorOutstandingRewardsList"].([]types.ValidatorOutstandingRewardsList)
genesis.StakerOutstandingRewardsList = validatorData["StakerOutstandingRewardsList"].([]types.StakerOutstandingRewardsList)

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
}
3 changes: 3 additions & 0 deletions x/feedistribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ func (k Keeper) processValidatorOutstandingRewards(key, value []byte, outList *[
}
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,
Expand Down

0 comments on commit 8d1059b

Please sign in to comment.