@@ -6,6 +6,7 @@ use std::time::Duration;
66
77use again:: RetryPolicy ;
88use clap:: Parser ;
9+ use ctrlc:: set_handler;
910use eth2:: types:: { BlockId , Hash256 } ;
1011use eth2:: { BeaconNodeHttpClient , SensitiveUrl , Timeouts } ;
1112use serde:: { Deserialize , Serialize } ;
@@ -16,12 +17,12 @@ use tracing_subscriber::layer::SubscriberExt;
1617use tracing_subscriber:: util:: SubscriberInitExt ;
1718use tracing_subscriber:: { fmt, EnvFilter } ;
1819
20+ use blob_archiver_beacon:: beacon_client;
1921use blob_archiver_beacon:: beacon_client:: BeaconClientEth2 ;
20- use blob_archiver_beacon:: { beacon_client, blob_test_helper} ;
2122use blob_archiver_storage:: fs:: FSStorage ;
22- use blob_archiver_storage:: s3:: S3Config ;
23+ use blob_archiver_storage:: s3:: { S3Config , S3Storage } ;
2324use blob_archiver_storage:: storage;
24- use blob_archiver_storage:: storage:: StorageType ;
25+ use blob_archiver_storage:: storage:: { Storage , StorageType } ;
2526
2627use crate :: archiver:: { Archiver , Config , STARTUP_FETCH_BLOB_MAXIMUM_RETRIES } ;
2728
@@ -34,27 +35,47 @@ static INIT: std::sync::Once = std::sync::Once::new();
3435async fn main ( ) {
3536 let args = CliArgs :: parse ( ) ;
3637
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+ ) ;
4048 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 ) ,
4351 ) ;
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+ ) )
5465 } ;
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 } ;
5576 let archiver = Archiver :: new (
5677 Arc :: new ( Mutex :: new ( beacon_client_eth2) ) ,
57- Arc :: new ( Mutex :: new ( storage) ) ,
78+ storage,
5879 config,
5980 shutdown_rx,
6081 ) ;
0 commit comments