Skip to content

Commit d48ac69

Browse files
committed
feat[upload-relay]: allow configuration of max_body_size_limit
1 parent 43a6df0 commit d48ac69

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

crates/walrus-e2e-tests/tests/test_client.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,12 +2612,14 @@ async fn test_store_with_upload_relay_no_tip() {
26122612
let upload_relay_sui_client = get_client_with_config(walrus_client_config, &registry)
26132613
.await
26142614
.expect("create upload relay sui client");
2615+
const BLOB_SIZE: usize = 40000;
26152616
let upload_relay_handle: UploadRelayHandle = walrus_upload_relay::start_upload_relay(
26162617
upload_relay_sui_client,
26172618
WalrusUploadRelayConfig {
26182619
tip_config: TipConfig::NoTip,
26192620
tx_freshness_threshold: Duration::from_mins(5),
26202621
tx_max_future_threshold: Duration::from_secs(10),
2622+
max_body_size_limit: BLOB_SIZE,
26212623
},
26222624
server_address,
26232625
registry,
@@ -2640,9 +2642,13 @@ async fn test_store_with_upload_relay_no_tip() {
26402642
)
26412643
.await
26422644
.expect("upload relay client creation should succeed");
2643-
match basic_store_and_read(&cluster_client, 1, 40000, Some(upload_relay_client), || {
2644-
Ok(())
2645-
})
2645+
match basic_store_and_read(
2646+
&cluster_client,
2647+
1,
2648+
BLOB_SIZE,
2649+
Some(upload_relay_client),
2650+
|| Ok(()),
2651+
)
26462652
.await
26472653
{
26482654
Ok(_) => {}
@@ -2725,6 +2731,7 @@ async fn test_store_with_upload_relay_with_tip() {
27252731

27262732
const TIP_BASE: u64 = 1000;
27272733
const TIP_MULTIPLIER: u64 = 100;
2734+
const BLOB_SIZE: usize = 40000;
27282735

27292736
let registry = Registry::default();
27302737

@@ -2743,6 +2750,7 @@ async fn test_store_with_upload_relay_with_tip() {
27432750
},
27442751
tx_freshness_threshold: Duration::from_mins(5),
27452752
tx_max_future_threshold: Duration::from_secs(10),
2753+
max_body_size_limit: BLOB_SIZE,
27462754
},
27472755
server_address,
27482756
registry,
@@ -2792,7 +2800,6 @@ async fn test_store_with_upload_relay_with_tip() {
27922800
.expect("get balance")
27932801
.total_balance;
27942802

2795-
const BLOB_SIZE: usize = 40000;
27962803
match basic_store_and_read(
27972804
&cluster_client,
27982805
1,

crates/walrus-upload-relay/src/controller.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ pub struct WalrusUploadRelayConfig {
8686
///
8787
/// This is to account for clock skew between the Walrus upload relay and the full nodes.
8888
pub tx_max_future_threshold: Duration,
89+
/// The maximum body size limit for incoming requests, in bytes. Defaults to 1 GiB.
90+
#[serde(default = "defaults::default_max_body_size_limit")]
91+
pub max_body_size_limit: usize,
8992
}
9093

9194
/// The subset of query parameters of the Walrus Upload Relay, necessary to check the tip.
@@ -388,7 +391,7 @@ async fn run_server(
388391
))
389392
.route(TIP_CONFIG_ROUTE, get(send_tip_config))
390393
.route(BLOB_UPLOAD_RELAY_ROUTE, post(blob_upload_relay_handler))
391-
.layer(DefaultBodyLimit::max(1024 * 1024 * 1024))
394+
.layer(DefaultBodyLimit::max(relay_config.max_body_size_limit))
392395
.with_state(Arc::new(Controller::new(
393396
client,
394397
n_shards,
@@ -598,6 +601,13 @@ pub async fn get_client_with_config(
598601
)?)
599602
}
600603

604+
mod defaults {
605+
/// The default maximum body size limit for incoming requests, in bytes.
606+
pub fn default_max_body_size_limit() -> usize {
607+
1024 * 1024 * 1024 // 1 GiB
608+
}
609+
}
610+
601611
#[cfg(test)]
602612
mod tests {
603613
use std::time::Duration;
@@ -607,7 +617,7 @@ mod tests {
607617
use utoipa_redoc::Redoc;
608618
use walrus_sdk::upload_relay::tip_config::{TipConfig, TipKind};
609619

610-
use super::{WalrusUploadRelayApiDoc, WalrusUploadRelayConfig};
620+
use super::{WalrusUploadRelayApiDoc, WalrusUploadRelayConfig, defaults};
611621

612622
const EXAMPLE_CONFIG_PATH: &str = "walrus_upload_relay_config_example.yaml";
613623

@@ -620,6 +630,7 @@ mod tests {
620630
},
621631
tx_freshness_threshold: Duration::from_hours(10),
622632
tx_max_future_threshold: Duration::from_secs(30),
633+
max_body_size_limit: defaults::default_max_body_size_limit(),
623634
};
624635

625636
walrus_test_utils::overwrite_file_and_fail_if_not_equal(

crates/walrus-upload-relay/walrus_upload_relay_config_example.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ tx_freshness_threshold_secs: 36000
55
tx_max_future_threshold:
66
secs: 30
77
nanos: 0
8+
max_body_size_limit: 1073741824

0 commit comments

Comments
 (0)