Skip to content

Commit

Permalink
Mae it configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Oct 10, 2024
1 parent 0c3eb01 commit 4ed00f2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Predefined>,

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down
9 changes: 5 additions & 4 deletions src/tasks/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<App>, chain_id: u64) -> eyre::Result<()> {
loop {
index_inner(app.clone(), chain_id).await?;
Expand All @@ -45,8 +43,11 @@ async fn index_inner(app: Arc<App>, 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)) => {
Expand Down
1 change: 1 addition & 0 deletions tests/common/service_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4ed00f2

Please sign in to comment.