Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global fee impr (#1209) #1210

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -15,7 +15,8 @@
"github.com/public-awesome/stargaze/v15/x/globalfee/types"
)

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)

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 @@
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)

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
Loading