11use std:: {
22 fs:: File ,
3- path:: Path ,
3+ path:: PathBuf ,
44 sync:: { mpsc:: channel, Arc , Mutex } ,
5- time:: Instant ,
5+ time:: { Duration , Instant } ,
66} ;
77
88use bitcoin:: { consensus, BlockHash , Network } ;
99use hintfile:: Hints ;
10- use kernel:: { ChainType , ChainstateManager , ChainstateManagerOptions , ContextBuilder } ;
10+ use kernel:: { ChainstateManager , ChainstateManagerOptions , ContextBuilder } ;
1111
1212use node:: {
1313 bootstrap_dns, elapsed_time, get_blocks_for_range, hashes_from_chain, sync_block_headers,
14- AccumulatorState ,
14+ AccumulatorState , ChainExt ,
1515} ;
16+ use p2p:: net:: TimeoutParams ;
1617
17- const CHAIN_TYPE : ChainType = ChainType :: SIGNET ;
18- const NETWORK : Network = Network :: Signet ;
1918const TASKS : usize = 256 ;
20- const BLOCK_FILE_PATH : & str = "./blockfiles" ;
19+ const PING_INTERVAL : Duration = Duration :: from_secs ( 15 ) ;
20+
21+ configure_me:: include_config!( ) ;
2122
2223fn main ( ) {
23- let mut args = std:: env:: args ( ) ;
24- let _ = args. next ( ) ;
25- let hint_path = args. next ( ) . expect ( "Usage: <path_to_hints_file>" ) ;
26- // Logging
24+ let ( config, _) = Config :: including_optional_config_files :: < & [ & str ] > ( & [ ] ) . unwrap_or_exit ( ) ;
25+ let hint_path = config. hintfile ;
26+ let blocks_dir = config. blocks_dir ;
27+ let network = config
28+ . network
29+ . parse :: < Network > ( )
30+ . expect ( "invalid network string" ) ;
31+ let ping_timeout = Duration :: from_secs ( config. ping_timeout ) ;
32+ let tcp_timeout = Duration :: from_secs ( config. tcp_timeout ) ;
33+ let read_timeout = Duration :: from_secs ( config. read_timeout ) ;
34+ let write_timeout = Duration :: from_secs ( config. write_timeout ) ;
35+ let mut timeout_conf = TimeoutParams :: new ( ) ;
36+ timeout_conf. read_timeout ( read_timeout) ;
37+ timeout_conf. write_timeout ( write_timeout) ;
38+ timeout_conf. tcp_handshake_timeout ( tcp_timeout) ;
39+ timeout_conf. ping_interval ( PING_INTERVAL ) ;
2740 let subscriber = tracing_subscriber:: FmtSubscriber :: new ( ) ;
2841 tracing:: subscriber:: set_global_default ( subscriber) . unwrap ( ) ;
2942 let hintfile_start_time = Instant :: now ( ) ;
3043 tracing:: info!( "Reading in {hint_path}" ) ;
3144 let mut hintfile = File :: open ( hint_path) . expect ( "invalid hintfile path" ) ;
3245 let hints = Arc :: new ( Hints :: from_file ( & mut hintfile) ) ;
3346 elapsed_time ( hintfile_start_time) ;
34- let block_file_path = Path :: new ( BLOCK_FILE_PATH ) ;
35- std:: fs:: create_dir ( block_file_path) . expect ( "could not create block file directory" ) ;
47+ let block_file_path = PathBuf :: from ( & blocks_dir ) ;
48+ std:: fs:: create_dir ( & block_file_path) . expect ( "could not create block file directory" ) ;
3649 let stop_hash =
3750 consensus:: deserialize :: < BlockHash > ( & hints. stop_hash ( ) ) . expect ( "stop hash is not valid" ) ;
3851 tracing:: info!( "Assume valid hash: {stop_hash}" ) ;
3952 tracing:: info!( "Finding peers with DNS" ) ;
4053 let dns_start_time = Instant :: now ( ) ;
41- let peers = bootstrap_dns ( NETWORK ) ;
54+ let peers = bootstrap_dns ( network ) ;
4255 elapsed_time ( dns_start_time) ;
4356 tracing:: info!( "Initializing bitcoin kernel" ) ;
4457 let kernel_start_time = Instant :: now ( ) ;
4558 let ctx = ContextBuilder :: new ( )
46- . chain_type ( CHAIN_TYPE )
59+ . chain_type ( network . chain_type ( ) )
4760 . build ( )
4861 . unwrap ( ) ;
4962 let options = ChainstateManagerOptions :: new ( & ctx, "." , "./blocks" ) . unwrap ( ) ;
@@ -52,7 +65,7 @@ fn main() {
5265 let tip = chainman. best_header ( ) . height ( ) ;
5366 tracing:: info!( "Kernel best header: {tip}" ) ;
5467 let chain = Arc :: new ( chainman) ;
55- sync_block_headers ( stop_hash, & peers, Arc :: clone ( & chain) , NETWORK ) ;
68+ sync_block_headers ( stop_hash, & peers, Arc :: clone ( & chain) , network , timeout_conf ) ;
5669 tracing:: info!( "Assume valid height: {}" , chain. best_header( ) . height( ) ) ;
5770 let ( tx, rx) = channel ( ) ;
5871 let main_routine_time = Instant :: now ( ) ;
@@ -67,11 +80,14 @@ fn main() {
6780 let tx = tx. clone ( ) ;
6881 let peers = Arc :: clone ( & peers) ;
6982 let hints = Arc :: clone ( & hints) ;
83+ let block_file_path = block_file_path. clone ( ) ;
7084 let block_task = std:: thread:: spawn ( move || {
7185 get_blocks_for_range (
7286 task_id as u32 ,
73- NETWORK ,
74- block_file_path,
87+ timeout_conf,
88+ ping_timeout,
89+ network,
90+ & block_file_path,
7591 chain,
7692 & hints,
7793 peers,
0 commit comments