Skip to content

Commit

Permalink
Make Celestia RPC timeout configurable (#482)
Browse files Browse the repository at this point in the history
* Make Celestia rpc timeout configurable

* fix comment

* Update demo-rollup celestia rpc timeout

* Update demo-rollup config comment

* Fix tests and bump default to 60 seconds (4*block time)

* Update test example

* Use 60 second timeouts in demo config

---------

Co-authored-by: Nikolai Golub <[email protected]>
  • Loading branch information
preston-evans98 and citizen-stig authored Jul 10, 2023
1 parent 225113e commit a691a28
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
35 changes: 22 additions & 13 deletions adapters/celestia/src/da_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::HashMap;
use std::future::Future;
use std::pin::Pin;
use std::str::FromStr;
use std::time::Duration;

use jsonrpsee::core::client::ClientT;
use jsonrpsee::core::params::ArrayParams;
Expand Down Expand Up @@ -97,6 +96,9 @@ pub struct DaServiceConfig {
/// The maximum size of a Celestia RPC response, in bytes
#[serde(default = "default_max_response_size")]
pub max_celestia_response_body_size: u32,
/// The timeout for a Celestia RPC request, in seconds
#[serde(default = "default_request_timeout_seconds")]
pub celestia_rpc_timeout_seconds: u64,
}

fn default_rpc_addr() -> String {
Expand All @@ -107,8 +109,8 @@ fn default_max_response_size() -> u32 {
1024 * 1024 * 100 // 100 MB
}

fn default_request_timeout_ms() -> u64 {
30_000
const fn default_request_timeout_seconds() -> u64 {
60
}

impl DaService for CelestiaService {
Expand All @@ -134,9 +136,10 @@ impl DaService for CelestiaService {

jsonrpsee::http_client::HttpClientBuilder::default()
.set_headers(headers)
// TODO: Should be replaced with config option https://github.com/Sovereign-Labs/sovereign-sdk/issues/478
.request_timeout(Duration::from_millis(default_request_timeout_ms()))
.max_request_body_size(config.max_celestia_response_body_size)
.max_request_body_size(config.max_celestia_response_body_size) // 100 MB
.request_timeout(std::time::Duration::from_secs(
config.celestia_rpc_timeout_seconds,
))
.build(&config.celestia_rpc_address)
}
.expect("Client initialization is valid");
Expand Down Expand Up @@ -341,7 +344,8 @@ mod tests {
use wiremock::matchers::{bearer_token, body_json, method, path};
use wiremock::{Mock, MockServer, Request, ResponseTemplate};

use crate::da_service::{default_request_timeout_ms, CelestiaService, DaServiceConfig};
use super::default_request_timeout_seconds;
use crate::da_service::{CelestiaService, DaServiceConfig};
use crate::parse_pfb_namespace;
use crate::shares::{NamespaceGroup, Share};
use crate::verifier::RollupParams;
Expand Down Expand Up @@ -383,14 +387,18 @@ mod tests {
}

// Last return value is namespace
async fn setup_service() -> (MockServer, DaServiceConfig, CelestiaService, [u8; 8]) {
async fn setup_service(
timeout_sec: Option<u64>,
) -> (MockServer, DaServiceConfig, CelestiaService, [u8; 8]) {
// Start a background HTTP server on a random local port
let mock_server = MockServer::start().await;

let timeout_sec = timeout_sec.unwrap_or_else(default_request_timeout_seconds);
let config = DaServiceConfig {
celestia_rpc_auth_token: "RPC_TOKEN".to_string(),
celestia_rpc_address: mock_server.uri(),
max_celestia_response_body_size: 120_000,
celestia_rpc_timeout_seconds: timeout_sec,
};
let namespace = [9u8; 8];
let da_service = CelestiaService::new(
Expand All @@ -413,7 +421,7 @@ mod tests {

#[tokio::test]
async fn test_submit_blob_correct() -> anyhow::Result<()> {
let (mock_server, config, da_service, namespace) = setup_service().await;
let (mock_server, config, da_service, namespace) = setup_service(None).await;

let blob: Vec<u8> = vec![1, 2, 3, 4, 5, 11, 12, 13, 14, 15];

Expand Down Expand Up @@ -469,7 +477,7 @@ mod tests {
#[tokio::test]
async fn test_submit_blob_application_level_error() -> anyhow::Result<()> {
// Our calculation of gas is off and gas limit exceeded, for example
let (mock_server, _config, da_service, _namespace) = setup_service().await;
let (mock_server, _config, da_service, _namespace) = setup_service(None).await;

let blob: Vec<u8> = vec![1, 2, 3, 4, 5, 11, 12, 13, 14, 15];

Expand Down Expand Up @@ -512,7 +520,7 @@ mod tests {

#[tokio::test]
async fn test_submit_blob_internal_server_error() -> anyhow::Result<()> {
let (mock_server, _config, da_service, _namespace) = setup_service().await;
let (mock_server, _config, da_service, _namespace) = setup_service(None).await;

let error_response = ResponseTemplate::new(500).set_body_bytes("Internal Error".as_bytes());

Expand Down Expand Up @@ -542,7 +550,8 @@ mod tests {
// https://github.com/Sovereign-Labs/sovereign-sdk/issues/478 is implemented
// Slower request timeout can be set
async fn test_submit_blob_response_timeout() -> anyhow::Result<()> {
let (mock_server, _config, da_service, _namespace) = setup_service().await;
let timeout = 1;
let (mock_server, _config, da_service, _namespace) = setup_service(Some(timeout)).await;

let response_json = json!({
"jsonrpc": "2.0",
Expand All @@ -563,7 +572,7 @@ mod tests {

let error_response = ResponseTemplate::new(200)
.append_header("Content-Type", "application/json")
.set_delay(Duration::from_millis(default_request_timeout_ms() + 100))
.set_delay(Duration::from_secs(timeout) + Duration::from_millis(100))
.set_body_json(response_json);

let blob: Vec<u8> = vec![1, 2, 3, 4, 5, 11, 12, 13, 14, 15];
Expand Down
2 changes: 2 additions & 0 deletions examples/demo-rollup/benches/rollup_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ celestia_rpc_auth_token = "MY.SECRET.TOKEN"
celestia_rpc_address = "http://localhost:11111/"
# The largest response the rollup will accept from the Celestia node. Defaults to 100 MB
max_celestia_response_body_size = 104_857_600
# The maximum time to wait for a response to an RPC query against Celestia node. Defaults to 60 seconds.
celestia_rpc_timeout_seconds = 60

[runner.storage]
# The path to the rollup's data directory. Paths that do not begin with `/` are interpreted as relative paths.
Expand Down
2 changes: 2 additions & 0 deletions examples/demo-rollup/rollup_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ celestia_rpc_auth_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJw
celestia_rpc_address = "http://127.0.0.1:26658"
# The largest response the rollup will accept from the Celestia node. Defaults to 100 MB
max_celestia_response_body_size = 104_857_600
# The maximum time to wait for a response to an RPC query against Celestia node. Defaults to 60 seconds.
celestia_rpc_timeout_seconds = 60

[runner.storage]
# The path to the rollup's data directory. Paths that do not begin with `/` are interpreted as relative paths.
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ mod tests {
celestia_rpc_auth_token: "SECRET_RPC_TOKEN".to_string(),
celestia_rpc_address: "http://localhost:11111/".into(),
max_celestia_response_body_size: 980,
celestia_rpc_timeout_seconds: 60,
},
runner: RunnerConfig {
storage: StorageConfig {
Expand Down

0 comments on commit a691a28

Please sign in to comment.