Skip to content

Commit

Permalink
refactor: update comments on globalfee, genutil module init order (#2494
Browse files Browse the repository at this point in the history
)

* docs: update comments on globalfee, genutil module init order

* rename GlobalMinFee GlobalMinFeeParamSource in FeeDecorator

* fix: deadlink
  • Loading branch information
yaruwangway committed Jun 2, 2023
1 parent f2a0d56 commit 4d96f85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 8 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ func orderInitBlockers() []string {
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
// The globalfee module should ideally be initialized before the genutil module in theory:
// The globalfee antehandler performs checks in DeliverTx, which is called by gentx.
// When the global fee > 0, gentx needs to pay the fee. However, this is not expected,
// (in our case, the global fee is initialized with an empty value, which might not be a problem
// if the globalfee in genesis is not changed.)
// To resolve this issue, we should initialize the globalfee module after genutil, ensuring that the global
// min fee is empty when gentx is called.
// For more details, please refer to the following link: https://github.com/cosmos/gaia/issues/2489
globalfee.ModuleName,
providertypes.ModuleName,
}
Expand Down
20 changes: 10 additions & 10 deletions x/globalfee/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
var _ sdk.AnteDecorator = FeeDecorator{}

type FeeDecorator struct {
GlobalMinFee globalfee.ParamSource
StakingSubspace paramtypes.Subspace
GlobalMinFeeParamSource globalfee.ParamSource
StakingSubspace paramtypes.Subspace
}

func NewFeeDecorator(globalfeeSubspace, stakingSubspace paramtypes.Subspace) FeeDecorator {
Expand All @@ -42,8 +42,8 @@ func NewFeeDecorator(globalfeeSubspace, stakingSubspace paramtypes.Subspace) Fee
}

return FeeDecorator{
GlobalMinFee: globalfeeSubspace,
StakingSubspace: stakingSubspace,
GlobalMinFeeParamSource: globalfeeSubspace,
StakingSubspace: stakingSubspace,
}
}

Expand Down Expand Up @@ -186,8 +186,8 @@ func (mfd FeeDecorator) GetGlobalFee(ctx sdk.Context, feeTx sdk.FeeTx) (sdk.Coin
err error
)

if mfd.GlobalMinFee.Has(ctx, types.ParamStoreKeyMinGasPrices) {
mfd.GlobalMinFee.Get(ctx, types.ParamStoreKeyMinGasPrices, &globalMinGasPrices)
if mfd.GlobalMinFeeParamSource.Has(ctx, types.ParamStoreKeyMinGasPrices) {
mfd.GlobalMinFeeParamSource.Get(ctx, types.ParamStoreKeyMinGasPrices, &globalMinGasPrices)
}
// global fee is empty set, set global fee to 0uatom
if len(globalMinGasPrices) == 0 {
Expand Down Expand Up @@ -239,16 +239,16 @@ func (mfd FeeDecorator) ContainsOnlyBypassMinFeeMsgs(ctx sdk.Context, msgs []sdk
}

func (mfd FeeDecorator) GetBypassMsgTypes(ctx sdk.Context) (res []string) {
if mfd.GlobalMinFee.Has(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes) {
mfd.GlobalMinFee.Get(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes, &res)
if mfd.GlobalMinFeeParamSource.Has(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes) {
mfd.GlobalMinFeeParamSource.Get(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes, &res)
}

return
}

func (mfd FeeDecorator) GetMaxTotalBypassMinFeeMsgGasUsage(ctx sdk.Context) (res uint64) {
if mfd.GlobalMinFee.Has(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage) {
mfd.GlobalMinFee.Get(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, &res)
if mfd.GlobalMinFeeParamSource.Has(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage) {
mfd.GlobalMinFeeParamSource.Get(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, &res)
}

return
Expand Down

0 comments on commit 4d96f85

Please sign in to comment.