@@ -357,12 +357,10 @@ impl InternalBitcoindConfig {
357
357
#[ derive( PartialEq , Eq , Debug , Clone ) ]
358
358
pub enum StartInternalBitcoindError {
359
359
CommandError ( String ) ,
360
- CouldNotCanonicalizeExePath ( String ) ,
361
360
CouldNotCanonicalizeDataDir ( String ) ,
362
- CouldNotCanonicalizeCookiePath ( String ) ,
363
- CookieFileNotFound ( String ) ,
364
361
BitcoinDError ( String ) ,
365
362
ExecutableNotFound ,
363
+ ProcessExited ( std:: process:: ExitStatus ) ,
366
364
}
367
365
368
366
impl std:: fmt:: Display for StartInternalBitcoindError {
@@ -371,24 +369,14 @@ impl std::fmt::Display for StartInternalBitcoindError {
371
369
Self :: CommandError ( e) => {
372
370
write ! ( f, "Command to start bitcoind returned an error: {}" , e)
373
371
}
374
- Self :: CouldNotCanonicalizeExePath ( e) => {
375
- write ! ( f, "Failed to canonicalize executable path: {}" , e)
376
- }
377
372
Self :: CouldNotCanonicalizeDataDir ( e) => {
378
373
write ! ( f, "Failed to canonicalize datadir: {}" , e)
379
374
}
380
- Self :: CouldNotCanonicalizeCookiePath ( e) => {
381
- write ! ( f, "Failed to canonicalize cookie path: {}" , e)
382
- }
383
- Self :: CookieFileNotFound ( path) => {
384
- write ! (
385
- f,
386
- "Cookie file was not found at the expected path: {}" ,
387
- path
388
- )
389
- }
390
375
Self :: BitcoinDError ( e) => write ! ( f, "bitcoind connection check failed: {}" , e) ,
391
376
Self :: ExecutableNotFound => write ! ( f, "bitcoind executable not found." ) ,
377
+ Self :: ProcessExited ( status) => {
378
+ write ! ( f, "bitcoind process exited with status '{}'." , status)
379
+ }
392
380
}
393
381
}
394
382
}
@@ -455,35 +443,43 @@ impl Bitcoind {
455
443
. map_err ( |e| StartInternalBitcoindError :: CommandError ( e. to_string ( ) ) ) ?;
456
444
457
445
// We've started bitcoind in the background, however it may fail to start for whatever
458
- // reason. And we need its JSONRPC interface to be available to continue. Thus wait for it
459
- // to have created the cookie file, regularly checking it did not fail to start.
460
- let cookie_path = internal_bitcoind_cookie_path ( & bitcoind_datadir, network) ;
446
+ // reason. And we need its JSONRPC interface to be available to continue. Thus wait for
447
+ // the interface to be created successfully, regularly checking it did not fail to start.
461
448
loop {
462
449
match process. try_wait ( ) {
463
450
Ok ( None ) => { }
464
451
Err ( e) => log:: error!( "Error while trying to wait for bitcoind: {}" , e) ,
465
452
Ok ( Some ( status) ) => {
466
453
log:: error!( "Bitcoind exited with status '{}'" , status) ;
467
- return Err ( StartInternalBitcoindError :: CookieFileNotFound (
468
- cookie_path. to_string_lossy ( ) . into_owned ( ) ,
469
- ) ) ;
454
+ return Err ( StartInternalBitcoindError :: ProcessExited ( status) ) ;
470
455
}
471
456
}
472
- if cookie_path. exists ( ) {
473
- log:: info!( "Bitcoind seems to have successfully started." ) ;
474
- break ;
457
+ match liana:: BitcoinD :: new ( & config, "internal_bitcoind_start" . to_string ( ) ) {
458
+ Ok ( _) => {
459
+ log:: info!( "Bitcoind seems to have successfully started." ) ;
460
+ return Ok ( Self {
461
+ config,
462
+ _process : Arc :: new ( process) ,
463
+ } ) ;
464
+ }
465
+ Err ( liana:: BitcoindError :: CookieFile ( _) ) => {
466
+ // This is only raised if we're using cookie authentication.
467
+ // Assume cookie file has not been created yet and try again.
468
+ }
469
+ Err ( e) => {
470
+ if !e. is_transient ( ) {
471
+ // Non-transient error could happen, e.g., if RPC auth credentials are wrong.
472
+ // Kill process now in case it's not possible to do via RPC command later.
473
+ if let Err ( e) = process. kill ( ) {
474
+ log:: error!( "Error trying to kill bitcoind process: '{}'" , e) ;
475
+ }
476
+ return Err ( StartInternalBitcoindError :: BitcoinDError ( e. to_string ( ) ) ) ;
477
+ }
478
+ }
475
479
}
476
480
log:: info!( "Waiting for bitcoind to start." ) ;
477
481
thread:: sleep ( time:: Duration :: from_millis ( 500 ) ) ;
478
482
}
479
-
480
- liana:: BitcoinD :: new ( & config, "internal_bitcoind_start" . to_string ( ) )
481
- . map_err ( |e| StartInternalBitcoindError :: BitcoinDError ( e. to_string ( ) ) ) ?;
482
-
483
- Ok ( Self {
484
- config,
485
- _process : Arc :: new ( process) ,
486
- } )
487
483
}
488
484
489
485
/// Stop (internal) bitcoind.
0 commit comments