@@ -3,11 +3,14 @@ use blob_archiver_storage::{
3
3
BackfillProcess , BackfillProcesses , BlobData , BlobSidecars , Header , LockFile , Storage ,
4
4
} ;
5
5
use eth2:: types:: { BlockHeaderData , BlockId , Hash256 } ;
6
- use eyre:: Result ;
6
+ use eyre:: { eyre , Result } ;
7
7
use serde:: { Deserialize , Serialize } ;
8
8
use std:: sync:: atomic:: { AtomicU64 , Ordering } ;
9
9
use std:: sync:: Arc ;
10
10
use std:: time:: Duration ;
11
+ use eth2:: { Error } ;
12
+ use eth2:: Error :: ServerMessage ;
13
+ use eth2:: types:: Slot ;
11
14
use tokio:: sync:: watch:: Receiver ;
12
15
use tokio:: time:: { interval, sleep} ;
13
16
use tracing:: log:: { debug, error, info, trace} ;
@@ -16,9 +19,9 @@ use blob_archiver_beacon::beacon_client::BeaconClient;
16
19
#[ allow( dead_code) ]
17
20
const LIVE_FETCH_BLOB_MAXIMUM_RETRIES : usize = 10 ;
18
21
#[ allow( dead_code) ]
19
- const STARTUP_FETCH_BLOB_MAXIMUM_RETRIES : i32 = 3 ;
22
+ const STARTUP_FETCH_BLOB_MAXIMUM_RETRIES : usize = 3 ;
20
23
#[ allow( dead_code) ]
21
- const REARCHIVE_MAXIMUM_RETRIES : i32 = 3 ;
24
+ const REARCHIVE_MAXIMUM_RETRIES : usize = 3 ;
22
25
#[ allow( dead_code) ]
23
26
const BACKFILL_ERROR_RETRY_INTERVAL : Duration = Duration :: from_secs ( 5 ) ;
24
27
#[ allow( dead_code) ]
@@ -30,6 +33,13 @@ const OBTAIN_LOCK_RETRY_INTERVAL_SECS: u64 = 10;
30
33
#[ allow( dead_code) ]
31
34
static OBTAIN_LOCK_RETRY_INTERVAL : AtomicU64 = AtomicU64 :: new ( OBTAIN_LOCK_RETRY_INTERVAL_SECS ) ;
32
35
36
+ #[ derive( Debug , Serialize , Deserialize ) ]
37
+ pub struct RearchiveResp {
38
+ pub from : u64 ,
39
+ pub to : u64 ,
40
+ pub error : Option < String > ,
41
+ }
42
+
33
43
#[ derive( Debug , PartialEq , Eq , Clone , Default , Serialize , Deserialize ) ]
34
44
pub struct Config {
35
45
pub poll_interval : Duration ,
@@ -43,9 +53,9 @@ pub struct Archiver {
43
53
pub beacon_client : Arc < dyn BeaconClient > ,
44
54
45
55
storage : Arc < dyn Storage > ,
46
- # [ allow ( dead_code ) ]
56
+
47
57
id : String ,
48
- # [ allow ( dead_code ) ]
58
+
49
59
pub config : Config ,
50
60
51
61
shutdown_rx : Receiver < bool > ,
@@ -322,7 +332,7 @@ impl Archiver {
322
332
let mut current_block_id = BlockId :: Head ;
323
333
324
334
loop {
325
- let retry_policy = RetryPolicy :: exponential ( Duration :: from_secs ( 1 ) )
335
+ let retry_policy = RetryPolicy :: exponential ( Duration :: from_millis ( 250 ) )
326
336
. with_jitter ( true )
327
337
. with_max_delay ( Duration :: from_secs ( 10 ) )
328
338
. with_max_retries ( LIVE_FETCH_BLOB_MAXIMUM_RETRIES ) ;
@@ -376,6 +386,58 @@ impl Archiver {
376
386
377
387
#[ allow( dead_code) ]
378
388
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
+ }
379
441
}
380
442
381
443
#[ cfg( test) ]
0 commit comments