forked from cerc-io/laconicd-deprecated
fix: OOM when eth_getLogs response too large (#860)
* fix: OOM when eth_getLogs response too large Closes: #858 - add limit to number of logs of filter response - make block limit and log limit configurable * return error if exceeds log limit * Apply suggestions from code review * parse from config * read cli flags * add to config template * fix bloomFilter * changelog * add validation Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
co-authored by
Federico Kunze Küllmer
parent
fdfe3d9761
commit
ced5280571
@@ -34,6 +34,10 @@ const (
|
||||
|
||||
DefaultFeeHistoryCap int32 = 100
|
||||
|
||||
DefaultLogsCap int32 = 10000
|
||||
|
||||
DefaultBlockRangeCap int32 = 10000
|
||||
|
||||
DefaultEVMTimeout = 5 * time.Second
|
||||
// default 1.0 eth
|
||||
DefaultTxFeeCap float64 = 1.0
|
||||
@@ -78,6 +82,10 @@ type JSONRPCConfig struct {
|
||||
FeeHistoryCap int32 `mapstructure:"feehistory-cap"`
|
||||
// Enable defines if the EVM RPC server should be enabled.
|
||||
Enable bool `mapstructure:"enable"`
|
||||
// LogsCap defines the max number of results can be returned from single `eth_getLogs` query.
|
||||
LogsCap int32 `mapstructure:"logs-cap"`
|
||||
// BlockRangeCap defines the max block range allowed for `eth_getLogs` query.
|
||||
BlockRangeCap int32 `mapstructure:"block-range-cap"`
|
||||
}
|
||||
|
||||
// TLSConfig defines the certificate and matching private key for the server.
|
||||
@@ -171,6 +179,8 @@ func DefaultJSONRPCConfig() *JSONRPCConfig {
|
||||
TxFeeCap: DefaultTxFeeCap,
|
||||
FilterCap: DefaultFilterCap,
|
||||
FeeHistoryCap: DefaultFeeHistoryCap,
|
||||
BlockRangeCap: DefaultBlockRangeCap,
|
||||
LogsCap: DefaultLogsCap,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +206,14 @@ func (c JSONRPCConfig) Validate() error {
|
||||
return errors.New("JSON-RPC EVM timeout duration cannot be negative")
|
||||
}
|
||||
|
||||
if c.LogsCap < 0 {
|
||||
return errors.New("JSON-RPC logs cap cannot be negative")
|
||||
}
|
||||
|
||||
if c.BlockRangeCap < 0 {
|
||||
return errors.New("JSON-RPC block range cap cannot be negative")
|
||||
}
|
||||
|
||||
// TODO: validate APIs
|
||||
seenAPIs := make(map[string]bool)
|
||||
for _, api := range c.API {
|
||||
@@ -253,6 +271,8 @@ func GetConfig(v *viper.Viper) Config {
|
||||
FeeHistoryCap: v.GetInt32("json-rpc.feehistory-cap"),
|
||||
TxFeeCap: v.GetFloat64("json-rpc.txfee-cap"),
|
||||
EVMTimeout: v.GetDuration("json-rpc.evm-timeout"),
|
||||
LogsCap: v.GetInt32("json-rpc.logs-cap"),
|
||||
BlockRangeCap: v.GetInt32("json-rpc.block-range-cap"),
|
||||
},
|
||||
TLS: TLSConfig{
|
||||
CertificatePath: v.GetString("tls.certificate-path"),
|
||||
|
||||
@@ -47,6 +47,11 @@ filter-cap = {{ .JSONRPC.FilterCap }}
|
||||
# FeeHistoryCap sets the global cap for total number of blocks that can be fetched
|
||||
feehistory-cap = {{ .JSONRPC.FeeHistoryCap }}
|
||||
|
||||
# LogsCap defines the max number of results can be returned from single 'eth_getLogs' query.
|
||||
logs-cap = {{ .JSONRPC.LogsCap }}
|
||||
|
||||
# BlockRangeCap defines the max block range allowed for 'eth_getLogs' query.
|
||||
block-range-cap = {{ .JSONRPC.BlockRangeCap }}
|
||||
|
||||
###############################################################################
|
||||
### TLS Configuration ###
|
||||
|
||||
+11
-9
@@ -26,15 +26,17 @@ const (
|
||||
|
||||
// JSON-RPC flags
|
||||
const (
|
||||
JSONRPCEnable = "json-rpc.enable"
|
||||
JSONRPCAPI = "json-rpc.api"
|
||||
JSONRPCAddress = "json-rpc.address"
|
||||
JSONWsAddress = "json-rpc.ws-address"
|
||||
JSONRPCGasCap = "json-rpc.gas-cap"
|
||||
JSONRPCEVMTimeout = "json-rpc.evm-timeout"
|
||||
JSONRPCTxFeeCap = "json-rpc.txfee-cap"
|
||||
JSONRPCFilterCap = "json-rpc.filter-cap"
|
||||
JSONRPFeeHistoryCap = "json-rpc.feehistory-cap"
|
||||
JSONRPCEnable = "json-rpc.enable"
|
||||
JSONRPCAPI = "json-rpc.api"
|
||||
JSONRPCAddress = "json-rpc.address"
|
||||
JSONWsAddress = "json-rpc.ws-address"
|
||||
JSONRPCGasCap = "json-rpc.gas-cap"
|
||||
JSONRPCEVMTimeout = "json-rpc.evm-timeout"
|
||||
JSONRPCTxFeeCap = "json-rpc.txfee-cap"
|
||||
JSONRPCFilterCap = "json-rpc.filter-cap"
|
||||
JSONRPFeeHistoryCap = "json-rpc.feehistory-cap"
|
||||
JSONRPCLogsCap = "json-rpc.logs-cap"
|
||||
JSONRPCBlockRangeCap = "json-rpc.block-range-cap"
|
||||
)
|
||||
|
||||
// EVM flags
|
||||
|
||||
@@ -157,6 +157,8 @@ which accepts a path for the resulting pprof file.
|
||||
cmd.Flags().Float64(srvflags.JSONRPCTxFeeCap, config.DefaultTxFeeCap, "Sets a cap on transaction fee that can be sent via the RPC APIs (1 = default 1 photon)")
|
||||
cmd.Flags().Int32(srvflags.JSONRPCFilterCap, config.DefaultFilterCap, "Sets the global cap for total number of filters that can be created")
|
||||
cmd.Flags().Duration(srvflags.JSONRPCEVMTimeout, config.DefaultEVMTimeout, "Sets a timeout used for eth_call (0=infinite)")
|
||||
cmd.Flags().Int32(srvflags.JSONRPCLogsCap, config.DefaultLogsCap, "Sets the max number of results can be returned from single `eth_getLogs` query")
|
||||
cmd.Flags().Int32(srvflags.JSONRPCBlockRangeCap, config.DefaultBlockRangeCap, "Sets the max block range allowed for `eth_getLogs` query")
|
||||
|
||||
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