@@ -6,6 +6,7 @@ use std::time::Duration;
6
6
7
7
use again:: RetryPolicy ;
8
8
use clap:: Parser ;
9
+ use ctrlc:: set_handler;
9
10
use eth2:: types:: { BlockId , Hash256 } ;
10
11
use eth2:: { BeaconNodeHttpClient , SensitiveUrl , Timeouts } ;
11
12
use serde:: { Deserialize , Serialize } ;
@@ -16,12 +17,12 @@ use tracing_subscriber::layer::SubscriberExt;
16
17
use tracing_subscriber:: util:: SubscriberInitExt ;
17
18
use tracing_subscriber:: { fmt, EnvFilter } ;
18
19
20
+ use blob_archiver_beacon:: beacon_client;
19
21
use blob_archiver_beacon:: beacon_client:: BeaconClientEth2 ;
20
- use blob_archiver_beacon:: { beacon_client, blob_test_helper} ;
21
22
use blob_archiver_storage:: fs:: FSStorage ;
22
- use blob_archiver_storage:: s3:: S3Config ;
23
+ use blob_archiver_storage:: s3:: { S3Config , S3Storage } ;
23
24
use blob_archiver_storage:: storage;
24
- use blob_archiver_storage:: storage:: StorageType ;
25
+ use blob_archiver_storage:: storage:: { Storage , StorageType } ;
25
26
26
27
use crate :: archiver:: { Archiver , Config , STARTUP_FETCH_BLOB_MAXIMUM_RETRIES } ;
27
28
@@ -34,27 +35,47 @@ static INIT: std::sync::Once = std::sync::Once::new();
34
35
async fn main ( ) {
35
36
let args = CliArgs :: parse ( ) ;
36
37
37
- let config = args. to_config ( ) ;
38
- println ! ( "{:#?}" , config) ;
39
- init_logging ( 0 , None , None ) ;
38
+ let config: Config = args. to_config ( ) ;
39
+ init_logging (
40
+ config. log_config . verbose ,
41
+ config. log_config . log_dir . clone ( ) ,
42
+ config
43
+ . log_config
44
+ . log_rotation
45
+ . clone ( )
46
+ . map ( |s| to_rotation ( s. as_str ( ) ) ) ,
47
+ ) ;
40
48
let beacon_client = BeaconNodeHttpClient :: new (
41
- SensitiveUrl :: from_str ( "https://ethereum-beacon-api.publicnode.com" ) . unwrap ( ) ,
42
- Timeouts :: set_all ( Duration :: from_secs ( 30 ) ) ,
49
+ SensitiveUrl :: from_str ( config . beacon_config . beacon_endpoint . as_str ( ) ) . unwrap ( ) ,
50
+ Timeouts :: set_all ( config . beacon_config . beacon_client_timeout ) ,
43
51
) ;
44
- let storage = FSStorage :: new ( PathBuf :: from ( "test_dir" ) ) . await . unwrap ( ) ;
45
- let ( _shutdown_tx, shutdown_rx) = tokio:: sync:: watch:: channel ( false ) ;
46
- let beacon_client_eth2 = BeaconClientEth2 { beacon_client } ;
47
- let config = Config {
48
- poll_interval : Duration :: from_secs ( 5 ) ,
49
- listen_addr : "" . to_string ( ) ,
50
- origin_block : * blob_test_helper:: ORIGIN_BLOCK ,
51
- beacon_config : Default :: default ( ) ,
52
- storage_config : Default :: default ( ) ,
53
- log_config : Default :: default ( ) ,
52
+ let storage: Arc < Mutex < dyn Storage > > = if config. storage_config . storage_type == StorageType :: FS
53
+ {
54
+ Arc :: new ( Mutex :: new (
55
+ FSStorage :: new ( config. storage_config . fs_dir . clone ( ) . unwrap ( ) )
56
+ . await
57
+ . unwrap ( ) ,
58
+ ) )
59
+ } else {
60
+ Arc :: new ( Mutex :: new (
61
+ S3Storage :: new ( config. storage_config . s3_config . clone ( ) . unwrap ( ) )
62
+ . await
63
+ . unwrap ( ) ,
64
+ ) )
54
65
} ;
66
+ let ( shutdown_tx, shutdown_rx) = tokio:: sync:: watch:: channel ( false ) ;
67
+ set_handler ( move || {
68
+ tracing:: info!( "shutting down" ) ;
69
+ shutdown_tx
70
+ . send ( true )
71
+ . expect ( "could not send shutdown signal" ) ;
72
+ } )
73
+ . expect ( "could not register shutdown handler" ) ;
74
+
75
+ let beacon_client_eth2 = BeaconClientEth2 { beacon_client } ;
55
76
let archiver = Archiver :: new (
56
77
Arc :: new ( Mutex :: new ( beacon_client_eth2) ) ,
57
- Arc :: new ( Mutex :: new ( storage) ) ,
78
+ storage,
58
79
config,
59
80
shutdown_rx,
60
81
) ;
0 commit comments