1414// You should have received a copy of the GNU Affero General Public License
1515// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
17- use std:: env;
1817use std:: fs;
1918use std:: path:: Path ;
2019use std:: sync:: { Arc , Weak } ;
21- use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
20+ use std:: time:: { SystemTime , UNIX_EPOCH } ;
2221
2322use ccore:: {
2423 AccountProvider , AccountProviderError , ChainNotify , Client , ClientConfig , ClientService , EngineInfo , EngineType ,
@@ -31,18 +30,16 @@ use ckeystore::KeyStore;
3130use clap:: ArgMatches ;
3231use clogger:: { self , LoggerConfig } ;
3332use cnetwork:: { Filters , NetworkConfig , NetworkControl , NetworkService , RoutingTable , SocketAddr } ;
34- use creactor:: EventLoop ;
3533use csync:: { BlockSyncExtension , BlockSyncSender , SnapshotService , TransactionSyncExtension } ;
3634use ctimer:: TimerLoop ;
3735use ctrlc:: CtrlC ;
3836use fdlimit:: raise_fd_limit;
39- use finally_block:: finally;
4037use kvdb:: KeyValueDB ;
4138use kvdb_rocksdb:: { Database , DatabaseConfig } ;
4239use parking_lot:: { Condvar , Mutex } ;
4340
4441use crate :: config:: { self , load_config} ;
45- use crate :: constants:: DEFAULT_KEYS_PATH ;
42+ use crate :: constants:: { DEFAULT_DB_PATH , DEFAULT_KEYS_PATH } ;
4643use crate :: dummy_network_service:: DummyNetworkService ;
4744use crate :: json:: PasswordFile ;
4845use crate :: rpc:: { rpc_http_start, rpc_ipc_start, rpc_ws_start} ;
@@ -203,8 +200,9 @@ fn unlock_accounts(ap: &AccountProvider, pf: &PasswordFile) -> Result<(), String
203200}
204201
205202pub fn open_db ( cfg : & config:: Operating , client_config : & ClientConfig ) -> Result < Arc < KeyValueDB > , String > {
206- let db_path = cfg. db_path . as_ref ( ) . map ( String :: as_str) . unwrap ( ) ;
207- let client_path = Path :: new ( db_path) ;
203+ let base_path = cfg. base_path . as_ref ( ) . unwrap ( ) . clone ( ) ;
204+ let db_path = cfg. db_path . as_ref ( ) . map ( String :: clone) . unwrap_or_else ( || base_path + "/" + DEFAULT_DB_PATH ) ;
205+ let client_path = Path :: new ( & db_path) ;
208206 let mut db_config = DatabaseConfig :: with_columns ( NUM_COLUMNS ) ;
209207
210208 db_config. memory_budget = client_config. db_cache_size ;
@@ -223,24 +221,11 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> {
223221 // increase max number of open files
224222 raise_fd_limit ( ) ;
225223
226- let _event_loop = EventLoop :: spawn ( ) ;
227224 let timer_loop = TimerLoop :: new ( 2 ) ;
228225
229226 let config = load_config ( matches) ?;
230227
231- // FIXME: It is the hotfix for #348.
232- // Remove the below code if you find the proper way to solve #348.
233- let _wait = finally ( || {
234- const DEFAULT : u64 = 1 ;
235- let wait_before_shutdown = env:: var_os ( "WAIT_BEFORE_SHUTDOWN" )
236- . and_then ( |sec| sec. into_string ( ) . ok ( ) )
237- . and_then ( |sec| sec. parse ( ) . ok ( ) )
238- . unwrap_or ( DEFAULT ) ;
239- :: std:: thread:: sleep ( Duration :: from_secs ( wait_before_shutdown) ) ;
240- } ) ;
241-
242228 let time_gap_params = config. mining . create_time_gaps ( ) ;
243-
244229 let scheme = match & config. operating . chain {
245230 Some ( chain) => chain. scheme ( ) ?,
246231 None => return Err ( "chain is not specified" . to_string ( ) ) ,
@@ -256,11 +241,10 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> {
256241 clogger:: init ( & LoggerConfig :: new ( instance_id) ) . expect ( "Logger must be successfully initialized" ) ;
257242
258243 let pf = load_password_file ( & config. operating . password_path ) ?;
259- let keys_path = match config. operating . keys_path {
260- Some ( ref keys_path) => keys_path,
261- None => DEFAULT_KEYS_PATH ,
262- } ;
263- let ap = prepare_account_provider ( keys_path) ?;
244+ let base_path = config. operating . base_path . as_ref ( ) . unwrap ( ) . clone ( ) ;
245+ let keys_path =
246+ config. operating . keys_path . as_ref ( ) . map ( String :: clone) . unwrap_or_else ( || base_path + "/" + DEFAULT_KEYS_PATH ) ;
247+ let ap = prepare_account_provider ( & keys_path) ?;
264248 unlock_accounts ( & * ap, & pf) ?;
265249
266250 let client_config: ClientConfig = Default :: default ( ) ;
0 commit comments