Skip to content

Commit

Permalink
Merge pull request #1210 from public-awesome/global-fee-impr
Browse files Browse the repository at this point in the history
global fee impr (#1209)
  • Loading branch information
jhernandezb authored Feb 11, 2025
2 parents 89f8ed2 + 8a1745c commit 15d9575
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 21 deletions.
8 changes: 4 additions & 4 deletions cmd/starsd/cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ type PreferredSetting struct {
var preferredSettings = []PreferredSetting{
{
ViperKey: "consensus.timeout_commit",
Value: "2750ms",
Value: "2500ms",
Set: func(serverCtx *server.Context, key, value string) error {
serverCtx.Viper.Set(key, value)
serverCtx.Config.Consensus.TimeoutCommit = 2750 * time.Millisecond
serverCtx.Config.Consensus.TimeoutCommit = 2500 * time.Millisecond
return nil
},
},
{
ViperKey: "consensus.timeout_propose",
Value: "1750ms",
Value: "1700ms",
Set: func(serverCtx *server.Context, key, value string) error {
serverCtx.Viper.Set(key, value)
serverCtx.Config.Consensus.TimeoutPropose = 1750 * time.Millisecond
serverCtx.Config.Consensus.TimeoutPropose = 1500 * time.Millisecond
return nil
},
},
Expand Down
36 changes: 28 additions & 8 deletions x/globalfee/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

var _ sdk.AnteDecorator = FeeDecorator{}

Check failure on line 18 in x/globalfee/ante/fee.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofumpt)
var maxGasPercent = sdkmath.LegacyNewDecWithPrec(10, 2) // 10%

type GlobalFeeReaderExpected interface {
GetContractAuthorization(ctx sdk.Context, contractAddr sdk.AccAddress) (types.ContractAuthorization, error)
Expand Down Expand Up @@ -57,26 +58,45 @@ func (mfd FeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
msgs := feeTx.GetMsgs()

// currently accepting zero fee transactions only when the tx contains only the authorized operations that can bypass the minimum fee
onlyZeroFeeMsgs := mfd.containsOnlyZeroFeeMsgs(ctx, msgs)

return mfd.checkFees(ctx, feeTx, tx, onlyZeroFeeMsgs, simulate, next) // https://github.com/cosmos/gaia/blob/6fe097e3280baa360a28b59a29b8cca964a5ae97/x/globalfee/ante/fee.go
onlyFreeMsgs, atLeastOneFreeMsg := mfd.freeMsgsCheck(ctx, msgs)
if atLeastOneFreeMsg {
maxGas := sdkmath.LegacyNewDec(ctx.ConsensusParams().Block.MaxGas).Mul(maxGasPercent)
if feeTx.GetGas() > uint64(maxGas.RoundInt64()) {
return ctx, errorsmod.Wrapf(sdkerrors.ErrInvalidGasLimit, "overallocated gas value")
}
}
return mfd.checkFees(ctx, feeTx, tx, onlyFreeMsgs, simulate, next) // https://github.com/cosmos/gaia/blob/6fe097e3280baa360a28b59a29b8cca964a5ae97/x/globalfee/ante/fee.go
}

func (mfd FeeDecorator) containsOnlyZeroFeeMsgs(ctx sdk.Context, msgs []sdk.Msg) bool {
func (mfd FeeDecorator) freeMsgsCheck(ctx sdk.Context, msgs []sdk.Msg) (onlyFreeMsgs, atLeastOneFreeMsg bool) {
totalMsgs := len(msgs)
freeMsgs := 0

for _, m := range msgs {
switch msg := m.(type) {
case *wasmtypes.MsgExecuteContract:
{
if !mfd.isZeroFeeMsg(ctx, msg) {
return false
if mfd.isZeroFeeMsg(ctx, msg) {
freeMsgs++
atLeastOneFreeMsg = true
} else {
onlyFreeMsgs = false
// exit early if there is at least one free msg
if atLeastOneFreeMsg {
return onlyFreeMsgs, atLeastOneFreeMsg
}
}

Check failure on line 89 in x/globalfee/ante/fee.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gofumpt)
}
default:
return false
return false, atLeastOneFreeMsg
}
}
if freeMsgs == totalMsgs {
return true, true
}

return true
return false, atLeastOneFreeMsg
}

func (mfd FeeDecorator) isZeroFeeMsg(ctx sdk.Context, msg *wasmtypes.MsgExecuteContract) bool {
Expand Down
12 changes: 10 additions & 2 deletions x/globalfee/ante/fee_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func (s *AnteHandlerTestSuite) SetupTest() {
}
app := simapp.SetupWithGenesisAccounts(s.T(), s.T().TempDir(), genAccounts, genBalances...)
h := cmtproto.Header{Height: app.LastBlockHeight() + 1}
ctx := sdk.NewContext(app.CommitMultiStore(), h, false, app.Logger()).WithBlockTime(time.Now())
ctx := sdk.NewContext(app.CommitMultiStore(), h, false, app.Logger()).WithBlockTime(time.Now()).WithConsensusParams(cmtproto.ConsensusParams{
Block: &cmtproto.BlockParams{
MaxGas: 225_000_000, // 225M
},
})

encodingConfig := stargazeapp.MakeEncodingConfig()

Expand All @@ -76,7 +80,11 @@ func (s *AnteHandlerTestSuite) SetupTestGlobalFeeStoreAndMinGasPrice(minGasPrice
err := s.app.Keepers.GlobalFeeKeeper.SetParams(s.ctx, types.Params{MinimumGasPrices: globalFees})
s.Require().NoError(err)

s.ctx = s.ctx.WithMinGasPrices(minGasPrice).WithIsCheckTx(true)
s.ctx = s.ctx.WithMinGasPrices(minGasPrice).WithIsCheckTx(true).WithConsensusParams(cmtproto.ConsensusParams{
Block: &cmtproto.BlockParams{
MaxGas: 225_000_000, // 225M
},
})

// build fee decorator
feeDecorator := ante.NewFeeDecorator(s.app.AppCodec(), s.app.Keepers.GlobalFeeKeeper, s.app.Keepers.StakingKeeper)
Expand Down
Loading

0 comments on commit 15d9575

Please sign in to comment.