Skip to content

Commit 67950ad

Browse files
authored
feat: add block max_gas and min_tip ingestion to app.go mempool config (#582)
* add block max_gas and minimum_gas_prices to app * add changelog * move methods out to config * add godoc * add tests * try depot again * back to gh runner * fix changelog error * remove wack evmd argument * add new flag * update changelog desc * change spaces to tab * repoint constant and add log * add const docs and change log to warn * fix lint * rm flag change
1 parent f03d2a4 commit 67950ad

File tree

10 files changed

+468
-18
lines changed

10 files changed

+468
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- [\#568](https://github.com/cosmos/evm/pull/568) Avoid unnecessary block notifications when the event bus is already set up.
2626
- [\#511](https://github.com/cosmos/evm/pull/511) Minor code cleanup for `AddPrecompileFn`.
2727
- [\#544](https://github.com/cosmos/evm/pull/544) Parse logs from the txResult.Data and avoid emitting EVM events to cosmos-sdk events.
28+
- [\#582](https://github.com/cosmos/evm/pull/582) Add block max-gas (from genesis.json) and new min-tip (from app.toml/flags) ingestion into mempool config
2829

2930
### FEATURES
3031

config/server_app_options.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package config
2+
3+
import (
4+
"math"
5+
"path/filepath"
6+
7+
"github.com/holiman/uint256"
8+
"github.com/spf13/cast"
9+
10+
srvflags "github.com/cosmos/evm/server/flags"
11+
12+
"cosmossdk.io/log"
13+
14+
"github.com/cosmos/cosmos-sdk/client/flags"
15+
sdkserver "github.com/cosmos/cosmos-sdk/server"
16+
servertypes "github.com/cosmos/cosmos-sdk/server/types"
17+
sdk "github.com/cosmos/cosmos-sdk/types"
18+
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
19+
)
20+
21+
// GetBlockGasLimit reads the genesis json file using AppGenesisFromFile
22+
// to extract the consensus block gas limit before InitChain is called.
23+
func GetBlockGasLimit(appOpts servertypes.AppOptions, logger log.Logger) uint64 {
24+
homeDir := cast.ToString(appOpts.Get(flags.FlagHome))
25+
if homeDir == "" {
26+
logger.Error("home directory not found in app options, using zero block gas limit")
27+
return math.MaxUint64
28+
}
29+
genesisPath := filepath.Join(homeDir, "config", "genesis.json")
30+
31+
appGenesis, err := genutiltypes.AppGenesisFromFile(genesisPath)
32+
if err != nil {
33+
logger.Error("failed to load genesis using SDK AppGenesisFromFile, using zero block gas limit", "path", genesisPath, "error", err)
34+
return 0
35+
}
36+
genDoc, err := appGenesis.ToGenesisDoc()
37+
if err != nil {
38+
logger.Error("failed to convert AppGenesis to GenesisDoc, using zero block gas limit", "path", genesisPath, "error", err)
39+
return 0
40+
}
41+
42+
if genDoc.ConsensusParams == nil {
43+
logger.Error("consensus parameters not found in genesis (nil), using zero block gas limit")
44+
return 0
45+
}
46+
47+
maxGas := genDoc.ConsensusParams.Block.MaxGas
48+
if maxGas == -1 {
49+
logger.Warn("genesis max_gas is unlimited (-1), using max uint64")
50+
return math.MaxUint64
51+
}
52+
if maxGas < -1 {
53+
logger.Error("invalid max_gas value in genesis, using zero block gas limit")
54+
return 0
55+
}
56+
blockGasLimit := uint64(maxGas) // #nosec G115 -- maxGas >= 0 checked above
57+
58+
logger.Debug(
59+
"extracted block gas limit from genesis using SDK AppGenesisFromFile",
60+
"genesis_path", genesisPath,
61+
"max_gas", maxGas,
62+
"block_gas_limit", blockGasLimit,
63+
)
64+
65+
return blockGasLimit
66+
}
67+
68+
// GetMinGasPrices reads the min gas prices from the app options, set from app.toml
69+
// This is currently not used, but is kept in case this is useful for the mempool,
70+
// in addition to the min tip flag
71+
func GetMinGasPrices(appOpts servertypes.AppOptions, logger log.Logger) sdk.DecCoins {
72+
minGasPricesStr := cast.ToString(appOpts.Get(sdkserver.FlagMinGasPrices))
73+
minGasPrices, err := sdk.ParseDecCoins(minGasPricesStr)
74+
if err != nil {
75+
logger.With("error", err).Info("failed to parse min gas prices, using empty DecCoins")
76+
minGasPrices = sdk.DecCoins{}
77+
}
78+
79+
return minGasPrices
80+
}
81+
82+
// GetMinTip reads the min tip from the app options, set from app.toml
83+
// This field is also known as the minimum priority fee
84+
func GetMinTip(appOpts servertypes.AppOptions, logger log.Logger) *uint256.Int {
85+
minTipUint64 := cast.ToUint64(appOpts.Get(srvflags.EVMMinTip))
86+
minTip := uint256.NewInt(minTipUint64)
87+
88+
if minTip.Cmp(uint256.NewInt(0)) >= 0 { // zero or positive
89+
return minTip
90+
}
91+
92+
logger.Error("invalid min tip value in app.toml or flag, falling back to nil", "min_tip", minTipUint64)
93+
return nil
94+
}

0 commit comments

Comments
 (0)