Skip to content

Commit

Permalink
fix(storage-provider): make default body limit max sector size (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmg-duarte authored Feb 10, 2025
1 parent 3d1b253 commit 3716ba1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
21 changes: 11 additions & 10 deletions storage-provider/server/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl RpcServerState {
}

let current_block = self.xt_client.height(true).await?;
if deal.start_block < current_block {
if current_block > deal.start_block {
return Err(RpcError::invalid_params(
format!(
"Deal starts in the past: current_block = {}, deal_start_block = {}",
Expand Down Expand Up @@ -108,8 +108,8 @@ impl RpcServerState {
if deal.piece_size > post_sector_size {
return Err(RpcError::invalid_params(
format!(
"Deal starts in the past: current_block = {}, deal_start_block = {}",
current_block, deal.start_block
"Deal piece size is larger than the supported sector size: piece_size = {}, sector_size = {}",
deal.piece_size, post_sector_size
),
None,
));
Expand All @@ -119,19 +119,20 @@ impl RpcServerState {
if deal.provider != provider_id {
return Err(RpcError::invalid_params(
format!(
"Deal starts in the past: current_block = {}, deal_start_block = {}",
current_block, deal.start_block
"Deal provider does not match current provider: deal_provider_id = {}, current_provider_id = {}",
deal.provider, provider_id
),
None,
));
}

let piece_cid_codec = deal.piece_cid.codec();
if piece_cid_codec != CommP::multicodec() {
let commp_codec = CommP::multicodec();
if piece_cid_codec != commp_codec {
return Err(RpcError::invalid_params(
format!(
"Deal starts in the past: current_block = {}, deal_start_block = {}",
current_block, deal.start_block
"Piece's CID codec is not a piece commitment: piece_cid_codec = {}, commitment_cid_codec = {}",
piece_cid_codec, commp_codec
),
None,
));
Expand All @@ -140,8 +141,8 @@ impl RpcServerState {
if !deal.piece_size.is_power_of_two() {
return Err(RpcError::invalid_params(
format!(
"Deal starts in the past: current_block = {}, deal_start_block = {}",
current_block, deal.start_block
"Deal's piece size not a power of two: piece_size = {}",
deal.piece_size
),
None,
));
Expand Down
24 changes: 22 additions & 2 deletions storage-provider/server/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,24 @@ pub async fn start_upload_server(
fn configure_router(state: Arc<StorageServerState>) -> Router {
#[cfg(feature = "delia")]
fn config_delia(state: Arc<StorageServerState>) -> Router {
use axum::extract::DefaultBodyLimit;

let cors = CorsLayer::new()
.allow_origin(Any)
.allow_methods([Method::GET, Method::POST, Method::PUT, Method::OPTIONS])
.allow_headers([header::CONTENT_TYPE])
.max_age(std::time::Duration::from_secs(3600));

Router::new()
.route("/upload/:cid", put(upload))
.route(
"/upload/:cid",
put(upload)
// Limit upload size to maximum sector size
.layer(DefaultBodyLimit::max(
// Cast is safe because we're not supporting 32-bit systems
state.post_proof.sector_size().bytes() as usize,
)),
)
.route("/download/:cid", get(download))
.route("/calculate_piece_cid", put(calculate_piece_cid))
.route("/encode_proposal", post(encode_proposal))
Expand Down Expand Up @@ -115,8 +125,18 @@ fn configure_router(state: Arc<StorageServerState>) -> Router {

#[cfg(not(feature = "delia"))]
fn config_non_delia(state: Arc<StorageServerState>) -> Router {
use axum::extract::DefaultBodyLimit;

Router::new()
.route("/upload/:cid", put(upload))
.route(
"/upload/:cid",
put(upload)
// Limit upload size to maximum sector size
.layer(DefaultBodyLimit::max(
// Cast is safe because we're not supporting 32-bit systems
state.post_proof.sector_size().bytes() as usize,
)),
)
.route("/download/:cid", get(download))
.with_state(state)
.layer(
Expand Down

0 comments on commit 3716ba1

Please sign in to comment.