Skip to content

Commit 283d393

Browse files
committed
respect effective_from from scheduling status
part of NET-68
1 parent 78900f5 commit 283d393

3 files changed

Lines changed: 23 additions & 14 deletions

File tree

crates/hotblocks-retain/src/cli.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,4 @@ pub struct Cli {
2525
/// Interval in seconds between refreshing the datasets list
2626
#[arg(long, default_value = "3600", value_parser = clap::value_parser!(u64).range(1..))]
2727
pub datasets_update_interval_secs: u64,
28-
29-
/// Delay in seconds between fetching dataset heights and applying retention
30-
#[arg(long, default_value = "300", value_parser = clap::value_parser!(u64).range(1..))]
31-
pub retain_delay_secs: u64,
3228
}

crates/hotblocks-retain/src/main.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use anyhow::Context;
88
use clap::Parser;
99
use cli::Cli;
1010
use std::collections::HashMap;
11-
use std::time::Duration;
11+
use std::time::{Duration, SystemTime, UNIX_EPOCH};
1212
use tokio::time::Instant;
1313
use types::{DatasetId, DatasetsConfig};
1414
use url::Url;
@@ -34,7 +34,6 @@ fn main() -> anyhow::Result<()> {
3434
args.status_url,
3535
args.datasets_url,
3636
datasets,
37-
Duration::from_secs(args.retain_delay_secs),
3837
Duration::from_secs(args.datasets_update_interval_secs),
3938
)
4039
.run(),
@@ -49,10 +48,10 @@ struct HotblocksRetain {
4948
status_url: Url,
5049
datasets_url: Url,
5150
datasets: DatasetsConfig,
52-
retain_delay: Duration,
5351
datasets_update_interval: Duration,
5452
name_to_id: HashMap<String, DatasetId>,
5553
last_datasets_refresh: Instant,
54+
last_effective_from: Option<u64>,
5655
}
5756

5857
impl HotblocksRetain {
@@ -61,7 +60,6 @@ impl HotblocksRetain {
6160
status_url: Url,
6261
datasets_url: Url,
6362
datasets: DatasetsConfig,
64-
retain_delay: Duration,
6563
datasets_update_interval: Duration,
6664
) -> Self {
6765
Self {
@@ -70,10 +68,10 @@ impl HotblocksRetain {
7068
status_url,
7169
datasets_url,
7270
datasets,
73-
retain_delay,
7471
datasets_update_interval,
7572
name_to_id: HashMap::new(),
7673
last_datasets_refresh: Instant::now() - datasets_update_interval,
74+
last_effective_from: None,
7775
}
7876
}
7977

@@ -90,11 +88,25 @@ impl HotblocksRetain {
9088
}
9189
};
9290

93-
tracing::info!(
94-
delay_secs = self.retain_delay.as_secs(),
95-
"fetched status, waiting before applying retention"
96-
);
97-
tokio::time::sleep(self.retain_delay).await;
91+
let now = SystemTime::now()
92+
.duration_since(UNIX_EPOCH)
93+
.unwrap()
94+
.as_secs();
95+
96+
if now < status.effective_from {
97+
if self.last_effective_from == Some(status.effective_from) {
98+
tracing::info!("effective_from unchanged, re-checking in 5 minutes");
99+
tokio::time::sleep(Duration::from_secs(300)).await;
100+
continue;
101+
}
102+
103+
self.last_effective_from = Some(status.effective_from);
104+
let wait_secs = status.effective_from - now;
105+
tracing::info!(wait_secs, effective_from = status.effective_from, "waiting for effective time");
106+
tokio::time::sleep(Duration::from_secs(wait_secs)).await;
107+
} else {
108+
self.last_effective_from = Some(status.effective_from);
109+
}
98110

99111
self.apply_retention(&status).await;
100112
}

crates/hotblocks-retain/src/status.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use sqd_primitives::BlockNumber;
55
#[derive(Debug, Deserialize)]
66
pub struct SchedulingStatus {
77
pub datasets: Vec<DatasetStatus>,
8+
pub effective_from: u64,
89
}
910

1011
#[derive(Debug, Deserialize)]

0 commit comments

Comments
 (0)