forked from cerc-io/laconicd-deprecated
rpc: configure gas cap (#457)
* rpc: configure gas cap * c++ * rm old const * docs
This commit is contained in:
+38
-1
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
@@ -24,6 +25,8 @@ const (
|
||||
|
||||
// DefaultEVMTracer is the default vm.Tracer type
|
||||
DefaultEVMTracer = "json"
|
||||
|
||||
DefaultGasCap uint64 = 25000000
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -113,6 +116,27 @@ type JSONRPCConfig struct {
|
||||
Enable bool `mapstructure:"enable"`
|
||||
// EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk)
|
||||
EnableUnsafeCORS bool `mapstructure:"enable-unsafe-cors"`
|
||||
// GasCap is the global gas cap for eth-call variants.
|
||||
GasCap uint64 `mapstructure:"gas-cap"`
|
||||
}
|
||||
|
||||
// Validate returns an error if the JSON-RPC configuration fields are invalid.
|
||||
func (c JSONRPCConfig) Validate() error {
|
||||
if c.Enable && len(c.API) == 0 {
|
||||
return errors.New("cannot enable JSON-RPC without defining any API namespace")
|
||||
}
|
||||
|
||||
// TODO: validate APIs
|
||||
seenAPIs := make(map[string]bool)
|
||||
for _, api := range c.API {
|
||||
if seenAPIs[api] {
|
||||
return fmt.Errorf("repeated API namespace '%s'", api)
|
||||
}
|
||||
|
||||
seenAPIs[api] = true
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DefaultJSONRPCConfig returns an EVM config with the JSON-RPC API enabled by default
|
||||
@@ -123,6 +147,7 @@ func DefaultJSONRPCConfig() *JSONRPCConfig {
|
||||
Address: DefaultJSONRPCAddress,
|
||||
WsAddress: DefaultJSONRPCWsAddress,
|
||||
EnableUnsafeCORS: false,
|
||||
GasCap: DefaultGasCap,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,17 +175,29 @@ func GetConfig(v *viper.Viper) Config {
|
||||
Address: v.GetString("json-rpc.address"),
|
||||
WsAddress: v.GetString("json-rpc.ws-address"),
|
||||
EnableUnsafeCORS: v.GetBool("json-rpc.enable-unsafe-cors"),
|
||||
GasCap: v.GetUint64("json-rpc.gas-cap"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ParseConfig retrieves the default environment configuration for the
|
||||
// application.
|
||||
func ParseConfig(v *viper.Viper) (*Config, error) {
|
||||
conf := DefaultConfig()
|
||||
err := v.Unmarshal(conf)
|
||||
|
||||
return conf, err
|
||||
}
|
||||
|
||||
// ValidateBasic returns an error any of the application configuration fields are invalid
|
||||
func (c Config) ValidateBasic() error {
|
||||
if err := c.EVM.Validate(); err != nil {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrAppConfig, "invalid evm config value: %s", err.Error())
|
||||
}
|
||||
|
||||
// TODO: validate JSON-RPC APIs
|
||||
if err := c.JSONRPC.Validate(); err != nil {
|
||||
return sdkerrors.Wrapf(sdkerrors.ErrAppConfig, "invalid json-rpc config value: %s", err.Error())
|
||||
}
|
||||
|
||||
return c.Config.ValidateBasic()
|
||||
}
|
||||
|
||||
@@ -34,4 +34,7 @@ api = "{{range $index, $elmt := .JSONRPC.API}}{{if $index}},{{$elmt}}{{else}}{{$
|
||||
|
||||
# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk)
|
||||
enable-unsafe-cors = "{{ .JSONRPC.EnableUnsafeCORS }}"
|
||||
|
||||
# GasCap sets a cap on gas that can be used in eth_call/estimateGas (0=infinite). Default: 25,000,000.
|
||||
gas-cap = {{ .JSONRPC.GasCap }}
|
||||
`
|
||||
|
||||
@@ -31,6 +31,7 @@ const (
|
||||
JSONRPCAddress = "json-rpc.address"
|
||||
JSONWsAddress = "json-rpc.ws-address"
|
||||
JSONEnableUnsafeCORS = "json-rpc.enable-unsafe-cors"
|
||||
JSONRPCGasCap = "json-rpc.gas-cap"
|
||||
)
|
||||
|
||||
// EVM flags
|
||||
|
||||
@@ -143,6 +143,7 @@ which accepts a path for the resulting pprof file.
|
||||
cmd.Flags().String(srvflags.JSONRPCAddress, config.DefaultJSONRPCAddress, "the JSON-RPC server address to listen on")
|
||||
cmd.Flags().String(srvflags.JSONWsAddress, config.DefaultJSONRPCWsAddress, "the JSON-RPC WS server address to listen on")
|
||||
cmd.Flags().Bool(srvflags.JSONEnableUnsafeCORS, false, "Define if the JSON-RPC server should enabled CORS (unsafe - use it at your own risk)")
|
||||
cmd.Flags().Uint64(srvflags.JSONRPCGasCap, config.DefaultGasCap, "Sets a cap on gas that can be used in eth_call/estimateGas (0=infinite)")
|
||||
|
||||
cmd.Flags().String(srvflags.EVMTracer, config.DefaultEVMTracer, "the EVM tracer type to collect execution traces from the EVM transaction execution (json|struct|access_list|markdown)")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user