refactor(core,x/**): simplify core service api and embed environment in keepers (#20071)
This commit is contained in:
@@ -104,7 +104,7 @@ func (k Keeper) AllocateTokensToValidator(ctx context.Context, val sdk.Validator
|
||||
}
|
||||
|
||||
// update current commission
|
||||
if err = k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
if err = k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeCommission,
|
||||
event.NewAttribute(sdk.AttributeKeyAmount, commission.String()),
|
||||
event.NewAttribute(types.AttributeKeyValidator, val.GetOperator()),
|
||||
@@ -136,7 +136,7 @@ func (k Keeper) AllocateTokensToValidator(ctx context.Context, val sdk.Validator
|
||||
}
|
||||
|
||||
// update outstanding rewards
|
||||
if err = k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
if err = k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeRewards,
|
||||
event.NewAttribute(sdk.AttributeKeyAmount, tokens.String()),
|
||||
event.NewAttribute(types.AttributeKeyValidator, val.GetOperator()),
|
||||
|
||||
@@ -42,7 +42,7 @@ func (k Keeper) initializeDelegation(ctx context.Context, val sdk.ValAddress, de
|
||||
// we don't store directly, so multiply delegation shares * (tokens per share)
|
||||
// note: necessary to truncate so we don't allow withdrawing more rewards than owed
|
||||
stake := validator.TokensFromSharesTruncated(delegation.GetShares())
|
||||
headerinfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerinfo := k.HeaderService.HeaderInfo(ctx)
|
||||
return k.DelegatorStartingInfo.Set(ctx, collections.Join(val, del), types.NewDelegatorStartingInfo(previousPeriod, stake, uint64(headerinfo.Height)))
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ func (k Keeper) CalculateDelegationRewards(ctx context.Context, val sdk.Validato
|
||||
return sdk.DecCoins{}, err
|
||||
}
|
||||
|
||||
headerinfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerinfo := k.HeaderService.HeaderInfo(ctx)
|
||||
if startingInfo.Height == uint64(headerinfo.Height) { // started this height, no rewards yet
|
||||
return sdk.DecCoins{}, nil
|
||||
}
|
||||
@@ -242,8 +242,7 @@ func (k Keeper) withdrawDelegationRewards(ctx context.Context, val sdk.Validator
|
||||
// of the decCoins due to operation order of the distribution mechanism.
|
||||
rewards := rewardsRaw.Intersect(outstanding)
|
||||
if !rewards.Equal(rewardsRaw) {
|
||||
logger := k.Logger(ctx)
|
||||
logger.Info(
|
||||
k.Logger.Info(
|
||||
"rounding error withdrawing rewards from validator",
|
||||
"delegator", del.GetDelegatorAddr(),
|
||||
"validator", val.GetOperator(),
|
||||
@@ -313,7 +312,7 @@ func (k Keeper) withdrawDelegationRewards(ctx context.Context, val sdk.Validator
|
||||
finalRewards = sdk.Coins{sdk.NewCoin(baseDenom, math.ZeroInt())}
|
||||
}
|
||||
|
||||
err = k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
err = k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeWithdrawRewards,
|
||||
event.NewAttribute(sdk.AttributeKeyAmount, finalRewards.String()),
|
||||
event.NewAttribute(types.AttributeKeyValidator, val.GetOperator()),
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/core/event"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/x/distribution/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@@ -21,7 +20,8 @@ import (
|
||||
|
||||
// Keeper of the distribution store
|
||||
type Keeper struct {
|
||||
environment appmodule.Environment
|
||||
appmodule.Environment
|
||||
|
||||
cdc codec.BinaryCodec
|
||||
authKeeper types.AccountKeeper
|
||||
bankKeeper types.BankKeeper
|
||||
@@ -69,7 +69,7 @@ func NewKeeper(
|
||||
|
||||
sb := collections.NewSchemaBuilder(env.KVStoreService)
|
||||
k := Keeper{
|
||||
environment: env,
|
||||
Environment: env,
|
||||
cdc: cdc,
|
||||
authKeeper: ak,
|
||||
bankKeeper: bk,
|
||||
@@ -145,11 +145,6 @@ func (k Keeper) GetAuthority() string {
|
||||
return k.authority
|
||||
}
|
||||
|
||||
// Logger returns a module-specific logger.
|
||||
func (k Keeper) Logger(ctx context.Context) log.Logger {
|
||||
return k.environment.Logger.With(log.ModuleKey, "x/"+types.ModuleName)
|
||||
}
|
||||
|
||||
// SetWithdrawAddr sets a new address that will receive the rewards upon withdrawal
|
||||
func (k Keeper) SetWithdrawAddr(ctx context.Context, delegatorAddr, withdrawAddr sdk.AccAddress) error {
|
||||
if k.bankKeeper.BlockedAddr(withdrawAddr) {
|
||||
@@ -170,7 +165,7 @@ func (k Keeper) SetWithdrawAddr(ctx context.Context, delegatorAddr, withdrawAddr
|
||||
return err
|
||||
}
|
||||
|
||||
if err = k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
if err = k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeSetWithdrawAddress,
|
||||
event.NewAttribute(types.AttributeKeyWithdrawAddress, addr),
|
||||
); err != nil {
|
||||
@@ -255,7 +250,7 @@ func (k Keeper) WithdrawValidatorCommission(ctx context.Context, valAddr sdk.Val
|
||||
}
|
||||
}
|
||||
|
||||
err = k.environment.EventService.EventManager(ctx).EmitKV(
|
||||
err = k.EventService.EventManager(ctx).EmitKV(
|
||||
types.EventTypeWithdrawCommission,
|
||||
event.NewAttribute(sdk.AttributeKeyAmount, commission.String()),
|
||||
)
|
||||
|
||||
@@ -33,7 +33,7 @@ func (m Migrator) Migrate2to3(ctx context.Context) error {
|
||||
// Migrate3to4 migrates the x/distribution module state to use collections
|
||||
// Additionally it migrates distribution fee pool to use protocol pool module account
|
||||
func (m Migrator) Migrate3to4(ctx context.Context) error {
|
||||
if err := v4.MigrateStore(ctx, m.keeper.environment, m.keeper.cdc); err != nil {
|
||||
if err := v4.MigrateStore(ctx, m.keeper.Environment, m.keeper.cdc); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -162,8 +162,7 @@ func (k msgServer) CommunityPoolSpend(ctx context.Context, msg *types.MsgCommuni
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logger := k.Logger(ctx)
|
||||
logger.Info("transferred from the community pool to recipient", "amount", msg.Amount.String(), "recipient", msg.Recipient)
|
||||
k.Logger.Info("transferred from the community pool to recipient", "amount", msg.Amount.String(), "recipient", msg.Recipient)
|
||||
|
||||
return &types.MsgCommunityPoolSpendResponse{}, nil
|
||||
}
|
||||
@@ -200,8 +199,7 @@ func (k msgServer) DepositValidatorRewardsPool(ctx context.Context, msg *types.M
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logger := k.Logger(ctx)
|
||||
logger.Info(
|
||||
k.Logger.Info(
|
||||
"transferred from rewards to validator rewards pool",
|
||||
"depositor", msg.Depositor,
|
||||
"amount", msg.Amount.String(),
|
||||
|
||||
@@ -155,7 +155,7 @@ func (k Keeper) updateValidatorSlashFraction(ctx context.Context, valAddr sdk.Va
|
||||
panic(fmt.Sprintf("fraction must be >=0 and <=1, current fraction: %v", fraction))
|
||||
}
|
||||
|
||||
headerinfo := k.environment.HeaderService.GetHeaderInfo(ctx)
|
||||
headerinfo := k.HeaderService.HeaderInfo(ctx)
|
||||
val, err := k.stakingKeeper.Validator(ctx, valAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user