Skip to content

Commit 3041071

Browse files
committed
feat:rearchive range
Signed-off-by: Chen Kai <[email protected]>
1 parent 82ea105 commit 3041071

File tree

1 file changed

+68
-6
lines changed

1 file changed

+68
-6
lines changed

bin/archiver/src/archiver.rs

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ use blob_archiver_storage::{
33
BackfillProcess, BackfillProcesses, BlobData, BlobSidecars, Header, LockFile, Storage,
44
};
55
use eth2::types::{BlockHeaderData, BlockId, Hash256};
6-
use eyre::Result;
6+
use eyre::{eyre, Result};
77
use serde::{Deserialize, Serialize};
88
use std::sync::atomic::{AtomicU64, Ordering};
99
use std::sync::Arc;
1010
use std::time::Duration;
11+
use eth2::{Error};
12+
use eth2::Error::ServerMessage;
13+
use eth2::types::Slot;
1114
use tokio::sync::watch::Receiver;
1215
use tokio::time::{interval, sleep};
1316
use tracing::log::{debug, error, info, trace};
@@ -16,9 +19,9 @@ use blob_archiver_beacon::beacon_client::BeaconClient;
1619
#[allow(dead_code)]
1720
const LIVE_FETCH_BLOB_MAXIMUM_RETRIES: usize = 10;
1821
#[allow(dead_code)]
19-
const STARTUP_FETCH_BLOB_MAXIMUM_RETRIES: i32 = 3;
22+
const STARTUP_FETCH_BLOB_MAXIMUM_RETRIES: usize = 3;
2023
#[allow(dead_code)]
21-
const REARCHIVE_MAXIMUM_RETRIES: i32 = 3;
24+
const REARCHIVE_MAXIMUM_RETRIES: usize = 3;
2225
#[allow(dead_code)]
2326
const BACKFILL_ERROR_RETRY_INTERVAL: Duration = Duration::from_secs(5);
2427
#[allow(dead_code)]
@@ -30,6 +33,13 @@ const OBTAIN_LOCK_RETRY_INTERVAL_SECS: u64 = 10;
3033
#[allow(dead_code)]
3134
static OBTAIN_LOCK_RETRY_INTERVAL: AtomicU64 = AtomicU64::new(OBTAIN_LOCK_RETRY_INTERVAL_SECS);
3235

36+
#[derive(Debug, Serialize, Deserialize)]
37+
pub struct RearchiveResp {
38+
pub from: u64,
39+
pub to: u64,
40+
pub error: Option<String>,
41+
}
42+
3343
#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)]
3444
pub struct Config {
3545
pub poll_interval: Duration,
@@ -43,9 +53,9 @@ pub struct Archiver {
4353
pub beacon_client: Arc<dyn BeaconClient>,
4454

4555
storage: Arc<dyn Storage>,
46-
#[allow(dead_code)]
56+
4757
id: String,
48-
#[allow(dead_code)]
58+
4959
pub config: Config,
5060

5161
shutdown_rx: Receiver<bool>,
@@ -322,7 +332,7 @@ impl Archiver {
322332
let mut current_block_id = BlockId::Head;
323333

324334
loop {
325-
let retry_policy = RetryPolicy::exponential(Duration::from_secs(1))
335+
let retry_policy = RetryPolicy::exponential(Duration::from_millis(250))
326336
.with_jitter(true)
327337
.with_max_delay(Duration::from_secs(10))
328338
.with_max_retries(LIVE_FETCH_BLOB_MAXIMUM_RETRIES);
@@ -376,6 +386,58 @@ impl Archiver {
376386

377387
#[allow(dead_code)]
378388
async fn start(&self) {}
389+
390+
#[allow(dead_code)]
391+
async fn rearchive_range(&self, from: u64, to: u64) -> RearchiveResp {
392+
for i in from..=to {
393+
info!("rearchiving block: {}",i);
394+
let retry_policy = RetryPolicy::exponential(Duration::from_millis(250))
395+
.with_jitter(true)
396+
.with_max_delay(Duration::from_secs(10))
397+
.with_max_retries(REARCHIVE_MAXIMUM_RETRIES);
398+
let r = retry_policy
399+
.retry(|| {
400+
self.rearchive(i)
401+
})
402+
.await;
403+
404+
match r {
405+
Err(e) => {
406+
error!("Error fetching blobs for block: {:#?}", e);
407+
return RearchiveResp {
408+
from,
409+
to,
410+
error: Some(e.downcast::<Error>().unwrap().to_string()),
411+
};
412+
}
413+
Ok(false) => {
414+
info!("block not found, skipping");
415+
}
416+
Ok(true) => {
417+
info!("block rearchived successfully")
418+
}
419+
}
420+
}
421+
RearchiveResp { from, to, error: None }
422+
}
423+
424+
async fn rearchive(&self, i: u64) -> Result<bool> {
425+
let res = self.persist_blobs_for_block(BlockId::Slot(Slot::new(i)), true).await;
426+
427+
match res {
428+
Err(e) => {
429+
if let Some(error) = e.downcast_ref::<Error>() {
430+
match error {
431+
ServerMessage(sm) if sm.code == 404 => Ok(false),
432+
_ => Err(eyre::eyre!(e)),
433+
}
434+
} else {
435+
Err(eyre!(e))
436+
}
437+
}
438+
Ok(_) => Ok(true)
439+
}
440+
}
379441
}
380442

381443
#[cfg(test)]

0 commit comments

Comments
 (0)