Skip to content

Commit 555f17f

Browse files
committed
make limit configurable
1 parent dd1083a commit 555f17f

File tree

6 files changed

+26
-1
lines changed

6 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4949
### Features
5050

5151
* (rpc) [#1682](https://github.com/evmos/ethermint/pull/1682) Add config for maximum number of bytes returned from eth_call.
52+
* (rpc) [#268](https://github.com/crypto-org-chain/ethermint/pull/268) Add config for maximum number of requests and bytes returned from a batched call.
5253

5354
### Bug Fixes
5455

server/config/config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ const (
6363

6464
// DefaultReturnDataLimit is maximum number of bytes returned from eth_call or similar invocations
6565
DefaultReturnDataLimit = 100000
66+
67+
// DefaultBatchRequestLimit is maximum number of requests in a batch
68+
DefaultBatchRequestLimit = 1000
69+
70+
// DefaultBatchResponseMaxSize maximum number of bytes returned from a batched call
71+
DefaultBatchResponseMaxSize = 25 * 1000 * 1000
6672
)
6773

6874
var evmTracers = []string{"json", "markdown", "struct", "access_list"}
@@ -126,6 +132,10 @@ type JSONRPCConfig struct {
126132
MetricsAddress string `mapstructure:"metrics-address"`
127133
// ReturnDataLimit defines maximum number of bytes returned from `eth_call` or similar invocations
128134
ReturnDataLimit int64 `mapstructure:"return-data-limit"`
135+
// BatchRequestLimit maximum number of requests in a batch
136+
BatchRequestLimit int64 `mapstructure:"batch-request-limit"`
137+
// BatchResponseMaxSize maximum number of bytes returned from a batched call
138+
BatchResponseMaxSize int64 `mapstructure:"batch-response-max-size"`
129139
// FixRevertGasRefundHeight defines the upgrade height for fix of revert gas refund logic when transaction reverted
130140
FixRevertGasRefundHeight int64 `mapstructure:"fix-revert-gas-refund-height"`
131141
}
@@ -231,6 +241,8 @@ func DefaultJSONRPCConfig() *JSONRPCConfig {
231241
EnableIndexer: false,
232242
MetricsAddress: DefaultJSONRPCMetricsAddress,
233243
ReturnDataLimit: DefaultReturnDataLimit,
244+
BatchRequestLimit: DefaultBatchRequestLimit,
245+
BatchResponseMaxSize: DefaultBatchResponseMaxSize,
234246
FixRevertGasRefundHeight: DefaultFixRevertGasRefundHeight,
235247
}
236248
}
@@ -343,6 +355,8 @@ func GetConfig(v *viper.Viper) (Config, error) {
343355
MetricsAddress: v.GetString("json-rpc.metrics-address"),
344356
ReturnDataLimit: v.GetInt64("json-rpc.return-data-limit"),
345357
FixRevertGasRefundHeight: v.GetInt64("json-rpc.fix-revert-gas-refund-height"),
358+
BatchRequestLimit: v.GetInt64("json-rpc.batch-request-limit"),
359+
BatchResponseMaxSize: v.GetInt64("json-rpc.batch-response-max-size"),
346360
},
347361
TLS: TLSConfig{
348362
CertificatePath: v.GetString("tls.certificate-path"),

server/config/toml.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ metrics-address = "{{ .JSONRPC.MetricsAddress }}"
8080
# Maximum number of bytes returned from eth_call or similar invocations.
8181
return-data-limit = {{ .JSONRPC.ReturnDataLimit }}
8282
83+
# Maximum number of requests in a batch.
84+
batch-request-limit = {{ .JSONRPC.BatchRequestLimit }}
85+
86+
# Maximum number of bytes returned from a batched call.
87+
batch-response-max-size = {{ .JSONRPC.BatchResponseMaxSize }}
88+
8389
# Upgrade height for fix of revert gas refund logic when transaction reverted.
8490
fix-revert-gas-refund-height = {{ .JSONRPC.FixRevertGasRefundHeight }}
8591

server/flags/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ const (
5555
// https://github.com/ethereum/go-ethereum/blob/master/metrics/metrics.go#L35-L55
5656
JSONRPCEnableMetrics = "metrics"
5757
JSONRPCReturnDataLimit = "json-rpc.return-data-limit"
58+
JSONRPCBatchRequestLimit = "json-rpc.batch-request-limit"
59+
JSONRPCBatchResponseMaxSize = "json-rpc.batch-response-max-size"
5860
JSONRPCFixRevertGasRefundHeight = "json-rpc.fix-revert-gas-refund-height"
5961
)
6062

server/json_rpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func StartJSONRPC(ctx *server.Context,
4242
}))
4343

4444
rpcServer := ethrpc.NewServer()
45-
rpcServer.SetBatchLimits(2, 1) // add 0x: (3594240 + 2) * 4
45+
rpcServer.SetBatchLimits(int(config.JSONRPC.BatchRequestLimit), int(config.JSONRPC.BatchResponseMaxSize)) // add 0x: (3594240 + 2) * 4
4646
allowUnprotectedTxs := config.JSONRPC.AllowUnprotectedTxs
4747
rpcAPIArr := config.JSONRPC.API
4848

tests/integration_tests/configs/exploit.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ config {
55
'app-config'+: {
66
'json-rpc'+: {
77
'return-data-limit': 3594241, // memory_byte_size + 1
8+
'batch-request-limit': 2,
9+
'batch-response-max-size': 10,
810
},
911
},
1012
},

0 commit comments

Comments
 (0)