@@ -21,6 +21,7 @@ use crate::node_configurator::node_configurator_standard::{
21
21
use crate :: node_configurator:: { initialize_database, DirsWrapper , NodeConfigurator } ;
22
22
use crate :: privilege_drop:: { IdWrapper , IdWrapperReal } ;
23
23
use crate :: server_initializer:: LoggerInitializerWrapper ;
24
+ use crate :: stream_handler_pool:: StreamHandlerPoolSubs ;
24
25
use crate :: sub_lib:: accountant;
25
26
use crate :: sub_lib:: accountant:: { PaymentThresholds , ScanIntervals } ;
26
27
use crate :: sub_lib:: blockchain_bridge:: BlockchainBridgeConfig ;
@@ -32,6 +33,7 @@ use crate::sub_lib::neighborhood::{NeighborhoodConfig, NeighborhoodMode};
32
33
use crate :: sub_lib:: node_addr:: NodeAddr ;
33
34
use crate :: sub_lib:: socket_server:: ConfiguredByPrivilege ;
34
35
use crate :: sub_lib:: ui_gateway:: UiGatewayConfig ;
36
+ use crate :: sub_lib:: utils:: db_connection_launch_panic;
35
37
use crate :: sub_lib:: wallet:: Wallet ;
36
38
use futures:: try_ready;
37
39
use itertools:: Itertools ;
@@ -515,15 +517,7 @@ impl ConfiguredByPrivilege for Bootstrapper {
515
517
if node_addr. ip_addr ( ) == Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) => { } // node_addr still coming
516
518
_ => Bootstrapper :: report_local_descriptor ( cryptdes. main , & self . config . node_descriptor ) , // here or not coming
517
519
}
518
- let stream_handler_pool_subs = self . actor_system_factory . make_and_start_actors (
519
- self . config . clone ( ) ,
520
- Box :: new ( ActorFactoryReal { } ) ,
521
- initialize_database (
522
- & self . config . data_directory ,
523
- DbInitializationConfig :: panic_on_migration ( ) ,
524
- ) ,
525
- ) ;
526
-
520
+ let stream_handler_pool_subs = self . start_actors_and_return_shp_subs ( ) ;
527
521
self . listener_handlers
528
522
. iter_mut ( )
529
523
. for_each ( |f| f. bind_subs ( stream_handler_pool_subs. add_sub . clone ( ) ) ) ;
@@ -612,6 +606,17 @@ impl Bootstrapper {
612
606
}
613
607
}
614
608
609
+ fn start_actors_and_return_shp_subs ( & self ) -> StreamHandlerPoolSubs {
610
+ self . actor_system_factory . make_and_start_actors (
611
+ self . config . clone ( ) ,
612
+ Box :: new ( ActorFactoryReal { } ) ,
613
+ initialize_database (
614
+ & self . config . data_directory ,
615
+ DbInitializationConfig :: panic_on_migration ( ) ,
616
+ ) ,
617
+ )
618
+ }
619
+
615
620
pub fn report_local_descriptor ( cryptde : & dyn CryptDE , descriptor : & NodeDescriptor ) {
616
621
let descriptor_msg = format ! (
617
622
"MASQ Node local descriptor: {}" ,
@@ -630,7 +635,9 @@ impl Bootstrapper {
630
635
& self . config . data_directory ,
631
636
DbInitializationConfig :: panic_on_migration ( ) ,
632
637
)
633
- . expect ( "Cannot initialize database" ) ;
638
+ . unwrap_or_else ( |err| {
639
+ db_connection_launch_panic ( err, & self . config . data_directory )
640
+ } ) ;
634
641
let config_dao = ConfigDaoReal :: new ( conn) ;
635
642
let mut persistent_config = PersistentConfigurationReal :: new ( Box :: new ( config_dao) ) ;
636
643
let clandestine_port = self . establish_clandestine_port ( & mut persistent_config) ;
@@ -728,7 +735,9 @@ mod tests {
728
735
use crate :: sub_lib:: cryptde:: PublicKey ;
729
736
use crate :: sub_lib:: cryptde:: { CryptDE , PlainData } ;
730
737
use crate :: sub_lib:: cryptde_null:: CryptDENull ;
731
- use crate :: sub_lib:: neighborhood:: { NeighborhoodConfig , NeighborhoodMode , NodeDescriptor } ;
738
+ use crate :: sub_lib:: neighborhood:: {
739
+ NeighborhoodConfig , NeighborhoodMode , NodeDescriptor , DEFAULT_RATE_PACK ,
740
+ } ;
732
741
use crate :: sub_lib:: node_addr:: NodeAddr ;
733
742
use crate :: sub_lib:: socket_server:: ConfiguredByPrivilege ;
734
743
use crate :: sub_lib:: stream_connector:: ConnectionInfo ;
@@ -738,7 +747,9 @@ mod tests {
738
747
use crate :: test_utils:: recorder:: Recording ;
739
748
use crate :: test_utils:: tokio_wrapper_mocks:: ReadHalfWrapperMock ;
740
749
use crate :: test_utils:: tokio_wrapper_mocks:: WriteHalfWrapperMock ;
741
- use crate :: test_utils:: unshared_test_utils:: make_simplified_multi_config;
750
+ use crate :: test_utils:: unshared_test_utils:: {
751
+ assert_on_initialization_with_panic_on_migration, make_simplified_multi_config,
752
+ } ;
742
753
use crate :: test_utils:: { assert_contains, rate_pack} ;
743
754
use crate :: test_utils:: { main_cryptde, make_wallet} ;
744
755
use actix:: Recipient ;
@@ -762,7 +773,7 @@ mod tests {
762
773
use std:: io:: ErrorKind ;
763
774
use std:: marker:: Sync ;
764
775
use std:: net:: { IpAddr , SocketAddr } ;
765
- use std:: path:: PathBuf ;
776
+ use std:: path:: { Path , PathBuf } ;
766
777
use std:: str:: FromStr ;
767
778
use std:: sync:: { Arc , Mutex } ;
768
779
use std:: thread;
@@ -1383,6 +1394,24 @@ mod tests {
1383
1394
assert_eq ! ( config. blockchain_bridge_config. gas_price, 11 ) ;
1384
1395
}
1385
1396
1397
+ #[ test]
1398
+ fn initialize_as_unprivileged_implements_panic_on_migration_for_make_and_start_actors ( ) {
1399
+ let _lock = INITIALIZATION . lock ( ) ;
1400
+ let data_dir = ensure_node_home_directory_exists (
1401
+ "bootstrapper" ,
1402
+ "initialize_as_unprivileged_implements_panic_on_migration_for_make_and_start_actors" ,
1403
+ ) ;
1404
+
1405
+ let act = |data_dir : & Path | {
1406
+ let mut config = BootstrapperConfig :: new ( ) ;
1407
+ config. data_directory = data_dir. to_path_buf ( ) ;
1408
+ let subject = BootstrapperBuilder :: new ( ) . config ( config) . build ( ) ;
1409
+ subject. start_actors_and_return_shp_subs ( ) ;
1410
+ } ;
1411
+
1412
+ assert_on_initialization_with_panic_on_migration ( & data_dir, & act) ;
1413
+ }
1414
+
1386
1415
#[ test]
1387
1416
fn initialize_with_clandestine_port_produces_expected_clandestine_discriminator_factories_vector (
1388
1417
) {
@@ -2022,6 +2051,26 @@ mod tests {
2022
2051
. is_none( ) ) ;
2023
2052
}
2024
2053
2054
+ #[ test]
2055
+ fn set_up_clandestine_port_panics_on_migration ( ) {
2056
+ let data_dir = ensure_node_home_directory_exists (
2057
+ "bootstrapper" ,
2058
+ "set_up_clandestine_port_panics_on_migration" ,
2059
+ ) ;
2060
+
2061
+ let act = |data_dir : & Path | {
2062
+ let mut config = BootstrapperConfig :: new ( ) ;
2063
+ config. data_directory = data_dir. to_path_buf ( ) ;
2064
+ config. neighborhood_config = NeighborhoodConfig {
2065
+ mode : NeighborhoodMode :: Standard ( NodeAddr :: default ( ) , vec ! [ ] , DEFAULT_RATE_PACK ) ,
2066
+ } ;
2067
+ let mut subject = BootstrapperBuilder :: new ( ) . config ( config) . build ( ) ;
2068
+ subject. set_up_clandestine_port ( ) ;
2069
+ } ;
2070
+
2071
+ assert_on_initialization_with_panic_on_migration ( & data_dir, & act) ;
2072
+ }
2073
+
2025
2074
#[ test]
2026
2075
#[ should_panic(
2027
2076
expected = "Database is corrupt: error setting clandestine port: TransactionError"
0 commit comments