Skip to content

Commit 0b1c028

Browse files
pepyakinrphmeier
authored andcommitted
adapters/sovereign: configurable timeout
Makes it possible to configure a timeout from the rollup_config.toml. At the same time increased the timeout for the sovereign demo.
1 parent a40395c commit 0b1c028

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

adapters/sovereign/src/service.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55
};
66
use async_trait::async_trait;
77
use sov_rollup_interface::da::DaSpec;
8+
use std::time::Duration;
89
use sugondat_shim_common_sovereign::SovereignRPCClient;
910

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

19+
fn default_rpc_timeout_seconds() -> u64 {
20+
60
21+
}
22+
1823
/// Runtime configuration for the DA service
1924
#[derive(Default, Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
2025
pub struct DaServiceConfig {
2126
#[serde(default = "default_rpc_addr")]
2227
pub sugondat_rpc: String,
28+
#[serde(default = "default_rpc_timeout_seconds")]
29+
pub rpc_timeout_seconds: u64,
2330
}
2431

2532
/// Implementation of the DA provider that uses sugondat.
@@ -32,7 +39,8 @@ pub struct DaProvider {
3239
impl DaProvider {
3340
/// Creates new instance of the service.
3441
pub fn new(config: DaServiceConfig, chain_params: ChainParams) -> Self {
35-
let client = Client::new(config.sugondat_rpc);
42+
let request_timeout = Duration::from_secs(config.rpc_timeout_seconds);
43+
let client = Client::new(config.sugondat_rpc, request_timeout);
3644
Self {
3745
namespace: sugondat_nmt::Namespace::from_raw_bytes(chain_params.namespace_id),
3846
client,

adapters/sovereign/src/service/client.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! A subxt client that is sync to initialize, but provides async interface.
22
33
use std::sync::Arc;
4+
use std::time::Duration;
45
use tokio::sync::Mutex;
56

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

1112
struct Inner {
1213
url: String,
14+
request_timeout: Duration,
1315
client: Option<ClientRef>,
1416
}
1517

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

2931
impl Client {
30-
pub fn new(url: String) -> Self {
32+
pub fn new(url: String, request_timeout: Duration) -> Self {
3133
Self {
32-
inner: Arc::new(Mutex::new(Inner { url, client: None })),
34+
inner: Arc::new(Mutex::new(Inner {
35+
url,
36+
request_timeout,
37+
client: None,
38+
})),
3339
}
3440
}
3541

@@ -40,6 +46,7 @@ impl Client {
4046
}
4147

4248
let client = jsonrpsee::ws_client::WsClientBuilder::new()
49+
.request_timeout(inner.request_timeout)
4350
.build(inner.url.clone())
4451
.await?;
4552
let client = ClientRef {

demo/sovereign/docker/rollup_config.docker.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[da]
22
sugondat_rpc = "ws://localhost:10995/"
3-
3+
rpc_timeout_seconds = 180
44

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

0 commit comments

Comments
 (0)