Skip to content

Commit

Permalink
feat(evmstaking): add validation of epoch duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Narangde committed Sep 22, 2024
1 parent 37d3d7d commit a6c4fd5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
23 changes: 23 additions & 0 deletions client/x/evmstaking/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func (k Keeper) InitGenesis(ctx context.Context, gs *types.GenesisState) error {
return err
}

// The epoch duration must be less than or equal to the unbonding time.
if err := k.validateEpochDuration(ctx, gs.Params.EpochIdentifier); err != nil {
panic(err)
}

if err := k.WithdrawalQueue.Initialize(ctx); err != nil {
log.Error(ctx, "InitGenesis.evmstaking not initialized", err)
return err
Expand Down Expand Up @@ -106,3 +111,21 @@ func (k Keeper) ValidateGenesis(gs *types.GenesisState) error {

return types.ValidateEpochIdentifier(gs.Params.EpochIdentifier)
}

func (k Keeper) validateEpochDuration(ctx context.Context, epochIdentifier string) error {
unbondingTime, err := k.stakingKeeper.UnbondingTime(ctx)
if err != nil {
return errors.Wrap(err, "get unbonding time of staking keeper")
}

epoch, err := k.epochsKeeper.GetEpochInfo(ctx, epochIdentifier)
if err != nil {
return errors.Wrap(err, "get epoch info from epochs keeper", "epoch_identifier", epochIdentifier)
}

if epoch.Duration > unbondingTime {
return errors.New("epoch duration must be less than or equal to the unbonding time", "unbondind_time", unbondingTime, "epoch_duration", epoch.Duration)
}

return nil
}
15 changes: 15 additions & 0 deletions client/x/evmstaking/testutil/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/x/evmstaking/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type StakingKeeper interface {
GetValidator(ctx context.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, err error)
GetAllValidators(ctx context.Context) (validators []stakingtypes.Validator, err error)
BondDenom(ctx context.Context) (string, error)
UnbondingTime(ctx context.Context) (time.Duration, error)

UBDQueueIterator(ctx context.Context, endTime time.Time) (corestore.Iterator, error)
// GetUnbondingDelegation returns a unbonding delegation.
Expand Down

0 comments on commit a6c4fd5

Please sign in to comment.