Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jsonrpc): Added configuration to the RPC payload size limit #3237

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions chain/jsonrpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ use near_primitives::utils::is_valid_account_id;
use near_primitives::views::{FinalExecutionOutcomeView, GenesisRecordsView, QueryRequest};
mod metrics;

/// Maximum byte size of the json payload.
const JSON_PAYLOAD_MAX_SIZE: usize = 2 * 1024 * 1024;
/// Max size of the query path (soft-deprecated)
const QUERY_DATA_MAX_SIZE: usize = 10 * 1024;

#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
Expand All @@ -66,11 +65,25 @@ impl Default for RpcPollingConfig {
}
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct RpcLimitsConfig {
/// Maximum byte size of the json payload.
pub json_payload_max_size: usize,
}

impl Default for RpcLimitsConfig {
fn default() -> Self {
Self { json_payload_max_size: 10 * 1024 * 1024 }
}
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct RpcConfig {
pub addr: String,
pub cors_allowed_origins: Vec<String>,
pub polling_config: RpcPollingConfig,
#[serde(default)]
pub limits_config: RpcLimitsConfig,
}

impl Default for RpcConfig {
Expand All @@ -79,6 +92,7 @@ impl Default for RpcConfig {
addr: "0.0.0.0:3030".to_owned(),
cors_allowed_origins: vec!["*".to_owned()],
polling_config: Default::default(),
limits_config: Default::default(),
}
}
}
Expand Down Expand Up @@ -926,7 +940,7 @@ pub fn start_http(
client_addr: Addr<ClientActor>,
view_client_addr: Addr<ViewClientActor>,
) {
let RpcConfig { addr, polling_config, cors_allowed_origins } = config;
let RpcConfig { addr, cors_allowed_origins, polling_config, limits_config } = config;
HttpServer::new(move || {
App::new()
.wrap(get_cors(&cors_allowed_origins))
Expand All @@ -936,7 +950,7 @@ pub fn start_http(
polling_config,
genesis: Arc::clone(&genesis),
})
.app_data(web::JsonConfig::default().limit(JSON_PAYLOAD_MAX_SIZE))
.app_data(web::JsonConfig::default().limit(limits_config.json_payload_max_size))
.wrap(middleware::Logger::default())
.service(web::resource("/").route(web::post().to(rpc_handler)))
.service(
Expand Down