diff --git a/src/config.rs b/src/config.rs index 1978ace..6974943 100644 --- a/src/config.rs +++ b/src/config.rs @@ -63,6 +63,13 @@ pub struct TxSitterConfig { )] pub hard_reorg_interval: Duration, + /// Max amount of time to wait for a new block from the RPC block stream + #[serde( + with = "humantime_serde", + default = "default::block_stream_timeout" + )] + pub block_stream_timeout: Duration, + #[serde(default, skip_serializing_if = "Option::is_none")] pub predefined: Option, @@ -219,6 +226,10 @@ mod default { Duration::from_secs(60 * 60) } + pub fn block_stream_timeout() -> Duration { + Duration::from_secs(60) + } + pub mod metrics { pub fn host() -> String { "127.0.0.1".to_string() @@ -249,6 +260,7 @@ mod tests { escalation_interval = "1h" soft_reorg_interval = "1m" hard_reorg_interval = "1h" + block_stream_timeout = "1m" [server] host = "127.0.0.1:3000" @@ -266,6 +278,7 @@ mod tests { escalation_interval = "1h" soft_reorg_interval = "1m" hard_reorg_interval = "1h" + block_stream_timeout = "1m" [server] host = "127.0.0.1:3000" @@ -289,6 +302,7 @@ mod tests { escalation_interval: Duration::from_secs(60 * 60), soft_reorg_interval: default::soft_reorg_interval(), hard_reorg_interval: default::hard_reorg_interval(), + block_stream_timeout: default::block_stream_timeout(), predefined: None, telemetry: None, }, @@ -317,6 +331,7 @@ mod tests { escalation_interval: Duration::from_secs(60 * 60), soft_reorg_interval: default::soft_reorg_interval(), hard_reorg_interval: default::hard_reorg_interval(), + block_stream_timeout: default::block_stream_timeout(), predefined: None, telemetry: None, }, diff --git a/src/tasks/index.rs b/src/tasks/index.rs index b914665..f601a92 100644 --- a/src/tasks/index.rs +++ b/src/tasks/index.rs @@ -23,8 +23,6 @@ const GAS_PRICE_FOR_METRICS_FACTOR: f64 = 1e-9; const MAX_RECENT_BLOCKS_TO_CHECK: u64 = 60; -const NEXT_BLOCK_TIMEOUT: Duration = Duration::from_secs(60); - pub async fn index_chain(app: Arc, chain_id: u64) -> eyre::Result<()> { loop { index_inner(app.clone(), chain_id).await?; @@ -45,8 +43,11 @@ async fn index_inner(app: Arc, chain_id: u64) -> eyre::Result<()> { } loop { - let next_block = - timeout(NEXT_BLOCK_TIMEOUT, blocks_stream.next()).await; + let next_block = timeout( + app.config.service.block_stream_timeout, + blocks_stream.next(), + ) + .await; match next_block { Ok(Some(block)) => { diff --git a/tests/common/service_builder.rs b/tests/common/service_builder.rs index 05c428e..48074f8 100644 --- a/tests/common/service_builder.rs +++ b/tests/common/service_builder.rs @@ -58,6 +58,7 @@ impl ServiceBuilder { escalation_interval: self.escalation_interval, soft_reorg_interval: self.soft_reorg_interval, hard_reorg_interval: self.hard_reorg_interval, + block_stream_timeout: Duration::from_secs(60), telemetry: None, predefined: Some(Predefined { network: PredefinedNetwork {