Skip to content

adapters/sovereign: configurable timeout #187

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

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion adapters/sovereign/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
};
use async_trait::async_trait;
use sov_rollup_interface::da::DaSpec;
use std::time::Duration;
use sugondat_shim_common_sovereign::SovereignRPCClient;

mod client;
Expand All @@ -15,11 +16,17 @@ fn default_rpc_addr() -> String {
"ws://localhost:10995/".into()
}

fn default_rpc_timeout_seconds() -> u64 {
60
}

/// Runtime configuration for the DA service
#[derive(Default, Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct DaServiceConfig {
#[serde(default = "default_rpc_addr")]
pub sugondat_rpc: String,
#[serde(default = "default_rpc_timeout_seconds")]
pub rpc_timeout_seconds: u64,
}

/// Implementation of the DA provider that uses sugondat.
Expand All @@ -32,7 +39,8 @@ pub struct DaProvider {
impl DaProvider {
/// Creates new instance of the service.
pub fn new(config: DaServiceConfig, chain_params: ChainParams) -> Self {
let client = Client::new(config.sugondat_rpc);
let request_timeout = Duration::from_secs(config.rpc_timeout_seconds);
let client = Client::new(config.sugondat_rpc, request_timeout);
Self {
namespace: sugondat_nmt::Namespace::from_raw_bytes(chain_params.namespace_id),
client,
Expand Down
11 changes: 9 additions & 2 deletions adapters/sovereign/src/service/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! A subxt client that is sync to initialize, but provides async interface.

use std::sync::Arc;
use std::time::Duration;
use tokio::sync::Mutex;

#[derive(Clone)]
Expand All @@ -10,6 +11,7 @@ pub struct Client {

struct Inner {
url: String,
request_timeout: Duration,
client: Option<ClientRef>,
}

Expand All @@ -27,9 +29,13 @@ impl std::ops::Deref for ClientRef {
}

impl Client {
pub fn new(url: String) -> Self {
pub fn new(url: String, request_timeout: Duration) -> Self {
Self {
inner: Arc::new(Mutex::new(Inner { url, client: None })),
inner: Arc::new(Mutex::new(Inner {
url,
request_timeout,
client: None,
})),
}
}

Expand All @@ -40,6 +46,7 @@ impl Client {
}

let client = jsonrpsee::ws_client::WsClientBuilder::new()
.request_timeout(inner.request_timeout)
.build(inner.url.clone())
.await?;
let client = ClientRef {
Expand Down
2 changes: 1 addition & 1 deletion demo/sovereign/docker/rollup_config.docker.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[da]
sugondat_rpc = "ws://localhost:10995/"

rpc_timeout_seconds = 180

[storage]
# The path to the rollup's data directory. Paths that do not begin with `/` are interpreted as relative paths.
Expand Down