refactor(core,x/**): simplify core service api and embed environment in keepers (#20071)
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
// IterateValidators iterates through the validator set and perform the provided function
|
||||
func (k Keeper) IterateValidators(ctx context.Context, fn func(index int64, validator sdk.ValidatorI) (stop bool)) error {
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
iterator, err := store.Iterator(types.ValidatorsKey, storetypes.PrefixEndBytes(types.ValidatorsKey))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -42,7 +42,7 @@ func (k Keeper) IterateValidators(ctx context.Context, fn func(index int64, vali
|
||||
|
||||
// IterateBondedValidatorsByPower iterates through the bonded validator set and perform the provided function
|
||||
func (k Keeper) IterateBondedValidatorsByPower(ctx context.Context, fn func(index int64, validator sdk.ValidatorI) (stop bool)) error {
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
maxValidators, err := k.MaxValidators(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -119,7 +119,7 @@ func (k Keeper) IterateDelegations(ctx context.Context, delAddr sdk.AccAddress,
|
||||
// GetAllSDKDelegations returns all delegations used during genesis dump
|
||||
// TODO: remove this func, change all usage for iterate functionality
|
||||
func (k Keeper) GetAllSDKDelegations(ctx context.Context) (delegations []types.Delegation, err error) {
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
iterator, err := store.Iterator(types.DelegationKey, storetypes.PrefixEndBytes(types.DelegationKey))
|
||||
if err != nil {
|
||||
return delegations, err
|
||||
|
||||
@@ -25,7 +25,7 @@ func (k Keeper) setConsPubKeyRotationHistory(
|
||||
ctx context.Context, valAddr sdk.ValAddress,
|
||||
oldPubKey, newPubKey *codectypes.Any, fee sdk.Coin,
|
||||
) error {
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
height := uint64(headerInfo.Height)
|
||||
history := types.ConsPubKeyRotationHistory{
|
||||
OperatorAddress: valAddr.Bytes(),
|
||||
@@ -233,7 +233,7 @@ func (k Keeper) getAndRemoveAllMaturedRotatedKeys(ctx context.Context, matureTim
|
||||
|
||||
// GetBlockConsPubKeyRotationHistory returns the rotation history for the current height.
|
||||
func (k Keeper) GetBlockConsPubKeyRotationHistory(ctx context.Context) ([]types.ConsPubKeyRotationHistory, error) {
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
|
||||
iterator, err := k.RotationHistory.Indexes.Block.MatchExact(ctx, uint64(headerInfo.Height))
|
||||
if err != nil {
|
||||
|
||||
@@ -165,7 +165,7 @@ func (k Keeper) GetUnbondingDelegation(ctx context.Context, delAddr sdk.AccAddre
|
||||
// GetUnbondingDelegationsFromValidator returns all unbonding delegations from a
|
||||
// particular validator.
|
||||
func (k Keeper) GetUnbondingDelegationsFromValidator(ctx context.Context, valAddr sdk.ValAddress) (ubds []types.UnbondingDelegation, err error) {
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
rng := collections.NewPrefixedPairRange[[]byte, []byte](valAddr)
|
||||
err = k.UnbondingDelegationByValIndex.Walk(
|
||||
ctx,
|
||||
@@ -652,7 +652,7 @@ func (k Keeper) InsertRedelegationQueue(ctx context.Context, red types.Redelegat
|
||||
// the queue.
|
||||
func (k Keeper) DequeueAllMatureRedelegationQueue(ctx context.Context, currTime time.Time) (matureRedelegations []types.DVVTriplet, err error) {
|
||||
var keys []time.Time
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
|
||||
// gets an iterator for all timeslices from time 0 until the current Blockheader time
|
||||
rng := (&collections.Range[time.Time]{}).EndInclusive(headerInfo.Time)
|
||||
@@ -889,7 +889,7 @@ func (k Keeper) getBeginInfo(
|
||||
if err != nil && errors.Is(err, types.ErrNoValidatorFound) {
|
||||
return completionTime, height, false, nil
|
||||
}
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
unbondingTime, err := k.UnbondingTime(ctx)
|
||||
if err != nil {
|
||||
return completionTime, height, false, err
|
||||
@@ -955,7 +955,7 @@ func (k Keeper) Undelegate(
|
||||
return time.Time{}, math.Int{}, err
|
||||
}
|
||||
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
completionTime := headerInfo.Time.Add(unbondingTime)
|
||||
ubd, err := k.SetUnbondingDelegationEntry(ctx, delAddr, valAddr, headerInfo.Height, completionTime, returnAmount)
|
||||
if err != nil {
|
||||
@@ -985,7 +985,7 @@ func (k Keeper) CompleteUnbonding(ctx context.Context, delAddr sdk.AccAddress, v
|
||||
}
|
||||
|
||||
balances := sdk.NewCoins()
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
ctxTime := headerInfo.Time
|
||||
|
||||
delegatorAddress, err := k.authKeeper.AddressCodec().StringToBytes(ubd.DelegatorAddress)
|
||||
@@ -1130,7 +1130,7 @@ func (k Keeper) CompleteRedelegation(
|
||||
}
|
||||
|
||||
balances := sdk.NewCoins()
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
ctxTime := headerInfo.Time
|
||||
|
||||
// loop through all the entries and complete mature redelegation entries
|
||||
|
||||
@@ -40,7 +40,7 @@ func (k Querier) Validators(ctx context.Context, req *types.QueryValidatorsReque
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid validator status %s", req.Status)
|
||||
}
|
||||
|
||||
store := runtime.KVStoreAdapter(k.environment.KVStoreService.OpenKVStore(ctx))
|
||||
store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx))
|
||||
valStore := prefix.NewStore(store, types.ValidatorsKey)
|
||||
|
||||
validators, pageRes, err := query.GenericFilteredPaginate(k.cdc, valStore, req.Pagination, func(key []byte, val *types.Validator) (*types.Validator, error) {
|
||||
@@ -143,7 +143,7 @@ func (k Querier) ValidatorDelegations(ctx context.Context, req *types.QueryValid
|
||||
}
|
||||
|
||||
func (k Querier) getValidatorDelegationsLegacy(ctx context.Context, req *types.QueryValidatorDelegationsRequest) ([]*types.Delegation, *query.PageResponse, error) {
|
||||
store := runtime.KVStoreAdapter(k.environment.KVStoreService.OpenKVStore(ctx))
|
||||
store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx))
|
||||
|
||||
valStore := prefix.NewStore(store, types.DelegationKey)
|
||||
return query.GenericFilteredPaginate(k.cdc, valStore, req.Pagination, func(key []byte, delegation *types.Delegation) (*types.Delegation, error) {
|
||||
@@ -177,7 +177,7 @@ func (k Querier) ValidatorUnbondingDelegations(ctx context.Context, req *types.Q
|
||||
return nil, err
|
||||
}
|
||||
|
||||
store := runtime.KVStoreAdapter(k.environment.KVStoreService.OpenKVStore(ctx))
|
||||
store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx))
|
||||
keys, pageRes, err := query.CollectionPaginate(
|
||||
ctx,
|
||||
k.UnbondingDelegationByValIndex,
|
||||
@@ -414,12 +414,12 @@ func (k Querier) Redelegations(ctx context.Context, req *types.QueryRedelegation
|
||||
var pageRes *query.PageResponse
|
||||
var err error
|
||||
|
||||
store := runtime.KVStoreAdapter(k.environment.KVStoreService.OpenKVStore(ctx))
|
||||
store := runtime.KVStoreAdapter(k.KVStoreService.OpenKVStore(ctx))
|
||||
switch {
|
||||
case req.DelegatorAddr != "" && req.SrcValidatorAddr != "" && req.DstValidatorAddr != "":
|
||||
redels, err = queryRedelegation(ctx, k, req)
|
||||
case req.DelegatorAddr == "" && req.SrcValidatorAddr != "" && req.DstValidatorAddr == "":
|
||||
redels, pageRes, err = queryRedelegationsFromSrcValidator(ctx, store, k, req)
|
||||
redels, pageRes, err = queryRedelegationsFromSrcValidator(ctx, k, req)
|
||||
default:
|
||||
redels, pageRes, err = queryAllRedelegations(ctx, store, k, req)
|
||||
}
|
||||
@@ -526,7 +526,7 @@ func queryRedelegation(ctx context.Context, k Querier, req *types.QueryRedelegat
|
||||
return redels, nil
|
||||
}
|
||||
|
||||
func queryRedelegationsFromSrcValidator(ctx context.Context, store storetypes.KVStore, k Querier, req *types.QueryRedelegationsRequest) (types.Redelegations, *query.PageResponse, error) {
|
||||
func queryRedelegationsFromSrcValidator(ctx context.Context, k Querier, req *types.QueryRedelegationsRequest) (types.Redelegations, *query.PageResponse, error) {
|
||||
valAddr, err := k.validatorAddressCodec.StringToBytes(req.SrcValidatorAddr)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -16,7 +16,7 @@ func (k Keeper) TrackHistoricalInfo(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
|
||||
// Prune store to ensure we only have parameter-defined historical entries.
|
||||
// In most cases, this will involve removing a single historical entry.
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"cosmossdk.io/collections/indexes"
|
||||
addresscodec "cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/math"
|
||||
"cosmossdk.io/x/staking/types"
|
||||
|
||||
@@ -68,7 +67,8 @@ func NewRotationHistoryIndexes(sb *collections.SchemaBuilder) rotationHistoryInd
|
||||
|
||||
// Keeper of the x/staking store
|
||||
type Keeper struct {
|
||||
environment appmodule.Environment
|
||||
appmodule.Environment
|
||||
|
||||
cdc codec.BinaryCodec
|
||||
authKeeper types.AccountKeeper
|
||||
bankKeeper types.BankKeeper
|
||||
@@ -159,7 +159,7 @@ func NewKeeper(
|
||||
}
|
||||
|
||||
k := &Keeper{
|
||||
environment: env,
|
||||
Environment: env,
|
||||
cdc: cdc,
|
||||
authKeeper: ak,
|
||||
bankKeeper: bk,
|
||||
@@ -311,11 +311,6 @@ func NewKeeper(
|
||||
return k
|
||||
}
|
||||
|
||||
// Logger returns a module-specific logger.
|
||||
func (k Keeper) Logger() log.Logger {
|
||||
return k.environment.Logger.With("module", "x/"+types.ModuleName)
|
||||
}
|
||||
|
||||
// Hooks gets the hooks for staking *Keeper {
|
||||
func (k *Keeper) Hooks() types.StakingHooks {
|
||||
if k.hooks == nil {
|
||||
|
||||
@@ -38,12 +38,12 @@ func (m Migrator) Migrate3to4(ctx context.Context) error {
|
||||
|
||||
// Migrate4to5 migrates x/staking state from consensus version 4 to 5.
|
||||
func (m Migrator) Migrate4to5(ctx context.Context) error {
|
||||
store := runtime.KVStoreAdapter(m.keeper.environment.KVStoreService.OpenKVStore(ctx))
|
||||
return v5.MigrateStore(ctx, store, m.keeper.cdc, m.keeper.Logger())
|
||||
store := runtime.KVStoreAdapter(m.keeper.KVStoreService.OpenKVStore(ctx))
|
||||
return v5.MigrateStore(ctx, store, m.keeper.cdc, m.keeper.Logger)
|
||||
}
|
||||
|
||||
// Migrate4to5 migrates x/staking state from consensus version 5 to 6.
|
||||
func (m Migrator) Migrate5to6(ctx context.Context) error {
|
||||
store := runtime.KVStoreAdapter(m.keeper.environment.KVStoreService.OpenKVStore(ctx))
|
||||
store := runtime.KVStoreAdapter(m.keeper.KVStoreService.OpenKVStore(ctx))
|
||||
return v6.MigrateStore(ctx, store, m.keeper.cdc)
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ func (k msgServer) CreateValidator(ctx context.Context, msg *types.MsgCreateVali
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
if err := k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeCreateValidator,
|
||||
event.NewAttribute(types.AttributeKeyValidator, msg.ValidatorAddress),
|
||||
event.NewAttribute(sdk.AttributeKeyAmount, msg.Value.String()),
|
||||
@@ -239,7 +239,7 @@ func (k msgServer) EditValidator(ctx context.Context, msg *types.MsgEditValidato
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
if err := k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeEditValidator,
|
||||
event.NewAttribute(types.AttributeKeyCommissionRate, validator.Commission.String()),
|
||||
event.NewAttribute(types.AttributeKeyMinSelfDelegation, validator.MinSelfDelegation.String()),
|
||||
@@ -302,7 +302,7 @@ func (k msgServer) Delegate(ctx context.Context, msg *types.MsgDelegate) (*types
|
||||
}()
|
||||
}
|
||||
|
||||
if err := k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
if err := k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeDelegate,
|
||||
event.NewAttribute(types.AttributeKeyValidator, msg.ValidatorAddress),
|
||||
event.NewAttribute(types.AttributeKeyDelegator, msg.DelegatorAddress),
|
||||
@@ -375,7 +375,7 @@ func (k msgServer) BeginRedelegate(ctx context.Context, msg *types.MsgBeginRedel
|
||||
}()
|
||||
}
|
||||
|
||||
if err := k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
if err := k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeRedelegate,
|
||||
event.NewAttribute(types.AttributeKeySrcValidator, msg.ValidatorSrcAddress),
|
||||
event.NewAttribute(types.AttributeKeyDstValidator, msg.ValidatorDstAddress),
|
||||
@@ -445,7 +445,7 @@ func (k msgServer) Undelegate(ctx context.Context, msg *types.MsgUndelegate) (*t
|
||||
}()
|
||||
}
|
||||
|
||||
if err := k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
if err := k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeUnbond,
|
||||
event.NewAttribute(types.AttributeKeyValidator, msg.ValidatorAddress),
|
||||
event.NewAttribute(types.AttributeKeyDelegator, msg.DelegatorAddress),
|
||||
@@ -544,7 +544,7 @@ func (k msgServer) CancelUnbondingDelegation(ctx context.Context, msg *types.Msg
|
||||
return nil, sdkerrors.ErrInvalidRequest.Wrap("amount is greater than the unbonding delegation entry balance")
|
||||
}
|
||||
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
if unbondEntry.CompletionTime.Before(headerInfo.Time) {
|
||||
return nil, sdkerrors.ErrInvalidRequest.Wrap("unbonding delegation is already processed")
|
||||
}
|
||||
@@ -576,7 +576,7 @@ func (k msgServer) CancelUnbondingDelegation(ctx context.Context, msg *types.Msg
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
if err := k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeCancelUnbondingDelegation,
|
||||
event.NewAttribute(sdk.AttributeKeyAmount, msg.Amount.String()),
|
||||
event.NewAttribute(types.AttributeKeyValidator, msg.ValidatorAddress),
|
||||
@@ -628,7 +628,7 @@ func (k msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams)
|
||||
val.Commission.CommissionRates.MaxRate = minRate
|
||||
}
|
||||
|
||||
val.Commission.UpdateTime = k.environment.HeaderService.GetHeaderInfo(ctx).Time
|
||||
val.Commission.UpdateTime = k.HeaderService.HeaderInfo(ctx).Time
|
||||
if err := k.SetValidator(ctx, val); err != nil {
|
||||
return nil, fmt.Errorf("failed to set validator after MinCommissionRate param change: %w", err)
|
||||
}
|
||||
|
||||
@@ -35,8 +35,6 @@ import (
|
||||
// Infraction was committed at the current height or at a past height,
|
||||
// but not at a height in the future
|
||||
func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, infractionHeight, power int64, slashFactor math.LegacyDec) (math.Int, error) {
|
||||
logger := k.Logger()
|
||||
|
||||
if slashFactor.IsNegative() {
|
||||
return math.NewInt(0), fmt.Errorf("attempted to slash with a negative slash factor: %v", slashFactor)
|
||||
}
|
||||
@@ -59,7 +57,7 @@ func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, infractionH
|
||||
return math.NewInt(0), err
|
||||
}
|
||||
|
||||
logger.Error(
|
||||
k.Logger.Error(
|
||||
"WARNING: ignored attempt to slash a nonexistent validator; we recommend you investigate immediately",
|
||||
"validator", conStr,
|
||||
)
|
||||
@@ -88,7 +86,7 @@ func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, infractionH
|
||||
// redelegations, as that stake has since unbonded
|
||||
remainingSlashAmount := slashAmount
|
||||
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
height := headerInfo.Height
|
||||
switch {
|
||||
case infractionHeight > height:
|
||||
@@ -100,7 +98,7 @@ func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, infractionH
|
||||
case infractionHeight == height:
|
||||
// Special-case slash at current height for efficiency - we don't need to
|
||||
// look through unbonding delegations or redelegations.
|
||||
logger.Info(
|
||||
k.Logger.Info(
|
||||
"slashing at current height; not scanning unbonding delegations & redelegations",
|
||||
"height", infractionHeight,
|
||||
)
|
||||
@@ -152,7 +150,7 @@ func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, infractionH
|
||||
// Nothing to burn, we can end this route immediately! We also don't
|
||||
// need to call the k.Hooks().BeforeValidatorSlashed hook as we won't
|
||||
// be slashing at all.
|
||||
logger.Info(
|
||||
k.Logger.Info(
|
||||
"no validator slashing because slash amount is zero",
|
||||
"validator", validator.GetOperator(),
|
||||
"slash_factor", slashFactor.String(),
|
||||
@@ -195,7 +193,7 @@ func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, infractionH
|
||||
return math.NewInt(0), fmt.Errorf("invalid validator status")
|
||||
}
|
||||
|
||||
logger.Info(
|
||||
k.Logger.Info(
|
||||
"validator slashed by slash factor",
|
||||
"validator", validator.GetOperator(),
|
||||
"slash_factor", slashFactor.String(),
|
||||
@@ -219,7 +217,7 @@ func (k Keeper) Jail(ctx context.Context, consAddr sdk.ConsAddress) error {
|
||||
return err
|
||||
}
|
||||
|
||||
k.Logger().Info("validator jailed", "validator", consAddr)
|
||||
k.Logger.Info("validator jailed", "validator", consAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -233,7 +231,7 @@ func (k Keeper) Unjail(ctx context.Context, consAddr sdk.ConsAddress) error {
|
||||
return err
|
||||
}
|
||||
|
||||
k.Logger().Info("validator un-jailed", "validator", consAddr)
|
||||
k.Logger.Info("validator un-jailed", "validator", consAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -245,7 +243,7 @@ func (k Keeper) Unjail(ctx context.Context, consAddr sdk.ConsAddress) error {
|
||||
func (k Keeper) SlashUnbondingDelegation(ctx context.Context, unbondingDelegation types.UnbondingDelegation,
|
||||
infractionHeight int64, slashFactor math.LegacyDec,
|
||||
) (totalSlashAmount math.Int, err error) {
|
||||
now := k.environment.HeaderService.GetHeaderInfo(ctx).Time
|
||||
now := k.HeaderService.HeaderInfo(ctx).Time
|
||||
totalSlashAmount = math.ZeroInt()
|
||||
burnedAmount := math.ZeroInt()
|
||||
|
||||
@@ -301,7 +299,7 @@ func (k Keeper) SlashUnbondingDelegation(ctx context.Context, unbondingDelegatio
|
||||
func (k Keeper) SlashRedelegation(ctx context.Context, srcValidator types.Validator, redelegation types.Redelegation,
|
||||
infractionHeight int64, slashFactor math.LegacyDec,
|
||||
) (totalSlashAmount math.Int, err error) {
|
||||
now := k.environment.HeaderService.GetHeaderInfo(ctx).Time
|
||||
now := k.HeaderService.HeaderInfo(ctx).Time
|
||||
totalSlashAmount = math.ZeroInt()
|
||||
bondedBurnedAmount, notBondedBurnedAmount := math.ZeroInt(), math.ZeroInt()
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
// ValidatorByPowerIndexExists does a certain by-power index record exist
|
||||
func ValidatorByPowerIndexExists(ctx context.Context, keeper *Keeper, power []byte) bool {
|
||||
store := keeper.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := keeper.KVStoreService.OpenKVStore(ctx)
|
||||
has, err := store.Has(power)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -28,7 +28,7 @@ func TestingUpdateValidator(keeper *Keeper, ctx sdk.Context, validator types.Val
|
||||
}
|
||||
|
||||
// Remove any existing power key for validator.
|
||||
store := keeper.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := keeper.KVStoreService.OpenKVStore(ctx)
|
||||
deleted := false
|
||||
|
||||
iterator, err := store.Iterator(types.ValidatorsByPowerIndexKey, storetypes.PrefixEndBytes(types.ValidatorsByPowerIndexKey))
|
||||
|
||||
@@ -75,7 +75,7 @@ func (k Keeper) GetUnbondingDelegationByUnbondingID(ctx context.Context, id uint
|
||||
|
||||
// GetRedelegationByUnbondingID returns a unbonding delegation that has an unbonding delegation entry with a certain ID
|
||||
func (k Keeper) GetRedelegationByUnbondingID(ctx context.Context, id uint64) (red types.Redelegation, err error) {
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
|
||||
redKey, err := k.UnbondingIndex.Get(ctx, id)
|
||||
if err != nil {
|
||||
@@ -109,7 +109,7 @@ func (k Keeper) GetRedelegationByUnbondingID(ctx context.Context, id uint64) (re
|
||||
|
||||
// GetValidatorByUnbondingID returns the validator that is unbonding with a certain unbonding op ID
|
||||
func (k Keeper) GetValidatorByUnbondingID(ctx context.Context, id uint64) (val types.Validator, err error) {
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
|
||||
valKey, err := k.UnbondingIndex.Get(ctx, id)
|
||||
if err != nil {
|
||||
@@ -283,7 +283,7 @@ func (k Keeper) unbondingDelegationEntryCanComplete(ctx context.Context, id uint
|
||||
ubd.Entries[i].UnbondingOnHoldRefCount--
|
||||
|
||||
// Check if entry is matured.
|
||||
if !ubd.Entries[i].OnHold() && ubd.Entries[i].IsMature(k.environment.HeaderService.GetHeaderInfo(ctx).Time) {
|
||||
if !ubd.Entries[i].OnHold() && ubd.Entries[i].IsMature(k.HeaderService.HeaderInfo(ctx).Time) {
|
||||
// If matured, complete it.
|
||||
delegatorAddress, err := k.authKeeper.AddressCodec().StringToBytes(ubd.DelegatorAddress)
|
||||
if err != nil {
|
||||
@@ -344,7 +344,7 @@ func (k Keeper) redelegationEntryCanComplete(ctx context.Context, id uint64) err
|
||||
}
|
||||
red.Entries[i].UnbondingOnHoldRefCount--
|
||||
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
if !red.Entries[i].OnHold() && red.Entries[i].IsMature(headerInfo.Time) {
|
||||
// If matured, complete it.
|
||||
// Remove entry
|
||||
|
||||
@@ -43,7 +43,7 @@ func (k Keeper) BlockValidatorUpdates(ctx context.Context) ([]appmodule.Validato
|
||||
return nil, err
|
||||
}
|
||||
|
||||
time := k.environment.HeaderService.GetHeaderInfo(ctx).Time
|
||||
time := k.HeaderService.HeaderInfo(ctx).Time
|
||||
// Remove all mature unbonding delegations from the ubd queue.
|
||||
matureUnbonds, err := k.DequeueAllMatureUBDQueue(ctx, time)
|
||||
if err != nil {
|
||||
@@ -65,7 +65,7 @@ func (k Keeper) BlockValidatorUpdates(ctx context.Context) ([]appmodule.Validato
|
||||
continue
|
||||
}
|
||||
|
||||
if err := k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
if err := k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeCompleteUnbonding,
|
||||
event.NewAttribute(sdk.AttributeKeyAmount, balances.String()),
|
||||
event.NewAttribute(types.AttributeKeyValidator, dvPair.ValidatorAddress),
|
||||
@@ -105,7 +105,7 @@ func (k Keeper) BlockValidatorUpdates(ctx context.Context) ([]appmodule.Validato
|
||||
continue
|
||||
}
|
||||
|
||||
if err := k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
if err := k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeCompleteRedelegation,
|
||||
event.NewAttribute(sdk.AttributeKeyAmount, balances.String()),
|
||||
event.NewAttribute(types.AttributeKeyDelegator, dvvTriplet.DelegatorAddress),
|
||||
@@ -454,7 +454,7 @@ func (k Keeper) BeginUnbondingValidator(ctx context.Context, validator types.Val
|
||||
|
||||
validator = validator.UpdateStatus(types.Unbonding)
|
||||
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
// set the unbonding completion time and completion height appropriately
|
||||
validator.UnbondingTime = headerInfo.Time.Add(params.UnbondingTime)
|
||||
validator.UnbondingHeight = headerInfo.Height
|
||||
|
||||
@@ -100,7 +100,7 @@ func (k Keeper) SetValidatorByPowerIndex(ctx context.Context, validator types.Va
|
||||
return nil
|
||||
}
|
||||
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
str, err := k.validatorAddressCodec.StringToBytes(validator.GetOperator())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -110,13 +110,13 @@ func (k Keeper) SetValidatorByPowerIndex(ctx context.Context, validator types.Va
|
||||
|
||||
// DeleteValidatorByPowerIndex deletes a record by power index
|
||||
func (k Keeper) DeleteValidatorByPowerIndex(ctx context.Context, validator types.Validator) error {
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
return store.Delete(types.GetValidatorsByPowerIndexKey(validator, k.PowerReduction(ctx), k.validatorAddressCodec))
|
||||
}
|
||||
|
||||
// SetNewValidatorByPowerIndex adds new entry by power index
|
||||
func (k Keeper) SetNewValidatorByPowerIndex(ctx context.Context, validator types.Validator) error {
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
str, err := k.validatorAddressCodec.StringToBytes(validator.GetOperator())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -187,7 +187,7 @@ func (k Keeper) UpdateValidatorCommission(ctx context.Context,
|
||||
validator types.Validator, newRate math.LegacyDec,
|
||||
) (types.Commission, error) {
|
||||
commission := validator.Commission
|
||||
blockTime := k.environment.HeaderService.GetHeaderInfo(ctx).Time
|
||||
blockTime := k.HeaderService.HeaderInfo(ctx).Time
|
||||
|
||||
if err := commission.ValidateNewRate(newRate, blockTime); err != nil {
|
||||
return commission, err
|
||||
@@ -231,7 +231,7 @@ func (k Keeper) RemoveValidator(ctx context.Context, address sdk.ValAddress) err
|
||||
}
|
||||
|
||||
// delete the old validator record
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
if err = k.Validators.Remove(ctx, address); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -260,7 +260,7 @@ func (k Keeper) RemoveValidator(ctx context.Context, address sdk.ValAddress) err
|
||||
|
||||
// GetAllValidators gets the set of all validators with no limits, used during genesis dump
|
||||
func (k Keeper) GetAllValidators(ctx context.Context) (validators []types.Validator, err error) {
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
|
||||
iterator, err := store.Iterator(types.ValidatorsKey, storetypes.PrefixEndBytes(types.ValidatorsKey))
|
||||
if err != nil {
|
||||
@@ -281,7 +281,7 @@ func (k Keeper) GetAllValidators(ctx context.Context) (validators []types.Valida
|
||||
|
||||
// GetValidators returns a given amount of all the validators
|
||||
func (k Keeper) GetValidators(ctx context.Context, maxRetrieve uint32) (validators []types.Validator, err error) {
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
validators = make([]types.Validator, maxRetrieve)
|
||||
|
||||
iterator, err := store.Iterator(types.ValidatorsKey, storetypes.PrefixEndBytes(types.ValidatorsKey))
|
||||
@@ -335,7 +335,7 @@ func (k Keeper) GetBondedValidatorsByPower(ctx context.Context) ([]types.Validat
|
||||
|
||||
// ValidatorsPowerStoreIterator returns an iterator for the current validator power store
|
||||
func (k Keeper) ValidatorsPowerStoreIterator(ctx context.Context) (corestore.Iterator, error) {
|
||||
store := k.environment.KVStoreService.OpenKVStore(ctx)
|
||||
store := k.KVStoreService.OpenKVStore(ctx)
|
||||
return store.ReverseIterator(types.ValidatorsByPowerIndexKey, storetypes.PrefixEndBytes(types.ValidatorsByPowerIndexKey))
|
||||
}
|
||||
|
||||
@@ -487,7 +487,7 @@ func (k Keeper) DeleteValidatorQueue(ctx context.Context, val types.Validator) e
|
||||
// UnbondAllMatureValidators unbonds all the mature unbonding validators that
|
||||
// have finished their unbonding period.
|
||||
func (k Keeper) UnbondAllMatureValidators(ctx context.Context) error {
|
||||
headerInfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerInfo := k.HeaderService.HeaderInfo(ctx)
|
||||
blockTime := headerInfo.Time
|
||||
blockHeight := uint64(headerInfo.Height)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user