Skip to content

Commit

Permalink
delete contract query limit config (#20)
Browse files Browse the repository at this point in the history
* delete contract query limit config

* default 3,000,000
  • Loading branch information
sh-cha authored May 24, 2024
1 parent 6e67d07 commit 1173928
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 19 deletions.
1 change: 1 addition & 0 deletions cmd/minitiad/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func initAppConfig() (string, interface{}) {
//
// In simapp, we set the min gas prices to 0.
srvCfg.MinGasPrices = fmt.Sprintf("0%s", types.BaseDenom)
srvCfg.QueryGasLimit = 3000000

// Enable API and unsafe CORS (CORS allowed from any host)
srvCfg.API.Enable = true
Expand Down
13 changes: 0 additions & 13 deletions x/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,35 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
)

// DefaultContractQueryGasLimit - default max query gas for external query
const DefaultContractQueryGasLimit = uint64(3_000_000)

// DefaultContractSimulationGasLimit - default max simulation gas
const DefaultContractSimulationGasLimit = uint64(3_000_000)

const (
flagContractSimulationGasLimit = "evm.contract-simulation-gas-limit"
flagContractQueryGasLimit = "evm.contract-query-gas-limit"
)

// EVMConfig is the extra config required for evm
type EVMConfig struct {
ContractSimulationGasLimit uint64 `mapstructure:"contract-simulation-gas-limit"`
ContractQueryGasLimit uint64 `mapstructure:"contract-query-gas-limit"`
}

// DefaultEVMConfig returns the default settings for EVMConfig
func DefaultEVMConfig() EVMConfig {
return EVMConfig{
ContractSimulationGasLimit: DefaultContractSimulationGasLimit,
ContractQueryGasLimit: DefaultContractQueryGasLimit,
}
}

// GetConfig load config values from the app options
func GetConfig(appOpts servertypes.AppOptions) EVMConfig {
return EVMConfig{
ContractSimulationGasLimit: cast.ToUint64(appOpts.Get(flagContractSimulationGasLimit)),
ContractQueryGasLimit: cast.ToUint64(appOpts.Get(flagContractQueryGasLimit)),
}
}

// AddConfigFlags implements servertypes.EVMConfigFlags interface.
func AddConfigFlags(startCmd *cobra.Command) {
startCmd.Flags().Uint64(flagContractSimulationGasLimit, DefaultContractSimulationGasLimit, "Set the max simulation gas for evm contract execution")
startCmd.Flags().Uint64(flagContractQueryGasLimit, DefaultContractQueryGasLimit, "Set the max gas that can be spent on executing a query with a Move contract")
}

// DefaultConfigTemplate default config template for evm
Expand All @@ -56,9 +48,4 @@ const DefaultConfigTemplate = `
# The maximum gas amount can be used in a tx simulation call.
contract-simulation-gas-limit = "{{ .EVMConfig.ContractSimulationGasLimit }}"
# The maximum gas amount can be spent for contract query.
# The contract query will invoke contract execution vm,
# so we need to restrict the max usage to prevent DoS attack
contract-query-gas-limit = "{{ .EVMConfig.ContractQueryGasLimit }}"
`
4 changes: 0 additions & 4 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ func NewKeeper(
evmConfig.ContractSimulationGasLimit = evmconfig.DefaultContractSimulationGasLimit
}

if evmConfig.ContractQueryGasLimit == 0 {
evmConfig.ContractQueryGasLimit = evmconfig.DefaultContractQueryGasLimit
}

k := &Keeper{
ac: ac,
cdc: cdc,
Expand Down
2 changes: 0 additions & 2 deletions x/evm/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -34,7 +33,6 @@ func (qs *queryServerImpl) Call(ctx context.Context, req *types.QueryCallRequest
}()

sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx = sdkCtx.WithGasMeter(storetypes.NewGasMeter(qs.config.ContractQueryGasLimit))

sender, err := qs.ac.StringToBytes(req.Sender)
if err != nil {
Expand Down

0 comments on commit 1173928

Please sign in to comment.