Skip to content

Commit 19859e3

Browse files
authored
feat: implement max/min req/res sizes (#10)
we need to prepare for implementation of FCUs deduplication (this avalanche problem still persists). that will require assembly of incoming requests before the decision whether to proxy them or not is made => and for that we will need buffers + reasonable limits.
2 parents 7e231f4 + bfa7ec8 commit 19859e3

File tree

7 files changed

+511
-259
lines changed

7 files changed

+511
-259
lines changed

crates/rproxy/src/server/proxy/config/authrpc.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,28 @@ pub(crate) struct ConfigAuthrpc {
131131
)]
132132
pub(crate) log_sanitise: bool,
133133

134+
/// max size of authrpc requests
135+
#[arg(
136+
default_value = "16",
137+
env = "RPROXY_AUTHRPC_MAX_REQUEST_SIZE_MB",
138+
help_heading = "authrpc",
139+
long("authrpc-max-request-size-mb"),
140+
name("authrpc_max_request_size_mb"),
141+
value_name = "megabytes"
142+
)]
143+
pub(crate) max_request_size_mb: usize,
144+
145+
/// max size of authrpc responses
146+
#[arg(
147+
default_value = "256",
148+
env = "RPROXY_AUTHRPC_MAX_RESPONSE_SIZE_MB",
149+
help_heading = "authrpc",
150+
long("authrpc-max-response-size-mb"),
151+
name("authrpc_max_response_size_mb"),
152+
value_name = "megabytes"
153+
)]
154+
pub(crate) max_response_size_mb: usize,
155+
134156
/// list of authrpc peers urls to mirror the requests to
135157
#[arg(
136158
env="RPROXY_AUTHRPC_MIRRORING_PEERS",
@@ -153,6 +175,28 @@ pub(crate) struct ConfigAuthrpc {
153175
#[clap(value_enum)]
154176
pub(crate) mirroring_strategy: ConfigProxyHttpMirroringStrategy,
155177

178+
/// size of preallocated authrpc request buffers
179+
#[arg(
180+
default_value = "1",
181+
env = "RPROXY_AUTHRPC_PREALLOCATED_RESPONSE_BUFFER_SIZE_KB",
182+
help_heading = "authrpc",
183+
long("authrpc-preallocated-request-buffer-size-kb"),
184+
name("authrpc_preallocated_request_buffer_size_kb"),
185+
value_name = "kilobytes"
186+
)]
187+
pub(crate) prealloacated_request_buffer_size_kb: usize,
188+
189+
/// size of preallocated authrpc response buffers
190+
#[arg(
191+
default_value = "1",
192+
env = "RPROXY_AUTHRPC_PREALLOCATED_RESPONSE_BUFFER_SIZE_KB",
193+
help_heading = "authrpc",
194+
long("authrpc-preallocated-response-buffer-size-kb"),
195+
name("authrpc_preallocated_response_buffer_size_kb"),
196+
value_name = "kilobytes"
197+
)]
198+
pub(crate) prealloacated_response_buffer_size_kb: usize,
199+
156200
/// remove authrpc backend from mirroring peers
157201
#[arg(
158202
env = "RPROXY_AUTHRPC_REMOVE_BACKEND_FROM_MIRRORING_PEERS",
@@ -329,6 +373,16 @@ impl ConfigProxyHttp for ConfigAuthrpc {
329373
self.log_sanitise
330374
}
331375

376+
#[inline]
377+
fn max_request_size(&self) -> usize {
378+
1024 * 1024 * self.max_request_size_mb
379+
}
380+
381+
#[inline]
382+
fn max_response_size(&self) -> usize {
383+
1024 * 1024 * self.max_response_size_mb
384+
}
385+
332386
#[inline]
333387
fn mirroring_peer_urls(&self) -> Vec<Url> {
334388
self.mirroring_peer_urls
@@ -341,6 +395,16 @@ impl ConfigProxyHttp for ConfigAuthrpc {
341395
fn mirroring_strategy(&self) -> &ConfigProxyHttpMirroringStrategy {
342396
&self.mirroring_strategy
343397
}
398+
399+
#[inline]
400+
fn prealloacated_request_buffer_size(&self) -> usize {
401+
1024 * self.prealloacated_request_buffer_size_kb
402+
}
403+
404+
#[inline]
405+
fn prealloacated_response_buffer_size(&self) -> usize {
406+
1024 * self.prealloacated_response_buffer_size_kb
407+
}
344408
}
345409

346410
// ConfigAuthrpcError --------------------------------------------------

crates/rproxy/src/server/proxy/config/flashblocks.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ pub(crate) struct ConfigFlashblocks {
6363
)]
6464
pub(crate) log_backend_messages: bool,
6565

66-
/// whether to log flashblocks backend messages
67-
#[arg(
68-
env = "RPROXY_FLASHBLOCKS_LOG_BACKEND_MESSAGES",
69-
help_heading = "flashblocks",
70-
long("flashblocks-log-backend-messages"),
71-
name("flashblocks_log_backend_messages")
72-
)]
73-
7466
/// whether to log flashblocks client messages
7567
#[arg(
7668
env = "RPROXY_FLASHBLOCKS_LOG_CLIENT_MESSAGES",

crates/rproxy/src/server/proxy/config/rpc.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,28 @@ pub(crate) struct ConfigRpc {
130130
)]
131131
pub(crate) log_sanitise: bool,
132132

133+
/// max size of rpc requests
134+
#[arg(
135+
default_value = "16",
136+
env = "RPROXY_RPC_MAX_REQUEST_SIZE_MB",
137+
help_heading = "rpc",
138+
long("rpc-max-request-size-mb"),
139+
name("rpc_max_request_size_mb"),
140+
value_name = "megabytes"
141+
)]
142+
pub(crate) max_request_size_mb: usize,
143+
144+
/// max size of rpc responses
145+
#[arg(
146+
default_value = "256",
147+
env = "RPROXY_RPC_MAX_RESPONSE_SIZE_MB",
148+
help_heading = "rpc",
149+
long("rpc-max-response-size-mb"),
150+
name("rpc_max_response_size_mb"),
151+
value_name = "megabytes"
152+
)]
153+
pub(crate) max_response_size_mb: usize,
154+
133155
/// whether the requests that returned an error from rpc backend should
134156
/// be mirrored to peers
135157
#[arg(
@@ -162,6 +184,28 @@ pub(crate) struct ConfigRpc {
162184
#[clap(value_enum)]
163185
pub(crate) mirroring_strategy: ConfigProxyHttpMirroringStrategy,
164186

187+
/// size of preallocated rpc request buffers
188+
#[arg(
189+
default_value = "1",
190+
env = "RPROXY_RPC_PREALLOCATED_RESPONSE_BUFFER_SIZE_KB",
191+
help_heading = "rpc",
192+
long("rpc-preallocated-request-buffer-size-kb"),
193+
name("rpc_preallocated_request_buffer_size_kb"),
194+
value_name = "kilobytes"
195+
)]
196+
pub(crate) prealloacated_request_buffer_size_kb: usize,
197+
198+
/// size of preallocated rpc response buffers
199+
#[arg(
200+
default_value = "256",
201+
env = "RPROXY_RPC_PREALLOCATED_RESPONSE_BUFFER_SIZE_KB",
202+
help_heading = "rpc",
203+
long("rpc-preallocated-response-buffer-size-kb"),
204+
name("rpc_preallocated_response_buffer_size_kb"),
205+
value_name = "kilobytes"
206+
)]
207+
pub(crate) prealloacated_response_buffer_size_kb: usize,
208+
165209
/// remove rpc backend from peers
166210
#[arg(
167211
env = "RPROXY_RPC_REMOVE_BACKEND_FROM_MIRRORING_PEERS",
@@ -335,6 +379,16 @@ impl ConfigProxyHttp for ConfigRpc {
335379
self.log_sanitise
336380
}
337381

382+
#[inline]
383+
fn max_request_size(&self) -> usize {
384+
1024 * 1024 * self.max_request_size_mb
385+
}
386+
387+
#[inline]
388+
fn max_response_size(&self) -> usize {
389+
1024 * 1024 * self.max_response_size_mb
390+
}
391+
338392
#[inline]
339393
fn mirroring_peer_urls(&self) -> Vec<Url> {
340394
self.mirroring_peer_urls
@@ -347,6 +401,16 @@ impl ConfigProxyHttp for ConfigRpc {
347401
fn mirroring_strategy(&self) -> &ConfigProxyHttpMirroringStrategy {
348402
&self.mirroring_strategy
349403
}
404+
405+
#[inline]
406+
fn prealloacated_request_buffer_size(&self) -> usize {
407+
1024 * self.prealloacated_request_buffer_size_kb
408+
}
409+
410+
#[inline]
411+
fn prealloacated_response_buffer_size(&self) -> usize {
412+
1024 * self.prealloacated_response_buffer_size_kb
413+
}
350414
}
351415

352416
// ConfigRpcError ------------------------------------------------------

crates/rproxy/src/server/proxy/http/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ pub(crate) trait ConfigProxyHttp: Clone + Send + Unpin + 'static {
1515
fn log_proxied_requests(&self) -> bool;
1616
fn log_proxied_responses(&self) -> bool;
1717
fn log_sanitise(&self) -> bool;
18+
fn max_request_size(&self) -> usize;
19+
fn max_response_size(&self) -> usize;
1820
fn mirroring_peer_urls(&self) -> Vec<Url>;
1921
fn mirroring_strategy(&self) -> &ConfigProxyHttpMirroringStrategy;
22+
fn prealloacated_request_buffer_size(&self) -> usize;
23+
fn prealloacated_response_buffer_size(&self) -> usize;
2024
}
2125

2226
// ConfigProxyHttpMirroringStrategy ------------------------------------

0 commit comments

Comments
 (0)