-
Notifications
You must be signed in to change notification settings - Fork 880
Expand file tree
/
Copy pathconfig.go
More file actions
301 lines (271 loc) · 10.3 KB
/
config.go
File metadata and controls
301 lines (271 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
package evmrpc
import (
"runtime"
"time"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/spf13/cast"
)
// EVMRPC Config defines configurations for EVM RPC server on this node
type Config struct {
// controls whether an HTTP EVM server is enabled
HTTPEnabled bool `mapstructure:"http_enabled"`
HTTPPort int `mapstructure:"http_port"`
// controls whether a websocket server is enabled
WSEnabled bool `mapstructure:"ws_enabled"`
WSPort int `mapstructure:"ws_port"`
// ReadTimeout is the maximum duration for reading the entire
// request, including the body.
//
// Because ReadTimeout does not let Handlers make per-request
// decisions on each request body's acceptable deadline or
// upload rate, most users will prefer to use
// ReadHeaderTimeout. It is valid to use them both.
ReadTimeout time.Duration `mapstructure:"read_timeout"`
// ReadHeaderTimeout is the amount of time allowed to read
// request headers. The connection's read deadline is reset
// after reading the headers and the Handler can decide what
// is considered too slow for the body. If ReadHeaderTimeout
// is zero, the value of ReadTimeout is used. If both are
// zero, there is no timeout.
ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout"`
// WriteTimeout is the maximum duration before timing out
// writes of the response. It is reset whenever a new
// request's header is read. Like ReadTimeout, it does not
// let Handlers make decisions on a per-request basis.
WriteTimeout time.Duration `mapstructure:"write_timeout"`
// IdleTimeout is the maximum amount of time to wait for the
// next request when keep-alives are enabled. If IdleTimeout
// is zero, the value of ReadTimeout is used. If both are
// zero, ReadHeaderTimeout is used.
IdleTimeout time.Duration `mapstructure:"idle_timeout"`
// Maximum gas limit for simulation
SimulationGasLimit uint64 `mapstructure:"simulation_gas_limit"`
// Timeout for EVM call in simulation
SimulationEVMTimeout time.Duration `mapstructure:"simulation_evm_timeout"`
// list of CORS allowed origins, separated by comma
CORSOrigins string `mapstructure:"cors_origins"`
// list of WS origins, separated by comma
WSOrigins string `mapstructure:"ws_origins"`
// timeout for filters
FilterTimeout time.Duration `mapstructure:"filter_timeout"`
// checkTx timeout for sig verify
CheckTxTimeout time.Duration `mapstructure:"checktx_timeout"`
// max number of txs to pull from mempool
MaxTxPoolTxs uint64 `mapstructure:"max_tx_pool_txs"`
// controls whether to have txns go through one by one
Slow bool `mapstructure:"slow"`
// Deny list defines list of methods that EVM RPC should fail fast
DenyList []string `mapstructure:"deny_list"`
// max number of logs returned if block range is open-ended
MaxLogNoBlock int64 `mapstructure:"max_log_no_block"`
// max number of blocks to query logs for
MaxBlocksForLog int64 `mapstructure:"max_blocks_for_log"`
// max number of concurrent NewHead subscriptions
MaxSubscriptionsNewHead uint64 `mapstructure:"max_subscriptions_new_head"`
// test api enables certain override apis for integration test situations
EnableTestAPI bool `mapstructure:"enable_test_api"`
// MaxConcurrentTraceCalls defines the maximum number of concurrent debug_trace calls.
// Set to 0 for unlimited.
MaxConcurrentTraceCalls uint64 `mapstructure:"max_concurrent_trace_calls"`
// MaxConcurrentSimulationCalls defines the maximum number of concurrent eth_call calls.
// Set to 0 for unlimited.
MaxConcurrentSimulationCalls int `mapstructure:"max_concurrent_simulation_calls"`
// Max number of blocks allowed to look back for tracing
MaxTraceLookbackBlocks int64 `mapstructure:"max_trace_lookback_blocks"`
// Timeout for each trace call
TraceTimeout time.Duration `mapstructure:"trace_timeout"`
// RPCStatsInterval for how often to report stats
RPCStatsInterval time.Duration `mapstructure:"rpc_stats_interval"`
}
var DefaultConfig = Config{
HTTPEnabled: true,
HTTPPort: 8545,
WSEnabled: true,
WSPort: 8546,
ReadTimeout: rpc.DefaultHTTPTimeouts.ReadTimeout,
ReadHeaderTimeout: rpc.DefaultHTTPTimeouts.ReadHeaderTimeout,
WriteTimeout: rpc.DefaultHTTPTimeouts.WriteTimeout,
IdleTimeout: rpc.DefaultHTTPTimeouts.IdleTimeout,
SimulationGasLimit: 10_000_000, // 10M
SimulationEVMTimeout: 60 * time.Second,
CORSOrigins: "*",
WSOrigins: "*",
FilterTimeout: 120 * time.Second,
CheckTxTimeout: 5 * time.Second,
MaxTxPoolTxs: 1000,
Slow: false,
DenyList: make([]string, 0),
MaxLogNoBlock: 10000,
MaxBlocksForLog: 2000,
MaxSubscriptionsNewHead: 10000,
EnableTestAPI: false,
MaxConcurrentTraceCalls: 10,
MaxConcurrentSimulationCalls: runtime.NumCPU(),
MaxTraceLookbackBlocks: 10000,
TraceTimeout: 30 * time.Second,
RPCStatsInterval: 10 * time.Second,
}
const (
flagHTTPEnabled = "evm.http_enabled"
flagHTTPPort = "evm.http_port"
flagWSEnabled = "evm.ws_enabled"
flagWSPort = "evm.ws_port"
flagReadTimeout = "evm.read_timeout"
flagReadHeaderTimeout = "evm.read_header_timeout"
flagWriteTimeout = "evm.write_timeout"
flagIdleTimeout = "evm.idle_timeout"
flagSimulationGasLimit = "evm.simulation_gas_limit"
flagSimulationEVMTimeout = "evm.simulation_evm_timeout"
flagCORSOrigins = "evm.cors_origins"
flagWSOrigins = "evm.ws_origins"
flagFilterTimeout = "evm.filter_timeout"
flagMaxTxPoolTxs = "evm.max_tx_pool_txs"
flagCheckTxTimeout = "evm.checktx_timeout"
flagSlow = "evm.slow"
flagDenyList = "evm.deny_list"
flagMaxLogNoBlock = "evm.max_log_no_block"
flagMaxBlocksForLog = "evm.max_blocks_for_log"
flagMaxSubscriptionsNewHead = "evm.max_subscriptions_new_head"
flagEnableTestAPI = "evm.enable_test_api"
flagMaxConcurrentTraceCalls = "evm.max_concurrent_trace_calls"
flagMaxConcurrentSimulationCalls = "evm.max_concurrent_simulation_calls"
flagMaxTraceLookbackBlocks = "evm.max_trace_lookback_blocks"
flagTraceTimeout = "evm.trace_timeout"
flagRPCStatsInterval = "evm.rpc_stats_interval"
)
func ReadConfig(opts servertypes.AppOptions) (Config, error) {
cfg := DefaultConfig // copy
var err error
if v := opts.Get(flagHTTPEnabled); v != nil {
if cfg.HTTPEnabled, err = cast.ToBoolE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagHTTPPort); v != nil {
if cfg.HTTPPort, err = cast.ToIntE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagWSEnabled); v != nil {
if cfg.WSEnabled, err = cast.ToBoolE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagWSPort); v != nil {
if cfg.WSPort, err = cast.ToIntE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagReadTimeout); v != nil {
if cfg.ReadTimeout, err = cast.ToDurationE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagReadHeaderTimeout); v != nil {
if cfg.ReadHeaderTimeout, err = cast.ToDurationE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagWriteTimeout); v != nil {
if cfg.WriteTimeout, err = cast.ToDurationE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagIdleTimeout); v != nil {
if cfg.IdleTimeout, err = cast.ToDurationE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagSimulationGasLimit); v != nil {
if cfg.SimulationGasLimit, err = cast.ToUint64E(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagSimulationEVMTimeout); v != nil {
if cfg.SimulationEVMTimeout, err = cast.ToDurationE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagCORSOrigins); v != nil {
if cfg.CORSOrigins, err = cast.ToStringE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagWSOrigins); v != nil {
if cfg.WSOrigins, err = cast.ToStringE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagFilterTimeout); v != nil {
if cfg.FilterTimeout, err = cast.ToDurationE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagCheckTxTimeout); v != nil {
if cfg.CheckTxTimeout, err = cast.ToDurationE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagMaxTxPoolTxs); v != nil {
if cfg.MaxTxPoolTxs, err = cast.ToUint64E(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagSlow); v != nil {
if cfg.Slow, err = cast.ToBoolE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagDenyList); v != nil {
if cfg.DenyList, err = cast.ToStringSliceE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagMaxLogNoBlock); v != nil {
if cfg.MaxLogNoBlock, err = cast.ToInt64E(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagMaxBlocksForLog); v != nil {
if cfg.MaxBlocksForLog, err = cast.ToInt64E(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagMaxSubscriptionsNewHead); v != nil {
if cfg.MaxSubscriptionsNewHead, err = cast.ToUint64E(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagEnableTestAPI); v != nil {
if cfg.EnableTestAPI, err = cast.ToBoolE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagMaxConcurrentTraceCalls); v != nil {
if cfg.MaxConcurrentTraceCalls, err = cast.ToUint64E(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagMaxConcurrentSimulationCalls); v != nil {
if cfg.MaxConcurrentSimulationCalls, err = cast.ToIntE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagMaxTraceLookbackBlocks); v != nil {
if cfg.MaxTraceLookbackBlocks, err = cast.ToInt64E(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagTraceTimeout); v != nil {
if cfg.TraceTimeout, err = cast.ToDurationE(v); err != nil {
return cfg, err
}
}
if v := opts.Get(flagRPCStatsInterval); v != nil {
if cfg.RPCStatsInterval, err = cast.ToDurationE(v); err != nil {
return cfg, err
}
}
return cfg, nil
}