Skip to content

Commit

Permalink
add config to disable evm indexer to safe the space
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Dec 2, 2024
1 parent 72f3e33 commit f5f5ff5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions indexer/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func (e *EVMIndexerImpl) ListenCommit(ctx context.Context, res abci.ResponseComm

// IndexBlock implements EVMIndexer.
func (e *EVMIndexerImpl) ListenFinalizeBlock(ctx context.Context, req abci.RequestFinalizeBlock, res abci.ResponseFinalizeBlock) error {
if !e.enabled {
return nil
}

sdkCtx := sdk.UnwrapSDKContext(ctx)

// load base fee from evm keeper
Expand Down
5 changes: 5 additions & 0 deletions indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type EVMIndexer interface {

// EVMIndexerImpl implements EVMIndexer.
type EVMIndexerImpl struct {
enabled bool

db dbm.DB
logger log.Logger
txConfig client.TxConfig
Expand Down Expand Up @@ -102,7 +104,10 @@ func NewEVMIndexer(
},
)

logger.Info("EVM Indexer", "enable", !cfg.DisableIndexer)
indexer := &EVMIndexerImpl{
enabled: !cfg.DisableIndexer,

db: db,
store: store,
logger: logger,
Expand Down
12 changes: 12 additions & 0 deletions x/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ import (
const (
// DefaultContractSimulationGasLimit - default max simulation gas
DefaultContractSimulationGasLimit = uint64(3_000_000)
// DefaultDisableIndexer is the default flag to disable indexer
DefaultDisableIndexer = false
// DefaultIndexerCacheSize is the default maximum size (MiB) of the cache.
DefaultIndexerCacheSize = 100
)

const (
flagContractSimulationGasLimit = "evm.contract-simulation-gas-limit"
flagDisableIndexer = "evm.disable-indexer"
flagIndexerCacheSize = "evm.indexer-cache-size"
)

// EVMConfig is the extra config required for evm
type EVMConfig struct {
// ContractSimulationGasLimit is the maximum gas amount can be used in a tx simulation call.
ContractSimulationGasLimit uint64 `mapstructure:"contract-simulation-gas-limit"`
// DisableIndexer is the flag to disable indexer
DisableIndexer bool `mapstructure:"disable-indexer"`
// IndexerCacheSize is the maximum size (MiB) of the cache.
IndexerCacheSize int `mapstructure:"indexer-cache-size"`
}
Expand All @@ -31,6 +36,7 @@ type EVMConfig struct {
func DefaultEVMConfig() EVMConfig {
return EVMConfig{
ContractSimulationGasLimit: DefaultContractSimulationGasLimit,
DisableIndexer: true,
IndexerCacheSize: DefaultIndexerCacheSize,
}
}
Expand All @@ -39,13 +45,15 @@ func DefaultEVMConfig() EVMConfig {
func GetConfig(appOpts servertypes.AppOptions) EVMConfig {
return EVMConfig{
ContractSimulationGasLimit: cast.ToUint64(appOpts.Get(flagContractSimulationGasLimit)),
DisableIndexer: cast.ToBool(appOpts.Get(flagDisableIndexer)),
IndexerCacheSize: cast.ToInt(appOpts.Get(flagIndexerCacheSize)),
}
}

// AddConfigFlags implements servertypes.EVMConfigFlags interface.
func AddConfigFlags(startCmd *cobra.Command) {
startCmd.Flags().Uint64(flagContractSimulationGasLimit, DefaultContractSimulationGasLimit, "Maximum simulation gas amount for evm contract execution")
startCmd.Flags().Bool(flagDisableIndexer, DefaultDisableIndexer, "Disable evm indexer")
startCmd.Flags().Int(flagIndexerCacheSize, DefaultIndexerCacheSize, "Maximum size (MiB) of the indexer cache")
}

Expand All @@ -60,6 +68,10 @@ const DefaultConfigTemplate = `
# The maximum gas amount can be used in a tx simulation call.
contract-simulation-gas-limit = "{{ .EVMConfig.ContractSimulationGasLimit }}"
# DisableIndexer is the flag to disable indexer. If true, evm jsonrpc queries will return
# empty results for block, tx, and receipt queries.
disable-indexer = {{ .EVMConfig.DisableIndexer }}
# IndexerCacheSize is the maximum size (MiB) of the cache for evm indexer.
indexer-cache-size = {{ .EVMConfig.IndexerCacheSize }}
`

0 comments on commit f5f5ff5

Please sign in to comment.